-
Notifications
You must be signed in to change notification settings - Fork 499
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: Add (asset, account_id) index to trust_lines table #4635
Conversation
Do we need to evaluate the performance implication on ingestion ? ( i.e. more indices typically slow down inserts/deletion ) |
Yes, we usually do all performance testing in stg when testing a release. |
Removed unused index in 77361d4. |
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.
LGTM, but is there any reason why this would cause worse performance on certain queries? We saw this with claimable balances and it took a couple of iterations.
@@ -0,0 +1,9 @@ | |||
-- +migrate Up | |||
|
|||
CREATE INDEX "trust_lines_by_type_code_issuer_account" ON trust_lines USING btree (asset_type, asset_code, asset_issuer, account_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.
@bartekn, any thoughts on the duration this may take to complete on a full db(from pubnet genesis)? this would get applied to staging db which has that volume as part of release testing steps, could observe then?
I checked the codebase and we we only use this index in
It is index on state tables so every horizon (full history or not) have the same number of rows. When I was creating it locally it took a couple of minutes so it should be really fast in prd DBs. |
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
needed with deprecations, added features, breaking changes, and DB schema changes.
semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
What
Adds a new index to
trust_lines
table on(asset_type, asset_code, asset_issuer, account_id)
fields.Close #4632.
Why
When filtering by
asset
in/accounts
endpoint the underlying query was using"trust_lines_by_type_code_issuer" btree (asset_type, asset_code, asset_issuer)
index. This can be slow when querying for a popular asset which (likeUSDC
) because when selected trust lines are found by a DB engine, they later need to be sorted by account id. A new index allow quick sorting of found trustlines.Query plan without a new index
Query plan **with** a new index
Known limitations
Additional index takes extra space. A new index is able to replace existing
"trust_lines_by_type_code_issuer" btree (asset_type, asset_code, asset_issuer)
. Maybe the old index should be removed?