-
Notifications
You must be signed in to change notification settings - Fork 121
fix: optimize address transactions query to prevent timeouts #2347
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
base: develop
Are you sure you want to change the base?
fix: optimize address transactions query to prevent timeouts #2347
Conversation
|
Another potential optimization is to materialize the This would trade off some storage and update complexity for faster reads, but my hunch says it's worthwhile given the scale and volume of data |
|
I ran You can see that the planning time is slower on the optimized version, however, the execution time is around 6x faster. Original QueryOptimized Query |
- Restructure query with early canonical filtering and optimized CTEs - Add database indexes for correlated subqueries - Add optimized function and migration script Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
4da659b to
4db2943
Compare
[WIP] Optimize getAddressTransactions query to eliminate timeouts
Status: Work in progress, seeking feedback on approach before finalizing
The
getAddressTransactionsendpoint times out for addresses with high transaction volumes, causing 500 errors for wallet apps and block explorers.I've analyzed query performance using the latest database archive from
archive.hiro.so/mainnet/stacks-blockchain-api-pgand identified bottlenecks in:Approach
Query Restructuring - Added
getAddressTransactionsV2function with:Database Indexes - Migration script creates optimized indexes for:
Performance Results
Query optimization alone: ~4x speedup (20.8s → ~5s)
With database indexes: Additional 2x improvement (~5s → 2.4s)
Total improvement: 8.7x faster execution
Testing Environment
SPDSMZGNMVKK48BHX45VKETX4VF8264NV0C9J692SP3SBQ9PZEMBNBAWTR7FRPE3XK0EFW9JWVX4G80S2(65k+ transactions) → original query exceeds 2.6 minutes when run locally on M3 MacBook Air, updated query takes around 24 seconds in comparisonNext Steps
Signed-off-by: Ramtin Mesgari 26694963+iamramtin@users.noreply.github.com