messages in table: 50003; target chat: 10000; noise chat: 40000 == first page (limit+1 = 51) SELECT * FROM messages WHERE chat_id = :chat_id ORDER BY created_at, id LIMIT :page Limit (actual time=0.006..0.015 rows=51 loops=1) Buffers: shared hit=4 -> Index Scan using ix_messages_chat_id_created_at_id on messages (actual time=0.006..0.012 rows=51 loops=1) Index Cond: (chat_id = '87629e85-f573-467a-b369-74d67ea5f2ac'::uuid) Buffers: shared hit=4 Planning: Buffers: shared hit=6 Planning Time: 0.051 ms Execution Time: 0.025 ms == page after cursor in the middle of history SELECT * FROM messages WHERE chat_id = :chat_id AND (created_at, id) > (:after_created_at, :after_id) ORDER BY created_at, id LIMIT :page Limit (actual time=0.007..0.023 rows=51 loops=1) Buffers: shared hit=6 -> Index Scan using ix_messages_chat_id_created_at_id on messages (actual time=0.007..0.020 rows=51 loops=1) Index Cond: ((chat_id = '87629e85-f573-467a-b369-74d67ea5f2ac'::uuid) AND (ROW(created_at, id) > ROW('2026-10-26 19:33:40.369572+00'::timestamp with time zone, '540382ff-297f-48c1-8515-aca3063b8347'::uuid))) Buffers: shared hit=6 Planning Time: 0.044 ms Execution Time: 0.046 ms == same page with index scans disabled (for comparison) SELECT * FROM messages WHERE chat_id = :chat_id AND (created_at, id) > (:after_created_at, :after_id) ORDER BY created_at, id LIMIT :page Limit (actual time=4.477..4.483 rows=51 loops=1) Buffers: shared hit=618 -> Sort (actual time=4.476..4.479 rows=51 loops=1) Sort Key: created_at, id Sort Method: top-N heapsort Memory: 31kB Buffers: shared hit=618 -> Seq Scan on messages (actual time=0.417..4.025 rows=4999 loops=1) Filter: ((chat_id = '87629e85-f573-467a-b369-74d67ea5f2ac'::uuid) AND (ROW(created_at, id) > ROW('2026-10-26 19:33:40.369572+00'::timestamp with time zone, '540382ff-297f-48c1-8515-aca3063b8347'::uuid))) Rows Removed by Filter: 45004 Buffers: shared hit=618 Planning Time: 0.038 ms Execution Time: 4.496 ms