=== no_indexes / first_page ===
Indexes: (none)
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be",51]

Limit  (cost=4027.78..4027.90 rows=51 width=316) (actual time=17.915..17.960 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=4027.78..4077.89 rows=20046 width=316) (actual time=17.913..17.953 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 52kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3359.00 rows=20046 width=316) (actual time=0.015..11.329 rows=20000 loops=1)
              Filter: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)
              Rows Removed by Filter: 40000
              Buffers: shared hit=2609
Planning Time: 0.082 ms
Execution Time: 17.989 ms

=== no_indexes / middle_page_or ===
Indexes: (none)
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid
  AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:16:39.000Z","f47542f1-8089-6114-80cd-9f75fcae23e0",51]

Limit  (cost=3922.40..3922.53 rows=51 width=316) (actual time=18.519..18.529 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=3922.40..3930.90 rows=3399 width=316) (actual time=18.517..18.521 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 51kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3809.00 rows=3399 width=316) (actual time=6.148..13.726 rows=10000 loops=1)
              Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))
              Rows Removed by Filter: 50000
              Buffers: shared hit=2609
Planning Time: 0.112 ms
Execution Time: 18.559 ms

=== no_indexes / late_page_or ===
Indexes: (none)
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid
  AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51]

Limit  (cost=3831.45..3831.58 rows=51 width=316) (actual time=16.897..16.908 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=3831.45..3833.14 rows=673 width=316) (actual time=16.895..16.900 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 51kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3809.00 rows=673 width=316) (actual time=15.036..16.370 rows=2000 loops=1)
              Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))
              Rows Removed by Filter: 58000
              Buffers: shared hit=2609
Planning Time: 0.114 ms
Execution Time: 16.993 ms

=== no_indexes / late_page_tuple ===
Indexes: (none)
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid)
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51]

Limit  (cost=3681.45..3681.58 rows=51 width=316) (actual time=21.195..21.205 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=3681.45..3683.14 rows=673 width=316) (actual time=21.194..21.198 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 51kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3659.00 rows=673 width=316) (actual time=13.066..16.387 rows=2000 loops=1)
              Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))
              Rows Removed by Filter: 58000
              Buffers: shared hit=2609
Planning Time: 0.163 ms
Execution Time: 21.242 ms

=== without_history_index / first_page ===
Indexes: messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be",51]

Limit  (cost=4025.31..4025.44 rows=51 width=316) (actual time=39.169..39.182 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=4025.31..4075.24 rows=19972 width=316) (actual time=39.167..39.174 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 52kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3359.00 rows=19972 width=316) (actual time=0.017..30.929 rows=20000 loops=1)
              Filter: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)
              Rows Removed by Filter: 40000
              Buffers: shared hit=2609
Planning Time: 0.104 ms
Execution Time: 39.214 ms

=== without_history_index / middle_page_or ===
Indexes: messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid
  AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:16:39.000Z","f47542f1-8089-6114-80cd-9f75fcae23e0",51]

Limit  (cost=3922.20..3922.33 rows=51 width=316) (actual time=22.514..22.524 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=3922.20..3930.68 rows=3393 width=316) (actual time=22.512..22.517 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 51kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3809.00 rows=3393 width=316) (actual time=7.398..15.354 rows=10000 loops=1)
              Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))
              Rows Removed by Filter: 50000
              Buffers: shared hit=2609
Planning Time: 0.168 ms
Execution Time: 22.562 ms

=== without_history_index / late_page_or ===
Indexes: messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid
  AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51]

Limit  (cost=3831.75..3831.88 rows=51 width=316) (actual time=13.129..13.138 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=3831.75..3833.46 rows=682 width=316) (actual time=13.127..13.131 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 51kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3809.00 rows=682 width=316) (actual time=10.949..12.462 rows=2000 loops=1)
              Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))
              Rows Removed by Filter: 58000
              Buffers: shared hit=2609
Planning:
  Buffers: shared hit=4
Planning Time: 0.170 ms
Execution Time: 13.163 ms

=== without_history_index / late_page_tuple ===
Indexes: messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid)
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51]

Limit  (cost=3681.75..3681.88 rows=51 width=316) (actual time=18.320..18.331 rows=51 loops=1)
  Buffers: shared hit=2609
  ->  Sort  (cost=3681.75..3683.46 rows=682 width=316) (actual time=18.318..18.323 rows=51 loops=1)
        Sort Key: created_at, id
        Sort Method: top-N heapsort  Memory: 51kB
        Buffers: shared hit=2609
        ->  Seq Scan on messages  (cost=0.00..3659.00 rows=682 width=316) (actual time=14.704..16.910 rows=2000 loops=1)
              Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))
              Rows Removed by Filter: 58000
              Buffers: shared hit=2609
Planning Time: 0.169 ms
Execution Time: 18.368 ms

=== with_history_index / first_page ===
Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be",51]

Limit  (cost=0.41..28.95 rows=51 width=316) (actual time=0.024..0.060 rows=51 loops=1)
  Buffers: shared hit=31
  ->  Index Scan using messages_chat_id_created_at_id_idx on messages  (cost=0.41..11101.66 rows=19840 width=316) (actual time=0.022..0.054 rows=51 loops=1)
        Index Cond: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)
        Buffers: shared hit=31
Planning Time: 0.100 ms
Execution Time: 0.081 ms

=== with_history_index / middle_page_or ===
Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid
  AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:16:39.000Z","f47542f1-8089-6114-80cd-9f75fcae23e0",51]

Limit  (cost=0.41..172.25 rows=51 width=316) (actual time=6.295..6.365 rows=51 loops=1)
  Buffers: shared hit=5203
  ->  Index Scan using messages_chat_id_created_at_id_idx on messages  (cost=0.41..11250.46 rows=3339 width=316) (actual time=6.293..6.355 rows=51 loops=1)
        Index Cond: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)
        Filter: ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))
        Rows Removed by Filter: 10000
        Buffers: shared hit=5203
Planning Time: 0.136 ms
Execution Time: 6.397 ms

=== with_history_index / late_page_or ===
Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid
  AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51]

Limit  (cost=0.41..905.39 rows=51 width=316) (actual time=15.793..15.831 rows=51 loops=1)
  Buffers: shared hit=9355
  ->  Index Scan using messages_chat_id_created_at_id_idx on messages  (cost=0.41..11250.46 rows=634 width=316) (actual time=15.791..15.822 rows=51 loops=1)
        Index Cond: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)
        Filter: ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))
        Rows Removed by Filter: 18000
        Buffers: shared hit=9355
Planning:
  Buffers: shared hit=4
Planning Time: 0.194 ms
Execution Time: 16.039 ms

=== with_history_index / late_page_tuple ===
Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx
SQL:
SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages"
WHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid)
ORDER BY created_at ASC, id ASC LIMIT $4
Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51]

Limit  (cost=0.41..180.32 rows=51 width=316) (actual time=0.029..0.066 rows=51 loops=1)
  Buffers: shared hit=29
  ->  Index Scan using messages_chat_id_created_at_id_idx on messages  (cost=0.41..2236.91 rows=634 width=316) (actual time=0.028..0.059 rows=51 loops=1)
        Index Cond: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))
        Buffers: shared hit=29
Planning Time: 0.132 ms
Execution Time: 0.090 ms
