FIRST
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id=%s ORDER BY created_at, id LIMIT %s
Limit  (cost=0.29..5.58 rows=51 width=70) (actual time=0.012..0.020 rows=51 loops=1)
  Buffers: shared hit=3
  ->  Index Scan using messages_chat_created_id_idx on messages  (cost=0.29..1038.88 rows=10000 width=70) (actual time=0.011..0.017 rows=51 loops=1)
        Index Cond: (chat_id = '24b671da-2531-454f-9569-2d97c3d3b45e'::uuid)
        Buffers: shared hit=3
Planning Time: 0.053 ms
Execution Time: 0.030 ms

MIDDLE
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id=%s AND (created_at, id) > (%s, %s) ORDER BY created_at, id LIMIT %s
Limit  (cost=0.29..7.15 rows=51 width=70) (actual time=0.011..0.021 rows=51 loops=1)
  Buffers: shared hit=4
  ->  Index Scan using messages_chat_created_id_idx on messages  (cost=0.29..665.89 rows=4945 width=70) (actual time=0.011..0.017 rows=51 loops=1)
        Index Cond: ((chat_id = '24b671da-2531-454f-9569-2d97c3d3b45e'::uuid) AND (ROW(created_at, id) > ROW('2026-10-30 21:30:51.163748+00'::timestamp with time zone, '49e8083b-b366-420a-a42e-7dd94e84e990'::uuid)))
        Buffers: shared hit=4
Planning Time: 0.052 ms
Execution Time: 0.031 ms

LATE
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id=%s AND (created_at, id) > (%s, %s) ORDER BY created_at, id LIMIT %s
Limit  (cost=0.29..83.03 rows=51 width=70) (actual time=0.008..0.020 rows=51 loops=1)
  Buffers: shared hit=4
  ->  Index Scan using messages_chat_created_id_idx on messages  (cost=0.29..159.29 rows=98 width=70) (actual time=0.007..0.016 rows=51 loops=1)
        Index Cond: ((chat_id = '24b671da-2531-454f-9569-2d97c3d3b45e'::uuid) AND (ROW(created_at, id) > ROW('2026-10-30 21:30:51.168648+00'::timestamp with time zone, '15bb3004-514a-4d41-b783-327659c3269a'::uuid)))
        Buffers: shared hit=4
Planning Time: 0.043 ms
Execution Time: 0.029 ms
