docs(evidence): add index comparison, write cost and restore verification
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
# Сравнение индексов: keyset-пагинация, chat_id=349f1aef-3bbc-42d1-8724-e8d22b8c2253
|
||||
# date: 2026-10-02T16:45:25Z
|
||||
|
||||
## A. Baseline (chat_id, created_at, id)
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..7.31 rows=50 width=69) (actual time=0.029..0.046 rows=50 loops=1)
|
||||
Buffers: shared hit=42 read=3
|
||||
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..7619.95 rows=55273 width=69) (actual time=0.028..0.042 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '349f1aef-3bbc-42d1-8724-e8d22b8c2253'::uuid)
|
||||
Buffers: shared hit=42 read=3
|
||||
Planning:
|
||||
Buffers: shared hit=106 read=1
|
||||
Planning Time: 0.664 ms
|
||||
Execution Time: 0.070 ms
|
||||
(9 rows)
|
||||
|
||||
|
||||
## B1. Covering (chat_id, created_at, id) INCLUDE (sender_id)
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..7.77 rows=50 width=69) (actual time=0.027..0.048 rows=50 loops=1)
|
||||
Buffers: shared hit=42 read=4
|
||||
-> Index Scan using messages_covering_small on messages (cost=0.42..8096.41 rows=55056 width=69) (actual time=0.026..0.044 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '349f1aef-3bbc-42d1-8724-e8d22b8c2253'::uuid)
|
||||
Buffers: shared hit=42 read=4
|
||||
Planning:
|
||||
Buffers: shared hit=111 read=1
|
||||
Planning Time: 0.639 ms
|
||||
Execution Time: 0.070 ms
|
||||
(9 rows)
|
||||
|
||||
|
||||
## B2. Covering (chat_id, created_at, id) INCLUDE (sender_id, text)
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..4.40 rows=50 width=69) (actual time=0.038..0.044 rows=50 loops=1)
|
||||
Buffers: shared hit=1 read=3
|
||||
-> Index Only Scan using messages_covering_full on messages (cost=0.42..4393.54 rows=55144 width=69) (actual time=0.037..0.041 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '349f1aef-3bbc-42d1-8724-e8d22b8c2253'::uuid)
|
||||
Heap Fetches: 0
|
||||
Buffers: shared hit=1 read=3
|
||||
Planning:
|
||||
Buffers: shared hit=112 read=1
|
||||
Planning Time: 0.717 ms
|
||||
Execution Time: 0.071 ms
|
||||
(10 rows)
|
||||
|
||||
|
||||
## C. Без индекса (Seq Scan)
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=4314.02..4319.77 rows=50 width=69) (actual time=7.709..9.590 rows=50 loops=1)
|
||||
Buffers: shared hit=1486
|
||||
-> Gather Merge (cost=4314.02..7988.96 rows=31956 width=69) (actual time=7.707..9.585 rows=50 loops=1)
|
||||
Workers Planned: 1
|
||||
Workers Launched: 1
|
||||
Buffers: shared hit=1486
|
||||
-> Sort (cost=3314.01..3393.90 rows=31956 width=69) (actual time=5.760..5.763 rows=50 loops=2)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 32kB
|
||||
Buffers: shared hit=1486
|
||||
Worker 0: Sort Method: top-N heapsort Memory: 32kB
|
||||
-> Parallel Seq Scan on messages (cost=0.00..2252.46 rows=31956 width=69) (actual time=0.009..3.673 rows=27500 loops=2)
|
||||
Filter: (chat_id = '349f1aef-3bbc-42d1-8724-e8d22b8c2253'::uuid)
|
||||
Rows Removed by Filter: 27611
|
||||
Buffers: shared hit=1442
|
||||
Planning:
|
||||
Buffers: shared hit=84
|
||||
Planning Time: 0.598 ms
|
||||
Execution Time: 9.660 ms
|
||||
(19 rows)
|
||||
|
||||
|
||||
## Восстанавливаем baseline
|
||||
indexname | size
|
||||
------------------------------+---------
|
||||
messages_chat_created_id_idx | 6360 kB
|
||||
messages_pkey | 4568 kB
|
||||
(2 rows)
|
||||
|
||||
Reference in New Issue
Block a user