explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 7y87 : slow query

Settings
# exclusive inclusive rows x rows loops node
1. 0.017 132,303.451 ↑ 1.0 1 1

Aggregate (cost=3,289,816.14..3,289,816.15 rows=1 width=8) (actual time=132,303.450..132,303.451 rows=1 loops=1)

2. 0.030 132,303.434 ↑ 248.6 52 1

Group (cost=2,632,299.01..3,289,654.56 rows=12,926 width=16) (actual time=132,303.395..132,303.434 rows=52 loops=1)

  • Group Key: api_user.id, ((SubPlan 1))
3. 0.127 132,303.404 ↑ 248.6 52 1

Sort (cost=2,632,299.01..2,632,331.33 rows=12,926 width=16) (actual time=132,303.392..132,303.404 rows=52 loops=1)

  • Sort Key: api_user.id, ((SubPlan 1))
  • Sort Method: quicksort Memory: 27kB
4. 39.685 132,303.277 ↑ 248.6 52 1

Seq Scan on api_user (cost=0.00..2,631,416.30 rows=12,926 width=16) (actual time=35,590.030..132,303.277 rows=52 loops=1)

  • Filter: ((SubPlan 2) > '2020-02-06 05:02:34.836229'::timestamp without time zone)
  • Rows Removed by Filter: 38663
5.          

SubPlan (for Seq Scan)

6. 0.104 168.012 ↑ 1.0 1 52

Limit (cost=0.29..50.85 rows=1 width=16) (actual time=3.230..3.231 rows=1 loops=52)

7. 167.908 167.908 ↑ 16.0 1 52

Index Scan using api_occupancy_start_b27ec6e0 on api_occupancy u0 (cost=0.29..809.25 rows=16 width=16) (actual time=3.229..3.229 rows=1 loops=52)

  • Filter: (user_id = api_user.id)
  • Rows Removed by Filter: 17776
8. 38.715 132,095.580 ↓ 0.0 0 38,715

Limit (cost=0.29..50.85 rows=1 width=16) (actual time=3.412..3.412 rows=0 loops=38,715)

9. 132,056.865 132,056.865 ↓ 0.0 0 38,715

Index Scan using api_occupancy_start_b27ec6e0 on api_occupancy u0_1 (cost=0.29..809.25 rows=16 width=16) (actual time=3.411..3.411 rows=0 loops=38,715)

  • Filter: (user_id = api_user.id)
  • Rows Removed by Filter: 17930
Planning time : 0.229 ms
Execution time : 132,303.500 ms