Skip to content

Commit f1d9b0d

Browse files
fix: tx out address index
1 parent 269ac93 commit f1d9b0d

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/index-service/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A Docker service for creating performance indexes on the cardano-db-sync Postgre
77
The index service creates additional database indexes to improve query performance. These indexes are **optional** but **recommended for production** because:
88

99
- `idx_ma_tx_mint_ident` is required for efficient asset polling (without it polls degrade from <1ms to 500ms+)
10-
- `idx_tx_out_address` significantly speeds up payment address queries
10+
- `idx_tx_out_address_texthash` is required for payment address / UTXO-by-address queries; without it these do a full sequential scan of `tx_out` (hundreds of millions of rows), which can saturate the connection pool under concurrent load
1111
- `idx_asset_fingerprint` speeds up asset fingerprint lookups
1212

1313
Index creation is not enabled by default because:
@@ -68,7 +68,7 @@ docker compose ps index-service
6868
| Index | Table | Speeds up |
6969
|-------|-------|-----------|
7070
| `idx_ma_tx_mint_ident` | `ma_tx_mint.ident` | New asset polling (critical for background service) |
71-
| `idx_tx_out_address` | `tx_out.address` | Payment address queries |
71+
| `idx_tx_out_address_texthash` | `tx_out.address` | Payment address / UTXO-by-address queries (prevents full-table scans) |
7272
| `idx_asset_fingerprint` | `Asset.fingerprint` | Asset fingerprint lookups |
7373

7474
## Operations
@@ -117,6 +117,7 @@ docker compose exec postgres psql -U $(cat placeholder-secrets/postgres_user) \
117117

118118
# Drop all custom indexes
119119
DROP INDEX CONCURRENTLY IF EXISTS idx_ma_tx_mint_ident;
120+
DROP INDEX CONCURRENTLY IF EXISTS idx_tx_out_address_texthash;
120121
DROP INDEX CONCURRENTLY IF EXISTS idx_tx_out_address;
121122
DROP INDEX CONCURRENTLY IF EXISTS idx_asset_fingerprint;
122123
```

packages/index-service/indexes.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
\echo '======================================================================'
1818
\echo ''
1919

20-
\echo '[1/3] Creating index on tx_out.address (hash)...'
21-
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tx_out_address ON tx_out USING hash (address);
22-
\echo '✓ Completed: idx_tx_out_address'
20+
\echo '[1/3] Creating index on tx_out.address (hash on text expression)...'
21+
DROP INDEX CONCURRENTLY IF EXISTS idx_tx_out_address;
22+
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tx_out_address_texthash ON tx_out USING hash ((address::text));
23+
\echo '✓ Completed: idx_tx_out_address_texthash'
2324
\echo ''
2425

2526
\echo '[2/3] Creating index on asset.fingerprint...'
@@ -48,7 +49,7 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_ma_tx_mint_ident ON ma_tx_mint(ident
4849
\echo ' docker compose exec postgres psql -U <user> -d <db> -c "\\di idx_*"'
4950
\echo ''
5051
\echo 'Indexes created:'
51-
\echo ' idx_tx_out_address - speeds up payment address queries'
52+
\echo ' idx_tx_out_address_texthash - speeds up payment address / UTXO-by-address queries'
5253
\echo ' idx_asset_fingerprint - speeds up asset fingerprint lookups'
5354
\echo ' idx_ma_tx_mint_ident - speeds up new asset polling'
5455
\echo ''

0 commit comments

Comments
 (0)