perf(ttx): index transactions by sender_eid/recipient_eid + stored_at#1842
Merged
adecaro merged 4 commits intoJul 6, 2026
Merged
Conversation
QueryTransactions filters (sender_eid = X OR recipient_eid = Y) ORDER BY stored_at LIMIT N, but the transactions table is only indexed on tx_id and stored_at. Without an index on sender_eid/recipient_eid the planner walks the entire stored_at index applying the filter row by row (~11M rows scanned to return a handful for a low-activity wallet, ~2.6s in our deployment). Add (sender_eid, stored_at DESC) and (recipient_eid, stored_at DESC) so it can BitmapOr the two and apply the limit cheaply (~1ms). Refs LFDT-Panurus#1841 Signed-off-by: Evan <evanyan@sign.global>
Contributor
|
thanks @EvanYan1024 |
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.
Refs #1841
What
Adds two composite indexes to the
transactionstable DDL inTransactionStore.GetSchema:(sender_eid, stored_at DESC)(recipient_eid, stored_at DESC)Why
QueryTransactionsfilters(sender_eid = X OR recipient_eid = Y)(viaHasTransactionParams) ordered bystored_atwith a limit, but the table is only indexed ontx_idandstored_at. The planner walks the wholestored_atindex applying the filter row by row.In our deployment (~11M transaction rows), listing transactions for a low-activity wallet scanned effectively the whole table (~2.6s). With these two indexes the planner BitmapOrs them and applies the limit cheaply — same query returns in ~1ms.
Testing
go build ./token/...,go vetcleango test ./token/services/storage/db/sql/common/ ./token/services/storage/db/sql/sqlite/pass (schema DDL is executed by the sqlite store tests)CREATE INDEX IF NOT EXISTSkeeps existing deployments upgrade-safe