COMPOSITE INDEX (chat_id, created_at, id) === first page === Limit (cost=0.42..8.43 rows=50 width=141) (actual time=0.021..0.043 rows=50 loops=1) Buffers: shared hit=5 -> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..9618.01 rows=60049 width=141) (actual time=0.020..0.040 rows=50 loops=1) Index Cond: (chat_id = 'd64fec89-08a6-4948-acc3-4ca99ac54f5a'::uuid) Buffers: shared hit=5 Planning: Buffers: shared hit=114 Planning Time: 0.268 ms Execution Time: 0.060 ms === deep keyset page, offset 30000 === Limit (cost=0.42..16.77 rows=50 width=141) (actual time=0.018..0.036 rows=50 loops=1) Buffers: shared hit=4 -> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..7361.87 rows=22511 width=141) (actual time=0.017..0.033 rows=50 loops=1) Index Cond: ((chat_id = 'd64fec89-08a6-4948-acc3-4ca99ac54f5a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:30.001+00'::timestamp with time zone, 'e77ba05c-13b1-46a4-ba9f-6f630e60f623'::uuid))) Buffers: shared hit=4 Planning: Buffers: shared hit=113 Planning Time: 0.259 ms Execution Time: 0.076 ms === naive OFFSET 30000 === Limit (cost=4805.29..4813.30 rows=50 width=141) (actual time=11.507..11.525 rows=50 loops=1) Buffers: shared hit=619 -> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..9618.01 rows=60049 width=141) (actual time=0.019..10.880 rows=30050 loops=1) Index Cond: (chat_id = 'd64fec89-08a6-4948-acc3-4ca99ac54f5a'::uuid) Buffers: shared hit=619 Planning: Buffers: shared hit=114 Planning Time: 0.271 ms Execution Time: 11.542 ms