-- btree(chat_id); hot chat, 24294 messages; keyset cursor at 50%
Limit  (cost=4708.68..4708.80 rows=51 width=213) (actual time=14.248..14.259 rows=51 loops=1)
  Buffers: shared hit=3642
  ->  Sort  (cost=4708.68..4738.72 rows=12019 width=213) (actual time=14.247..14.254 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 42kB
        Buffers: shared hit=3642
        ->  Bitmap Heap Scan on messages  (cost=271.12..4307.70 rows=12019 width=213) (actual time=6.934..12.540 rows=12147 loops=1)
              Recheck Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
              Filter: (ROW(created_at, id) > ROW('2026-02-04 13:58:00+03'::timestamp with time zone, 'dc3c4cd9-029a-40dd-976c-64cd71098149'::uuid))
              Rows Removed by Filter: 12147
              Heap Blocks: exact=3614
              Buffers: shared hit=3636
              ->  Bitmap Index Scan on hist_idx  (cost=0.00..268.11 rows=23976 width=0) (actual time=1.156..1.156 rows=24294 loops=1)
                    Index Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
                    Buffers: shared hit=22
Planning:
  Buffers: shared hit=132
Planning Time: 0.426 ms
Execution Time: 14.305 ms

-- same chat, OFFSET 12147
Limit  (cost=5968.35..5968.48 rows=51 width=213) (actual time=24.772..24.782 rows=51 loops=1)
  Buffers: shared hit=3642, temp read=535 written=676
  ->  Sort  (cost=5937.98..5997.92 rows=23976 width=213) (actual time=22.894..24.401 rows=12198 loops=1)
        Sort Key: created_at, id
        Sort Method: external merge  Disk: 5392kB
        Buffers: shared hit=3642, temp read=535 written=676
        ->  Bitmap Heap Scan on messages  (cost=274.11..4190.81 rows=23976 width=213) (actual time=1.657..11.046 rows=24294 loops=1)
              Recheck Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
              Heap Blocks: exact=3614
              Buffers: shared hit=3636
              ->  Bitmap Index Scan on hist_idx  (cost=0.00..268.11 rows=23976 width=0) (actual time=1.179..1.179 rows=24294 loops=1)
                    Index Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
                    Buffers: shared hit=22
Planning:
  Buffers: shared hit=133
Planning Time: 0.460 ms
Execution Time: 25.426 ms
