research: record keyset track2 baseline and reproducible analysis

This commit is contained in:
2026-10-02 04:26:21 +03:00
parent 6d2240ce9f
commit 8e7d4183e3
13 changed files with 1127 additions and 0 deletions
@@ -0,0 +1,78 @@
# План запроса истории: класс tiny, чат 10
Код: src_sha256 8a7e256c540af433, commit 6d2240ce9fec; вариант индекса: keyset
Страница истории читаемого чата (limit 50); позиция — сколько
сообщений истории до страницы:
- first: после 0
## Планы приложения
auto_explain (ANALYZE, BUFFERS, TIMING): запрос, параметры и план,
с которыми его выполнило приложение (prepared statement asyncpg).
### first
duration: 0.052 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 = '961fcc42-545b-4f88-bf41-c6bae3507eb7', $2 = '51'
Limit (cost=73.42..73.47 rows=18 width=204) (actual time=0.048..0.049 rows=10.00 loops=1)
Buffers: shared hit=19
-> Sort (cost=73.42..73.47 rows=18 width=204) (actual time=0.048..0.048 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.012..0.019 rows=10.00 loops=1)
Recheck Cond: (chat_id = '961fcc42-545b-4f88-bf41-c6bae3507eb7'::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.006..0.006 rows=10.00 loops=1)
Index Cond: (chat_id = '961fcc42-545b-4f88-bf41-c6bae3507eb7'::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.158..0.162 rows=10.00 loops=1)
Buffers: shared hit=19
-> Sort (cost=73.42..73.47 rows=18 width=204) (actual time=0.156..0.157 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.058..0.130 rows=10.00 loops=1)
Recheck Cond: (chat_id = '961fcc42-545b-4f88-bf41-c6bae3507eb7'::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.034..0.034 rows=10.00 loops=1)
Index Cond: (chat_id = '961fcc42-545b-4f88-bf41-c6bae3507eb7'::uuid)
Index Searches: 1
Buffers: shared hit=3
Planning:
Buffers: shared hit=142
Planning Time: 0.423 ms
Execution Time: 0.197 ms
### Без индекса ix_messages_chat_id_created_at_id
Limit (cost=5342.38..5342.42 rows=18 width=204) (actual time=20.430..20.432 rows=10.00 loops=1)
Buffers: shared hit=3767
-> Sort (cost=5342.38..5342.42 rows=18 width=204) (actual time=20.429..20.430 rows=10.00 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 27kB
Buffers: shared hit=3767
-> Seq Scan on messages (cost=0.00..5342.00 rows=18 width=204) (actual time=2.625..20.418 rows=10.00 loops=1)
Filter: (chat_id = '961fcc42-545b-4f88-bf41-c6bae3507eb7'::uuid)
Rows Removed by Filter: 125990
Buffers: shared hit=3767
Planning:
Buffers: shared hit=17
Planning Time: 0.118 ms
Execution Time: 20.451 ms