Skip to content

Commit

Permalink
services/horizon: added indexes by id for cb and liquidity pool on tx…
Browse files Browse the repository at this point in the history
…/ops tables (#4477)
  • Loading branch information
sreuland authored Jul 27, 2022
1 parent ccd515b commit c2d52f0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
2 changes: 2 additions & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
- Run postgres autovacuum on `history_trades_60000` table more frequently
([4412](https://github.com/stellar/go/pull/4412)).

- Added indexes by id for claimable balance and liquidity pool id's in the respective tx/ops tables ([4455](https://github.com/stellar/go/pull/4477))


## 2.18.1
* Enabled txsub system to work if/when underlying horizon db connection is read only. ([4418](https://github.com/stellar/go/pull/4418))
Expand Down
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,14 @@
-- +migrate Up

CREATE INDEX "index_history_operation_claimable_balances_on_id" ON history_operation_claimable_balances USING btree (history_claimable_balance_id);
CREATE INDEX "index_history_transaction_claimable_balances_on_id" ON history_transaction_claimable_balances USING btree (history_claimable_balance_id);
CREATE INDEX "index_history_operation_liquidity_pools_on_id" ON history_operation_liquidity_pools USING btree (history_liquidity_pool_id);
CREATE INDEX "index_history_transaction_liquidity_pools_on_id" ON history_transaction_liquidity_pools USING btree (history_liquidity_pool_id);

-- +migrate Down

DROP INDEX "index_history_operation_claimable_balances_on_id";
DROP INDEX "index_history_transaction_claimable_balances_on_id";
DROP INDEX "index_history_operation_liquidity_pools_on_id";
DROP INDEX "index_history_transaction_liquidity_pools_on_id";

4 changes: 4 additions & 0 deletions services/horizon/internal/test/scenarios/base-horizon.sql
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ CREATE TABLE history_operation_claimable_balances (

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_operation_claimable_balances_on_operation_id" ON history_operation_claimable_balances USING btree (history_operation_id);
CREATE INDEX "index_history_operation_claimable_balances_on_id" ON history_operation_claimable_balances USING btree (history_claimable_balance_id);

CREATE TABLE history_transaction_claimable_balances (
history_transaction_id bigint NOT NULL,
Expand All @@ -371,6 +372,7 @@ CREATE TABLE history_transaction_claimable_balances (

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 "index_history_transaction_claimable_balances_on_transaction_id" ON history_transaction_claimable_balances USING btree (history_transaction_id);
CREATE INDEX "index_history_transaction_claimable_balances_on_id" ON history_transaction_claimable_balances USING btree (history_claimable_balance_id);


INSERT INTO history_claimable_balances VALUES (1, '00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9');
Expand Down Expand Up @@ -1503,6 +1505,7 @@ CREATE TABLE history_operation_liquidity_pools (

CREATE UNIQUE INDEX index_history_operation_liquidity_pools_on_ids ON history_operation_liquidity_pools USING btree (history_operation_id , history_liquidity_pool_id);
CREATE INDEX index_history_operation_liquidity_pools_on_operation_id ON history_operation_liquidity_pools USING btree (history_operation_id);
CREATE INDEX index_history_operation_liquidity_pools_on_id ON history_operation_liquidity_pools USING btree (history_liquidity_pool_id);

CREATE TABLE history_transaction_liquidity_pools (
history_transaction_id bigint NOT NULL,
Expand All @@ -1511,6 +1514,7 @@ CREATE TABLE history_transaction_liquidity_pools (

CREATE UNIQUE INDEX index_history_transaction_liquidity_pools_on_ids ON history_transaction_liquidity_pools USING btree (history_transaction_id , history_liquidity_pool_id);
CREATE INDEX index_history_transaction_liquidity_pools_on_transaction_id ON history_transaction_liquidity_pools USING btree (history_transaction_id);
CREATE INDEX index_history_transaction_liquidity_pools_on_id ON history_transaction_liquidity_pools USING btree (history_liquidity_pool_id);

ALTER TABLE trust_lines ADD liquidity_pool_id text;
CREATE INDEX trust_lines_by_liquidity_pool_id ON trust_lines USING BTREE(liquidity_pool_id);
Expand Down
12 changes: 6 additions & 6 deletions services/horizon/internal/test/scenarios/bindata.go

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion services/horizon/internal/test/scenarios/kahuna-horizon.sql
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ CREATE TABLE history_operation_claimable_balances (

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_operation_claimable_balances_on_operation_id" ON history_operation_claimable_balances USING btree (history_operation_id);
CREATE INDEX "index_history_operation_claimable_balances_on_id" ON history_operation_claimable_balances USING btree (history_claimable_balance_id);

CREATE TABLE history_transaction_claimable_balances (
history_transaction_id bigint NOT NULL,
Expand All @@ -373,7 +374,7 @@ CREATE TABLE history_transaction_claimable_balances (

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 "index_history_transaction_claimable_balances_on_transaction_id" ON history_transaction_claimable_balances USING btree (history_transaction_id);

CREATE INDEX "index_history_transaction_claimable_balances_on_id" ON history_transaction_claimable_balances USING btree (history_claimable_balance_id);

INSERT INTO history_claimable_balances VALUES (1, '00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9');
SELECT pg_catalog.setval('history_claimable_balances_id_seq', 1, true);
Expand Down Expand Up @@ -2090,6 +2091,7 @@ CREATE TABLE history_operation_liquidity_pools (

CREATE UNIQUE INDEX index_history_operation_liquidity_pools_on_ids ON history_operation_liquidity_pools USING btree (history_operation_id , history_liquidity_pool_id);
CREATE INDEX index_history_operation_liquidity_pools_on_operation_id ON history_operation_liquidity_pools USING btree (history_operation_id);
CREATE INDEX index_history_operation_liquidity_pools_on_id ON history_operation_liquidity_pools USING btree (history_liquidity_pool_id);

CREATE TABLE history_transaction_liquidity_pools (
history_transaction_id bigint NOT NULL,
Expand All @@ -2098,6 +2100,7 @@ CREATE TABLE history_transaction_liquidity_pools (

CREATE UNIQUE INDEX index_history_transaction_liquidity_pools_on_ids ON history_transaction_liquidity_pools USING btree (history_transaction_id , history_liquidity_pool_id);
CREATE INDEX index_history_transaction_liquidity_pools_on_transaction_id ON history_transaction_liquidity_pools USING btree (history_transaction_id);
CREATE INDEX index_history_transaction_liquidity_pools_on_id ON history_transaction_liquidity_pools USING btree (history_liquidity_pool_id);

ALTER TABLE trust_lines ADD liquidity_pool_id text;
CREATE INDEX trust_lines_by_liquidity_pool_id ON trust_lines USING BTREE(liquidity_pool_id);
Expand Down

0 comments on commit c2d52f0

Please sign in to comment.