From cd6aa2c1ebe82fab983786301fcf214825596ca9 Mon Sep 17 00:00:00 2001 From: Matthew Eric Bassett Date: Thu, 13 Aug 2020 00:45:11 +0100 Subject: [PATCH] db: Add indices on tx_out and pool_update Closes: https://github.com/input-output-hk/cardano-db-sync/pull/246 --- schema/migration-3-0004-20200810.sql | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 schema/migration-3-0004-20200810.sql diff --git a/schema/migration-3-0004-20200810.sql b/schema/migration-3-0004-20200810.sql new file mode 100644 index 000000000..9cd946cfb --- /dev/null +++ b/schema/migration-3-0004-20200810.sql @@ -0,0 +1,28 @@ +CREATE FUNCTION migrate() RETURNS void AS $$ +DECLARE + next_version int ; +BEGIN + SELECT stage_three + 1 INTO next_version FROM schema_version ; + IF next_version <= 4 THEN + -- ------------------------------------------------------------------------- + -- More hand crafted indices for performance + + -- helpful in case anyone is looking for a utxo by a payment credential. + + CREATE INDEX idx_tx_out_payment_cred + ON tx_out(payment_cred); + + CREATE INDEX idx_pool_update_hash_id + ON pool_update(hash_id); + + -- ------------------------------------------------------------------------- + + UPDATE schema_version SET stage_three = 4 ; + RAISE NOTICE 'DB has been migrated to stage_three version %', next_version ; + END IF ; +END ; +$$ LANGUAGE plpgsql ; + +SELECT migrate() ; + +DROP FUNCTION migrate() ;