COMPARATIVE EXPLAIN REPORT Generated: 2026-11-07 10:05:04 UTC Chat ID: 42fc25ff-bf02-40ec-aafb-186d4c9b0f76 Messages: 10000 1. WITH INDEX Limit (cost=0.29..5.51 rows=51 width=78) (actual time=0.284..0.296 rows=51 loops=1) Buffers: shared hit=2 read=2 -> Index Scan using messages_chat_created_id_idx on messages (cost=0.29..1024.49 rows=10000 width=78) (actual time=0.282..0.290 rows=51 loops=1) Index Cond: (chat_id = '42fc25ff-bf02-40ec-aafb-186d4c9b0f76'::uuid) Buffers: shared hit=2 read=2 Planning: Buffers: shared hit=21 Planning Time: 0.358 ms Execution Time: 0.386 ms 2. WITHOUT INDEX Limit (cost=603.81..603.94 rows=51 width=78) (actual time=4.723..4.731 rows=51 loops=1) Buffers: shared hit=142 -> Sort (cost=603.81..628.81 rows=10000 width=78) (actual time=4.721..4.724 rows=51 loops=1) Sort Key: created_at, id Sort Method: top-N heapsort Memory: 38kB Buffers: shared hit=142 -> Seq Scan on messages (cost=0.00..270.19 rows=10000 width=78) (actual time=0.041..1.098 rows=10000 loops=1) Filter: (chat_id = '42fc25ff-bf02-40ec-aafb-186d4c9b0f76'::uuid) Rows Removed by Filter: 255 Buffers: shared hit=142 Planning Time: 0.395 ms Execution Time: 5.279 ms KEY OBSERVATIONS Variant 1 uses 'Index Scan using messages_chat_created_id_idx' Variant 2 uses 'Seq Scan' + 'Sort' (full table scan) Compare 'Buffers: shared hit=...' and 'Execution Time'