Skip to content

Commit d8d4d4c

Browse files
authored
fix: deactivate indices before subdomain import (#1086)
1 parent f6d7d0c commit d8d4d4c

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

src/import-v1/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,15 @@ export async function importV1BnsData(db: PgDataStore, importDir: string) {
430430
const client = await db.pool.connect();
431431
try {
432432
await client.query('BEGIN');
433+
// Temporarily disable BNS table indices to speed up INSERTs.
434+
await client.query(`
435+
UPDATE pg_index
436+
SET indisready = false, indisvalid = false
437+
WHERE indrelid = ANY (
438+
SELECT oid FROM pg_class
439+
WHERE relname IN ('subdomains', 'zonefiles', 'namespaces', 'names')
440+
)
441+
`);
433442
const zhashes = await readZones(path.join(importDir, 'name_zonefiles.txt'));
434443
await pipeline(
435444
fs.createReadStream(path.join(importDir, 'chainstate.txt')),
@@ -458,13 +467,20 @@ export async function importV1BnsData(db: PgDataStore, importDir: string) {
458467
logger.info(`Subdomains imported: ${subdomainsImported}`);
459468
}
460469
}
470+
logger.info(`Subdomains imported: ${subdomainsImported}`);
461471

462472
const updatedConfigState: DbConfigState = {
463473
...configState,
464474
bns_names_onchain_imported: true,
465475
bns_subdomains_imported: true,
466476
};
467477
await db.updateConfigState(updatedConfigState, client);
478+
479+
// Re-enable indices
480+
await client.query(`REINDEX TABLE subdomains`);
481+
await client.query(`REINDEX TABLE zonefiles`);
482+
await client.query(`REINDEX TABLE namespaces`);
483+
await client.query(`REINDEX TABLE names`);
468484
await client.query('COMMIT');
469485
} catch (error) {
470486
await client.query('ROLLBACK');

src/migrations/1608030374841_namespaces.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,5 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
9292
});
9393

9494
pgm.createIndex('namespaces', 'namespace_id', { method: 'hash' });
95-
pgm.createIndex('namespaces', 'microblock_hash', { method: 'hash' });
9695
pgm.createIndex('namespaces', [{ name: 'ready_block', sort: 'DESC' }]);
97-
pgm.createIndex('namespaces', [
98-
{ name: 'namespace_id' },
99-
{ name: 'ready_block', sort: 'DESC' },
100-
{ name: 'tx_index', sort: 'DESC' },
101-
]);
10296
}

src/migrations/1608030374842_names.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,5 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
8787
pgm.createIndex('names', 'name', { method: 'hash' });
8888
pgm.createIndex('names', 'namespace_id', { method: 'hash' });
8989
pgm.createIndex('names', 'zonefile_hash', { method: 'hash' });
90-
pgm.createIndex('names', 'index_block_hash', { method: 'hash' });
91-
pgm.createIndex('names', 'microblock_hash', { method: 'hash' });
9290
pgm.createIndex('names', [{ name: 'registered_at', sort: 'DESC' }]);
93-
pgm.createIndex('names', [
94-
{ name: 'name' },
95-
{ name: 'registered_at', sort: 'DESC' },
96-
{ name: 'tx_index', sort: 'DESC' },
97-
]);
9891
}

src/migrations/1610030345948_subdomains.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,7 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
8585
});
8686

8787
pgm.createIndex('subdomains', 'owner', { method: 'hash' });
88-
pgm.createIndex('subdomains', 'tx_id', { method: 'hash' });
89-
pgm.createIndex('subdomains', 'index_block_hash', { method: 'hash' });
90-
pgm.createIndex('subdomains', 'microblock_hash', { method: 'hash' });
91-
pgm.createIndex('subdomains', 'name', { method: 'hash' });
88+
pgm.createIndex('subdomains', 'zonefile_hash', { method: 'hash' });
9289
pgm.createIndex('subdomains', 'fully_qualified_subdomain', { method: 'hash' });
93-
pgm.createIndex('subdomains', [
94-
{ name: 'fully_qualified_subdomain' },
95-
{ name: 'block_height', sort: 'DESC' },
96-
{ name: 'tx_index', sort: 'DESC' },
97-
]);
90+
pgm.createIndex('subdomains', [{ name: 'block_height', sort: 'DESC' }]);
9891
}

0 commit comments

Comments
 (0)