-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
services/horizon: Fix ReapLookupTables query #4525
Changes from 12 commits
63c4e8d
fde02a6
12ef5b9
afaf1e9
9b1cf59
25267c2
0b3b8d9
98e68be
a4b6172
964fc71
112c742
d32a2fb
8c2e40c
0317d5a
ceba772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,11 +102,11 @@ func TestConstructReapLookupTablesQuery(t *testing.T) { | |
assert.Equal(t, | ||
"delete from history_accounts where id IN "+ | ||
"(select id from "+ | ||
"(select id, (select count(*) from history_effects where history_account_id = hcb.id) as c0, "+ | ||
"(select count(*) from history_operation_participants where history_account_id = hcb.id) as c1, "+ | ||
"(select count(*) from history_trades where base_account_id = hcb.id) as c2, "+ | ||
"(select count(*) from history_trades where counter_account_id = hcb.id) as c3, "+ | ||
"(select count(*) from history_transaction_participants where history_account_id = hcb.id) as c4, "+ | ||
"1 as cx from history_accounts hcb order by id limit 10 offset 0) as sub "+ | ||
"where c0 = 0 and c1 = 0 and c2 = 0 and c3 = 0 and c4 = 0 and 1=1);", query) | ||
"(select id, (select 1 from history_effects where history_account_id = hcb.id limit 1) as c0, "+ | ||
"(select 1 from history_operation_participants where history_account_id = hcb.id limit 1) as c1, "+ | ||
"(select 1 from history_trades where base_account_id = hcb.id limit 1) as c2, "+ | ||
"(select 1 from history_trades where counter_account_id = hcb.id limit 1) as c3, "+ | ||
"(select 1 from history_transaction_participants where history_account_id = hcb.id limit 1) as c4, "+ | ||
"1 as cx from history_accounts hcb where id >= 0 order by id limit 10) as sub "+ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are negative ids possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could probably clean this up with |
||
"where c0 IS NULL and c1 IS NULL and c2 IS NULL and c3 IS NULL and c4 IS NULL and 1=1);", query) | ||
} |
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,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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice optimization 👍