Timing is on. INSERT 0 1 Time: 13.869 ms INSERT 0 1 Time: 4.424 ms INSERT 0 1 Time: 12.415 ms INSERT 0 100 Time: 21.993 ms INSERT 0 100 Time: 28.881 ms INSERT 0 90000 Time: 13459.359 ms (00:13.459) INSERT 0 10000 Time: 1345.306 ms (00:01.345) ANALYZE Time: 406.609 ms === dataset shape === research_messages | research_chats | largest_chat_messages | smallest_chat_messages -------------------+----------------+-----------------------+------------------------ 100000 | 101 | 90000 | 100 (1 row) Time: 266.713 ms === source integrity summary === count | first_message | last_message | text_bytes --------+----------------------------+--------------------------+------------ 100000 | 2026-02-01 00:00:00.001+00 | 2026-02-02 00:00:10.1+00 | 1697294 (1 row) Time: 75.790 ms === index A: production composite (chat_id, created_at, id) === QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.42..17.44 rows=50 width=73) (actual time=0.022..0.060 rows=50 loops=1) Buffers: shared hit=6 -> Index Scan using messages_chat_order_idx on messages (cost=0.42..5720.16 rows=16804 width=73) (actual time=0.020..0.048 rows=50 loops=1) Index Cond: ((chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb'::uuid) AND (ROW(created_at, id) > ROW('2026-02-01 00:01:20+00'::timestamp with time zone, '1b846638-5f59-3b99-00f4-160ef4a51437'::uuid))) Buffers: shared hit=6 Planning: Buffers: shared hit=6 Planning Time: 0.352 ms Execution Time: 0.128 ms (9 rows) Time: 1.572 ms === index B: chat_id-only alternative (temporary, rolled back) === BEGIN Time: 0.244 ms DROP INDEX Time: 19.803 ms CREATE INDEX Time: 223.602 ms ANALYZE Time: 342.025 ms QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=4006.30..4012.05 rows=50 width=73) (actual time=70.068..89.652 rows=50 loops=1) Buffers: shared hit=1525 -> Gather Merge (cost=4006.30..5145.03 rows=9902 width=73) (actual time=70.063..89.630 rows=50 loops=1) Workers Planned: 1 Workers Launched: 1 Buffers: shared hit=1525 -> Sort (cost=3006.29..3031.05 rows=9902 width=73) (actual time=42.016..42.177 rows=41 loops=2) Sort Key: created_at, id Sort Method: top-N heapsort Memory: 31kB Buffers: shared hit=1525 Worker 0: Sort Method: top-N heapsort Memory: 31kB -> Parallel Seq Scan on messages (cost=0.00..2677.35 rows=9902 width=73) (actual time=31.887..40.024 rows=5000 loops=2) Filter: ((chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb'::uuid) AND (ROW(created_at, id) > ROW('2026-02-01 00:01:20+00'::timestamp with time zone, '1b846638-5f59-3b99-00f4-160ef4a51437'::uuid))) Rows Removed by Filter: 51700 Buffers: shared hit=1510 Planning: Buffers: shared hit=20 read=1 Planning Time: 0.790 ms Execution Time: 89.728 ms (19 rows) Time: 92.602 ms ROLLBACK Time: 4.178 ms === backup === NOTICE: database "messenger_grade5_restore" does not exist, skipping === source integrity === 100000|2026-02-01 00:00:00.001+00|2026-02-02 00:00:10.1+00|1697294 === restored integrity === 100000|2026-02-01 00:00:00.001+00|2026-02-02 00:00:10.1+00|1697294