tasks for 4

This commit is contained in:
EgorAnti
2026-10-21 20:10:27 +03:00
parent 7565b65997
commit a70992ccdb
20 changed files with 617 additions and 41 deletions
+38
View File
@@ -0,0 +1,38 @@
# Message history index evidence
Проверка выполнена командой `make explain-history`. Скрипт `scripts/explain_message_history.sql`
создаёт 10 000 сообщений внутри транзакции, выполняет `ANALYZE` и
`EXPLAIN (ANALYZE, BUFFERS)`, после чего делает `ROLLBACK`.
Проверяемый запрос соответствует JDBC-запросу страницы истории:
```sql
SELECT id, chat_id, sender_id, text, created_at
FROM messages
WHERE chat_id = $1
AND (created_at, id) > ($2, $3)
ORDER BY created_at, id
LIMIT 100;
```
Фактический существенный фрагмент плана:
```text
Limit (cost=0.29..10.75 rows=100 width=74) (actual time=0.008..0.028 rows=100 loops=1)
Buffers: shared hit=6
-> Index Scan using messages_chat_created_id_idx on messages
(cost=0.29..524.11 rows=5007 width=74)
(actual time=0.007..0.021 rows=100 loops=1)
Index Cond: ((chat_id = '70000000-0000-4000-8000-000000000002'::uuid)
AND (ROW(created_at, id) > ROW(
'2026-01-01 00:00:05+00'::timestamptz,
'70000000-0000-4000-8000-000000005000'::uuid)))
Buffers: shared hit=6
Planning Time: 0.177 ms
Execution Time: 0.062 ms
```
Вывод: PostgreSQL начинает чтение с позиции курсора по индексу
`messages_chat_created_id_idx(chat_id, created_at, id)` и останавливается после 100 строк.
`Seq Scan on messages` отсутствует; стоимость страницы не требует повторного полного просмотра
10 000 предыдущих сообщений.