--- Q1 первая страница большого чата (80 000), keyset QUERY PLAN -------------------------------------------------------------------------------------- Limit (actual rows=51 loops=1) Buffers: shared hit=1930 -> Gather Merge (actual rows=51 loops=1) Workers Planned: 1 Workers Launched: 1 Buffers: shared hit=1930 -> Sort (actual rows=40 loops=2) Sort Key: messages.created_at, messages.id Sort Method: top-N heapsort Memory: 36kB Buffers: shared hit=1930 Worker 0: Sort Method: top-N heapsort Memory: 36kB -> Parallel Seq Scan on messages (actual rows=40000 loops=2) Filter: (chat_id = '60e7163e-605c-470b-81c0-820c332cfec7'::uuid) Rows Removed by Filter: 17500 Buffers: shared hit=1886 Planning: Buffers: shared hit=133 Planning Time: 0.474 ms Execution Time: 14.564 ms (19 rows) --- Q2 страница из середины большого чата, keyset QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (actual rows=51 loops=1) Buffers: shared hit=1901 -> Gather Merge (actual rows=51 loops=1) Workers Planned: 1 Workers Launched: 1 Buffers: shared hit=1901 -> Sort (actual rows=40 loops=2) Sort Key: messages.created_at, messages.id Sort Method: top-N heapsort Memory: 35kB Buffers: shared hit=1901 Worker 0: Sort Method: top-N heapsort Memory: 36kB -> Parallel Seq Scan on messages (actual rows=20008 loops=2) Filter: ((chat_id = '60e7163e-605c-470b-81c0-820c332cfec7'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 11:06:24+00'::timestamp with time zone, '3126d0c5-166f-481e-96bf-c950463908dc'::uuid))) Rows Removed by Filter: 37492 Buffers: shared hit=1886 Planning Time: 0.081 ms Execution Time: 12.118 ms (17 rows) --- Q3 последняя страница большого чата, keyset QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (actual rows=32 loops=1) Buffers: shared hit=1886 -> Sort (actual rows=32 loops=1) Sort Key: messages.created_at, messages.id Sort Method: quicksort Memory: 29kB Buffers: shared hit=1886 -> Seq Scan on messages (actual rows=32 loops=1) Filter: ((chat_id = '60e7163e-605c-470b-81c0-820c332cfec7'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 22:12:48+00'::timestamp with time zone, 'c8a497c3-78fd-44f5-8bc7-3abcc4d06d1d'::uuid))) Rows Removed by Filter: 114968 Buffers: shared hit=1886 Planning Time: 0.162 ms Execution Time: 10.543 ms (12 rows) --- Q4 маленький чат (5 сообщений) QUERY PLAN ------------------------------------------------------------------------------------------------ Limit (actual rows=5 loops=1) Buffers: shared hit=7 -> Sort (actual rows=5 loops=1) Sort Key: messages.created_at, messages.id Sort Method: quicksort Memory: 25kB Buffers: shared hit=7 -> Index Scan using ix_messages_chat_id_sender_id on messages (actual rows=5 loops=1) Index Cond: (chat_id = 'a7223743-6f48-4880-9b67-0e0cc8635177'::uuid) Buffers: shared hit=7 Planning Time: 0.080 ms Execution Time: 0.036 ms (11 rows) --- Q5 середина большого чата, OFFSET 40000 (для сравнения с keyset) QUERY PLAN -------------------------------------------------------------------------------- Limit (actual rows=51 loops=1) Buffers: shared hit=1886, temp read=782 written=1109 -> Sort (actual rows=40051 loops=1) Sort Key: created_at, id Sort Method: external merge Disk: 8848kB Buffers: shared hit=1886, temp read=782 written=1109 -> Seq Scan on messages m (actual rows=80000 loops=1) Filter: (chat_id = '60e7163e-605c-470b-81c0-820c332cfec7'::uuid) Rows Removed by Filter: 35000 Buffers: shared hit=1886 Planning Time: 0.040 ms Execution Time: 50.742 ms (12 rows)