From ae1a6e9d31c4d50b8f39751e978fe091e1f31138 Mon Sep 17 00:00:00 2001 From: i-norden Date: Mon, 10 Jan 2022 21:51:04 -0600 Subject: [PATCH] disable and renable indexes correctly --- Makefile | 2 - .../00018_create_log_indexes.sql | 20 ++++---- .../00019_disable_log_indexes.sql | 45 +++++++++++++++++ .../00019_remove_log_indexes.sql | 15 ------ ...00020_reenable_and_rebuild_log_indexes.sql | 48 +++++++++++++++++++ ...ts.sql => 00021_create_pk_constraints.sql} | 0 ...ogged.sql => 00022_make_tables_logged.sql} | 0 ...ions.sql => 00023_create_fk_relations.sql} | 0 ...=> 00024_create_postgraphile_comments.sql} | 0 ...dexes.sql => 00025_create_cid_indexes.sql} | 6 --- ....sql => 00026_create_stored_functions.sql} | 0 ...=> 00027_create_postgraphile_triggers.sql} | 0 12 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 db/post_batch_processing_migrations/00019_disable_log_indexes.sql delete mode 100644 db/post_batch_processing_migrations/00019_remove_log_indexes.sql create mode 100644 db/post_batch_processing_migrations/00020_reenable_and_rebuild_log_indexes.sql rename db/post_batch_processing_migrations/{00020_create_pk_constraints.sql => 00021_create_pk_constraints.sql} (100%) rename db/post_batch_processing_migrations/{00021_make_tables_logged.sql => 00022_make_tables_logged.sql} (100%) rename db/post_batch_processing_migrations/{00022_create_fk_relations.sql => 00023_create_fk_relations.sql} (100%) rename db/post_batch_processing_migrations/{00023_create_postgraphile_comments.sql => 00024_create_postgraphile_comments.sql} (100%) rename db/post_batch_processing_migrations/{00024_create_cid_indexes.sql => 00025_create_cid_indexes.sql} (92%) rename db/post_batch_processing_migrations/{00025_create_stored_functions.sql => 00026_create_stored_functions.sql} (100%) rename db/post_batch_processing_migrations/{00026_create_postgraphile_triggers.sql => 00027_create_postgraphile_triggers.sql} (100%) diff --git a/Makefile b/Makefile index 700a838..223d7fd 100644 --- a/Makefile +++ b/Makefile @@ -57,13 +57,11 @@ rollback_to: $(GOOSE) checkmigration checkdbvars .PHONY: `rollback_pre_batch_set` rollback_pre_batch_set: $(GOOSE) checkdbvars $(GOOSE) -dir db/pre_batch_processing_migrations postgres "$(CONNECT_STRING)" down - pg_dump -O -s $(CONNECT_STRING) > schema.sql ## Rollback post_batch_set .PHONY: rollback_post_batch_set rollback_post_batch_set: $(GOOSE) checkdbvars $(GOOSE) -dir db/post_batch_processing_migrations postgres "$(CONNECT_STRING)" down - pg_dump -O -s $(CONNECT_STRING) > schema.sql ## Apply the next up migration .PHONY: migrate_up_by_one diff --git a/db/post_batch_processing_migrations/00018_create_log_indexes.sql b/db/post_batch_processing_migrations/00018_create_log_indexes.sql index 5986606..260cfb2 100644 --- a/db/post_batch_processing_migrations/00018_create_log_indexes.sql +++ b/db/post_batch_processing_migrations/00018_create_log_indexes.sql @@ -1,15 +1,15 @@ -- +goose Up -CREATE INDEX log_mh_index_index ON eth.log_cids USING btree (leaf_mh_key); +CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key); CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); -CREATE INDEX header_hash_index ON eth.header_cids USING btree (block_hash); -CREATE INDEX tx_header_hash_index ON eth.transaction_cids USING btree (header_id); -CREATE INDEX transaction_hash_index ON eth.transaction_cids USING btree (tx_hash); -CREATE INDEX log_tx_hash_index ON eth.log_cids USING btree (rct_id); +CREATE INDEX header_block_hash_index ON eth.header_cids USING btree (block_hash); +CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id); +CREATE INDEX tx_tx_hash_index ON eth.transaction_cids USING btree (tx_hash); +CREATE INDEX log_cids_index ON eth.log_cids USING btree (rct_id, index); -- +goose Down -DROP INDEX eth.log_tx_hash_index; -DROP INDEX eth.transaction_hash_index; -DROP INDEX eth.tx_header_hash_index; -DROP INDEX eth.header_hash_index; +DROP INDEX eth.log_cids_index; +DROP INDEX eth.tx_tx_hash_index; +DROP INDEX eth.tx_header_id_index; +DROP INDEX eth.header_block_hash_index; DROP INDEX eth.block_number_index; -DROP INDEX eth.log_mh_index_index; +DROP INDEX eth.log_mh_index; diff --git a/db/post_batch_processing_migrations/00019_disable_log_indexes.sql b/db/post_batch_processing_migrations/00019_disable_log_indexes.sql new file mode 100644 index 0000000..8c0ea2a --- /dev/null +++ b/db/post_batch_processing_migrations/00019_disable_log_indexes.sql @@ -0,0 +1,45 @@ +-- +goose Up +UPDATE pg_index +SET indisready=false +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.log_cids' +); +UPDATE pg_index +SET indisready=false +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.transaction_cids' +); +UPDATE pg_index +SET indisready=false +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.header_cids' +); + +-- +goose Down +UPDATE pg_index +SET indisready=true +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.header_cids' +); +UPDATE pg_index +SET indisready=true +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.transaction_cids' +); +UPDATE pg_index +SET indisready=true +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.log_cids' +); diff --git a/db/post_batch_processing_migrations/00019_remove_log_indexes.sql b/db/post_batch_processing_migrations/00019_remove_log_indexes.sql deleted file mode 100644 index 3bd4b8f..0000000 --- a/db/post_batch_processing_migrations/00019_remove_log_indexes.sql +++ /dev/null @@ -1,15 +0,0 @@ --- +goose Up -DROP INDEX eth.log_tx_hash_index; -DROP INDEX eth.transaction_hash_index; -DROP INDEX eth.tx_header_hash_index; -DROP INDEX eth.header_hash_index; -DROP INDEX eth.block_number_index; -DROP INDEX eth.log_mh_index_index; - --- +goose Down -CREATE INDEX log_mh_index_index ON eth.log_cids USING btree (leaf_mh_key); -CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); -CREATE INDEX header_hash_index ON eth.header_cids USING btree (block_hash); -CREATE INDEX tx_header_hash_index ON eth.transaction_cids USING btree (header_id); -CREATE INDEX transaction_hash_index ON eth.transaction_cids USING btree (tx_hash); -CREATE INDEX log_tx_hash_index ON eth.log_cids USING btree (rct_id); diff --git a/db/post_batch_processing_migrations/00020_reenable_and_rebuild_log_indexes.sql b/db/post_batch_processing_migrations/00020_reenable_and_rebuild_log_indexes.sql new file mode 100644 index 0000000..b136c67 --- /dev/null +++ b/db/post_batch_processing_migrations/00020_reenable_and_rebuild_log_indexes.sql @@ -0,0 +1,48 @@ +-- +goose Up +UPDATE pg_index +SET indisready=true +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.header_cids' +); +UPDATE pg_index +SET indisready=true +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.transaction_cids' +); +UPDATE pg_index +SET indisready=true +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.log_cids' +); +REINDEX TABLE eth.header_cids; +REINDEX TABLE eth.transaction_cids; +REINDEX TABLE eth.log_cids; + +-- +goose Down +UPDATE pg_index +SET indisready=false +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.log_cids' +); +UPDATE pg_index +SET indisready=false +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.transaction_cids' +); +UPDATE pg_index +SET indisready=false +WHERE indrelid = ( + SELECT oid + FROM pg_class + WHERE relname='eth.header_cids' +); diff --git a/db/post_batch_processing_migrations/00020_create_pk_constraints.sql b/db/post_batch_processing_migrations/00021_create_pk_constraints.sql similarity index 100% rename from db/post_batch_processing_migrations/00020_create_pk_constraints.sql rename to db/post_batch_processing_migrations/00021_create_pk_constraints.sql diff --git a/db/post_batch_processing_migrations/00021_make_tables_logged.sql b/db/post_batch_processing_migrations/00022_make_tables_logged.sql similarity index 100% rename from db/post_batch_processing_migrations/00021_make_tables_logged.sql rename to db/post_batch_processing_migrations/00022_make_tables_logged.sql diff --git a/db/post_batch_processing_migrations/00022_create_fk_relations.sql b/db/post_batch_processing_migrations/00023_create_fk_relations.sql similarity index 100% rename from db/post_batch_processing_migrations/00022_create_fk_relations.sql rename to db/post_batch_processing_migrations/00023_create_fk_relations.sql diff --git a/db/post_batch_processing_migrations/00023_create_postgraphile_comments.sql b/db/post_batch_processing_migrations/00024_create_postgraphile_comments.sql similarity index 100% rename from db/post_batch_processing_migrations/00023_create_postgraphile_comments.sql rename to db/post_batch_processing_migrations/00024_create_postgraphile_comments.sql diff --git a/db/post_batch_processing_migrations/00024_create_cid_indexes.sql b/db/post_batch_processing_migrations/00025_create_cid_indexes.sql similarity index 92% rename from db/post_batch_processing_migrations/00024_create_cid_indexes.sql rename to db/post_batch_processing_migrations/00025_create_cid_indexes.sql index 3759801..7a00e3a 100644 --- a/db/post_batch_processing_migrations/00024_create_cid_indexes.sql +++ b/db/post_batch_processing_migrations/00025_create_cid_indexes.sql @@ -1,6 +1,5 @@ -- +goose Up -- header indexes -CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid); CREATE INDEX header_mh_index ON eth.header_cids USING btree (mh_key); CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root); @@ -10,7 +9,6 @@ CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp); CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id); -- transaction indexes -CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id); CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); CREATE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); @@ -46,7 +44,6 @@ CREATE INDEX access_list_element_address_index ON eth.access_list_elements USING CREATE INDEX access_list_storage_keys_index ON eth.access_list_elements USING gin (storage_keys); -- log indexes -CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key); CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid); CREATE INDEX log_address_index ON eth.log_cids USING btree (address); CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0); @@ -62,7 +59,6 @@ DROP INDEX eth.log_topic1_index; DROP INDEX eth.log_topic0_index; DROP INDEX eth.log_address_index; DROP INDEX eth.log_cid_index; -DROP INDEX eth.log_mh_index; -- access list indexes DROP INDEX eth.access_list_storage_keys_index; @@ -98,7 +94,6 @@ DROP INDEX eth.tx_src_index; DROP INDEX eth.tx_dst_index; DROP INDEX eth.tx_mh_index; DROP INDEX eth.tx_cid_index; -DROP INDEX eth.tx_header_id_index; -- uncle indexes DROP INDEX eth.uncle_header_id_index; @@ -108,4 +103,3 @@ DROP INDEX eth.timestamp_index; DROP INDEX eth.state_root_index; DROP INDEX eth.header_mh_index; DROP INDEX eth.header_cid_index; -DROP INDEX eth.block_number_index; diff --git a/db/post_batch_processing_migrations/00025_create_stored_functions.sql b/db/post_batch_processing_migrations/00026_create_stored_functions.sql similarity index 100% rename from db/post_batch_processing_migrations/00025_create_stored_functions.sql rename to db/post_batch_processing_migrations/00026_create_stored_functions.sql diff --git a/db/post_batch_processing_migrations/00026_create_postgraphile_triggers.sql b/db/post_batch_processing_migrations/00027_create_postgraphile_triggers.sql similarity index 100% rename from db/post_batch_processing_migrations/00026_create_postgraphile_triggers.sql rename to db/post_batch_processing_migrations/00027_create_postgraphile_triggers.sql