|
| 1 | +# 19 - Hash Index Exact-Match Lookup Workflow |
| 2 | + |
| 3 | +[View source code]({{ config.repo_url }}/blob/{{ config.extra.version_tag }}/bindings/python/examples/19_hash_index_exact_match.py){ .md-button } |
| 4 | + |
| 5 | +This example demonstrates a fuller HASH index workflow that mirrors several of the |
| 6 | +behaviors already covered by the Java engine tests: |
| 7 | + |
| 8 | +- creating a unique HASH index with `UNIQUE_HASH` |
| 9 | +- creating non-unique HASH indexes with `NOTUNIQUE_HASH` |
| 10 | +- creating composite HASH indexes for multi-column exact matches |
| 11 | +- inserting deterministic product and warehouse inventory records |
| 12 | +- running equality lookups against single-property and composite HASH indexes |
| 13 | +- inspecting HASH index metadata from the Python schema API |
| 14 | +- verifying missing-key behavior |
| 15 | +- updating indexed values and verifying HASH index maintenance |
| 16 | +- showing duplicate-key rejection plus rollback semantics |
| 17 | +- closing and reopening the database to verify index persistence |
| 18 | + |
| 19 | +## Run |
| 20 | + |
| 21 | +From `bindings/python/examples`: |
| 22 | + |
| 23 | +```bash |
| 24 | +python3 19_hash_index_exact_match.py |
| 25 | +``` |
| 26 | + |
| 27 | +With a custom database path: |
| 28 | + |
| 29 | +```bash |
| 30 | +python3 19_hash_index_exact_match.py --db-path ./my_test_databases/hash_index_demo |
| 31 | +``` |
| 32 | + |
| 33 | +## Notes |
| 34 | + |
| 35 | +- The example is intentionally SQL-first. |
| 36 | +- HASH indexes are the right fit for exact-match predicates such as `sku = ?`, `category |
| 37 | + = ?`, or `(warehouse = ? AND sku = ?)`. |
| 38 | +- For range predicates or ordered scans, prefer `UNIQUE` / `NOTUNIQUE` `LSM_TREE` |
| 39 | + indexes instead. |
| 40 | +- If the packaged runtime does not include HASH index support, the script prints a short |
| 41 | + explanation and exits. |
| 42 | +- The example intentionally includes a reopen phase so persisted HASH index metadata and |
| 43 | + exact-match lookups are exercised in a fresh database session. |
| 44 | + |
| 45 | +## Why This Example Exists |
| 46 | + |
| 47 | +The Java engine already has focused HASH index coverage for: |
| 48 | + |
| 49 | +- SQL creation via `UNIQUE_HASH` and `NOTUNIQUE_HASH` |
| 50 | +- unique and non-unique lookup behavior |
| 51 | +- composite HASH keys |
| 52 | +- missing-key behavior |
| 53 | +- duplicate-key rejection |
| 54 | +- persistence across reopen |
| 55 | + |
| 56 | +This Python example mirrors that behavior with the public bindings API so the examples |
| 57 | +set includes a dedicated exact-match index workflow. |
0 commit comments