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

Slow get single account balance and token balances query #2020

Closed
xin-hedera opened this issue May 26, 2021 · 0 comments · Fixed by #2060
Closed

Slow get single account balance and token balances query #2020

xin-hedera opened this issue May 26, 2021 · 0 comments · Fixed by #2060
Assignees
Labels
bug Type: Something isn't working database Area: Database P1 rest Area: REST API
Milestone

Comments

@xin-hedera
Copy link
Collaborator

Detailed Description
The single account rest request /api/v1/accounts/0.0.1129 is very slow in perfnet. Analysis shows the account balance and token balances db query of the rest request takes seconds to finish:

pg explain analyze:

 Hash Full Join  (cost=64608.65..413475.09 rows=2 width=106) (actual time=3683.482..3924.771 rows=1 loops=1)
   Hash Cond: ((ab.account_id)::bigint = entity.id)
   Filter: (((ab.account_id)::bigint = 1129) OR (entity.id = 1129))
   Rows Removed by Filter: 742763
   ->  Nested Loop  (cost=1.20..319480.36 rows=772116 width=24) (actual time=0.074..348.685 rows=742762 loops=1)
         ->  Result  (cost=0.63..0.64 rows=1 width=8) (actual time=0.051..0.051 rows=1 loops=1)
               InitPlan 2 (returns $2)
                 ->  Limit  (cost=0.57..0.63 rows=1 width=8) (actual time=0.047..0.047 rows=1 loops=1)
                       ->  Index Only Scan Backward using account_balance__pk on account_balance  (cost=0.57..12781658.29 rows=223141583 width=8) (actual time=0.046..0.046 rows=1 loops=1)
                             Index Cond: (consensus_timestamp IS NOT NULL)
                             Heap Fetches: 1
         ->  Index Scan using account_balance__pk on account_balance ab  (cost=0.57..311758.56 rows=772116 width=24) (actual time=0.017..240.906 rows=742762 loops=1)
               Index Cond: ((consensus_timestamp)::bigint = ($2))
   ->  Hash  (cost=47568.95..47568.95 rows=733080 width=58) (actual time=2848.622..2848.622 rows=742589 loops=1)
         Buckets: 524288  Batches: 2  Memory Usage: 34531kB
         ->  Seq Scan on entity  (cost=0.00..47568.95 rows=733080 width=58) (actual time=0.027..1641.357 rows=742589 loops=1)
               Filter: (type < 3)
               Rows Removed by Filter: 309208
   SubPlan 1
     ->  Aggregate  (cost=747.76..747.77 rows=1 width=32) (actual time=0.094..0.094 rows=1 loops=1)
           ->  Index Scan using token_balance__pk on token_balance tb  (cost=0.57..733.43 rows=1433 width=16) (actual time=0.038..0.039 rows=1 loops=1)
                 Index Cond: (((ab.consensus_timestamp)::bigint = consensus_timestamp) AND ((ab.account_id)::bigint = (account_id)::bigint))
 Planning time: 0.822 ms
 Execution time: 3926.015 ms

Actual Behavior
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'

Expected Behavior

Environment:

Additional Context

@xin-hedera xin-hedera added bug Type: Something isn't working rest Area: REST API database Area: Database P1 labels May 26, 2021
@steven-sheehy steven-sheehy added this to the Mirror 0.35.0 milestone Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Something isn't working database Area: Database P1 rest Area: REST API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants