Skip to content

Introduce database indices - #1376

Merged
mxsrc merged 4 commits into
mainfrom
database-indices
Sep 23, 2026
Merged

mxsrc merged 4 commits into
mainfrom
database-indices

Conversation

@mxsrc

@mxsrc mxsrc commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Secondary lookups in DBController used to be full-table scans plus an in-memory filter, because entities live under a flat or compound keys and the only access path was a prefix scan. This adds declared secondary indices: a model lists them in _INDEXES (models/indices.py). Entries live in a disjoint index/<Class>/<name>/<value…>/<entity-id> keyspace and store the entity's get_id(), so a reader reconstructs the object key without parsing the index key; a Unique index omits the trailing entity id, making the key itself the constraint. Maintenance happens in the same FDB transaction as the entity write (write_to_db / remove / atomic_update), so an index can never describe a record that was never written. Reads go through a single DBController.query() primitive that range-reads the index and pipelines the point reads. The mechanism has been tested against realistic and targeted workloads in terms of entity size, validating the constant-time lookups.

On upgrade, writes immediately write the new indices. The upgrade code backfills the indices for the remaining indices. Optimized reads through indices are gated on the index indicating its readiness, falling back to the current table scans.

Comment thread tests/unit/models/test_indices.py Fixed
Comment thread simplyblock_core/index_ops.py Fixed
Comment thread tests/unit/models/test_indices.py Fixed
@mxsrc
mxsrc marked this pull request as draft September 18, 2026 09:36
@mxsrc
mxsrc force-pushed the database-indices branch 4 times, most recently from 47c9b8e to 366b479 Compare September 21, 2026 14:31
Comment thread simplyblock_cli/cli.py Dismissed
@mxsrc
mxsrc marked this pull request as ready for review September 21, 2026 15:58

@Hamdy-khader Hamdy-khader left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@mxsrc
mxsrc merged commit 6485394 into main Sep 23, 2026
20 of 21 checks passed
@mxsrc
mxsrc deleted the database-indices branch September 23, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants