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 value_fetched_at #1527

Merged
merged 1 commit into from
Mar 5, 2019
Merged

add index to value_fetched_at #1527

merged 1 commit into from
Mar 5, 2019

Conversation

ayrat555
Copy link
Contributor

@ayrat555 ayrat555 commented Mar 5, 2019

Motivation

the query is using value_fetched_at field to filter records

  def stream_unfetched_balances(initial, reducer) when is_function(reducer, 2) do
    query =
      from(
        balance in CoinBalance,
        where: is_nil(balance.value_fetched_at),
        select: %{address_hash: balance.address_hash, block_number: balance.block_number}
      )

    Repo.stream_reduce(query, initial, reducer)
  end

https://github.com/poanetwork/blockscout/blob/master/apps/explorer/lib/explorer/chain.ex#L1121

before adding index:

Gather  (cost=1000.00..12287343.90 rows=20456553 width=29)
  Workers Planned: 2
  ->  Parallel Seq Scan on address_coin_balances a0  (cost=0.00..10240688.60 rows=8523564 width=29)
        Filter: (value_fetched_at IS NULL)

after adding index:

Bitmap Heap Scan on address_coin_balances a0  (cost=383588.04..8443884.54 rows=20493350 width=29)
  Recheck Cond: (value_fetched_at IS NULL)
  ->  Bitmap Index Scan on address_coin_balances_value_fetched_at_index  (cost=0.00..378464.70 rows=20493350 width=0)
        Index Cond: (value_fetched_at IS NULL)

Changelog

  • add index to value_fetched_at

@ghost ghost assigned ayrat555 Mar 5, 2019
@ghost ghost added the in progress label Mar 5, 2019
@vbaranov vbaranov merged commit 1832b40 into master Mar 5, 2019
@ghost ghost removed the in progress label Mar 5, 2019
@vbaranov vbaranov deleted the ab-value-fetched_at-index branch March 5, 2019 20:07
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.

None yet

3 participants