Skip to content
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

Fix slow query in Payments for Account endpoint #515

Closed
bartekn opened this issue Jun 25, 2018 · 2 comments
Closed

Fix slow query in Payments for Account endpoint #515

bartekn opened this issue Jun 25, 2018 · 2 comments
Labels

Comments

@bartekn
Copy link
Contributor

bartekn commented Jun 25, 2018

history_operation_participants has a composite index hist_op_p_id on (history_account_id, history_operation_id) fields. When running "payments for account" query:

SELECT hop.id, hop.transaction_id, hop.application_order, hop.type, hop.details, hop.source_account, ht.transaction_hash FROM history_operations hop LEFT JOIN history_transactions ht ON ht.id = hop.transaction_id JOIN history_operation_participants hopp ON hopp.history_operation_id = hop.id WHERE hop.type IN ($1,$2,$3,$4) AND hopp.history_account_id = $5 AND hop.id > $6 ORDER BY hop.id asc LIMIT 10

Postgres query planner opt to use history_account_id part of the index and because history_operation_id is not used in a query the execution was slow.

This can be fixed by changing the query to use hopp.history_operation_id instead of hop.id when filtering and ordering results. The query is equivalent to the previous one but is using all fields of history_operation_participants.hist_op_p_id index.

Initial fix in #439 but was closed because the code should be improved.

@bartekn bartekn added this to the Horizon v0.15.0 milestone Sep 5, 2018
@bartekn bartekn added the horizon label Sep 5, 2018
@bartekn bartekn modified the milestones: Horizon v0.15.0, Horizon v0.14.x - patch releases Sep 6, 2018
@howardtw
Copy link
Contributor

@bartekn Is this PR still blocked by the improvement of the query builder as suggested here #439 (comment)? Do we have a ticket for the improvement?

@bartekn
Copy link
Contributor Author

bartekn commented Jan 14, 2019

@howardtw it's not an issue with the query builder, more with PR #439. It was a quick fix so it just requires better code to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants