Reorganize queries and indexes for internal_transactions table #2910
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.
#2879
Motivation
internal transactions
table are not optimized efficientlyinternal_transactions_to_address_hash_from_address_hash_created" btree (to_address_hash, from_address_hash, created_contract_address_hash, type, index)
is the largest index in the table (351 Gb on ETH Mainnet instance) and it is not used by the query to get internal transactions on address, but it was specifically created for that query.The idea is to get rid of this large index and improve the query to get internal transactions for address for both cases: page and API endpoint.
Changelog
DB Migartion
internal_transactions_to_address_hash_from_address_hash_created
indexto_address_hash
,from_address_hash
,created_contract_address_hash
with a specific clause used by the query to get rid of firstcall
trace of transactions:This change leverages 222 Gb on ETH Mainned DB instance:
Before:
After:
and addresses the performance of queries to get internal transactions on the address. Though, the queries need to be changed a little bit to use new partial indexes.
Queries update
In order to start using those new partial indexes, the queries to get internal transactions for an address should be changed from using
OR
clause to useUNION
. Specifically, we want to get rid of this clause:in favour:
Here is the analysis of the "OR"-based query with a huge multi-column index:
And here is the result of "UNION"-based query with partial index:
As a result, 3x speed-up of the query
CHANGELOG.md
with this PRmaster
in the Version column. Changes will be reflected in this table: https://docs.blockscout.com/for-developers/information-and-settings/env-variables.