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 performance of coin supply API endpoints #3132

Merged
merged 3 commits into from
May 27, 2020

Conversation

vbaranov
Copy link
Member

@vbaranov vbaranov commented May 27, 2020

Fixes #3131

Motivation

Queries for coin supply endpoints are slow. For instance:

select SUM(a0.fetched_coin_balance) from addresses a0;

Changelog

However, addresses table has index "addresses_fetched_coin_balance_index" btree (fetched_coin_balance) on fetched_coin_balance column which excludes empty or zero balances and it is not used by the query. We can modify query adding where fetched_coin_balance > 0 clause to speed-up it without changing the result of the query.

core=> explain analyze select SUM(a0.fetched_coin_balance) from addresses a0 where fetched_coin_balance > 0;
                                                                                QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=3011.43..3011.44 rows=1 width=32) (actual time=48.242..48.243 rows=1 loops=1)
   ->  Index Only Scan using addresses_fetched_coin_balance_index on addresses a0  (cost=0.44..2807.17 rows=81704 width=3) (actual time=0.027..27.634 rows=73969 loops=1)
         Index Cond: (fetched_coin_balance > '0'::numeric)
         Heap Fetches: 2834
 Planning time: 0.244 ms
 Execution time: 48.284 ms
(6 rows)

Checklist for your Pull Request (PR)

@vbaranov vbaranov force-pushed the vb-fix-performance-of-coin-supply-api branch from 9dd32bd to 1b3a80b Compare May 27, 2020 09:31
@coveralls
Copy link

coveralls commented May 27, 2020

Pull Request Test Coverage Report for Build 8d6cc613-5a8b-4f2e-b77a-8cfa15c561d9

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 75.151%

Totals Coverage Status
Change from base Build 46f5ee1f-79aa-4653-acc8-11d470595cdd: 0.1%
Covered Lines: 5728
Relevant Lines: 7622

💛 - Coveralls

@vbaranov vbaranov self-assigned this May 27, 2020
…terpolated (using ^) so it may be cast accordingly in query
@vbaranov vbaranov merged commit bffd24e into master May 27, 2020
@vbaranov vbaranov deleted the vb-fix-performance-of-coin-supply-api branch May 9, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coin supply endpoints return 0.0 supply
2 participants