improve execution data related query performance#599
Merged
Conversation
qu0b
approved these changes
Mar 5, 2026
barnabasbusa
approved these changes
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a PostgreSQL compatibility bug and optimizes address page database queries for accounts with large transaction counts.
Bug Fix
GetElTransactionsByAccountIDCombinedandGetElTokenTransfersByAccountIDCombinedthat causedsubquery in FROM must have an aliaserrors on PostgreSQL (introduced in 62847ad for SQLite compatibility)Performance Improvements
Measured via
EXPLAIN ANALYZEagainst a production-scale database (14M transactions, 11.5M token transfers, 56.9M internal transactions):Changes
UNION ALLcount patterns with separate index-only scans per direction (from_id / to_id counted independently). Slightly overcounts self-referencing entries but is acceptable since counts are already capped at 100k.HasElTransactionsInternalByAccountandHasElWithdrawalsByAccountIDusingSELECT EXISTS(...)instead of running full count queries just to check if rows exist.el_token_transfers: Composite indexes(from_id, token_type)and(to_id, token_type)to enable index-only scans for token transfer count queries filtered by token type.el_transactions_internal: Single-column indexes(from_id)and(to_id)for efficient count and EXISTS queries. These are smaller than the existing composite indexes and reduce heap fetches from 100k+ to <200 for index-only scans.All queries verified on both PostgreSQL and SQLite.
PostgreSQL tuning notes
Analysis revealed that
shared_buffers = 128MBon a 37GB database causes severe cold-cache performance issues (e.g., index-only scans hitting disk for every heap fetch). Recommended:shared_buffersto at least 2-4GBrandom_page_cost = 1.1if using SSD storage