forked from near/near-indexer-for-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve performance of assets__* by changing PKs
* fix: improve performance of assets__* by changing PKs * docs: add explanations to readme
- Loading branch information
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
migrations/2023-02-02-100000_fungible_token_events_pk_changed/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- These commands are heavy for the full DB, consider adding CONCURRENTLY | ||
CREATE UNIQUE INDEX assets__fungible_idx_tmp | ||
ON assets__fungible_token_events (emitted_for_receipt_id, | ||
emitted_at_block_timestamp, | ||
emitted_in_shard_id, | ||
emitted_index_of_event_entry_in_shard, | ||
emitted_by_contract_account_id, | ||
amount, | ||
event_kind, | ||
token_old_owner_account_id, | ||
token_new_owner_account_id, | ||
event_memo); | ||
CREATE UNIQUE INDEX assets__fungible_token_events_unique | ||
ON assets__fungible_token_events (emitted_for_receipt_id, emitted_index_of_event_entry_in_shard); | ||
|
||
-- Next block runs ~1 sec even on the full DB | ||
-- If you apply this manually, uncomment BEGIN TRANSACTION and COMMIT | ||
|
||
-- BEGIN TRANSACTION; | ||
SAVEPOINT change_ft_pks_back; | ||
ALTER TABLE assets__fungible_token_events | ||
DROP CONSTRAINT assets__fungible_token_events_pkey; | ||
-- This command will automatically rename assets__fungible_idx_tmp to assets__fungible_token_events_pkey | ||
ALTER TABLE assets__fungible_token_events | ||
ADD CONSTRAINT assets__fungible_token_events_pkey PRIMARY KEY USING INDEX assets__fungible_idx_tmp; | ||
RELEASE SAVEPOINT change_ft_pks_back; | ||
-- COMMIT; |
18 changes: 18 additions & 0 deletions
18
migrations/2023-02-02-100000_fungible_token_events_pk_changed/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- This command is heavy for the full DB, consider adding CONCURRENTLY | ||
CREATE UNIQUE INDEX assets__fungible_idx_tmp | ||
ON assets__fungible_token_events (emitted_for_receipt_id, emitted_index_of_event_entry_in_shard); | ||
|
||
-- Next block runs ~1 sec even on the full DB | ||
-- If you apply this manually, uncomment BEGIN TRANSACTION and COMMIT | ||
|
||
-- BEGIN TRANSACTION; | ||
SAVEPOINT change_ft_pks; | ||
ALTER TABLE assets__fungible_token_events | ||
DROP CONSTRAINT assets__fungible_token_events_pkey; | ||
ALTER TABLE assets__fungible_token_events | ||
DROP CONSTRAINT assets__fungible_token_events_unique; | ||
-- This command will automatically rename assets__fungible_idx_tmp to assets__fungible_token_events_pkey | ||
ALTER TABLE assets__fungible_token_events | ||
ADD CONSTRAINT assets__fungible_token_events_pkey PRIMARY KEY USING INDEX assets__fungible_idx_tmp; | ||
RELEASE SAVEPOINT change_ft_pks; | ||
-- COMMIT; |
28 changes: 28 additions & 0 deletions
28
migrations/2023-02-02-110000_non_fungible_token_events_pk_changed/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- These commands are heavy for the full DB, consider adding CONCURRENTLY | ||
CREATE UNIQUE INDEX assets__non_fungible_idx_tmp | ||
ON assets__non_fungible_token_events (emitted_for_receipt_id, | ||
emitted_at_block_timestamp, | ||
emitted_in_shard_id, | ||
emitted_index_of_event_entry_in_shard, | ||
emitted_by_contract_account_id, | ||
token_id, | ||
event_kind, | ||
token_old_owner_account_id, | ||
token_new_owner_account_id, | ||
token_authorized_account_id, | ||
event_memo); | ||
CREATE UNIQUE INDEX assets__non_fungible_token_events_unique | ||
ON assets__non_fungible_token_events (emitted_for_receipt_id, emitted_index_of_event_entry_in_shard); | ||
|
||
-- Next block runs ~1 sec even on the full DB | ||
-- If you apply this manually, uncomment BEGIN TRANSACTION and COMMIT | ||
|
||
-- BEGIN TRANSACTION; | ||
SAVEPOINT change_nft_pks_back; | ||
ALTER TABLE assets__non_fungible_token_events | ||
DROP CONSTRAINT assets__non_fungible_token_events_pkey; | ||
-- This command will automatically rename assets__non_fungible_idx_tmp to assets__non_fungible_token_events_pkey | ||
ALTER TABLE assets__non_fungible_token_events | ||
ADD CONSTRAINT assets__non_fungible_token_events_pkey PRIMARY KEY USING INDEX assets__non_fungible_idx_tmp; | ||
RELEASE SAVEPOINT change_nft_pks_back; | ||
-- COMMIT; |
18 changes: 18 additions & 0 deletions
18
migrations/2023-02-02-110000_non_fungible_token_events_pk_changed/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- This command is heavy for the full DB, consider adding CONCURRENTLY | ||
CREATE UNIQUE INDEX assets__non_fungible_idx_tmp | ||
ON assets__non_fungible_token_events (emitted_for_receipt_id, emitted_index_of_event_entry_in_shard); | ||
|
||
-- Next block runs ~1 sec even on the full DB | ||
-- If you apply this manually, uncomment BEGIN TRANSACTION and COMMIT | ||
|
||
-- BEGIN TRANSACTION; | ||
SAVEPOINT change_nft_pks; | ||
ALTER TABLE assets__non_fungible_token_events | ||
DROP CONSTRAINT assets__non_fungible_token_events_pkey; | ||
ALTER TABLE assets__non_fungible_token_events | ||
DROP CONSTRAINT assets__non_fungible_token_events_unique; | ||
-- This command will automatically rename assets__non_fungible_idx_tmp to assets__non_fungible_token_events_pkey | ||
ALTER TABLE assets__non_fungible_token_events | ||
ADD CONSTRAINT assets__non_fungible_token_events_pkey PRIMARY KEY USING INDEX assets__non_fungible_idx_tmp; | ||
RELEASE SAVEPOINT change_nft_pks; | ||
-- COMMIT; |