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.014 rows=51 loops=1) Buffers: shared hit=4 -> Index Scan using ix_messages_chat_id_created_at_id on messages (actual time=0.005..0.011 rows=51 loops=1) Index Cond: (chat_id = '5355155b-ec73-4a3a-ac44-2417871c9ddf'::uuid) Buffers: shared hit=4 Planning: Buffers: shared hit=6 Planning Time: 0.046 ms Execution Time: 0.022 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.006..0.018 rows=51 loops=1) Buffers: shared hit=6 -> Index Scan using ix_messages_chat_id_created_at_id on messages (actual time=0.006..0.015 rows=51 loops=1) Index Cond: ((chat_id = '5355155b-ec73-4a3a-ac44-2417871c9ddf'::uuid) AND (ROW(created_at, id) > ROW('2026-10-28 16:00:20.004077+00'::timestamp with time zone, 'c9e332b5-5dd0-4279-a4dd-bf2e1451cc69'::uuid))) Buffers: shared hit=6 Planning Time: 0.037 ms Execution Time: 0.040 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.010..4.015 rows=51 loops=1) Buffers: shared hit=618 -> Sort (actual time=4.009..4.011 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.379..3.601 rows=4999 loops=1) Filter: ((chat_id = '5355155b-ec73-4a3a-ac44-2417871c9ddf'::uuid) AND (ROW(created_at, id) > ROW('2026-10-28 16:00:20.004077+00'::timestamp with time zone, 'c9e332b5-5dd0-4279-a4dd-bf2e1451cc69'::uuid))) Rows Removed by Filter: 45004 Buffers: shared hit=618 Planning Time: 0.036 ms Execution Time: 4.024 ms