date=2026-10-15T21:41:08Z
chat_id=a9b8867c-4828-4847-ab1d-39f3cd4dcdbb
count=10001

=== keyset with index messages_history_idx ===
                                                                                                          QUERY PLAN                                                                                                          
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=46.77..46.81 rows=14 width=88) (actual time=3.557..3.567 rows=50 loops=1)
   Buffers: shared hit=258
   ->  Sort  (cost=46.77..46.81 rows=14 width=88) (actual time=3.556..3.560 rows=50 loops=1)
         Sort Key: created_at, id
         Sort Method: top-N heapsort  Memory: 31kB
         Buffers: shared hit=258
         ->  Bitmap Heap Scan on messages  (cost=4.43..46.50 rows=14 width=88) (actual time=1.233..2.307 rows=10001 loops=1)
               Recheck Cond: ((chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid) AND (ROW(created_at, id) > ROW('1970-01-01 00:00:00+00'::timestamp with time zone, '00000000-0000-4000-8000-000000000000'::uuid)))
               Heap Blocks: exact=123
               Buffers: shared hit=252
               ->  Bitmap Index Scan on messages_history_idx  (cost=0.00..4.42 rows=14 width=0) (actual time=1.194..1.195 rows=10001 loops=1)
                     Index Cond: ((chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid) AND (ROW(created_at, id) > ROW('1970-01-01 00:00:00+00'::timestamp with time zone, '00000000-0000-4000-8000-000000000000'::uuid)))
                     Buffers: shared hit=129
 Planning:
   Buffers: shared hit=101
 Planning Time: 1.515 ms
 Execution Time: 3.739 ms
(17 rows)


=== OFFSET page ~200 (full scan risk) ===
                                                                  QUERY PLAN                                                                  
----------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=93.55..93.55 rows=1 width=88) (actual time=5.617..5.627 rows=50 loops=1)
   Buffers: shared hit=258
   ->  Sort  (cost=93.44..93.55 rows=43 width=88) (actual time=5.054..5.347 rows=5050 loops=1)
         Sort Key: created_at, id
         Sort Method: quicksort  Memory: 1713kB
         Buffers: shared hit=258
         ->  Bitmap Heap Scan on messages  (cost=4.62..92.28 rows=43 width=88) (actual time=0.847..2.033 rows=10001 loops=1)
               Recheck Cond: (chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid)
               Heap Blocks: exact=123
               Buffers: shared hit=252
               ->  Bitmap Index Scan on messages_history_idx  (cost=0.00..4.61 rows=43 width=0) (actual time=0.818..0.818 rows=10001 loops=1)
                     Index Cond: (chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid)
                     Buffers: shared hit=129
 Planning:
   Buffers: shared hit=102
 Planning Time: 1.926 ms
 Execution Time: 5.951 ms
(17 rows)

