Files
mtusi2026lab5/evidence/bench/unit-of-work-after/explain-5k.txt
T
2026-11-01 00:34:03 +03:00

694 lines
38 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# План запроса истории: размер 5k
Commit 6ba74b1
Читаемый чат — 5000 сообщений; фоновые чаты: 2 × 1k, 10 × 100, 50 × 10.
Страница — `limit` профиля; «после» — сколько сообщений чата до
страницы.
## Планы приложения
auto_explain (ANALYZE, BUFFERS, TIMING): запрос, параметры и план,
с которыми его выполнило приложение (prepared statement asyncpg).
### read 5k: first, после 0
duration: 0.156 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID ORDER BY messages.created_at, messages.id
LIMIT $2::INTEGER
Query Parameters: $1 = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6', $2 = '51'
Limit (cost=0.29..11.48 rows=51 width=153) (actual time=0.045..0.114 rows=51.00 loops=1)
Buffers: shared hit=25
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..1097.45 rows=5000 width=153) (actual time=0.045..0.111 rows=51.00 loops=1)
Index Cond: (chat_id = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6'::uuid)
Index Searches: 1
Buffers: shared hit=25
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### read 5k: middle, после 2500
duration: 0.178 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID AND (messages.created_at, messages.id) > ($2::TIMESTAMP WITH TIME ZONE, $3::UUID) ORDER BY messages.created_at, messages.id
LIMIT $4::INTEGER
Query Parameters: $1 = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6', $2 = '2026-10-31 20:24:38.589912+00', $3 = '53146b82-aceb-4178-811a-86a646e422ce', $4 = '51'
Limit (cost=0.29..14.23 rows=4 width=153) (actual time=0.036..0.138 rows=51.00 loops=1)
Buffers: shared hit=53
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..157.21 rows=45 width=153) (actual time=0.034..0.134 rows=51.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=53
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### read 5k: last, после 4900
duration: 0.159 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID AND (messages.created_at, messages.id) > ($2::TIMESTAMP WITH TIME ZONE, $3::UUID) ORDER BY messages.created_at, messages.id
LIMIT $4::INTEGER
Query Parameters: $1 = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6', $2 = '2026-10-31 20:24:46.567187+00', $3 = '7bd2d45d-95d6-4adb-baaa-00598e6d08bc', $4 = '51'
Limit (cost=0.29..14.23 rows=4 width=153) (actual time=0.030..0.122 rows=51.00 loops=1)
Buffers: shared hit=50
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..157.21 rows=45 width=153) (actual time=0.029..0.119 rows=51.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=50
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### bg 1k: first, после 0
duration: 0.113 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID ORDER BY messages.created_at, messages.id
LIMIT $2::INTEGER
Query Parameters: $1 = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3', $2 = '51'
Limit (cost=0.29..39.26 rows=51 width=153) (actual time=0.021..0.082 rows=51.00 loops=1)
Buffers: shared hit=42
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..764.58 rows=1000 width=153) (actual time=0.020..0.079 rows=51.00 loops=1)
Index Cond: (chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid)
Index Searches: 1
Buffers: shared hit=42
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### bg 1k: middle, после 500
duration: 0.128 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID AND (messages.created_at, messages.id) > ($2::TIMESTAMP WITH TIME ZONE, $3::UUID) ORDER BY messages.created_at, messages.id
LIMIT $4::INTEGER
Query Parameters: $1 = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3', $2 = '2026-10-31 20:24:38.568925+00', $3 = 'f4606134-1824-43bd-a240-3ea3b55a63ec', $4 = '51'
Limit (cost=0.29..14.23 rows=4 width=153) (actual time=0.017..0.095 rows=51.00 loops=1)
Buffers: shared hit=46
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..157.21 rows=45 width=153) (actual time=0.016..0.092 rows=51.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=46
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### bg 1k: last, после 900
duration: 0.108 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID AND (messages.created_at, messages.id) > ($2::TIMESTAMP WITH TIME ZONE, $3::UUID) ORDER BY messages.created_at, messages.id
LIMIT $4::INTEGER
Query Parameters: $1 = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3', $2 = '2026-10-31 20:24:45.262628+00', $3 = '9f773982-da33-47e1-834f-64b654a77314', $4 = '51'
Limit (cost=0.29..14.23 rows=4 width=153) (actual time=0.013..0.085 rows=51.00 loops=1)
Buffers: shared hit=50
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..157.21 rows=45 width=153) (actual time=0.012..0.081 rows=51.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=50
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### bg 100: first, после 0
duration: 0.172 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID ORDER BY messages.created_at, messages.id
LIMIT $2::INTEGER
Query Parameters: $1 = 'fb160065-34cc-4298-8362-ba055cc9499f', $2 = '51'
Limit (cost=0.29..154.68 rows=51 width=153) (actual time=0.022..0.143 rows=51.00 loops=1)
Buffers: shared hit=51
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..303.03 rows=100 width=153) (actual time=0.021..0.140 rows=51.00 loops=1)
Index Cond: (chat_id = 'fb160065-34cc-4298-8362-ba055cc9499f'::uuid)
Index Searches: 1
Buffers: shared hit=51
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
### bg 10: first, после 0
duration: 0.052 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at, array((SELECT message_attachments.attachment_id
FROM message_attachments
WHERE message_attachments.message_id = messages.id ORDER BY message_attachments.position)) AS attachment_ids
FROM messages
WHERE messages.chat_id = $1::UUID ORDER BY messages.created_at, messages.id
LIMIT $2::INTEGER
Query Parameters: $1 = '3dcf3ed2-fde3-4c72-8da6-3d291584e568', $2 = '51'
Limit (cost=37.81..37.83 rows=10 width=153) (actual time=0.047..0.048 rows=10.00 loops=1)
Buffers: shared hit=12
-> Sort (cost=37.81..37.83 rows=10 width=153) (actual time=0.047..0.047 rows=10.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=12
-> Bitmap Heap Scan on messages (cost=4.36..37.64 rows=10 width=153) (actual time=0.021..0.042 rows=10.00 loops=1)
Recheck Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Heap Blocks: exact=10
Buffers: shared hit=12
-> Bitmap Index Scan on ix_messages_chat_id_created_at_id (cost=0.00..4.36 rows=10 width=0) (actual time=0.009..0.009 rows=10.00 loops=1)
Index Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Index Searches: 1
Buffers: shared hit=2
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=10)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Filter: (message_id = messages.id)
## Страницы сравнения в psql: варианты
Тот же текст запроса и те же параметры, что у плана приложения этой
страницы, в одной транзакции, которая откатывается: индексы базы
после неё те же. Каждый вариант выполнен дважды, здесь — второе
выполнение. `psql` — индекс приложения, custom plan; `generic` — он
же с force_generic_plan; `or-cursor` — условие курсора через OR;
`no-index` — без индекса приложения; варианты индекса вместо него:
`chat_only` (chat_id), `covering` (chat_id, created_at, id) INCLUDE (sender_id, text).
### read 5k: middle, после 2500
#### psql
Limit (cost=0.29..18.53 rows=51 width=153) (actual time=0.010..0.056 rows=51.00 loops=1)
Buffers: shared hit=53
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..894.15 rows=2499 width=153) (actual time=0.010..0.053 rows=51.00 loops=1)
Index Cond: ((chat_id = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.589912+00'::timestamp with time zone, '53146b82-aceb-4178-811a-86a646e422ce'::uuid)))
Index Searches: 1
Buffers: shared hit=53
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.063 ms
Execution Time: 0.065 ms
#### generic
Limit (cost=0.29..14.23 rows=4 width=153) (actual time=0.019..0.064 rows=51.00 loops=1)
Buffers: shared hit=53
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..157.21 rows=45 width=153) (actual time=0.018..0.062 rows=51.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=53
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning Time: 0.010 ms
Execution Time: 0.077 ms
#### or-cursor
Limit (cost=0.29..22.67 rows=51 width=153) (actual time=0.322..0.374 rows=51.00 loops=1)
Buffers: shared hit=2365
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..1097.45 rows=2500 width=153) (actual time=0.322..0.371 rows=51.00 loops=1)
Index Cond: (chat_id = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6'::uuid)
Filter: ((created_at > '2026-10-31 20:24:38.589912+00'::timestamp with time zone) OR ((created_at = '2026-10-31 20:24:38.589912+00'::timestamp with time zone) AND (id > '53146b82-aceb-4178-811a-86a646e422ce'::uuid)))
Rows Removed by Filter: 2500
Index Searches: 1
Buffers: shared hit=2365
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.052 ms
Execution Time: 0.380 ms
#### no-index
Limit (cost=453.61..453.73 rows=51 width=153) (actual time=2.113..2.117 rows=51.00 loops=1)
Buffers: shared hit=184
-> Sort (cost=453.61..459.85 rows=2499 width=153) (actual time=2.113..2.114 rows=51.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: top-N heapsort Memory: 44kB
Buffers: shared hit=184
-> Seq Scan on messages (cost=0.00..370.24 rows=2499 width=153) (actual time=0.154..1.813 rows=2500.00 loops=1)
Filter: ((chat_id = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.589912+00'::timestamp with time zone, '53146b82-aceb-4178-811a-86a646e422ce'::uuid)))
Rows Removed by Filter: 6000
Buffers: shared hit=184
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=2500)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=2500)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.038 ms
Execution Time: 2.122 ms
#### chat_only
Limit (cost=453.61..453.73 rows=51 width=153) (actual time=2.113..2.117 rows=51.00 loops=1)
Buffers: shared hit=184
-> Sort (cost=453.61..459.85 rows=2499 width=153) (actual time=2.113..2.115 rows=51.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: top-N heapsort Memory: 44kB
Buffers: shared hit=184
-> Seq Scan on messages (cost=0.00..370.24 rows=2499 width=153) (actual time=0.180..1.802 rows=2500.00 loops=1)
Filter: ((chat_id = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.589912+00'::timestamp with time zone, '53146b82-aceb-4178-811a-86a646e422ce'::uuid)))
Rows Removed by Filter: 6000
Buffers: shared hit=184
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=2500)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=2500)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.048 ms
Execution Time: 2.124 ms
#### covering
Limit (cost=0.41..6.28 rows=51 width=153) (actual time=0.006..0.046 rows=51.00 loops=1)
Buffers: shared hit=5
-> Index Only Scan using bench_variant on messages (cost=0.41..287.88 rows=2499 width=153) (actual time=0.006..0.043 rows=51.00 loops=1)
Index Cond: ((chat_id = 'e12c9819-0da8-4ba6-83cf-a8f7e1be48b6'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.589912+00'::timestamp with time zone, '53146b82-aceb-4178-811a-86a646e422ce'::uuid)))
Heap Fetches: 0
Index Searches: 1
Buffers: shared hit=5
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.041 ms
Execution Time: 0.053 ms
### bg 1k: middle, после 500
#### psql
Limit (cost=0.29..74.03 rows=51 width=153) (actual time=0.011..0.053 rows=51.00 loops=1)
Buffers: shared hit=46
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..724.74 rows=501 width=153) (actual time=0.011..0.050 rows=51.00 loops=1)
Index Cond: ((chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.568925+00'::timestamp with time zone, 'f4606134-1824-43bd-a240-3ea3b55a63ec'::uuid)))
Index Searches: 1
Buffers: shared hit=46
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.072 ms
Execution Time: 0.064 ms
#### generic
Limit (cost=0.29..14.23 rows=4 width=153) (actual time=0.009..0.057 rows=51.00 loops=1)
Buffers: shared hit=46
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..157.21 rows=45 width=153) (actual time=0.009..0.054 rows=51.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=46
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning Time: 0.005 ms
Execution Time: 0.064 ms
#### or-cursor
Limit (cost=0.29..78.09 rows=51 width=153) (actual time=0.073..0.109 rows=51.00 loops=1)
Buffers: shared hit=498
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..764.59 rows=501 width=153) (actual time=0.073..0.107 rows=51.00 loops=1)
Index Cond: (chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid)
Filter: ((created_at > '2026-10-31 20:24:38.568925+00'::timestamp with time zone) OR ((created_at = '2026-10-31 20:24:38.568925+00'::timestamp with time zone) AND (id > 'f4606134-1824-43bd-a240-3ea3b55a63ec'::uuid)))
Rows Removed by Filter: 500
Index Searches: 1
Buffers: shared hit=498
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.049 ms
Execution Time: 0.114 ms
#### no-index
Limit (cost=356.98..357.11 rows=51 width=153) (actual time=0.560..0.563 rows=51.00 loops=1)
Buffers: shared hit=184
-> Sort (cost=356.98..358.23 rows=501 width=153) (actual time=0.559..0.561 rows=51.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: top-N heapsort Memory: 39kB
Buffers: shared hit=184
-> Seq Scan on messages (cost=0.00..340.26 rows=501 width=153) (actual time=0.127..0.499 rows=500.00 loops=1)
Filter: ((chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.568925+00'::timestamp with time zone, 'f4606134-1824-43bd-a240-3ea3b55a63ec'::uuid)))
Rows Removed by Filter: 8000
Buffers: shared hit=184
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=500)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=500)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.040 ms
Execution Time: 0.568 ms
#### chat_only
Limit (cost=241.64..241.77 rows=51 width=153) (actual time=0.425..0.428 rows=51.00 loops=1)
Buffers: shared hit=186
-> Sort (cost=241.64..242.89 rows=501 width=153) (actual time=0.424..0.426 rows=51.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: top-N heapsort Memory: 39kB
Buffers: shared hit=186
-> Bitmap Heap Scan on messages (cost=15.91..224.93 rows=501 width=153) (actual time=0.078..0.374 rows=500.00 loops=1)
Recheck Cond: (chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid)
Filter: (ROW(created_at, id) > ROW('2026-10-31 20:24:38.568925+00'::timestamp with time zone, 'f4606134-1824-43bd-a240-3ea3b55a63ec'::uuid))
Rows Removed by Filter: 500
Heap Blocks: exact=184
Buffers: shared hit=186
-> Bitmap Index Scan on bench_variant (cost=0.00..15.79 rows=1000 width=0) (actual time=0.017..0.018 rows=1000.00 loops=1)
Index Cond: (chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid)
Index Searches: 1
Buffers: shared hit=2
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=500)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=500)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.047 ms
Execution Time: 0.435 ms
#### covering
Limit (cost=0.41..6.27 rows=51 width=153) (actual time=0.007..0.043 rows=51.00 loops=1)
Buffers: shared hit=5
-> Index Only Scan using bench_variant on messages (cost=0.41..57.94 rows=501 width=153) (actual time=0.006..0.041 rows=51.00 loops=1)
Index Cond: ((chat_id = '296f4cbe-97a0-4dfe-a14b-2c3b1a4440a3'::uuid) AND (ROW(created_at, id) > ROW('2026-10-31 20:24:38.568925+00'::timestamp with time zone, 'f4606134-1824-43bd-a240-3ea3b55a63ec'::uuid)))
Heap Fetches: 0
Index Searches: 1
Buffers: shared hit=5
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.066 ms
Execution Time: 0.053 ms
### bg 100: first, после 0
#### psql
Limit (cost=0.29..154.68 rows=51 width=153) (actual time=0.007..0.055 rows=51.00 loops=1)
Buffers: shared hit=51
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..303.03 rows=100 width=153) (actual time=0.007..0.052 rows=51.00 loops=1)
Index Cond: (chat_id = 'fb160065-34cc-4298-8362-ba055cc9499f'::uuid)
Index Searches: 1
Buffers: shared hit=51
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.040 ms
Execution Time: 0.061 ms
#### generic
Limit (cost=0.29..39.44 rows=14 width=153) (actual time=0.011..0.057 rows=51.00 loops=1)
Buffers: shared hit=51
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..377.84 rows=135 width=153) (actual time=0.010..0.055 rows=51.00 loops=1)
Index Cond: (chat_id = $1)
Index Searches: 1
Buffers: shared hit=51
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.001 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning Time: 0.003 ms
Execution Time: 0.063 ms
#### no-index
Limit (cost=295.07..295.20 rows=51 width=153) (actual time=0.264..0.267 rows=51.00 loops=1)
Buffers: shared hit=184
-> Sort (cost=295.07..295.32 rows=100 width=153) (actual time=0.263..0.265 rows=51.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: quicksort Memory: 50kB
Buffers: shared hit=184
-> Seq Scan on messages (cost=0.00..291.75 rows=100 width=153) (actual time=0.007..0.248 rows=100.00 loops=1)
Filter: (chat_id = 'fb160065-34cc-4298-8362-ba055cc9499f'::uuid)
Rows Removed by Filter: 8400
Buffers: shared hit=184
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=100)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=100)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.038 ms
Execution Time: 0.273 ms
#### chat_only
Limit (cost=171.84..171.97 rows=51 width=153) (actual time=0.117..0.120 rows=51.00 loops=1)
Buffers: shared hit=84
-> Sort (cost=171.84..172.09 rows=100 width=153) (actual time=0.116..0.118 rows=51.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: quicksort Memory: 50kB
Buffers: shared hit=84
-> Bitmap Heap Scan on messages (cost=5.06..168.52 rows=100 width=153) (actual time=0.014..0.102 rows=100.00 loops=1)
Recheck Cond: (chat_id = 'fb160065-34cc-4298-8362-ba055cc9499f'::uuid)
Heap Blocks: exact=82
Buffers: shared hit=84
-> Bitmap Index Scan on bench_variant (cost=0.00..5.04 rows=100 width=0) (actual time=0.005..0.005 rows=100.00 loops=1)
Index Cond: (chat_id = 'fb160065-34cc-4298-8362-ba055cc9499f'::uuid)
Index Searches: 1
Buffers: shared hit=2
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=100)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=100)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.051 ms
Execution Time: 0.129 ms
#### covering
Limit (cost=0.41..6.15 rows=51 width=153) (actual time=0.005..0.041 rows=51.00 loops=1)
Buffers: shared hit=5
-> Index Only Scan using bench_variant on messages (cost=0.41..11.66 rows=100 width=153) (actual time=0.005..0.039 rows=51.00 loops=1)
Index Cond: (chat_id = 'fb160065-34cc-4298-8362-ba055cc9499f'::uuid)
Heap Fetches: 0
Index Searches: 1
Buffers: shared hit=5
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=51)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.046 ms
Execution Time: 0.048 ms
### bg 10: first, после 0
#### psql
Limit (cost=37.81..37.83 rows=10 width=153) (actual time=0.020..0.021 rows=10.00 loops=1)
Buffers: shared hit=12
-> Sort (cost=37.81..37.83 rows=10 width=153) (actual time=0.020..0.020 rows=10.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=12
-> Bitmap Heap Scan on messages (cost=4.36..37.64 rows=10 width=153) (actual time=0.009..0.018 rows=10.00 loops=1)
Recheck Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Heap Blocks: exact=10
Buffers: shared hit=12
-> Bitmap Index Scan on ix_messages_chat_id_created_at_id (cost=0.00..4.36 rows=10 width=0) (actual time=0.004..0.004 rows=10.00 loops=1)
Index Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Index Searches: 1
Buffers: shared hit=2
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.040 ms
Execution Time: 0.030 ms
#### generic
Limit (cost=0.29..39.44 rows=14 width=153) (actual time=0.009..0.020 rows=10.00 loops=1)
Buffers: shared hit=12
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.29..377.84 rows=135 width=153) (actual time=0.008..0.019 rows=10.00 loops=1)
Index Cond: (chat_id = $1)
Index Searches: 1
Buffers: shared hit=12
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=10)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Filter: (message_id = messages.id)
Planning Time: 0.003 ms
Execution Time: 0.024 ms
#### no-index
Limit (cost=290.57..290.59 rows=10 width=153) (actual time=0.197..0.198 rows=10.00 loops=1)
Buffers: shared hit=184
-> Sort (cost=290.57..290.59 rows=10 width=153) (actual time=0.197..0.197 rows=10.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=184
-> Seq Scan on messages (cost=0.00..290.40 rows=10 width=153) (actual time=0.009..0.194 rows=10.00 loops=1)
Filter: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Rows Removed by Filter: 8490
Buffers: shared hit=184
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=10)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.035 ms
Execution Time: 0.202 ms
#### chat_only
Limit (cost=37.81..37.83 rows=10 width=153) (actual time=0.015..0.017 rows=10.00 loops=1)
Buffers: shared hit=12
-> Sort (cost=37.81..37.83 rows=10 width=153) (actual time=0.015..0.016 rows=10.00 loops=1)
Sort Key: messages.created_at, messages.id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=12
-> Bitmap Heap Scan on messages (cost=4.36..37.64 rows=10 width=153) (actual time=0.005..0.014 rows=10.00 loops=1)
Recheck Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Heap Blocks: exact=10
Buffers: shared hit=12
-> Bitmap Index Scan on bench_variant (cost=0.00..4.36 rows=10 width=0) (actual time=0.002..0.002 rows=10.00 loops=1)
Index Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Index Searches: 1
Buffers: shared hit=2
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.036 ms
Execution Time: 0.022 ms
#### covering
Limit (cost=0.41..4.74 rows=10 width=153) (actual time=0.005..0.013 rows=10.00 loops=1)
Buffers: shared hit=4
-> Index Only Scan using bench_variant on messages (cost=0.41..4.74 rows=10 width=153) (actual time=0.005..0.012 rows=10.00 loops=1)
Index Cond: (chat_id = '3dcf3ed2-fde3-4c72-8da6-3d291584e568'::uuid)
Heap Fetches: 0
Index Searches: 1
Buffers: shared hit=4
SubPlan 1
-> Sort (cost=0.01..0.02 rows=1 width=18) (actual time=0.001..0.001 rows=0.00 loops=10)
Sort Key: message_attachments."position"
Sort Method: quicksort Memory: 25kB
-> Seq Scan on message_attachments (cost=0.00..0.00 rows=1 width=18) (actual time=0.000..0.000 rows=0.00 loops=10)
Filter: (message_id = messages.id)
Planning:
Buffers: shared hit=3
Planning Time: 0.037 ms
Execution Time: 0.019 ms