-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
services/horizon: Fix ReapLookupTables query (#4525)
This commit fixes the query added in ee063a7. The previous query was using `limit ... offset ...` which becomes slow for larger `offset` values. This is happening because (from docs[1]): > The rows skipped by an OFFSET clause still have to be computed inside the > server; therefore a large OFFSET might be inefficient. I rewrote the query to use `id` field in tables in `where id > ...`. Before each run, the new `id` offset is fetched from the table that is later returned to be used in the next cycle. I also realized that rewriting `count(*)` in subqueries to `1` with `limit 1` further improves the query performance. This is because instead of counting all rows in parent tables it just check if there are _any_ rows in tables (what we need to determine if the row is orphaned or not). This allows running the reaper also for `history_accounts` and `history_assets` tables. Finally this commit adds logging and enable reaper only when `--history-retention-count` is set. [1] https://www.postgresql.org/docs/current/queries-limit.html
- Loading branch information
Showing
9 changed files
with
199 additions
and
46 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
services/horizon/internal/db2/schema/migrations/59_remove_foreign_key_constraints.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,20 @@ | ||
-- +migrate Up | ||
|
||
ALTER TABLE ONLY history_trades DROP CONSTRAINT history_trades_base_account_id_fkey; | ||
ALTER TABLE ONLY history_trades DROP CONSTRAINT history_trades_base_asset_id_fkey; | ||
ALTER TABLE ONLY history_trades DROP CONSTRAINT history_trades_counter_account_id_fkey; | ||
ALTER TABLE ONLY history_trades DROP CONSTRAINT history_trades_counter_asset_id_fkey; | ||
|
||
-- +migrate Down | ||
|
||
ALTER TABLE ONLY history_trades | ||
ADD CONSTRAINT history_trades_base_account_id_fkey FOREIGN KEY (base_account_id) REFERENCES history_accounts(id); | ||
|
||
ALTER TABLE ONLY history_trades | ||
ADD CONSTRAINT history_trades_base_asset_id_fkey FOREIGN KEY (base_asset_id) REFERENCES history_assets(id); | ||
|
||
ALTER TABLE ONLY history_trades | ||
ADD CONSTRAINT history_trades_counter_account_id_fkey FOREIGN KEY (counter_account_id) REFERENCES history_accounts(id); | ||
|
||
ALTER TABLE ONLY history_trades | ||
ADD CONSTRAINT history_trades_counter_asset_id_fkey FOREIGN KEY (counter_asset_id) REFERENCES history_assets(id); |
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
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
Oops, something went wrong.