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 address to logs query #2924

Merged
merged 3 commits into from
Dec 20, 2019

Conversation

vbaranov
Copy link
Member

@vbaranov vbaranov commented Dec 18, 2019

Motivation

Logs tab on address page:

Screenshot 2019-12-18 at 18 07 07

For almost all addresses if there are tons of transactions in the chain like in ETH Mainnet.

Changelog

  1. Replace index on logs table on block_number field with a multicolumn index block_number DESC, index DESC to be able to sort in logs table

  2. Change the query to use this index.

The query is transformed from

SELECT l0.* FROM logs AS l0
INNER JOIN transactions AS t1
ON ((t1.block_hash = l0.block_hash)
AND (t1.block_number = l0.block_number))
AND (t1.hash = l0.transaction_hash)
WHERE (((t1.block_number < 9125388))
OR ((t1.block_number = 9125388)
AND (t1.index > 0))
OR (((t1.block_number = 9125388) AND (t1.index = 0))
AND (l0.index > 0)))
AND ((l0.address_hash = '\xdac17f958d2ee523a2206206994597c13d831ec7')
AND (l0.block_hash = t1.block_hash))
ORDER BY t1.block_number DESC, t1.index DESC LIMIT 51;

to

SELECT COUNT(a.*) FROM (
  SELECT l0.*
  FROM logs AS l0
  INNER JOIN transactions AS t1
  ON t1.hash = l0.transaction_hash
  WHERE (l0.address_hash = '\xdac17f958d2ee523a2206206994597c13d831ec7')
  AND (((t1.block_number < 9125388))
  OR ((t1.block_number = 9125388)
  AND (t1.index > 0))
  OR (((t1.block_number = 9125388) AND (t1.index = 0))
  AND (l0.index > 0)))
  ORDER BY l0.block_number DESC, l0.index DESC LIMIT 51
) a
INNER JOIN transactions AS t1 ON a.block_hash = t1.block_hash
AND a.block_number = t1.block_number
AND a.transaction_hash = t1.hash

Checklist for your Pull Request (PR)

@vbaranov vbaranov added the wip label Dec 18, 2019
@vbaranov vbaranov force-pushed the vb-speedup-address-to-logs-query branch from 6085255 to 12905cf Compare December 18, 2019 15:17
@vbaranov vbaranov self-assigned this Dec 18, 2019
@coveralls
Copy link

coveralls commented Dec 18, 2019

Pull Request Test Coverage Report for Build 37d89e4a-0835-4cd7-9a8b-34fa3fd93339

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 75.447%

Totals Coverage Status
Change from base Build 40db3a00-b82e-4dfe-90f8-b3b8b7d7679a: 0.007%
Covered Lines: 5313
Relevant Lines: 7042

💛 - Coveralls

@vbaranov vbaranov added ready for review This PR is ready for reviews. and removed wip labels Dec 18, 2019
@vbaranov vbaranov added this to the 3.0.0 milestone Dec 18, 2019
@vbaranov vbaranov merged commit 2a80777 into pp-pending-blocks-ops Dec 20, 2019
@vbaranov vbaranov deleted the vb-speedup-address-to-logs-query branch December 20, 2019 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
indexing ready for review This PR is ready for reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants