Skip to content

Commit

Permalink
services/horizon: remove unused indexes from Horizon database
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Oct 4, 2023
1 parent facabfc commit 5efeae3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
23 changes: 23 additions & 0 deletions services/horizon/internal/db2/schema/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- +migrate Up

-- unused indices
DROP INDEX IF EXISTS accounts_home_domain;
DROP INDEX IF EXISTS accounts_inflation_destination;
DROP INDEX IF EXISTS asset_by_issuer;
DROP INDEX IF EXISTS claimabable_balances_by_claimants;
DROP INDEX IF EXISTS htrd_time_lookup;
DROP INDEX IF EXISTS index_history_effects_on_type;
DROP INDEX IF EXISTS index_history_ledgers_on_closed_at;
DROP INDEX IF EXISTS index_history_ledgers_on_importer_version;
DROP INDEX IF EXISTS index_history_ledgers_on_ledger_hash;
DROP INDEX IF EXISTS index_history_ledgers_on_previous_ledger_hash;
DROP INDEX IF EXISTS index_history_operation_claimable_balances_on_ids;
DROP INDEX IF EXISTS index_history_operations_on_type;
DROP INDEX IF EXISTS index_history_transaction_claimable_balances_on_ids;
DROP INDEX IF EXISTS trade_effects_by_order_book;
DROP INDEX IF EXISTS trust_lines_by_issuer;

-- +migrate Down
CREATE INDEX accounts_home_domain ON accounts USING BTREE(home_domain);
CREATE INDEX accounts_inflation_destination ON accounts USING BTREE(inflation_destination);
CREATE INDEX asset_by_issuer ON history_assets USING btree (asset_issuer);
CREATE INDEX claimabable_balances_by_claimants ON claimable_balances USING gin(claimants jsonb_path_ops);
CREATE INDEX htrd_time_lookup ON history_trades USING BTREE(ledger_closed_at);
CREATE INDEX index_history_effects_on_type ON history_effects USING btree (type);
CREATE INDEX index_history_ledgers_on_closed_at ON history_ledgers USING btree (closed_at);
CREATE INDEX index_history_ledgers_on_importer_version ON history_ledgers USING btree (importer_version);
CREATE UNIQUE INDEX index_history_ledgers_on_ledger_hash ON history_ledgers USING btree (ledger_hash);
CREATE UNIQUE INDEX index_history_ledgers_on_previous_ledger_hash ON history_ledgers USING btree (previous_ledger_hash);
CREATE UNIQUE INDEX "index_history_operation_claimable_balances_on_ids" ON history_operation_claimable_balances USING btree (history_operation_id , history_claimable_balance_id);
CREATE INDEX index_history_operations_on_type ON history_operations USING btree (type);
CREATE UNIQUE INDEX "index_history_transaction_claimable_balances_on_ids" ON history_transaction_claimable_balances USING btree (history_transaction_id , history_claimable_balance_id);
CREATE INDEX trade_effects_by_order_book ON history_effects USING btree (((details ->> 'sold_asset_type'::text)), ((details ->> 'sold_asset_code'::text)), ((details ->> 'sold_asset_issuer'::text)), ((details ->> 'bought_asset_type'::text)), ((details ->> 'bought_asset_code'::text)), ((details ->> 'bought_asset_issuer'::text))) WHERE (type = 33);
CREATE INDEX trust_lines_by_issuer ON trust_lines USING BTREE(asset_issuer);
3 changes: 2 additions & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const (
// claimable balances for claimant queries.
// - 17: Add contract_id column to exp_asset_stats table which is derived by ingesting
// contract data ledger entries.
CurrentVersion = 17
// - 18: Remove unused indexes (https://github.com/stellar/go/issues/5061)
CurrentVersion = 18

// MaxDBConnections is the size of the postgres connection pool dedicated to Horizon ingestion:
// * Ledger ingestion,
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const assetStatsBatchSize = 500
// check them.
// There is a test that checks it, to fix it: update the actual `verifyState`
// method instead of just updating this value!
const stateVerifierExpectedIngestionVersion = 17
const stateVerifierExpectedIngestionVersion = 18

// verifyState is called as a go routine from pipeline post hook every 64
// ledgers. It checks if the state is correct. If another go routine is already
Expand Down

0 comments on commit 5efeae3

Please sign in to comment.