fix(store/schema): remove redundant indexes#2115
Merged
Mirko-von-Leipzig merged 3 commits intoMay 22, 2026
Merged
Conversation
With the default Debug implementation for `SchemaHash` it's pretty hard to update assertions in tests after making changes to the schema.
In SQLite, a composite index only supports queries that filter on a leftmost prefix of the indexed columns. This also means that an index on `(a, b, c)` makes a separate index on `(a)` redundant for equality/range lookup starts. The following indexes seem to be redundant in our store SQLite schema: - `idx_accounts_id_block` on `(account_id, block_num DESC)` is covered by `accounts` primary key `(account_id, block_num)`. - `idx_notes_committed_at` on `(committed_at)` is covered by `notes` primary key `(committed_at, batch_index, note_index)`. - `idx_account_storage_account_block` on `(account_id, block_num)` is covered by `account_storage_map_values` primary key `(account_id, block_num, slot_name, key)`. - `idx_vault_assets_account_block` on `(account_id, block_num)` is covered by `account_vault_assets` primary key `(account_id, block_num, vault_key)`. - `idx_transactions_account_id` on `(account_id)` is covered by `idx_transactions_account_block_txid` on `(account_id, block_num, transaction_id)`.
Mirko-von-Leipzig
approved these changes
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In SQLite, a composite index only supports queries that filter on a leftmost prefix of the indexed columns.
This also means that an index on
(a, b, c)makes a separate index on(a)redundant for equality/range lookup starts.The following indexes seem to be redundant in our store SQLite schema:
idx_accounts_id_blockon(account_id, block_num DESC)is covered byaccountsprimary key(account_id, block_num).idx_notes_committed_aton(committed_at)is covered bynotesprimary key(committed_at, batch_index, note_index).idx_account_storage_account_blockon(account_id, block_num)is covered byaccount_storage_map_valuesprimary key(account_id, block_num, slot_name, key).idx_vault_assets_account_blockon(account_id, block_num)is covered byaccount_vault_assetsprimary key(account_id, block_num, vault_key).idx_transactions_account_idon(account_id)is covered byidx_transactions_account_block_txidon(account_id, block_num, transaction_id).