explain.depesz.com

PostgreSQL's explain analyze made readable

Result: YESM

Settings
# exclusive inclusive rows x rows loops node
1. 0.005 3,867.704 ↑ 1.0 10 1

Limit (cost=505,279.13..505,279.15 rows=10 width=12) (actual time=3,867.700..3,867.704 rows=10 loops=1)

  • Buffers: shared hit=136067
2. 1.389 3,867.699 ↑ 140.4 10 1

Sort (cost=505,279.13..505,282.64 rows=1,404 width=12) (actual time=3,867.698..3,867.699 rows=10 loops=1)

  • Sort Key: ((SubPlan 1)) DESC
  • Sort Method: top-N heapsort Memory: 25kB
  • Buffers: shared hit=136067
3. 6.904 3,866.310 ↓ 2.8 4,000 1

Group (cost=0.28..505,248.79 rows=1,404 width=12) (actual time=2.217..3,866.310 rows=4,000 loops=1)

  • Group Key: v.video_id
  • Buffers: shared hit=136064
4. 3.406 3.406 ↓ 2.8 4,000 1

Index Only Scan using video_pkey on video v (cost=0.28..177.34 rows=1,404 width=4) (actual time=0.077..3.406 rows=4,000 loops=1)

  • Heap Fetches: 4000
  • Buffers: shared hit=38
5.          

SubPlan (forGroup)

6. 20.000 3,856.000 ↑ 1.0 1 4,000

Aggregate (cost=359.73..359.74 rows=1 width=8) (actual time=0.964..0.964 rows=1 loops=4,000)

  • Buffers: shared hit=136026
7. 0.000 3,836.000 ↓ 0.0 0 4,000

Nested Loop (cost=88.30..359.58 rows=60 width=4) (actual time=0.946..0.959 rows=0 loops=4,000)

  • Join Filter: ((l.user_id <> f.user_id) AND ((f.friend_id = l.user_id) OR (f2.friend_id = l.user_id)))
  • Rows Removed by Join Filter: 27
  • Buffers: shared hit=136023
8. 1,739.269 3,372.000 ↑ 10.0 67 4,000

Hash Join (cost=88.30..204.22 rows=672 width=12) (actual time=0.008..0.843 rows=67 loops=4,000)

  • Hash Cond: (f2.user_id = f.friend_id)
  • Join Filter: (f.friend_id <> f2.friend_id)
  • Buffers: shared hit=92023
9. 1,632.000 1,632.000 ↑ 1.0 5,000 4,000

Seq Scan on friend f2 (cost=0.00..74.98 rows=5,198 width=8) (actual time=0.004..0.408 rows=5,000 loops=4,000)

  • Buffers: shared hit=92000
10. 0.012 0.731 ↑ 2.2 12 1

Hash (cost=87.98..87.98 rows=26 width=8) (actual time=0.731..0.731 rows=12 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
  • Buffers: shared hit=23
11. 0.719 0.719 ↑ 2.2 12 1

Seq Scan on friend f (cost=0.00..87.98 rows=26 width=8) (actual time=0.279..0.719 rows=12 loops=1)

  • Filter: (user_id = 1)
  • Rows Removed by Filter: 4988
  • Buffers: shared hit=23
12. 148.000 536.000 ↓ 0.0 0 268,000

Materialize (cost=0.00..34.42 rows=9 width=8) (actual time=0.001..0.002 rows=0 loops=268,000)

  • Buffers: shared hit=44000
13. 388.000 388.000 ↓ 0.0 0 4,000

Seq Scan on likes l (cost=0.00..34.38 rows=9 width=8) (actual time=0.080..0.097 rows=0 loops=4,000)

  • Filter: (video_id = v.video_id)
  • Rows Removed by Filter: 1600
  • Buffers: shared hit=44000