feat(cold-sql): add topic indexes for log filtering#54
Merged
Conversation
Only topic0 was indexed previously. Most ERC-20/721 Transfer event lookups filter on topic1 (from address) or topic2 (to address), causing sequential scans on the logs table. Adds migration 002 with indexes on all three remaining topic columns. Uses CREATE INDEX IF NOT EXISTS for idempotent application. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
prestwich
reviewed
Apr 16, 2026
| @@ -0,0 +1,9 @@ | |||
| -- Add indexes on topic1, topic2, topic3 for log filtering. | |||
| -- | |||
Member
There was a problem hiding this comment.
aren't these two files identical?
Member
Author
There was a problem hiding this comment.
you are correct, correcting.
Member
Author
There was a problem hiding this comment.
[Claude Code] Yes — the CREATE INDEX IF NOT EXISTS syntax is identical across SQLite and PostgreSQL, so the two files were needlessly duplicated. Consolidated to a single 002_add_topic_indexes.sql and moved the include_str! out of the backend match arm.
The 002 migration SQL is dialect-agnostic (CREATE INDEX IF NOT EXISTS), so a single file suffices for both PostgreSQL and SQLite. Removes the duplicate _pg variant and uses a shared include_str! outside the backend match arm. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
prestwich
approved these changes
Apr 16, 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.
Summary
topic1,topic2,topic3columns in thelogstabletopic0was previously indexed; most ERC-20/721 Transfer lookups filter ontopic1(from) ortopic2(to), requiring sequential scansCREATE INDEX IF NOT EXISTSfor idempotent applicationContext
Identified during sidecar RPC performance investigation. Log queries filtering by topic1/2/3 fall back to sequential scans, which compounds with the pool starvation issue under moderate load.
For existing databases, these indexes can also be created directly with
CREATE INDEX CONCURRENTLYto avoid locking.Test plan
cargo +nightly fmt -- --checkcargo clippy -p signet-cold-sql --all-targets --features postgrescargo t -p signet-cold-sql🤖 Generated with Claude Code