Skip to content

perf(ttx): index transactions by sender_eid/recipient_eid + stored_at#1842

Merged
adecaro merged 4 commits into
LFDT-Panurus:mainfrom
Built-by-Sign:perf/index-transactions-eid-storedat
Jul 6, 2026
Merged

perf(ttx): index transactions by sender_eid/recipient_eid + stored_at#1842
adecaro merged 4 commits into
LFDT-Panurus:mainfrom
Built-by-Sign:perf/index-transactions-eid-storedat

Conversation

@EvanYan1024

Copy link
Copy Markdown
Contributor

Refs #1841

What

Adds two composite indexes to the transactions table DDL in TransactionStore.GetSchema:

  • (sender_eid, stored_at DESC)
  • (recipient_eid, stored_at DESC)

Why

QueryTransactions filters (sender_eid = X OR recipient_eid = Y) (via HasTransactionParams) ordered by stored_at with a limit, but the table is only indexed on tx_id and stored_at. The planner walks the whole stored_at index 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 vet clean
  • go 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 EXISTS keeps existing deployments upgrade-safe

EvanYan1024 and others added 2 commits July 2, 2026 12:05
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>

@AkramBitar AkramBitar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@adecaro adecaro merged commit e434f43 into LFDT-Panurus:main Jul 6, 2026
52 checks passed
@adecaro

adecaro commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

thanks @EvanYan1024

@EvanYan1024 EvanYan1024 deleted the perf/index-transactions-eid-storedat branch July 6, 2026 05:57
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.

Transactions queries filtered by sender/recipient enrollment id scan the whole table

3 participants