27 lines
1.7 KiB
Plaintext
Executable File
27 lines
1.7 KiB
Plaintext
Executable File
-- L14 (b) LATERAL top-3 per parent — the winning strategy (index seek)
|
|
-- FeedTopNIT.l14ExplainThreeWayPlanCompareIsTheCrownJewel (seed 1000, page 20, K=3)
|
|
-- SELECT p.id, top3.color, top3.text, top3.created_at
|
|
-- FROM (SELECT fi.id FROM feed_items fi ORDER BY fi.first_highlighted_at DESC, fi.id ASC LIMIT 20) p
|
|
-- CROSS JOIN LATERAL (SELECT h.color, h.text, h.created_at FROM highlights h
|
|
-- WHERE h.feed_item_id = p.id ORDER BY h.created_at DESC LIMIT 3) top3
|
|
-- 읽기 포인트: 부모마다 ix_highlights_feed_items_created 를 Index Scan 하고 Limit 3 에서 멈춘다
|
|
-- (loops=20, 각 rows=3). buffers shared hit=204 로 세 해법 중 최소.
|
|
|
|
Nested Loop (cost=172.25..432.10 rows=60 width=686) (actual time=0.257..0.310 rows=60 loops=1)
|
|
Buffers: shared hit=204
|
|
-> Limit (cost=171.97..172.02 rows=20 width=24) (actual time=0.239..0.240 rows=20 loops=1)
|
|
Buffers: shared hit=141
|
|
-> Sort (cost=171.97..174.09 rows=846 width=24) (actual time=0.238..0.239 rows=20 loops=1)
|
|
Sort Key: fi.first_highlighted_at DESC, fi.id
|
|
Sort Method: top-N heapsort Memory: 26kB
|
|
Buffers: shared hit=141
|
|
-> Seq Scan on feed_items fi (cost=0.00..149.46 rows=846 width=24) (actual time=0.111..0.175 rows=1000 loops=1)
|
|
Buffers: shared hit=141
|
|
-> Limit (cost=0.28..12.96 rows=3 width=670) (actual time=0.003..0.003 rows=3 loops=20)
|
|
Buffers: shared hit=63
|
|
-> Index Scan using ix_highlights_feed_items_created on highlights h (cost=0.28..80.61 rows=19 width=670) (actual time=0.003..0.003 rows=3 loops=20)
|
|
Index Cond: (feed_item_id = fi.id)
|
|
Buffers: shared hit=63
|
|
Planning Time: 0.068 ms
|
|
Execution Time: 0.323 ms
|