Documentation
10. Indexes
Create, inspect and use normal and encrypted blind indexes.
What indexes do
Indexes speed up simple equality queries. RelPyDB indexes map from index keys to stable internal row ids, not list positions.
Best case:
where(col("email") == "alice@example.com") with an index on email.Index functions
| Function | Signature | Meaning |
|---|---|---|
create_index | create_index(table_name, columns, name=None, unique=False, nulls_distinct=True) | Creates a single or composite index. |
drop_index | drop_index(index_name) | Removes an index. |
list_indexes | list_indexes(table_name=None) | Lists index names, optionally for one table. |
describe_index | describe_index(index_name) | Shows index metadata and key counts. |
describe_indexes | describe_indexes(table_name=None) | Describes multiple indexes. |
Single and composite indexes
Single-column index
db.create_index("users", "email")Composite index
db.create_index("orders", ["user_id", "status"])A composite index can be used by exact left-prefix lookups. An index on ["user_id", "status"] can help with user_id == 1 and with user_id == 1 AND status == "paid", but not with only status == "paid".
Encrypted indexes
If the indexed column is encrypted, RelPyDB indexes the blind index rather than the plaintext or ciphertext.
key = RelPy.generate_encryption_key()
db = RelPy(encryption_key=key)
db.add_column("users", "email", str, nullable=False, is_encrypted=True)
db.create_index("users", "email")
rows = db.query("users").where(col("email") == "alice@example.com").to_list()