Files
mtusi2026lab2/evidence/bench/t2-chat-only/explain-small-200.txt
T

129 lines
6.7 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.
# План запроса истории: класс small, чат 200
Код: src_sha256 8a7e256c540af433, commit fee6f77c3bf1; вариант индекса: chat-only
Страница истории читаемого чата (limit 50); позиция — сколько
сообщений истории до страницы:
- first: после 0
- middle: после 100
- last: после 150
## Планы приложения
auto_explain (ANALYZE, BUFFERS, TIMING): запрос, параметры и план,
с которыми его выполнило приложение (prepared statement asyncpg).
### first
duration: 0.185 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at
FROM messages
WHERE messages.chat_id = $1::UUID ORDER BY messages.created_at, messages.id
LIMIT $2::INTEGER
Query Parameters: $1 = '315fcfd5-602f-4e19-9eed-7ef8aecfd977', $2 = '51'
Limit (cost=69.39..69.43 rows=17 width=204) (actual time=0.159..0.163 rows=51.00 loops=1)
Buffers: shared hit=196
-> Sort (cost=69.39..69.43 rows=17 width=204) (actual time=0.159..0.161 rows=51.00 loops=1)
Sort Key: created_at, id
Sort Method: top-N heapsort Memory: 38kB
Buffers: shared hit=196
-> Index Scan using ix_messages_chat_id on messages (cost=0.29..69.04 rows=17 width=204) (actual time=0.009..0.138 rows=200.00 loops=1)
Index Cond: (chat_id = '315fcfd5-602f-4e19-9eed-7ef8aecfd977'::uuid)
Index Searches: 1
Buffers: shared hit=196
### middle
duration: 0.123 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at
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 = '315fcfd5-602f-4e19-9eed-7ef8aecfd977', $2 = '2026-10-02 01:37:17.328707+00', $3 = 'e0231ec3-1679-447a-9562-85fff07474e7', $4 = '51'
Limit (cost=603.27..603.29 rows=6 width=204) (actual time=0.101..0.104 rows=51.00 loops=1)
Buffers: shared hit=196
-> Sort (cost=603.27..603.42 rows=60 width=204) (actual time=0.100..0.101 rows=51.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 50kB
Buffers: shared hit=196
-> Bitmap Heap Scan on messages (cost=5.67..601.50 rows=60 width=204) (actual time=0.041..0.090 rows=100.00 loops=1)
Recheck Cond: (chat_id = $1)
Filter: (ROW(created_at, id) > ROW($2, $3))
Rows Removed by Filter: 100
Heap Blocks: exact=194
Buffers: shared hit=196
-> Bitmap Index Scan on ix_messages_chat_id (cost=0.00..5.65 rows=181 width=0) (actual time=0.008..0.008 rows=200.00 loops=1)
Index Cond: (chat_id = $1)
Index Searches: 1
Buffers: shared hit=2
### last
duration: 0.107 ms plan:
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at
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 = '315fcfd5-602f-4e19-9eed-7ef8aecfd977', $2 = '2026-10-02 01:37:44.586195+00', $3 = '2e888f4e-3252-4ce9-9c5d-4de795337863', $4 = '51'
Limit (cost=603.27..603.29 rows=6 width=204) (actual time=0.084..0.087 rows=50.00 loops=1)
Buffers: shared hit=196
-> Sort (cost=603.27..603.42 rows=60 width=204) (actual time=0.083..0.085 rows=50.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 37kB
Buffers: shared hit=196
-> Bitmap Heap Scan on messages (cost=5.67..601.50 rows=60 width=204) (actual time=0.063..0.078 rows=50.00 loops=1)
Recheck Cond: (chat_id = $1)
Filter: (ROW(created_at, id) > ROW($2, $3))
Rows Removed by Filter: 150
Heap Blocks: exact=194
Buffers: shared hit=196
-> Bitmap Index Scan on ix_messages_chat_id (cost=0.00..5.65 rows=181 width=0) (actual time=0.008..0.008 rows=200.00 loops=1)
Index Cond: (chat_id = $1)
Index Searches: 1
Buffers: shared hit=2
## Страница middle в psql: с индексом и без
Тот же текст запроса и те же параметры, что у плана middle.
psql планирует их заново (custom plan). DROP INDEX — внутри
транзакции, затем ROLLBACK: индекс остаётся в базе.
### С индексом ix_messages_chat_id
Limit (cost=69.23..69.24 rows=7 width=204) (actual time=0.834..0.841 rows=51.00 loops=1)
Buffers: shared hit=202
-> Sort (cost=69.23..69.24 rows=7 width=204) (actual time=0.833..0.835 rows=51.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 50kB
Buffers: shared hit=202
-> Index Scan using ix_messages_chat_id on messages (cost=0.29..69.13 rows=7 width=204) (actual time=0.268..0.801 rows=100.00 loops=1)
Index Cond: (chat_id = '315fcfd5-602f-4e19-9eed-7ef8aecfd977'::uuid)
Filter: (ROW(created_at, id) > ROW('2026-10-02 01:37:17.328707+00'::timestamp with time zone, 'e0231ec3-1679-447a-9562-85fff07474e7'::uuid))
Rows Removed by Filter: 100
Index Searches: 1
Buffers: shared hit=196
Planning:
Buffers: shared hit=130
Planning Time: 0.404 ms
Execution Time: 0.882 ms
### Без индекса ix_messages_chat_id
Limit (cost=5671.55..5671.57 rows=7 width=204) (actual time=4.897..5.953 rows=51.00 loops=1)
Buffers: shared hit=3752
-> Sort (cost=5671.55..5671.57 rows=7 width=204) (actual time=4.897..5.949 rows=51.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 50kB
Buffers: shared hit=3752
-> Gather (cost=1000.00..5671.45 rows=7 width=204) (actual time=2.792..5.922 rows=100.00 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=3752
-> Parallel Seq Scan on messages (cost=0.00..4670.75 rows=3 width=204) (actual time=1.963..3.612 rows=33.33 loops=3)
Filter: ((chat_id = '315fcfd5-602f-4e19-9eed-7ef8aecfd977'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 01:37:17.328707+00'::timestamp with time zone, 'e0231ec3-1679-447a-9562-85fff07474e7'::uuid)))
Rows Removed by Filter: 41967
Buffers: shared hit=3752
Planning:
Buffers: shared hit=17
Planning Time: 0.161 ms
Execution Time: 5.966 ms