diff --git a/evidence/lab2_track2_explain.md b/evidence/lab2_track2_explain.md index 80e74f70..f8d09684 100644 --- a/evidence/lab2_track2_explain.md +++ b/evidence/lab2_track2_explain.md @@ -1,6 +1,13 @@ -# Track 2: EXPLAIN (ANALYZE, BUFFERS) +# Трек 2. EXPLAIN (ANALYZE, BUFFERS): 3 варианта индекса + +Данные: 160 001 сообщение, неравномерные чаты (61818 / 54545 / 18182 / 9777 / … / 1). +Запрос: `SELECT ... FROM messages WHERE chat_id = AND (created_at, id) > (<середина>, …) ORDER BY created_at, id LIMIT 51`. +Большой чат ~62k, маленький чат ~1. + +## 1. Без индекса, большой чат + +`Parallel Seq Scan` по всей таблице, затем `Sort (top-N heapsort)`. Прочитано ~2013 буферов. `Execution Time = 39.988 ms`. -## big chat ``` Limit (cost=4887.94..4893.75 rows=51 width=69) (actual time=36.242..39.932 rows=51.00 loops=1) Buffers: shared hit=2028 @@ -21,10 +28,12 @@ Planning: Buffers: shared hit=88 Planning Time: 1.550 ms Execution Time: 39.988 ms - ``` -## small chat +## 2. Без индекса, маленький чат + +Тот же `Parallel Seq Scan` по всей таблице, но условий мало — `Sort (quicksort)`. `Execution Time = 41.093 ms`. + ``` Limit (cost=4660.63..4660.64 rows=5 width=69) (actual time=36.246..41.037 rows=1.00 loops=1) Buffers: shared hit=2019 @@ -44,10 +53,12 @@ Planning: Buffers: shared hit=88 Planning Time: 1.837 ms Execution Time: 41.093 ms - ``` -## no_index +## 3. Индекс (chat_id), большой чат + +`Bitmap Index Scan` по `idx_messages_chat_only`, затем `Bitmap Heap Scan` и `Sort`. ~863 буфера. `Execution Time = 9.220 ms`. + ``` Limit (cost=4135.73..4135.86 rows=51 width=69) (actual time=9.172..9.177 rows=51.00 loops=1) Buffers: shared hit=863 @@ -69,10 +80,12 @@ Planning: Buffers: shared hit=100 Planning Time: 1.562 ms Execution Time: 9.220 ms - ``` -## chat_only +## 4. Индекс (chat_id), маленький чат + +`Index Scan using idx_messages_chat_only` + `Sort (quicksort)`. ~9 буферов. `Execution Time = 0.069 ms`. + ``` Limit (cost=28.62..28.64 rows=11 width=69) (actual time=0.040..0.041 rows=1.00 loops=1) Buffers: shared hit=9 @@ -89,10 +102,12 @@ Planning: Buffers: shared hit=100 Planning Time: 1.450 ms Execution Time: 0.069 ms - ``` -## full (chat_id, created_at, id) +## 5. Полный индекс (chat_id, created_at, id), большой чат + +`Index Scan using idx_messages_chat_created`, **без `Sort`**. ~52 буфера. `Execution Time = 0.214 ms`. + ``` Limit (cost=0.42..28.88 rows=51 width=69) (actual time=0.072..0.187 rows=51.00 loops=1) Buffers: shared hit=51 read=1 @@ -104,5 +119,21 @@ Planning: Buffers: shared hit=111 Planning Time: 2.685 ms Execution Time: 0.214 ms +``` + +## 6. Полный индекс (chat_id, created_at, id), маленький чат + +`Index Scan` без `Sort`. ~4 буфера. `Execution Time = 0.072 ms`. ``` +Limit (cost=0.42..28.71 rows=8 width=69) (actual time=0.029..0.030 rows=1.00 loops=1) + Buffers: shared hit=4 + -> Index Scan using idx_messages_chat_created on messages (cost=0.42..28.71 rows=8 width=69) (actual time=0.026..0.027 rows=1.00 loops=1) + Index Cond: ((chat_id = '730e474b-405e-4558-8cf3-ac6a17c2a7d1'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 01:23:13.456347+03'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))) + Index Searches: 1 + Buffers: shared hit=4 +Planning: + Buffers: shared hit=111 +Planning Time: 2.160 ms +Execution Time: 0.072 ms +```