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

Speedup pending txs list query #3042

Merged
merged 1 commit into from
Mar 10, 2020
Merged

Speedup pending txs list query #3042

merged 1 commit into from
Mar 10, 2020

Conversation

vbaranov
Copy link
Member

@vbaranov vbaranov commented Mar 10, 2020

Motivation

The currently implemented query is slow because it doesn't use current indexes effectively. Current query execution plan:

explain select * from transactions where block_hash is null and error is null order by inserted_at desc, hash desc limit 50;
                                                       QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=7535181.93..7535182.05 rows=50 width=398)
   ->  Sort  (cost=7535181.93..7541132.96 rows=2380414 width=398)
         Sort Key: inserted_at DESC, hash DESC
         ->  Bitmap Heap Scan on transactions  (cost=107203.94..7456106.29 rows=2380414 width=398)
               Recheck Cond: ((block_hash IS NULL) AND (error IS NULL))
               ->  Bitmap Index Scan on transactions_block_hash_error_index  (cost=0.00..106608.84 rows=2380414 width=0)
                     Index Cond: ((block_hash IS NULL) AND (error IS NULL))
(7 rows)

Changelog

Change the order of columns in the sorting to utilize "transactions_hash_inserted_at_index" btree (hash, inserted_at) index

explain select * from transactions where block_hash is null and error is null order by hash desc, inserted_at desc limit 50;
                                                               QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.70..54264.67 rows=50 width=398)
   ->  Index Scan Backward using transactions_hash_inserted_at_index on transactions  (cost=0.70..2583414415.84 rows=2380414 width=398)
         Filter: ((block_hash IS NULL) AND (error IS NULL))
(3 rows)

Checklist for your Pull Request (PR)

@coveralls
Copy link

coveralls commented Mar 10, 2020

Pull Request Test Coverage Report for Build 4cc1192d-046e-4174-872c-422c3a4b411b

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 75.095%

Files with Coverage Reduction New Missed Lines %
apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex 2 71.43%
Totals Coverage Status
Change from base Build e1bb55f3-1833-4488-81ba-238c7a276264: -0.01%
Covered Lines: 5506
Relevant Lines: 7332

💛 - Coveralls

@vbaranov vbaranov merged commit ef770a9 into master Mar 10, 2020
@vbaranov vbaranov deleted the vb-speedup-pendinng-list branch March 10, 2020 13:28
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.

2 participants