-
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: Improve performance of claimable balances queries #4690
services/horizon: Improve performance of claimable balances queries #4690
Conversation
services/horizon/internal/db2/schema/migrations/62_claimable_balance_claimants.sql
Show resolved
Hide resolved
services/horizon/internal/db2/schema/migrations/62_claimable_balance_claimants.sql
Show resolved
Hide resolved
I was finally able to test the code in this PR in stg and the results aren't great. In one of Horizon meetings I mentioned that we should avoid a mistake we made in Unfortunately, while replaying production Another observation was that, contrary to history tables like participants mentioned above, current state tables are not immutable. This means that if a claimable balance entry changes (ex. by adding/changing a sponsor) all of it's destinations in a new table This makes me think we have two options:
The second option is easier and, to be honest, I don't understand why we sort results by Both solutions have pros and cons so decided to open a discussion here. |
I decided to add order by field to I also noticed that "Claimable Balances for Asset" and "Claimable Balances for Sponsor" also have performance issues if an asset or sponsor is popular. I added new indexes to support such queries and fixed the query builder. |
OK, initial tests in stg look very good. PTAL! I'll share detailed comparison report tomorrow. |
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
Add a new table
claimable_balance_claimants
which holds all claimants' destinations for corresponding claimable balances IDs. Also, improve other filters (bysponsor
andasset
) but adding better indexes for such queries.Why
We noticed that "claimable balances for claimants" query (
/claimable_balances?claimant=...
) is very slow in Postgres 12. The reason, apart from possible changes to gin index onclaimants
field, is that theclaimable_balances
table size significantly increased in the last couple months.Known limitations
This change requires a state rebuild to fill the new table. The new query has not been tested yet in stg because this environment is currently being rebuilt. I will test the query performance before merging the PR.