Skip to content

feat(cold-sql): add topic indexes for log filtering#54

Merged
rswanson merged 2 commits intomainfrom
feat/add-topic-indexes
Apr 16, 2026
Merged

feat(cold-sql): add topic indexes for log filtering#54
rswanson merged 2 commits intomainfrom
feat/add-topic-indexes

Conversation

@rswanson
Copy link
Copy Markdown
Member

Summary

  • Add indexes on topic1, topic2, topic3 columns in the logs table
  • Only topic0 was previously indexed; most ERC-20/721 Transfer lookups filter on topic1 (from) or topic2 (to), requiring sequential scans
  • Migration 002, uses CREATE INDEX IF NOT EXISTS for idempotent application

Context

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 CONCURRENTLY to avoid locking.

Test plan

  • cargo +nightly fmt -- --check
  • cargo clippy -p signet-cold-sql --all-targets --features postgres
  • cargo t -p signet-cold-sql
  • Verify index creation on a test PostgreSQL instance

🤖 Generated with Claude Code

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>
@rswanson
Copy link
Copy Markdown
Member Author

Code review

No 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 👎.

@@ -0,0 +1,9 @@
-- Add indexes on topic1, topic2, topic3 for log filtering.
--
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

aren't these two files identical?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you are correct, correcting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[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>
@rswanson rswanson merged commit e422918 into main Apr 16, 2026
7 checks passed
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