explain.depesz.com

PostgreSQL's explain analyze made readable

Result: PAv5

Settings
# exclusive inclusive rows x rows loops node
1. 0.006 3,506.134 ↑ 1.0 10 1

Limit (cost=430,457.33..430,457.35 rows=10 width=12) (actual time=3,506.130..3,506.134 rows=10 loops=1)

  • Buffers: shared hit=101649
2. 1.807 3,506.128 ↑ 140.4 10 1

Sort (cost=430,457.33..430,460.84 rows=1,404 width=12) (actual time=3,506.128..3,506.128 rows=10 loops=1)

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

Group (cost=0.28..430,426.99 rows=1,404 width=12) (actual time=1.166..3,504.321 rows=4,000 loops=1)

  • Group Key: v.video_id
  • Buffers: shared hit=101649
4. 2.705 2.705 ↓ 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.009..2.705 rows=4,000 loops=1)

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

SubPlan (forGroup)

6. 24.000 3,496.000 ↑ 1.0 1 4,000

Aggregate (cost=306.43..306.44 rows=1 width=8) (actual time=0.874..0.874 rows=1 loops=4,000)

  • Buffers: shared hit=101611
7. 96.000 3,472.000 ↓ 0.0 0 4,000

Nested Loop (cost=90.15..306.31 rows=49 width=4) (actual time=0.855..0.868 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=101611
8. 1,755.714 3,376.000 ↑ 9.3 67 4,000

Hash Join (cost=85.81..191.62 rows=622 width=12) (actual time=0.008..0.844 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,620.000 1,620.000 ↑ 1.0 5,000 4,000

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

  • Buffers: shared hit=92000
10. 0.004 0.286 ↑ 2.1 12 1

Hash (cost=85.50..85.50 rows=25 width=8) (actual time=0.286..0.286 rows=12 loops=1)

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

Seq Scan on friend f (cost=0.00..85.50 rows=25 width=8) (actual time=0.114..0.282 rows=12 loops=1)

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

Materialize (cost=4.34..15.19 rows=8 width=8) (actual time=0.000..0.000 rows=0 loops=268,000)

  • Buffers: shared hit=9588
13. 4.000 12.000 ↓ 0.0 0 4,000

Bitmap Heap Scan on likes l (cost=4.34..15.15 rows=8 width=8) (actual time=0.003..0.003 rows=0 loops=4,000)

  • Recheck Cond: (video_id = v.video_id)
  • Heap Blocks: exact=1576
  • Buffers: shared hit=9588
14. 8.000 8.000 ↓ 0.0 0 4,000

Bitmap Index Scan on likes_video_id (cost=0.00..4.34 rows=8 width=0) (actual time=0.002..0.002 rows=0 loops=4,000)

  • Index Cond: (video_id = v.video_id)
  • Buffers: shared hit=8012