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

add index to blocks' consensus #1509

Merged
merged 4 commits into from
Mar 4, 2019
Merged

add index to blocks' consensus #1509

merged 4 commits into from
Mar 4, 2019

Conversation

ayrat555
Copy link
Contributor

@ayrat555 ayrat555 commented Mar 1, 2019

Motivation

Some slow queries use consensus field in blocks table:

SELECT b1."number" FROM "blocks" AS b0 INNER JOIN "blocks" AS b1 ON b1."hash" = b0."parent_hash" WHERE (b0."consensus" = TRUE) AND (b1."consensus" = FALSE)

After migration, added index (blocks_consensus_index) is used in this query

Gather  (cost=1000.99..141914.57 rows=67195 width=8)
  Workers Planned: 1
  ->  Nested Loop  (cost=0.99..134195.07 rows=39526 width=8)
        ->  Parallel Index Scan using blocks_consensus_index on blocks b1  (cost=0.43..4864.70 rows=39904 width=41)
              Index Cond: (consensus = false)
              Filter: (NOT consensus)
        ->  Index Only Scan using one_consensus_child_per_parent on blocks b0  (cost=0.56..3.24 rows=1 width=33)
              Index Cond: (parent_hash = b1.hash)

Changelog

  • add index to blocks' consensus

@ghost ghost assigned ayrat555 Mar 1, 2019
@ghost ghost added the in progress label Mar 1, 2019
@ghost ghost assigned vbaranov Mar 1, 2019
@coveralls
Copy link

coveralls commented Mar 1, 2019

Pull Request Test Coverage Report for Build d2f2e653-8ff0-47a4-bff2-e267705dc021

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.888%

Totals Coverage Status
Change from base Build f5454a4c-36cb-48cd-8283-20b2d5b2f402: 0.0%
Covered Lines: 4269
Relevant Lines: 5029

💛 - Coveralls

@vbaranov vbaranov self-requested a review March 1, 2019 14:10
@vbaranov vbaranov removed their assignment Mar 1, 2019
Copy link
Member

@vbaranov vbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any time estimations of how a query works before and after index implementing?

@vbaranov
Copy link
Member

vbaranov commented Mar 4, 2019

@ayrat555 ☝️

@ayrat555
Copy link
Contributor Author

ayrat555 commented Mar 4, 2019

@vbaranov

"Gather  (cost=1000.56..316544.24 rows=67195 width=8)"
"  Workers Planned: 2"
"  ->  Nested Loop  (cost=0.56..308824.74 rows=27998 width=8)"
"        ->  Parallel Seq Scan on blocks b1  (cost=0.00..217216.81 rows=28265 width=41)"
"              Filter: (NOT consensus)"
"        ->  Index Only Scan using one_consensus_child_per_parent on blocks b0  (cost=0.56..3.24 rows=1 width=33)"
"              Index Cond: (parent_hash = b1.hash)"

Here a query without the index. Parallel Seq Scan is much more expensive operation

@vbaranov vbaranov self-requested a review March 4, 2019 14:00
@vbaranov vbaranov requested a review from zachdaniel March 4, 2019 14:00
@ghost ghost assigned vbaranov Mar 4, 2019
@vbaranov vbaranov merged commit 1628b95 into master Mar 4, 2019
@ghost ghost removed the in progress label Mar 4, 2019
@vbaranov vbaranov deleted the ab-add-index-to-consensus branch March 4, 2019 16:48
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.

4 participants