db: add (pubkey, updated_at) index#975
Conversation
WalkthroughThis PR adds database migrations to create an index on the vtxo table across PostgreSQL and SQLite databases. The index is created on the (pubkey, updated_at) column combination, with corresponding down-migrations to drop the index if needed. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Review —
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/infrastructure/db/postgres/migration/20260318074150_vtxo_indexes.up.sql (1)
1-2: ConsiderCONCURRENTLYfor production deployments with large tables.The index design is correct for the query patterns in
SelectVtxosWithPubkeysandSelectPendingSpentVtxosWithPubkeys. However, standardCREATE INDEXacquires a lock that blocks writes on thevtxotable until completion. For large tables in production, consider using:CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_vtxo_pubkey_updated_at ON vtxo (pubkey, updated_at);Note:
CONCURRENTLYcannot run inside a transaction block, so this may require adjusting how migrations are applied if your migration tool wraps statements in transactions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/infrastructure/db/postgres/migration/20260318074150_vtxo_indexes.up.sql` around lines 1 - 2, The CREATE INDEX currently defined for idx_vtxo_pubkey_updated_at on table vtxo will take a write lock on vtxo for the duration of the operation; update the migration to create the index CONCURRENTLY (i.e., use CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_vtxo_pubkey_updated_at ON vtxo (pubkey, updated_at)) so writes are not blocked in production, and ensure your migration runner does not wrap this statement in a transaction (or split it out) since CONCURRENTLY cannot run inside a transaction block.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@internal/infrastructure/db/postgres/migration/20260318074150_vtxo_indexes.up.sql`:
- Around line 1-2: The CREATE INDEX currently defined for
idx_vtxo_pubkey_updated_at on table vtxo will take a write lock on vtxo for the
duration of the operation; update the migration to create the index CONCURRENTLY
(i.e., use CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_vtxo_pubkey_updated_at ON
vtxo (pubkey, updated_at)) so writes are not blocked in production, and ensure
your migration runner does not wrap this statement in a transaction (or split it
out) since CONCURRENTLY cannot run inside a transaction block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a8b64db2-83a1-4c9b-8962-bf11e0b35724
📒 Files selected for processing (4)
internal/infrastructure/db/postgres/migration/20260318074150_vtxo_indexes.down.sqlinternal/infrastructure/db/postgres/migration/20260318074150_vtxo_indexes.up.sqlinternal/infrastructure/db/sqlite/migration/20260318074028_vtxo_indexes.down.sqlinternal/infrastructure/db/sqlite/migration/20260318074028_vtxo_indexes.up.sql
@sekulicd @altafan please review
Summary by CodeRabbit