Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/cold-sql/migrations/002_add_topic_indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Add indexes on topic1, topic2, topic3 for log filtering.
--
-- topic0 already has an index (001_initial). Most ERC-20/721
-- Transfer lookups filter on topic1 (from) or topic2 (to), which
-- previously required sequential scans.

CREATE INDEX IF NOT EXISTS idx_logs_topic1 ON logs (topic1);
CREATE INDEX IF NOT EXISTS idx_logs_topic2 ON logs (topic2);
CREATE INDEX IF NOT EXISTS idx_logs_topic3 ON logs (topic3);
3 changes: 3 additions & 0 deletions crates/cold-sql/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ impl SqlColdBackend {
// connection that subsequent queries will use.
let is_postgres = backend == "PostgreSQL";
sqlx::raw_sql(migration).execute(&pool).await?;
sqlx::raw_sql(include_str!("../migrations/002_add_topic_indexes.sql"))
.execute(&pool)
.await?;
Ok(Self { pool, is_postgres })
}

Expand Down
Loading