explain.depesz.com

PostgreSQL's explain analyze made readable

Result: JfGL

Settings
# exclusive inclusive rows x rows loops node
1. 0.005 5,428.813 ↑ 1.0 10 1

Limit (cost=351,050.84..351,050.87 rows=10 width=12) (actual time=5,428.805..5,428.813 rows=10 loops=1)

  • Buffers: shared hit=101637
2. 2.585 5,428.808 ↑ 140.4 10 1

Sort (cost=351,050.84..351,054.35 rows=1,404 width=12) (actual time=5,428.803..5,428.808 rows=10 loops=1)

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

Group (cost=0.28..351,020.50 rows=1,404 width=12) (actual time=0.915..5,426.223 rows=4,000 loops=1)

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

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

SubPlan (forGroup)

6. 36.000 5,416.000 ↑ 1.0 1 4,000

Aggregate (cost=249.88..249.89 rows=1 width=8) (actual time=1.353..1.354 rows=1 loops=4,000)

  • Buffers: shared hit=101599
7. 144.000 5,380.000 ↓ 0.0 0 4,000

Nested Loop (cost=33.59..249.75 rows=49 width=4) (actual time=1.324..1.345 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=101599
8. 2,723.973 5,236.000 ↑ 9.3 67 4,000

Hash Join (cost=29.26..135.07 rows=622 width=12) (actual time=0.012..1.309 rows=67 loops=4,000)

  • Hash Cond: (f2.user_id = f.friend_id)
  • Join Filter: (f.friend_id <> f2.friend_id)
  • Buffers: shared hit=92011
9. 2,512.000 2,512.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.006..0.628 rows=5,000 loops=4,000)

  • Buffers: shared hit=92000
10. 0.005 0.027 ↑ 2.1 12 1

Hash (cost=28.94..28.94 rows=25 width=8) (actual time=0.027..0.027 rows=12 loops=1)

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

Bitmap Heap Scan on friend f (cost=4.48..28.94 rows=25 width=8) (actual time=0.016..0.022 rows=12 loops=1)

  • Recheck Cond: (user_id = $1)
  • Heap Blocks: exact=9
  • Buffers: shared hit=11
12. 0.012 0.012 ↑ 2.1 12 1

Bitmap Index Scan on friends_user_id (cost=0.00..4.47 rows=25 width=0) (actual time=0.012..0.012 rows=12 loops=1)

  • Index Cond: (user_id = $1)
  • Buffers: shared hit=2
13. 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
14. 8.000 20.000 ↓ 0.0 0 4,000

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

  • Recheck Cond: (video_id = v.video_id)
  • Heap Blocks: exact=1576
  • Buffers: shared hit=9588
15. 12.000 12.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.003..0.003 rows=0 loops=4,000)

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