add index for runtime rel tx queries #369
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@csillag reported that this query was timing out:
https://index-staging.oasislabs.com/v1/emerald/transactions?limit=10&offset=0&rel=oasis1qzl89gapk5y3e8fk6x7d6zrmz2qvedjsqg6q4lxp
Further investigation revealed that the query plan was not able to use the existing indexes effectively:
We do have indexes for
address
and(round, index)
separately, but most rel tx queries normally haveorder by round desc
and require filtering on both address and round. The query planner ends up traversing the txs in reverse chronological order until it finds enough txs that are linked to the rel address, which becomes problematic at scale.Adding this index reduces the query time back to ~5ms in staging testing.