Files
mtusi2026lab2/evidence/bench/t2-keyset-2/explain-tiny-10.txt
T

79 lines
3.9 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.
# План запроса истории: класс tiny, чат 10
Код: src_sha256 8a7e256c540af433, commit 8e7d4183e32c; вариант индекса: keyset
Страница истории читаемого чата (limit 50); позиция — сколько
сообщений истории до страницы:
- first: после 0
## Планы приложения
auto_explain (ANALYZE, BUFFERS, TIMING): запрос, параметры и план,
с которыми его выполнило приложение (prepared statement asyncpg).
### first
duration: 0.048 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 = '65fe5cdf-444f-4ee9-aaa1-210aed8d75cd', $2 = '51'
Limit (cost=73.42..73.47 rows=18 width=204) (actual time=0.044..0.045 rows=10.00 loops=1)
Buffers: shared hit=19
-> Sort (cost=73.42..73.47 rows=18 width=204) (actual time=0.043..0.044 rows=10.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=19
-> Bitmap Heap Scan on messages (cost=4.56..73.05 rows=18 width=204) (actual time=0.010..0.017 rows=10.00 loops=1)
Recheck Cond: (chat_id = '65fe5cdf-444f-4ee9-aaa1-210aed8d75cd'::uuid)
Heap Blocks: exact=10
Buffers: shared hit=13
-> Bitmap Index Scan on ix_messages_chat_id_created_at_id (cost=0.00..4.55 rows=18 width=0) (actual time=0.005..0.005 rows=10.00 loops=1)
Index Cond: (chat_id = '65fe5cdf-444f-4ee9-aaa1-210aed8d75cd'::uuid)
Index Searches: 1
Buffers: shared hit=3
## Страница first в psql: с индексом и без
Тот же текст запроса и те же параметры, что у плана first.
psql планирует их заново (custom plan). DROP INDEX — внутри
транзакции, затем ROLLBACK: индекс остаётся в базе.
### С индексом ix_messages_chat_id_created_at_id
Limit (cost=73.42..73.47 rows=18 width=204) (actual time=0.100..0.102 rows=10.00 loops=1)
Buffers: shared hit=19
-> Sort (cost=73.42..73.47 rows=18 width=204) (actual time=0.099..0.099 rows=10.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=19
-> Bitmap Heap Scan on messages (cost=4.56..73.05 rows=18 width=204) (actual time=0.032..0.082 rows=10.00 loops=1)
Recheck Cond: (chat_id = '65fe5cdf-444f-4ee9-aaa1-210aed8d75cd'::uuid)
Heap Blocks: exact=10
Buffers: shared hit=13
-> Bitmap Index Scan on ix_messages_chat_id_created_at_id (cost=0.00..4.55 rows=18 width=0) (actual time=0.021..0.021 rows=10.00 loops=1)
Index Cond: (chat_id = '65fe5cdf-444f-4ee9-aaa1-210aed8d75cd'::uuid)
Index Searches: 1
Buffers: shared hit=3
Planning:
Buffers: shared hit=142
Planning Time: 0.338 ms
Execution Time: 0.126 ms
### Без индекса ix_messages_chat_id_created_at_id
Limit (cost=5334.38..5334.42 rows=18 width=204) (actual time=13.622..13.624 rows=10.00 loops=1)
Buffers: shared hit=3759
-> Sort (cost=5334.38..5334.42 rows=18 width=204) (actual time=13.620..13.622 rows=10.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=3759
-> Seq Scan on messages (cost=0.00..5334.00 rows=18 width=204) (actual time=1.689..13.613 rows=10.00 loops=1)
Filter: (chat_id = '65fe5cdf-444f-4ee9-aaa1-210aed8d75cd'::uuid)
Rows Removed by Filter: 125990
Buffers: shared hit=3759
Planning:
Buffers: shared hit=17
Planning Time: 0.067 ms
Execution Time: 13.635 ms