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 count relevant transactions #1969

Merged
merged 2 commits into from
Apr 5, 2024
Merged

Fix count relevant transactions #1969

merged 2 commits into from
Apr 5, 2024

Conversation

moisses89
Copy link
Member

@moisses89 moisses89 commented Apr 4, 2024

Bug description

Count of relevant transactions was wrongly calculated with outgoing ether transfers.
The count value is part of the cache key of all-transactions. Issues in this value was causing cache invalidation issues for that endpoint.

Query performance

The Ether transfer query was separated in Incoming transfers and Outgoing transfers to keep using the index history_internal_transfer_idx.
A partial index was added to _from field.
At this way the database is not scanning tables and just using Index Only for both queries.

 ->  Aggregate  (cost=84.26..84.27 rows=1 width=8) (actual time=0.176..0.177 rows=1 loops=1)
               ->  Index Only Scan using history_internal_transfer_idx on history_internaltx  (cost=0.28..81.77 rows=999 width=0) (actual time=0.022..0.143 rows=998 loops=1)
                     Index Cond: ("to" = '\xf5951f6fb664819ddba656ab228fbb8e8f5a1c33'::bytea)
                     Heap Fetches: 0
 ->  Aggregate  (cost=10.32..10.33 rows=1 width=8) (actual time=0.030..0.031 rows=1 loops=1)
               ->  Index Only Scan using history_internal_transfer_from on history_internaltx history_internaltx_1  (cost=0.28..10.07 rows=102 width=0) (actual time=0.015..0.027 rows=102 loops=1)
                     Index Cond: (_from = '\xf5951f6fb664819ddba656ab228fbb8e8f5a1c33'::bytea)
                     Heap Fetches: 0

@moisses89 moisses89 requested a review from a team as a code owner April 4, 2024 16:16
@moisses89
Copy link
Member Author

@Uxio0 we could add another conditional index for _from query if we need it.

@Uxio0
Copy link
Member

Uxio0 commented Apr 4, 2024

@Uxio0 we could add another conditional index for _from query if we need it.

I prefer that Bitmap Heap Scan to go to Index Only Scan if possible

@moisses89
Copy link
Member Author

@Uxio0 we could add another conditional index for _from query if we need it.

I prefer that Bitmap Heap Scan to go to Index Only Scan if possible

@Uxio0 looks like OR is not possible because is doing a bitmap OR and using different index.

         ->  Aggregate  (cost=166.10..166.11 rows=1 width=8) (actual time=0.322..0.323 rows=1 loops=1)
               ->  Bitmap Heap Scan on history_internaltx  (cost=49.37..163.41 rows=1076 width=0) (actual time=0.075..0.290 rows=1100 loops=1)
                     Recheck Cond: (("to" = '\xf5951f6fb664819ddba656ab228fbb8e8f5a1c33'::bytea) OR (_from = '\xf5951f6fb664819ddba656ab228fbb8e8f5a1c33'::bytea))
                     Filter: ((value > '0'::numeric) AND (call_type = 0))
                     Rows Removed by Filter: 2
                     Heap Blocks: exact=26
                     ->  BitmapOr  (cost=49.37..49.37 rows=1102 width=0) (actual time=0.064..0.064 rows=0 loops=1)
                           ->  Bitmap Index Scan on history_int_to_e72886_idx  (cost=0.00..43.78 rows=1000 width=0) (actual time=0.059..0.059 rows=1000 loops=1)
                                 Index Cond: ("to" = '\xf5951f6fb664819ddba656ab228fbb8e8f5a1c33'::bytea)
                           ->  Bitmap Index Scan on history_internaltx__from_36470cfd  (cost=0.00..5.05 rows=102 width=0) (actual time=0.005..0.005 rows=102 loops=1)
                                 Index Cond: (_from = '\xf5951f6fb664819ddba656ab228fbb8e8f5a1c33'::bytea)

@moisses89 moisses89 merged commit fc77032 into main Apr 5, 2024
6 checks passed
@moisses89 moisses89 deleted the fix_relevant_elements branch April 5, 2024 11:24
@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2024
@moisses89 moisses89 self-assigned this Apr 8, 2024
@JagoFigueroa
Copy link

Hola! On friday I was transacting on staging with the fix in place and after 40 txs or so I was not able to reproduce it whereas before it it was quite easy to do.

Looking good to me 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants