From 1ca62930fe7ef446a3306deec04372b32c40e63c Mon Sep 17 00:00:00 2001 From: Zertonixa Date: Wed, 14 Oct 2026 06:30:23 +0300 Subject: [PATCH] docs(report): record cache experiments and validation results --- REPORT.md | 82 +- evidence/cache-epochs-after-short.json | 372 + evidence/cache-epochs-after.json | 373 + evidence/cache-epochs-before-short.json | 359 + evidence/cache-epochs-before.json | 364 + evidence/cache-epochs-environment.json | 36 + evidence/cache-epochs-full-restart.json | 79 + ...cache-epochs-optimization-environment.json | 14 + evidence/cache-epochs-optimized.json | 364 + evidence/cache-epochs-smoke.txt | 1 + evidence/cache-strategy-averages.json | 130 + evidence/cache-strategy-buckets-averages.json | 98 + .../cache-strategy-buckets-experiment.json | 79 + evidence/cache-strategy-buckets-full.json | 262 + ...e-strategy-buckets-no-redis-no-epochs.json | 258 + evidence/cache-strategy-experiment.json | 64 + evidence/cache-strategy-full.json | 338 + evidence/cache-strategy-long-averages.json | 98 + evidence/cache-strategy-long-experiment.json | 79 + evidence/cache-strategy-long-full.json | 271 + ...ache-strategy-long-no-redis-no-epochs.json | 270 + .../cache-strategy-no-redis-no-epochs.json | 347 + evidence/checks-rerun.json | 37 + evidence/checks-rerun.txt | 24 + evidence/epoch-variants-averages.json | 122 + evidence/epoch-variants-code.json | 111 + evidence/epoch-variants-sources.json | 30 + evidence/epoch-variants-validation.json | 15 + evidence/epoch-variants.json | 617 ++ evidence/history-index-explain.json | 7277 +++++++++++++++++ evidence/history-index-plans.txt | 242 + evidence/persistence-full-restart.json | 79 + evidence/persistence-public.json | 79 + evidence/redis-comparison-averages.json | 68 + evidence/redis-comparison.json | 509 ++ 35 files changed, 13530 insertions(+), 18 deletions(-) create mode 100644 evidence/cache-epochs-after-short.json create mode 100644 evidence/cache-epochs-after.json create mode 100644 evidence/cache-epochs-before-short.json create mode 100644 evidence/cache-epochs-before.json create mode 100644 evidence/cache-epochs-environment.json create mode 100644 evidence/cache-epochs-full-restart.json create mode 100644 evidence/cache-epochs-optimization-environment.json create mode 100644 evidence/cache-epochs-optimized.json create mode 100644 evidence/cache-epochs-smoke.txt create mode 100644 evidence/cache-strategy-averages.json create mode 100644 evidence/cache-strategy-buckets-averages.json create mode 100644 evidence/cache-strategy-buckets-experiment.json create mode 100644 evidence/cache-strategy-buckets-full.json create mode 100644 evidence/cache-strategy-buckets-no-redis-no-epochs.json create mode 100644 evidence/cache-strategy-experiment.json create mode 100644 evidence/cache-strategy-full.json create mode 100644 evidence/cache-strategy-long-averages.json create mode 100644 evidence/cache-strategy-long-experiment.json create mode 100644 evidence/cache-strategy-long-full.json create mode 100644 evidence/cache-strategy-long-no-redis-no-epochs.json create mode 100644 evidence/cache-strategy-no-redis-no-epochs.json create mode 100644 evidence/checks-rerun.json create mode 100644 evidence/checks-rerun.txt create mode 100644 evidence/epoch-variants-averages.json create mode 100644 evidence/epoch-variants-code.json create mode 100644 evidence/epoch-variants-sources.json create mode 100644 evidence/epoch-variants-validation.json create mode 100644 evidence/epoch-variants.json create mode 100644 evidence/history-index-explain.json create mode 100644 evidence/history-index-plans.txt create mode 100644 evidence/persistence-full-restart.json create mode 100644 evidence/persistence-public.json create mode 100644 evidence/redis-comparison-averages.json create mode 100644 evidence/redis-comparison.json diff --git a/REPORT.md b/REPORT.md index e42f2b0..347fa45 100644 --- a/REPORT.md +++ b/REPORT.md @@ -1,37 +1,83 @@ # Отчёт — лабораторная 2 -- Автор, группа: TODO -- Целевая оценка; выбранный трек 5, если нужен: TODO -- Commit/PR: TODO после публикации -- Использованные источники, библиотеки и помощь ИИ: TODO +- Автор, группа: **Пинаев Олег Константинович, БПИ2302**. +- Целевая оценка: **5, трек 1 — согласованность кэша**. +- Коммиты: API `6fff618`, инфраструктура `1dc5f08`, проверки `6cccda1`, инструменты замеров `6866407`. Хеши измеренных модулей и образов сохранены в `evidence/`. +- Источники: `README.md`, `contracts/`, документация PostgreSQL, Redis и Node.js; ИИ использовался для разработки, подготовки тестов, замеров и черновика отчёта. ## Запуск из чистого clone -TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных. +Docker с Compose, Python 3.9+ и `make`. Для локальной сборки и собственных тестов — Node.js **24.20.0**, pnpm **10.14.0**. + +```sh +cp .env.example .env +docker compose --env-file .env config --quiet +docker compose --env-file .env up -d --build --wait +make test PYTHON=python BASE_URL=http://127.0.0.1:8080 +make test-persistence ACTION_SCRIPT=scripts/restart.sh PYTHON=python BASE_URL=http://127.0.0.1:8080 +``` + +`APP_PORT` задаёт опубликованный порт API; `POSTGRES_*` — настройки БД, `REDIS_PORT` — локальный порт Redis. Внутри Compose `DATABASE_URL` и `CACHE_URL` указывают на сервисы `postgres` и `redis`; локальные команды используют адреса из `.env`. `SESSION_TTL_SECONDS` — срок сессии, `CACHE_PREFIX` — пространство ключей; `SESSION_STORE=postgres`. Учебный пароль в `.env.example` следует заменить в локальном `.env`. + ## Архитектура и решения -TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab1, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации. +NestJS/Fastify → PostgreSQL; Redis используется как кэш. Из lab1 сохранены пользователи, чаты, проверка членства, формат ошибок и cursor-пагинация. Состояние перенесено из памяти в таблицы `users`, `chats`, `chat_members`, `messages`, `sessions`; добавлены PK/FK, уникальность username и индексы. Создание чата, участников и увеличение эпох списков выполняются одной транзакцией. История упорядочена по `(created_at, id)` и имеет индекс `(chat_id, created_at, id)`; поздние страницы используют сравнение пары, без OFFSET. + +Пароли хранятся как **Argon2id** в PHC-формате: 19 MiB, 2 прохода, parallelism=1, соль 16 байт, ключ 32 байта. Basic применяется при входе; бизнес-запросы требуют opaque Bearer. В PostgreSQL хранится SHA-256 токена, срок истечения и признак отзыва. По умолчанию сессия действует 3600 секунд, logout отзывает её; + +PostgreSQL — источник истины. Redis хранит сущности на 300 секунд, страницы на 30 секунд. Ключ истории включает эпоху из БД и параметры страницы. Эпоха — сумма до **16 счётчиков** `chat_message_epochs`: запись атомарно увеличивает один из них и вставляет сообщение одним CTE. Это распределяет блокировки записей одного чата. Проверка сессии, публичный профиль, членство и эпоха для GET истории получаются одним SQL. Эпоха списка чатов хранится в `users.chats_epoch` и меняется вместе с созданием чата. + +После подтверждённой записи следующий GET получает новую эпоху и не использует старый ключ, даже если Redis пропустил инвалидацию. Задержавшаяся загрузка может заполнить только ключ старой эпохи; он исчезнет по TTL. При недоступном Redis API читает PostgreSQL; при недоступной БД возвращает 503. Ожидание подключения и SQL — 5 секунд, транзакция — 10 секунд; Redis-команда — 300 мс. Dockerfile разделяет сборку, миграции и runtime, запускает API от UID/GID 10001. ## Доказательства критериев -| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства | -| --- | --- | --- | --- | -| Публичный smoke | make test | TODO | TODO | -| Остальные пункты уровня 3 | TODO | TODO | TODO | -| Все пункты уровня 4, если заявлен | TODO | TODO | TODO | -| Выбранный трек 5, если заявлен | TODO | TODO | TODO | +| Проверка | Команда/сценарий | Результат | +| --- | --- | --- | +| Сборка, миграции, линтер | `docker compose build backend migrate`, `docker compose up -d backend`, `pnpm.cmd lint` | PASS, backend healthy; [проверки выбранной версии](evidence/epoch-variants-validation.json) | +| Публичный smoke | `python -X utf8 tests/smoke.py --base-url http://127.0.0.1:8080` | PASS на текущем образе; [повторные проверки](evidence/checks-rerun.json) | +| Полный перезапуск | `python -X utf8 scripts/test-persistence.py --scenario full-restart --base-url http://127.0.0.1:8080 --output evidence/cache-epochs-full-restart.json` | Сохранён PASS, 49,081 с на весь сценарий: те же контейнеры и volumes, данные и прежние токены сохранены; [JSON](evidence/cache-epochs-full-restart.json) | +| Публичная сохранность | `python -X utf8 scripts/test-persistence.py --scenario public --base-url http://127.0.0.1:8080 --output evidence/persistence-public.json` | PASS на текущем образе, исходный HTTP-дедлайн 2 с; 34,502 с на сценарий. Все три сервиса перезапущены, контейнеры и volumes сохранены; [JSON](evidence/persistence-public.json) | +| KDF, сессии, гонки и rollback | Проверки `test/passwords.mjs`, `test/persistence.mjs`, `test/resilience.mjs` через `node --test` в benchmark-контейнере | PASS на текущем образе, включая короткий TTL, logout, неверный пароль и отказы зависимостей; вместе с кэшем и пагинацией 15/15, [команда и результат](evidence/checks-rerun.json) | +| Кэш и актуальные эпохи | `docker compose -f compose.yaml -f test/compose.benchmark.yaml run --rm --no-deps --pull never benchmark node --test test/cache-epochs.mjs test/cache.mjs` | PASS: 3 теста на текущей схеме, свежесть, конкурентная запись и rollback; [JSON](evidence/epoch-variants-validation.json) | +| Индекс и пагинация | `node test/explain-history.mjs`, `pnpm test:pagination` | EXPLAIN на 60 000 сообщений; проверены границы timestamp, отсутствие пропусков/дублей и изоляция чатов; +| Трек 1 | Конкурентный старый SELECT, пропущенная инвалидация, восстановление Redis со старыми ключами | Stale read воспроизведён до защиты; после — PASS. -TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены. +Hook `scripts/restart.sh` останавливает backend, PostgreSQL и Redis, запускает существующие контейнеры, ждёт готовности хранилищ и сохраняет volumes. `scripts/restart.cmd` вызывает его через Git Bash. Публичная проверка с HTTP-дедлайном 2 секунды прошла; проверки KDF, сессий, отказов, кэша и пагинации — 15/15 PASS. Запуск из чистого clone пока не проверен. ## Эксперименты и отказы -TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения. +Гипотеза трека 1: эпоха в PostgreSQL, изменяемая атомарно с сообщением, устраняет stale read при отказе Redis и запоздалом заполнении кэша. До защиты два сценария возвращали старую историю: восстановление Redis с прежними ключами и завершение старого SELECT после новой записи. После добавления эпох оба проходят. Первое сравнение: 10 000 сообщений, конкурентность 16, прогрев 3 с, чтение 10 с, 512 записей, три повтора. Медианы до / после: чтение — SQL/HTTP **1,412 / 2,011**, p95 **292,651 / 332,510 мс**; запись — SQL/HTTP **2,313 / 4**, p95 **216,752 / 894,578 мс**. Свежесть исправлена ценой дополнительных SQL и блокировки счётчика; -| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных | -| --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | +Затем запись сведена к одному CTE, профиль включён в проверку сессии, проверки доступа объединены, общая эпоха разделена на 16 счётчиков. Матрица с меняющимся порядком, три повтора, 100 000 сообщений, 32 клиента, чтения по минуте и 4096 записей: + +| Вариант | Чтение, RPS | Запись, RPS | SQL/HTTP чтения | +| --- | ---: | ---: | ---: | +| Прежний CTE и один счётчик | 226,076 | 90,772 | 2,004 | +| Профиль из JOIN сессии | 170,523 | 141,474 | 2,010 | +| Единая проверка сессии/членства/эпохи | 246,934 | 117,777 | 1,006 | +| Та же проверка и 16 счётчиков | **242,548** | **165,061** | **1,004** | + +Выбран последний вариант: близкая скорость чтения и лучшая средняя скорость записи в этой матрице. + +Отдельный контроль сравнивает выбранный код с теми же SQL-оптимизациями, но без Redis и чтения/обновления эпох. Три повтора, 100 000 сообщений, limit=50, конкурентность 32, прогрев 10 с, чтение 60 с, 4096 записей на повтор: + +| Метрика | Redis и эпохи | Без кэша и эпох | +| --- | ---: | ---: | +| Средний RPS чтения | **184,211** | 130,213 | +| Средняя задержка чтения, мс | **173,466** | 245,478 | +| Среднее p95 чтения, мс | **427,674** | 762,396 | +| SQL/HTTP чтения | **1,009** | 2 | +| Средний RPS записи | 120,634 | **128,279** | +| Средняя задержка записи, мс | 264,880 | **249,032** | +| Среднее p95 записи, мс | 666,798 | **556,831** | + +Чтение быстрее по среднему RPS на **41,5%**, запись медленнее на **6,0%**. Всего **81 693 успешных запроса**, ошибок нет. С Redis чтение быстрее во всех трёх повторах, но преимущество меняется от 5,7% до 120,2%; результаты записи пересекаются. + +Индекс исследован отдельно через `EXPLAIN (ANALYZE, BUFFERS)` на 60 000 сообщений. Медиана первой страницы — **28,718 → 0,094 мс** после индекса. На странице после 18 000 сообщений замена OR на сравнение пары снижает проверенные строки **18 051 → 51**, время **10,479 → 0,080 мс**. Результаты выборок совпадают; изменения экспериментальной схемы отменены ROLLBACK. [Планы](evidence/history-index-plans.txt). ## Ограничения и следующие шаги -TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза. +Один PostgreSQL и один Docker-host: проверена устойчивость к потере кэша, высокая доступность БД не реализована. Гарантия свежести относится к GET, начатому после подтверждения записи; чтения идут в основной PostgreSQL. Изменения данных в обход приложения должны увеличивать эпоху. После восстановления БД из старого backup нужно сменить `CACHE_PREFIX` или очистить Redis. Cache stampede отдельно не устранён. + +Нагрузка closed-loop; API, генератор и инструментация делят процесс, другие контейнеры делят host. CPU/RSS и p50/p95/p99 сохранены в сырых JSON; CPU PostgreSQL отдельно не измерялся. Средние p95 в таблице — среднее перцентилей повторов. Синтетические сессии обходят KDF; нагрузка измеряет первую страницу и запись в один чат. Последовательное сравнение с отключённым кэшем не позволяет точно отделить стоимость Redis от стоимости эпох. diff --git a/evidence/cache-epochs-after-short.json b/evidence/cache-epochs-after-short.json new file mode 100644 index 0000000..e8be7bf --- /dev/null +++ b/evidence/cache-epochs-after-short.json @@ -0,0 +1,372 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T10:03:46.698Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented separate API process in running backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 5, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 128, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; idle production backend shares container; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "6fefd2a334e97f595e86699f8ec3832792b353c9f3a47568da802d36f1495027", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 1.945, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 16.45, + "latency_ms": { + "p50": 1799.65, + "p95": 1899.363, + "p99": 1908.217 + }, + "sql_queries": 66, + "sql_per_request": 2.0625, + "sql_calls": { + "SELECT:sessions": 51, + "SELECT:chat_members": 51, + "SELECT:messages": 2 + }, + "process_cpu_percent_one_core": 88.25, + "peak_process_rss_mib": 325.54 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 5.508, + "successes": 142, + "errors": 0, + "error_ratio": 0, + "successful_rps": 25.78, + "latency_ms": { + "p50": 585.765, + "p95": 844.356, + "p99": 977.564 + }, + "sql_queries": 300, + "sql_per_request": 2.1127, + "sql_calls": { + "SELECT:sessions": 179, + "SELECT:chat_members": 186, + "SELECT:chats": 7, + "SELECT:messages": 38, + "SELECT:users": 1 + }, + "process_cpu_percent_one_core": 68.2, + "peak_process_rss_mib": 314.38 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 5.218, + "successes": 261, + "errors": 0, + "error_ratio": 0, + "successful_rps": 50.023, + "latency_ms": { + "p50": 246.755, + "p95": 745.696, + "p99": 939.045 + }, + "sql_queries": 794, + "sql_per_request": 3.0421, + "sql_calls": { + "SELECT:sessions": 262, + "SELECT:chat_members": 268, + "SELECT:messages": 261, + "SELECT:users": 1, + "SELECT:chats": 7, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 99.49, + "peak_process_rss_mib": 332.13 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 6.953, + "successes": 128, + "errors": 0, + "error_ratio": 0, + "successful_rps": 18.409, + "latency_ms": { + "p50": 573.249, + "p95": 2180.804, + "p99": 2490.244 + }, + "sql_queries": 532, + "sql_per_request": 4.1563, + "sql_calls": { + "SELECT:sessions": 129, + "SELECT:chat_members": 140, + "BEGIN:other": 128, + "UPDATE:chats": 128, + "SELECT:chats": 11, + "INSERT:messages": 128, + "COMMIT:other": 128, + "SELECT:messages": 1, + "SELECT:users": 1 + }, + "process_cpu_percent_one_core": 92.16, + "peak_process_rss_mib": 333.42 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.436, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 73.396, + "latency_ms": { + "p50": 392.182, + "p95": 407.46, + "p99": 430.132 + }, + "sql_queries": 96, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 54, + "SELECT:chat_members": 54, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 105.73, + "peak_process_rss_mib": 333.79 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 5.376, + "successes": 230, + "errors": 0, + "error_ratio": 0, + "successful_rps": 42.787, + "latency_ms": { + "p50": 273.166, + "p95": 1119.423, + "p99": 1464.099 + }, + "sql_queries": 490, + "sql_per_request": 2.1304, + "sql_calls": { + "SELECT:sessions": 241, + "SELECT:chat_members": 251, + "SELECT:chats": 10, + "SELECT:users": 8, + "SELECT:messages": 13 + }, + "process_cpu_percent_one_core": 65.23, + "peak_process_rss_mib": 334.04 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 5.546, + "successes": 126, + "errors": 0, + "error_ratio": 0, + "successful_rps": 22.721, + "latency_ms": { + "p50": 710.161, + "p95": 1038.287, + "p99": 1090.633 + }, + "sql_queries": 378, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 127, + "SELECT:chat_members": 128, + "SELECT:messages": 126, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 67.71, + "peak_process_rss_mib": 334.54 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 2.104, + "successes": 128, + "errors": 0, + "error_ratio": 0, + "successful_rps": 60.838, + "latency_ms": { + "p50": 169.632, + "p95": 445.91, + "p99": 625.63 + }, + "sql_queries": 512, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 129, + "SELECT:chat_members": 130, + "BEGIN:other": 128, + "UPDATE:chats": 128, + "INSERT:messages": 128, + "COMMIT:other": 128, + "SELECT:messages": 1, + "SELECT:users": 1, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 162.61, + "peak_process_rss_mib": 335.29 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.53, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 60.386, + "latency_ms": { + "p50": 237.037, + "p95": 441.614, + "p99": 519.501 + }, + "sql_queries": 96, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 114, + "SELECT:chat_members": 114, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 108.61, + "peak_process_rss_mib": 335.29 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 5.076, + "successes": 959, + "errors": 0, + "error_ratio": 0, + "successful_rps": 188.921, + "latency_ms": { + "p50": 66.867, + "p95": 192.487, + "p99": 286.838 + }, + "sql_queries": 1918, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 997, + "SELECT:chat_members": 997, + "SELECT:messages": 38 + }, + "process_cpu_percent_one_core": 116.88, + "peak_process_rss_mib": 338.79 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 5.099, + "successes": 190, + "errors": 0, + "error_ratio": 0, + "successful_rps": 37.26, + "latency_ms": { + "p50": 329.709, + "p95": 1031.744, + "p99": 1254.223 + }, + "sql_queries": 585, + "sql_per_request": 3.0789, + "sql_calls": { + "SELECT:sessions": 191, + "SELECT:chat_members": 198, + "SELECT:messages": 190, + "SELECT:chats": 8, + "SELECT:users": 3, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 71.36, + "peak_process_rss_mib": 338.79 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 1.849, + "successes": 128, + "errors": 0, + "error_ratio": 0, + "successful_rps": 69.223, + "latency_ms": { + "p50": 209.047, + "p95": 381.466, + "p99": 495.091 + }, + "sql_queries": 512, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 136, + "SELECT:chat_members": 142, + "BEGIN:other": 132, + "UPDATE:chats": 130, + "INSERT:messages": 130, + "COMMIT:other": 132, + "SELECT:messages": 7, + "INSERT:chats": 2, + "INSERT:chat_members": 2, + "SELECT:chats": 8, + "SELECT:users": 4, + "DELETE:chats": 1, + "DELETE:users": 1 + }, + "process_cpu_percent_one_core": 108.54, + "peak_process_rss_mib": 338.79 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": true + }, + "empty_cache_recovery": true, + "delayed_old_fill": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-epochs-after.json b/evidence/cache-epochs-after.json new file mode 100644 index 0000000..a92fc28 --- /dev/null +++ b/evidence/cache-epochs-after.json @@ -0,0 +1,373 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T10:10:30.537Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 10, + "warmup_seconds": 3, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 512, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "6fefd2a334e97f595e86699f8ec3832792b353c9f3a47568da802d36f1495027", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 0.691, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 46.329, + "latency_ms": { + "p50": 611.222, + "p95": 672.153, + "p99": 672.232 + }, + "sql_queries": 66, + "sql_per_request": 2.0625, + "sql_calls": { + "SELECT:sessions": 106, + "SELECT:chat_members": 106, + "SELECT:messages": 2 + }, + "process_cpu_percent_one_core": 149.33, + "peak_process_rss_mib": 320.66 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.244, + "successes": 638, + "errors": 0, + "error_ratio": 0, + "successful_rps": 62.279, + "latency_ms": { + "p50": 169.157, + "p95": 677.14, + "p99": 952.33 + }, + "sql_queries": 1289, + "sql_per_request": 2.0204, + "sql_calls": { + "SELECT:sessions": 719, + "SELECT:chat_members": 723, + "SELECT:chats": 4, + "SELECT:users": 1, + "SELECT:messages": 85 + }, + "process_cpu_percent_one_core": 100.85, + "peak_process_rss_mib": 336.96 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.317, + "successes": 397, + "errors": 0, + "error_ratio": 0, + "successful_rps": 38.482, + "latency_ms": { + "p50": 423.359, + "p95": 719.312, + "p99": 974.855 + }, + "sql_queries": 1203, + "sql_per_request": 3.0302, + "sql_calls": { + "SELECT:sessions": 398, + "SELECT:chat_members": 404, + "SELECT:messages": 397, + "SELECT:chats": 7, + "SELECT:users": 2, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 85.4, + "peak_process_rss_mib": 337.38 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 12.201, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 41.963, + "latency_ms": { + "p50": 270.615, + "p95": 1006.641, + "p99": 1396.859 + }, + "sql_queries": 2053, + "sql_per_request": 4.0098, + "sql_calls": { + "SELECT:sessions": 513, + "SELECT:chat_members": 516, + "BEGIN:other": 512, + "UPDATE:chats": 512, + "INSERT:messages": 512, + "COMMIT:other": 512, + "SELECT:chats": 3, + "SELECT:users": 2, + "SELECT:messages": 1 + }, + "process_cpu_percent_one_core": 83.81, + "peak_process_rss_mib": 338.63 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.146, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 219.517, + "latency_ms": { + "p50": 138.981, + "p95": 142.972, + "p99": 143.135 + }, + "sql_queries": 96, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 230, + "SELECT:chat_members": 230, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 131.45, + "peak_process_rss_mib": 338.75 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.025, + "successes": 1394, + "errors": 0, + "error_ratio": 0, + "successful_rps": 139.051, + "latency_ms": { + "p50": 67.992, + "p95": 332.51, + "p99": 672.764 + }, + "sql_queries": 2788, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 1645, + "SELECT:chat_members": 1645, + "SELECT:messages": 251 + }, + "process_cpu_percent_one_core": 97.71, + "peak_process_rss_mib": 341.38 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.185, + "successes": 1024, + "errors": 0, + "error_ratio": 0, + "successful_rps": 100.544, + "latency_ms": { + "p50": 124.908, + "p95": 373.546, + "p99": 531.859 + }, + "sql_queries": 3072, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 1025, + "SELECT:chat_members": 1026, + "SELECT:messages": 1024, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 108.45, + "peak_process_rss_mib": 341.75 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 12.073, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 42.407, + "latency_ms": { + "p50": 286.47, + "p95": 894.578, + "p99": 1310.622 + }, + "sql_queries": 2048, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 513, + "SELECT:chat_members": 514, + "BEGIN:other": 512, + "UPDATE:chats": 512, + "INSERT:messages": 512, + "COMMIT:other": 512, + "SELECT:messages": 1, + "SELECT:users": 1, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 83.69, + "peak_process_rss_mib": 337.67 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.333, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 96.08, + "latency_ms": { + "p50": 284.727, + "p95": 327.815, + "p99": 330.075 + }, + "sql_queries": 94, + "sql_per_request": 2.9375, + "sql_calls": { + "SELECT:sessions": 287, + "SELECT:chat_members": 287, + "SELECT:messages": 30 + }, + "process_cpu_percent_one_core": 118.44, + "peak_process_rss_mib": 337.67 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.044, + "successes": 1223, + "errors": 0, + "error_ratio": 0, + "successful_rps": 121.768, + "latency_ms": { + "p50": 91.481, + "p95": 321.382, + "p99": 734.962 + }, + "sql_queries": 2459, + "sql_per_request": 2.0106, + "sql_calls": { + "SELECT:sessions": 1473, + "SELECT:chat_members": 1478, + "SELECT:users": 3, + "SELECT:chats": 5, + "SELECT:messages": 250 + }, + "process_cpu_percent_one_core": 89.51, + "peak_process_rss_mib": 338.67 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.068, + "successes": 1546, + "errors": 0, + "error_ratio": 0, + "successful_rps": 153.558, + "latency_ms": { + "p50": 80.795, + "p95": 232.002, + "p99": 308.766 + }, + "sql_queries": 4638, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 1547, + "SELECT:chat_members": 1548, + "SELECT:messages": 1546, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 110.91, + "peak_process_rss_mib": 340.04 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 5.183, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 98.793, + "latency_ms": { + "p50": 128.122, + "p95": 353.18, + "p99": 583.008 + }, + "sql_queries": 2048, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 520, + "SELECT:chat_members": 526, + "BEGIN:other": 516, + "UPDATE:chats": 514, + "INSERT:messages": 514, + "COMMIT:other": 516, + "SELECT:messages": 7, + "INSERT:chats": 2, + "INSERT:chat_members": 2, + "SELECT:chats": 8, + "SELECT:users": 4, + "DELETE:chats": 1, + "DELETE:users": 1 + }, + "process_cpu_percent_one_core": 111.91, + "peak_process_rss_mib": 340.17 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": true + }, + "empty_cache_recovery": true, + "delayed_old_fill": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed", + "provenance_note": "Final measurements ran in dedicated benchmark containers via test/compose.benchmark.yaml; inherited exec-harness descriptions corrected; numeric measurements unchanged." +} diff --git a/evidence/cache-epochs-before-short.json b/evidence/cache-epochs-before-short.json new file mode 100644 index 0000000..f2fd7e6 --- /dev/null +++ b/evidence/cache-epochs-before-short.json @@ -0,0 +1,359 @@ +{ + "stage": "before", + "recorded_at": "2026-10-13T09:59:22.646Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented separate API process in running backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 5, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 128, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; idle production backend shares container; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "ea872420afc90a45acbffaebcc88137b8347928c9c13b9c4bdaa2d5a6feb1afb", + "cache/cache.service.js": "734ab028e3f492b5c85834b83f2a1cd099a1103f5ede165d4122d3d117a90e11" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 0.563, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 56.794, + "latency_ms": { + "p50": 514.259, + "p95": 549.926, + "p99": 550.079 + }, + "sql_queries": 50, + "sql_per_request": 1.5625, + "sql_calls": { + "SELECT:sessions": 81, + "SELECT:chat_members": 64, + "SELECT:messages": 3 + }, + "process_cpu_percent_one_core": 150.22, + "peak_process_rss_mib": 315.73 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 5.073, + "successes": 548, + "errors": 0, + "error_ratio": 0, + "successful_rps": 108.032, + "latency_ms": { + "p50": 130.008, + "p95": 291.287, + "p99": 356.116 + }, + "sql_queries": 769, + "sql_per_request": 1.4033, + "sql_calls": { + "SELECT:sessions": 620, + "SELECT:chat_members": 293, + "SELECT:messages": 72 + }, + "process_cpu_percent_one_core": 129.91, + "peak_process_rss_mib": 342.21 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 5.068, + "successes": 367, + "errors": 0, + "error_ratio": 0, + "successful_rps": 72.409, + "latency_ms": { + "p50": 181.984, + "p95": 561.768, + "p99": 733.63 + }, + "sql_queries": 864, + "sql_per_request": 2.3542, + "sql_calls": { + "SELECT:sessions": 368, + "SELECT:chat_members": 132, + "SELECT:messages": 367, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 84.44, + "peak_process_rss_mib": 341.98 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 1.191, + "successes": 128, + "errors": 0, + "error_ratio": 0, + "successful_rps": 107.445, + "latency_ms": { + "p50": 124.085, + "p95": 255.319, + "p99": 275.39 + }, + "sql_queries": 287, + "sql_per_request": 2.2422, + "sql_calls": { + "SELECT:sessions": 129, + "SELECT:chat_members": 33, + "INSERT:messages": 128, + "SELECT:messages": 1, + "SELECT:users": 1, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 107.51, + "peak_process_rss_mib": 342.6 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.139, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 230.08, + "latency_ms": { + "p50": 106.698, + "p95": 133.11, + "p99": 134.927 + }, + "sql_queries": 53, + "sql_per_request": 1.6563, + "sql_calls": { + "SELECT:sessions": 125, + "SELECT:chat_members": 95, + "SELECT:messages": 19 + }, + "process_cpu_percent_one_core": 164.26, + "peak_process_rss_mib": 342.85 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 5.037, + "successes": 944, + "errors": 0, + "error_ratio": 0, + "successful_rps": 187.429, + "latency_ms": { + "p50": 70.743, + "p95": 135.177, + "p99": 358.38 + }, + "sql_queries": 1439, + "sql_per_request": 1.5244, + "sql_calls": { + "SELECT:sessions": 1015, + "SELECT:chat_members": 566, + "SELECT:messages": 71 + }, + "process_cpu_percent_one_core": 114.96, + "peak_process_rss_mib": 345.48 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 5.098, + "successes": 366, + "errors": 0, + "error_ratio": 0, + "successful_rps": 71.799, + "latency_ms": { + "p50": 184.166, + "p95": 436.018, + "p99": 589.32 + }, + "sql_queries": 833, + "sql_per_request": 2.276, + "sql_calls": { + "SELECT:sessions": 367, + "SELECT:chat_members": 103, + "SELECT:messages": 366, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 88.68, + "peak_process_rss_mib": 345.6 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 0.922, + "successes": 128, + "errors": 0, + "error_ratio": 0, + "successful_rps": 138.768, + "latency_ms": { + "p50": 95.911, + "p95": 195.872, + "p99": 199.522 + }, + "sql_queries": 293, + "sql_per_request": 2.2891, + "sql_calls": { + "SELECT:sessions": 129, + "SELECT:chat_members": 39, + "INSERT:messages": 128, + "SELECT:messages": 1, + "SELECT:users": 1, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 127.07, + "peak_process_rss_mib": 345.6 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.179, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 179.248, + "latency_ms": { + "p50": 162.178, + "p95": 171.677, + "p99": 171.76 + }, + "sql_queries": 54, + "sql_per_request": 1.6875, + "sql_calls": { + "SELECT:sessions": 84, + "SELECT:chat_members": 54, + "SELECT:messages": 20 + }, + "process_cpu_percent_one_core": 142.84, + "peak_process_rss_mib": 345.6 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 5.034, + "successes": 901, + "errors": 0, + "error_ratio": 0, + "successful_rps": 178.972, + "latency_ms": { + "p50": 77.543, + "p95": 176.298, + "p99": 237.299 + }, + "sql_queries": 1312, + "sql_per_request": 1.4562, + "sql_calls": { + "SELECT:sessions": 937, + "SELECT:chat_members": 447, + "SELECT:messages": 36 + }, + "process_cpu_percent_one_core": 112.3, + "peak_process_rss_mib": 345.37 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 5.178, + "successes": 306, + "errors": 0, + "error_ratio": 0, + "successful_rps": 59.098, + "latency_ms": { + "p50": 260.185, + "p95": 428.119, + "p99": 458.774 + }, + "sql_queries": 686, + "sql_per_request": 2.2418, + "sql_calls": { + "SELECT:sessions": 307, + "SELECT:chat_members": 76, + "SELECT:messages": 306, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 86.24, + "peak_process_rss_mib": 345.37 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 1.401, + "successes": 128, + "errors": 0, + "error_ratio": 0, + "successful_rps": 91.365, + "latency_ms": { + "p50": 150.748, + "p95": 257.31, + "p99": 349.809 + }, + "sql_queries": 298, + "sql_per_request": 2.3281, + "sql_calls": { + "SELECT:sessions": 136, + "SELECT:chat_members": 56, + "INSERT:messages": 130, + "SELECT:messages": 5, + "BEGIN:other": 2, + "INSERT:chats": 2, + "INSERT:chat_members": 2, + "SELECT:chats": 8, + "COMMIT:other": 2, + "SELECT:users": 4, + "DELETE:chats": 1, + "DELETE:users": 1 + }, + "process_cpu_percent_one_core": 109.86, + "peak_process_rss_mib": 345.49 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": false + }, + "empty_cache_recovery": true, + "delayed_old_fill": false + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-epochs-before.json b/evidence/cache-epochs-before.json new file mode 100644 index 0000000..8151f1e --- /dev/null +++ b/evidence/cache-epochs-before.json @@ -0,0 +1,364 @@ +{ + "stage": "before", + "recorded_at": "2026-10-13T10:07:18.394Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 10, + "warmup_seconds": 3, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 512, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "ea872420afc90a45acbffaebcc88137b8347928c9c13b9c4bdaa2d5a6feb1afb", + "cache/cache.service.js": "734ab028e3f492b5c85834b83f2a1cd099a1103f5ede165d4122d3d117a90e11" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 0.447, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 71.563, + "latency_ms": { + "p50": 401.423, + "p95": 423.105, + "p99": 425.045 + }, + "sql_queries": 51, + "sql_per_request": 1.5938, + "sql_calls": { + "SELECT:sessions": 232, + "SELECT:chat_members": 216, + "SELECT:messages": 3 + }, + "process_cpu_percent_one_core": 155.27, + "peak_process_rss_mib": 324.13 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.269, + "successes": 1129, + "errors": 0, + "error_ratio": 0, + "successful_rps": 109.938, + "latency_ms": { + "p50": 122.379, + "p95": 292.651, + "p99": 616.608 + }, + "sql_queries": 1562, + "sql_per_request": 1.3835, + "sql_calls": { + "SELECT:sessions": 1197, + "SELECT:chat_members": 501, + "SELECT:messages": 68, + "SELECT:users": 1 + }, + "process_cpu_percent_one_core": 110.56, + "peak_process_rss_mib": 347.14 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.322, + "successes": 1222, + "errors": 0, + "error_ratio": 0, + "successful_rps": 118.389, + "latency_ms": { + "p50": 102.258, + "p95": 343.74, + "p99": 535.564 + }, + "sql_queries": 2859, + "sql_per_request": 2.3396, + "sql_calls": { + "SELECT:sessions": 1223, + "SELECT:chat_members": 416, + "SELECT:messages": 1222, + "SELECT:users": 1, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 102.93, + "peak_process_rss_mib": 347.76 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 13.557, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 37.766, + "latency_ms": { + "p50": 326.629, + "p95": 922.782, + "p99": 1374.53 + }, + "sql_queries": 1179, + "sql_per_request": 2.3027, + "sql_calls": { + "SELECT:sessions": 513, + "SELECT:chat_members": 155, + "INSERT:messages": 512, + "SELECT:users": 3, + "SELECT:messages": 1, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 83.01, + "peak_process_rss_mib": 348.89 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.945, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 33.861, + "latency_ms": { + "p50": 822.475, + "p95": 920.815, + "p99": 929.771 + }, + "sql_queries": 66, + "sql_per_request": 2.0625, + "sql_calls": { + "SELECT:sessions": 93, + "SELECT:chat_members": 63, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 72.88, + "peak_process_rss_mib": 349.01 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.065, + "successes": 937, + "errors": 0, + "error_ratio": 0, + "successful_rps": 93.097, + "latency_ms": { + "p50": 142.64, + "p95": 332.841, + "p99": 1107.841 + }, + "sql_queries": 1323, + "sql_per_request": 1.412, + "sql_calls": { + "SELECT:sessions": 1180, + "SELECT:chat_members": 614, + "SELECT:users": 6, + "SELECT:messages": 252 + }, + "process_cpu_percent_one_core": 105.28, + "peak_process_rss_mib": 350.01 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.047, + "successes": 1286, + "errors": 0, + "error_ratio": 0, + "successful_rps": 127.998, + "latency_ms": { + "p50": 98.94, + "p95": 288.491, + "p99": 565.282 + }, + "sql_queries": 3059, + "sql_per_request": 2.3787, + "sql_calls": { + "SELECT:sessions": 1287, + "SELECT:chat_members": 489, + "SELECT:messages": 1286, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 108.02, + "peak_process_rss_mib": 346.76 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 3.862, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 132.588, + "latency_ms": { + "p50": 106.471, + "p95": 216.752, + "p99": 308.493 + }, + "sql_queries": 1184, + "sql_per_request": 2.3125, + "sql_calls": { + "SELECT:sessions": 513, + "SELECT:chat_members": 162, + "INSERT:messages": 512, + "SELECT:messages": 1, + "SELECT:users": 1, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 114.95, + "peak_process_rss_mib": 347.01 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.161, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 199.281, + "latency_ms": { + "p50": 120.258, + "p95": 158.674, + "p99": 158.852 + }, + "sql_queries": 66, + "sql_per_request": 2.0625, + "sql_calls": { + "SELECT:sessions": 281, + "SELECT:chat_members": 251, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 100.51, + "peak_process_rss_mib": 347.01 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.023, + "successes": 1156, + "errors": 0, + "error_ratio": 0, + "successful_rps": 115.338, + "latency_ms": { + "p50": 125.309, + "p95": 267.044, + "p99": 339.122 + }, + "sql_queries": 1658, + "sql_per_request": 1.4343, + "sql_calls": { + "SELECT:sessions": 1340, + "SELECT:chat_members": 686, + "SELECT:messages": 184 + }, + "process_cpu_percent_one_core": 98.86, + "peak_process_rss_mib": 348.14 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.177, + "successes": 1261, + "errors": 0, + "error_ratio": 0, + "successful_rps": 123.902, + "latency_ms": { + "p50": 81.035, + "p95": 385.746, + "p99": 562.039 + }, + "sql_queries": 3074, + "sql_per_request": 2.4377, + "sql_calls": { + "SELECT:sessions": 1262, + "SELECT:chat_members": 554, + "SELECT:messages": 1261, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 101.1, + "peak_process_rss_mib": 348.26 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 4.582, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 111.731, + "latency_ms": { + "p50": 142.22, + "p95": 206.768, + "p99": 278.867 + }, + "sql_queries": 1222, + "sql_per_request": 2.3867, + "sql_calls": { + "SELECT:sessions": 520, + "SELECT:chat_members": 212, + "INSERT:messages": 514, + "SELECT:messages": 5, + "BEGIN:other": 2, + "INSERT:chats": 2, + "INSERT:chat_members": 2, + "SELECT:chats": 8, + "COMMIT:other": 2, + "SELECT:users": 4, + "DELETE:chats": 1, + "DELETE:users": 1 + }, + "process_cpu_percent_one_core": 97.65, + "peak_process_rss_mib": 348.26 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": false + }, + "empty_cache_recovery": true, + "delayed_old_fill": false + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed", + "provenance_note": "Final measurements ran in dedicated benchmark containers via test/compose.benchmark.yaml; inherited exec-harness descriptions corrected; numeric measurements unchanged." +} diff --git a/evidence/cache-epochs-environment.json b/evidence/cache-epochs-environment.json new file mode 100644 index 0000000..8f41a1a --- /dev/null +++ b/evidence/cache-epochs-environment.json @@ -0,0 +1,36 @@ +{ + "recorded_at": "2026-10-13T10:08:09.0775006Z", + "host_cpu": "AMD Ryzen 3 3250U with Radeon Graphics ", + "host_physical_cores": 2, + "host_logical_processors": 4, + "host_ram_bytes": 6358704128, + "docker_version": "28.3.2", + "docker_cpu_count": 4, + "docker_ram_bytes": 3008614400, + "docker_kernel": "6.6.87.2-microsoft-standard-WSL2", + "containers": [ + { + "name": "/mtusi2026lab2-fork-backend-1", + "image": "sha256:3f5578294952186fbdcf8c100f866b2397d17d08073cab66f1543f0a121e0196", + "memory_limit_bytes": 0, + "nano_cpus_limit": 0, + "cpu_quota": 0 + }, + { + "name": "/mtusi2026lab2-fork-postgres-1", + "image": "sha256:f3bd19c606e442c3d7bdfa8002e03fe260a1023351e0ea4598032022b68dd6e3", + "memory_limit_bytes": 0, + "nano_cpus_limit": 0, + "cpu_quota": 0 + }, + { + "name": "/mtusi2026lab2-fork-redis-1", + "image": "sha256:bb186d083732f669da90be8b0f975a37812b15e913465bb14d845db72a4e3e08", + "memory_limit_bytes": 0, + "nano_cpus_limit": 0, + "cpu_quota": 0 + } + ], + "before_image": "sha256:075170aed76a42aa98b435cfb918d83879259b7e17177275d5274e328198e119", + "before_image_local_tag": "lab2-cache-epochs:before" +} diff --git a/evidence/cache-epochs-full-restart.json b/evidence/cache-epochs-full-restart.json new file mode 100644 index 0000000..ded5116 --- /dev/null +++ b/evidence/cache-epochs-full-restart.json @@ -0,0 +1,79 @@ +{ + "recorded_at": "2026-10-13T10:15:19.958451+00:00", + "scenario": "full-restart", + "command": "python test/test-persistence.py --scenario full-restart --base-url http://127.0.0.1:8080", + "hook": "test/restart.cmd", + "elapsed_seconds": 49.081, + "result": "PASS", + "test_output": "Restarting backend, PostgreSQL and Redis; hook output suppressed.\nPASS: users, chat, membership, confirmed message and all existing sessions survived; access control, new writes and logout work after restart.", + "before": { + "backend": { + "id": "3bbcc8a6cb099f673f0fa5ab017c4a3e0a3a392eefc45c3b87478b2209c6f737", + "started_at": "2026-10-13T10:02:49.349051437Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_backend_data", + "destination": "/app/data" + } + ] + }, + "postgres": { + "id": "c2fbbfded445fbedeff7ae87dcc06b05bedb0d2b2c89050e4a1a2236b06398f5", + "started_at": "2026-10-13T09:02:55.540382028Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_postgres_data", + "destination": "/var/lib/postgresql/data" + } + ] + }, + "redis": { + "id": "547184576f5e04a076d8c41e504cb0669c4f7c17daed437a6ae1db41ee5d1435", + "started_at": "2026-10-13T09:02:55.507017233Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_redis_data", + "destination": "/data" + } + ] + } + }, + "after": { + "backend": { + "id": "3bbcc8a6cb099f673f0fa5ab017c4a3e0a3a392eefc45c3b87478b2209c6f737", + "started_at": "2026-10-13T10:15:01.980331864Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_backend_data", + "destination": "/app/data" + } + ] + }, + "postgres": { + "id": "c2fbbfded445fbedeff7ae87dcc06b05bedb0d2b2c89050e4a1a2236b06398f5", + "started_at": "2026-10-13T10:14:53.938044159Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_postgres_data", + "destination": "/var/lib/postgresql/data" + } + ] + }, + "redis": { + "id": "547184576f5e04a076d8c41e504cb0669c4f7c17daed437a6ae1db41ee5d1435", + "started_at": "2026-10-13T10:14:53.936011949Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_redis_data", + "destination": "/data" + } + ] + } + } +} diff --git a/evidence/cache-epochs-optimization-environment.json b/evidence/cache-epochs-optimization-environment.json new file mode 100644 index 0000000..696f95b --- /dev/null +++ b/evidence/cache-epochs-optimization-environment.json @@ -0,0 +1,14 @@ +{ + "recorded_on": "2026-10-13", + "build_command": "docker compose build backend migrate", + "startup_command": "docker compose up -d backend", + "backend_image": "sha256:a4799affbf3b82d4a120296b16306e7693c13007013061a911fb5d38ceb6d945", + "backend_status_after_measurement": "running healthy", + "benchmark_command": "docker compose -f compose.yaml -f test/compose.benchmark.yaml run --rm --no-deps --pull never benchmark node test/cache-benchmark.mjs after /results/cache-epochs-optimized.json", + "baseline": "cache-epochs-after.json", + "baseline_rerun": false, + "baseline_rerun_note": "The old image was unavailable after rebuilding and recreating backend; comparison uses the previously recorded measurement.", + "result": "cache-epochs-optimized.json", + "shared_host": true, + "password_kdf_measured": false +} diff --git a/evidence/cache-epochs-optimized.json b/evidence/cache-epochs-optimized.json new file mode 100644 index 0000000..663ca8f --- /dev/null +++ b/evidence/cache-epochs-optimized.json @@ -0,0 +1,364 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T12:44:51.207Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 10, + "warmup_seconds": 3, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 512, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "f0f8b0cd357dcbb2ba6f401e30dadfcf19ab0deb7c1a812b306126d0478289e2", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 0.98, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 32.646, + "latency_ms": { + "p50": 810.778, + "p95": 904.858, + "p99": 925.845 + }, + "sql_queries": 68, + "sql_per_request": 2.125, + "sql_calls": { + "SELECT:sessions": 309, + "SELECT:chat_members": 309, + "SELECT:messages": 4 + }, + "process_cpu_percent_one_core": 137.76, + "peak_process_rss_mib": 324.18 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.11, + "successes": 1488, + "errors": 0, + "error_ratio": 0, + "successful_rps": 147.176, + "latency_ms": { + "p50": 86.063, + "p95": 234.439, + "p99": 312.104 + }, + "sql_queries": 2976, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 1545, + "SELECT:chat_members": 1545, + "SELECT:messages": 57 + }, + "process_cpu_percent_one_core": 106.27, + "peak_process_rss_mib": 337.46 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.374, + "successes": 322, + "errors": 0, + "error_ratio": 0, + "successful_rps": 31.039, + "latency_ms": { + "p50": 436.283, + "p95": 929.932, + "p99": 1474.923 + }, + "sql_queries": 976, + "sql_per_request": 3.0311, + "sql_calls": { + "SELECT:sessions": 323, + "SELECT:chat_members": 324, + "SELECT:messages": 322, + "SELECT:users": 10, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 66.54, + "peak_process_rss_mib": 337.96 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.287, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 49.771, + "latency_ms": { + "p50": 260.806, + "p95": 738.898, + "p99": 965.908 + }, + "sql_queries": 1034, + "sql_per_request": 2.0195, + "sql_calls": { + "SELECT:sessions": 513, + "WITH:messages": 512, + "SELECT:users": 11, + "SELECT:messages": 1, + "SELECT:chat_members": 2, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 93.87, + "peak_process_rss_mib": 338.84 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.77, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 41.537, + "latency_ms": { + "p50": 672.643, + "p95": 745.713, + "p99": 748.905 + }, + "sql_queries": 96, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 93, + "SELECT:chat_members": 93, + "SELECT:messages": 32, + "SELECT:users": 1 + }, + "process_cpu_percent_one_core": 58.09, + "peak_process_rss_mib": 338.96 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.214, + "successes": 833, + "errors": 0, + "error_ratio": 0, + "successful_rps": 81.558, + "latency_ms": { + "p50": 128.736, + "p95": 448.026, + "p99": 1544.627 + }, + "sql_queries": 1681, + "sql_per_request": 2.018, + "sql_calls": { + "SELECT:sessions": 930, + "SELECT:chat_members": 930, + "SELECT:messages": 107, + "SELECT:users": 5 + }, + "process_cpu_percent_one_core": 94.41, + "peak_process_rss_mib": 340.34 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.064, + "successes": 1255, + "errors": 0, + "error_ratio": 0, + "successful_rps": 124.707, + "latency_ms": { + "p50": 106.65, + "p95": 266.189, + "p99": 359.971 + }, + "sql_queries": 3765, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 1256, + "SELECT:chat_members": 1257, + "SELECT:messages": 1255, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 111.86, + "peak_process_rss_mib": 340.84 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 6.533, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 78.376, + "latency_ms": { + "p50": 177.2, + "p95": 449.017, + "p99": 845.318 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 513, + "WITH:messages": 512, + "SELECT:messages": 1, + "SELECT:users": 1, + "SELECT:chat_members": 2, + "SELECT:chats": 1 + }, + "process_cpu_percent_one_core": 73.1, + "peak_process_rss_mib": 336.5 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.195, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 164.292, + "latency_ms": { + "p50": 154.84, + "p95": 192.727, + "p99": 193.302 + }, + "sql_queries": 96, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 363, + "SELECT:chat_members": 363, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 145.63, + "peak_process_rss_mib": 336.5 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.083, + "successes": 1743, + "errors": 0, + "error_ratio": 0, + "successful_rps": 172.865, + "latency_ms": { + "p50": 70.009, + "p95": 264.654, + "p99": 375.625 + }, + "sql_queries": 3486, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 2064, + "SELECT:chat_members": 2064, + "SELECT:messages": 321 + }, + "process_cpu_percent_one_core": 99.18, + "peak_process_rss_mib": 337.63 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.049, + "successes": 1211, + "errors": 0, + "error_ratio": 0, + "successful_rps": 120.513, + "latency_ms": { + "p50": 95.552, + "p95": 318.854, + "p99": 545.995 + }, + "sql_queries": 3634, + "sql_per_request": 3.0008, + "sql_calls": { + "SELECT:sessions": 1212, + "SELECT:chat_members": 1213, + "SELECT:messages": 1211, + "SELECT:users": 1, + "BEGIN:other": 1, + "INSERT:chats": 1, + "INSERT:chat_members": 1, + "SELECT:chats": 2, + "COMMIT:other": 1 + }, + "process_cpu_percent_one_core": 103.04, + "peak_process_rss_mib": 337.88 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 2.292, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 223.362, + "latency_ms": { + "p50": 67.388, + "p95": 116.128, + "p99": 143.105 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 520, + "WITH:messages": 514, + "SELECT:messages": 7, + "BEGIN:other": 2, + "INSERT:chats": 2, + "INSERT:chat_members": 2, + "SELECT:chats": 2, + "COMMIT:other": 2, + "SELECT:chat_members": 6, + "SELECT:users": 4, + "DELETE:chats": 1, + "DELETE:users": 1 + }, + "process_cpu_percent_one_core": 116.59, + "peak_process_rss_mib": 337.88 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": true + }, + "empty_cache_recovery": true, + "delayed_old_fill": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-epochs-smoke.txt b/evidence/cache-epochs-smoke.txt new file mode 100644 index 0000000..9215419 --- /dev/null +++ b/evidence/cache-epochs-smoke.txt @@ -0,0 +1 @@ +PASS: lab2 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/cache-strategy-averages.json b/evidence/cache-strategy-averages.json new file mode 100644 index 0000000..5edffc0 --- /dev/null +++ b/evidence/cache-strategy-averages.json @@ -0,0 +1,130 @@ +[ + { + "workload": "cold-history-burst", + "variant": "Redis и эпохи", + "successes": 96, + "errors": 0, + "mean_rps": 40.78164825828378, + "mean_latency_ms": 696.118, + "mean_p95_ms": 747.7330000000001, + "sql_per_request": 2.6875, + "median_rps": 152.051, + "repeat_rps": [ + 15.856, + 253.886, + 152.051 + ] + }, + { + "workload": "cold-history-burst", + "variant": "Без Redis и эпох", + "successes": 96, + "errors": 0, + "mean_rps": 13.292716698975354, + "mean_latency_ms": 1928.236666666667, + "mean_p95_ms": 2329.4153333333334, + "sql_per_request": 4, + "median_rps": 14.503, + "repeat_rps": [ + 7.221, + 14.503, + 54.771 + ] + }, + { + "workload": "warm-history", + "variant": "Redis и эпохи", + "successes": 5021, + "errors": 0, + "mean_rps": 166.20324395895398, + "mean_latency_ms": 95.88716530571598, + "mean_p95_ms": 234.04766666666663, + "sql_per_request": 2.0005974905397332, + "median_rps": 164.773, + "repeat_rps": [ + 117.759, + 215.98, + 164.773 + ] + }, + { + "workload": "warm-history", + "variant": "Без Redis и эпох", + "successes": 1328, + "errors": 0, + "mean_rps": 42.89544235924932, + "mean_latency_ms": 367.9795504518072, + "mean_p95_ms": 1276.5203333333334, + "sql_per_request": 4, + "median_rps": 32.229, + "repeat_rps": [ + 10.493, + 32.229, + 87.24 + ] + }, + { + "workload": "history-cache-bypassed", + "variant": "Redis и эпохи", + "successes": 4361, + "errors": 0, + "mean_rps": 144.25112463614713, + "mean_latency_ms": 110.48886677367577, + "mean_p95_ms": 245.43433333333334, + "sql_per_request": 3, + "median_rps": 138.041, + "repeat_rps": [ + 121.508, + 173.29, + 138.041 + ] + }, + { + "workload": "history-cache-bypassed", + "variant": "Без Redis и эпох", + "successes": 2310, + "errors": 0, + "mean_rps": 75.05360972122945, + "mean_latency_ms": 211.4604606060606, + "mean_p95_ms": 652.2803333333334, + "sql_per_request": 4, + "median_rps": 85.347, + "repeat_rps": [ + 29.122, + 85.347, + 111.971 + ] + }, + { + "workload": "writes-single-chat", + "variant": "Redis и эпохи", + "successes": 1536, + "errors": 0, + "mean_rps": 125.02034836399152, + "mean_latency_ms": 126.96133333333334, + "mean_p95_ms": 288.68533333333335, + "sql_per_request": 2, + "median_rps": 144.623, + "repeat_rps": [ + 144.623, + 230.243, + 78.507 + ] + }, + { + "workload": "writes-single-chat", + "variant": "Без Redis и эпох", + "successes": 1536, + "errors": 0, + "mean_rps": 38.749716188602136, + "mean_latency_ms": 410.8933333333334, + "mean_p95_ms": 903.404, + "sql_per_request": 3, + "median_rps": 57.224, + "repeat_rps": [ + 20.933, + 57.224, + 82.146 + ] + } +] diff --git a/evidence/cache-strategy-buckets-averages.json b/evidence/cache-strategy-buckets-averages.json new file mode 100644 index 0000000..a688f79 --- /dev/null +++ b/evidence/cache-strategy-buckets-averages.json @@ -0,0 +1,98 @@ +[ + { + "workload": "cold-history-burst", + "variant": "Redis и эпохи", + "successes": 192, + "errors": 0, + "mean_rps": 46.66990763247448, + "mean_latency_ms": 999.8886666666667, + "mean_p95_ms": 1320.421, + "sql_per_request": 1.6354166666666667, + "median_rps": 146.31, + "repeat_rps": [ + 18.471, + 146.31, + 301.879 + ] + }, + { + "workload": "cold-history-burst", + "variant": "Без Redis и эпох", + "successes": 192, + "errors": 0, + "mean_rps": 25.29977599156674, + "mean_latency_ms": 1941.6126666666669, + "mean_p95_ms": 2450.7083333333335, + "sql_per_request": 2, + "median_rps": 205.101, + "repeat_rps": [ + 9.141, + 231.506, + 205.101 + ] + }, + { + "workload": "warm-history", + "variant": "Redis и эпохи", + "successes": 33260, + "errors": 0, + "mean_rps": 184.21081781627657, + "mean_latency_ms": 173.46601040288635, + "mean_p95_ms": 427.6743333333334, + "sql_per_request": 1.0089897775105232, + "median_rps": 174.524, + "repeat_rps": [ + 156.764, + 221.493, + 174.524 + ] + }, + { + "workload": "warm-history", + "variant": "Без Redis и эпох", + "successes": 23473, + "errors": 0, + "mean_rps": 130.21312948642563, + "mean_latency_ms": 245.4783085672901, + "mean_p95_ms": 762.3959999999998, + "sql_per_request": 2, + "median_rps": 154.284, + "repeat_rps": [ + 71.208, + 154.284, + 165.155 + ] + }, + { + "workload": "writes-single-chat", + "variant": "Redis и эпохи", + "successes": 12288, + "errors": 0, + "mean_rps": 120.6337986687872, + "mean_latency_ms": 264.88033333333334, + "mean_p95_ms": 666.798, + "sql_per_request": 2, + "median_rps": 112.463, + "repeat_rps": [ + 86.54, + 226.178, + 112.463 + ] + }, + { + "workload": "writes-single-chat", + "variant": "Без Redis и эпох", + "successes": 12288, + "errors": 0, + "mean_rps": 128.2792746708981, + "mean_latency_ms": 249.03166666666667, + "mean_p95_ms": 556.831, + "sql_per_request": 2, + "median_rps": 135.958, + "repeat_rps": [ + 114.551, + 136.96, + 135.958 + ] + } +] diff --git a/evidence/cache-strategy-buckets-experiment.json b/evidence/cache-strategy-buckets-experiment.json new file mode 100644 index 0000000..ab2e5d6 --- /dev/null +++ b/evidence/cache-strategy-buckets-experiment.json @@ -0,0 +1,79 @@ +{ + "recorded_at": "2026-10-13T15:33:12.472Z", + "image": "sha256:02a5d9ca3816781e5931a82926b6a62858b1abf1eb9a0244da79d45e5787b020", + "modified_sources": { + "Chat/chat.service.ts": { + "original_source": "31261ecc0c40ddb40de947e8b7dc27d9a4b0269e0d8c4ff7818c5449953f36bc", + "experiment_source": "5941c5311816cfcaedad4ec40952d29b9b3f464b2d039e0345b7dbc9285c1ffa", + "experiment_js": "8d5b8d2072c8d3f2ea5736a065782778f58cd8932ea69877a41e45b555b99536" + }, + "Auth/auth.service.ts": { + "original_source": "78c7c8567a12347a9a65343d3ead5c931cecba34f0b83565f41205f8d61aa5b1", + "experiment_source": "2a87a69ec2f7e66602c3f601da8568520a7a89c2539fd1802f01e43e2a1cf105", + "experiment_js": "75af4ff945f2c3af7a224ca773e0d4357e27e0fbe64cdc050bc6b1875c04d0e9" + }, + "User/user.guard.ts": { + "original_source": "20b05a0e5272a4ee1ccbddef83494e62621ffb0236e56a15c17e7f8f0083f6d7", + "experiment_source": "508995073333183df4bda2fb5a0b97311ba40ebec6cbcd56bf8d947b3849a6e4", + "experiment_js": "4c2b79845c3e83b84d0a219b233c0b7d6f3782ecd80758cd7be6e461ce87cdd7" + }, + "Chat/chat.controller.ts": { + "original_source": "1e3b1e0a5abc053625c5b1a6dc14f5b5b3e87676b1af0bdd73e78ad95d1eb325", + "experiment_source": "a08adb9a951725731262f4332901fac2a6653441442b184800b12e02a47a36f3", + "experiment_js": "df7593892dcf458e23c7f85dde69b945b137c6226373e3ee4b75df5d82b45aba" + }, + "cache/cache.service.ts": { + "original_source": "f27ab6ff5a0f8da05936272bafbc7cea38198074e5c7d17c2e01ae0bf29986b3", + "experiment_source": "d9abf1e2b368010934214a8730ca99d085eda57c748bbc69ccd5a0a085d66a9a", + "experiment_js": "fa132f28aa07f0a7118d308a073c296dd319131b63c15bd9a700d8ac874cd7a1" + }, + "User/user.service.ts": { + "original_source": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "experiment_source": "7596e2b9a5aacb4f19f5de32cd502c89b09080235ae5b8cf821f35b95ae8056c", + "experiment_js": "90cfd8c45b02a6d4a5220a869d86ab5bac66b6b4c6a9f79685cd7c24a97fc2cb" + } + }, + "command": [ + "docker", + "compose", + "-f", + "compose.yaml", + "-f", + "test/compose.benchmark.yaml", + "-f", + "C:\\Users\\olpin\\AppData\\Local\\Temp\\lab2-no-epochs-y2Di7V\\compose.no-epochs.yaml", + "run", + "--rm", + "--no-deps", + "--pull", + "never", + "benchmark", + "node", + "/experiment/cache-benchmark.mjs", + "after", + "/results/cache-strategy-buckets-no-redis-no-epochs.json", + "--concurrency", + "32", + "--duration-seconds", + "60", + "--warmup-seconds", + "10", + "--repetitions", + "3", + "--seed-messages", + "100000", + "--cold-burst", + "64", + "--writes-per-repeat", + "4096", + "--skip-history-control" + ], + "implementation": "Separate temporary source copies compiled with TypeScript and mounted over six application modules. Workspace sources and running backend remain unchanged.", + "schema": "Epoch storage remains in the database; experiment API paths do not update counters or read authoritative epoch values.", + "redis": "Application starts without CACHE_URL. Observer/proxy are retained only for benchmark setup and cleanup.", + "full_result": "cache-strategy-buckets-full.json", + "experiment_result": "cache-strategy-buckets-no-redis-no-epochs.json", + "exit_code": 0, + "signal": null, + "sources_unchanged": true +} diff --git a/evidence/cache-strategy-buckets-full.json b/evidence/cache-strategy-buckets-full.json new file mode 100644 index 0000000..a0c82bc --- /dev/null +++ b/evidence/cache-strategy-buckets-full.json @@ -0,0 +1,262 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T15:25:47.899Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 32, + "duration_seconds": 60, + "warmup_seconds": 10, + "repetitions": 3, + "seed_messages": 100000, + "cold_burst_requests": 64, + "writes_per_repeat": 4096, + "history_control": false, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "d2b548d5ecb769de012a710d04a04658096b60a05e3776ec5aa05d30b827cb8b", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693", + "Auth/auth.service.js": "813d4cd5152687f4a32b4f12c1852c2070fea9ec3540a6951e691e3a7f975787", + "User/user.guard.js": "7b0ac310735e9678c36b2996b960f7719a6e590463b2ece04719b79919fbcc2d", + "Chat/chat.controller.js": "cce401ec9757fb9b074219f2c6e54b7ae029c18d857bcd3b1e45d9c205bbb5f0" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 64, + "elapsed_seconds": 3.465, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 18.471, + "latency_ms": { + "mean": 2479.197, + "p50": 2606.245, + "p95": 3324.299, + "p99": 3354.605 + }, + "sql_queries": 69, + "sql_per_request": 1.0781, + "sql_calls": { + "SELECT:chat_members": 64, + "SELECT:messages": 5 + }, + "process_cpu_percent_one_core": 76.08, + "peak_process_rss_mib": 518.86 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 60.416, + "successes": 9471, + "errors": 0, + "error_ratio": 0, + "successful_rps": 156.764, + "latency_ms": { + "mean": 203.598, + "p50": 139.567, + "p95": 525.738, + "p99": 1023.581 + }, + "sql_queries": 9628, + "sql_per_request": 1.0166, + "sql_calls": { + "SELECT:chat_members": 9471, + "SELECT:messages": 157 + }, + "process_cpu_percent_one_core": 101.3, + "peak_process_rss_mib": 535.37 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 47.331, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 86.54, + "latency_ms": { + "mean": 369.031, + "p50": 280.196, + "p95": 924.786, + "p99": 1332.847 + }, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 4096, + "WITH:messages": 4096 + }, + "process_cpu_percent_one_core": 88.15, + "peak_process_rss_mib": 536.11 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 64, + "elapsed_seconds": 0.437, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 146.31, + "latency_ms": { + "mean": 359.503, + "p50": 353.104, + "p95": 428.472, + "p99": 433.08 + }, + "sql_queries": 122, + "sql_per_request": 1.9063, + "sql_calls": { + "SELECT:chat_members": 64, + "SELECT:messages": 58 + }, + "process_cpu_percent_one_core": 114.66, + "peak_process_rss_mib": 536.23 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 60.083, + "successes": 13308, + "errors": 0, + "error_ratio": 0, + "successful_rps": 221.493, + "latency_ms": { + "mean": 144.365, + "p50": 115.355, + "p95": 319.893, + "p99": 425.247 + }, + "sql_queries": 13345, + "sql_per_request": 1.0028, + "sql_calls": { + "SELECT:chat_members": 13308, + "SELECT:messages": 37 + }, + "process_cpu_percent_one_core": 102.17, + "peak_process_rss_mib": 538.23 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 18.11, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 226.178, + "latency_ms": { + "mean": 141.366, + "p50": 107.516, + "p95": 342.712, + "p99": 584.61 + }, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 4096, + "WITH:messages": 4096 + }, + "process_cpu_percent_one_core": 105.53, + "peak_process_rss_mib": 538.23 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 64, + "elapsed_seconds": 0.212, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 301.879, + "latency_ms": { + "mean": 160.966, + "p50": 166.123, + "p95": 208.492, + "p99": 209.047 + }, + "sql_queries": 123, + "sql_per_request": 1.9219, + "sql_calls": { + "SELECT:chat_members": 64, + "SELECT:messages": 59 + }, + "process_cpu_percent_one_core": 97.81, + "peak_process_rss_mib": 538.23 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 60.055, + "successes": 10481, + "errors": 0, + "error_ratio": 0, + "successful_rps": 174.524, + "latency_ms": { + "mean": 183.188, + "p50": 129.296, + "p95": 437.392, + "p99": 820.34 + }, + "sql_queries": 10586, + "sql_per_request": 1.01, + "sql_calls": { + "SELECT:chat_members": 10481, + "SELECT:messages": 105 + }, + "process_cpu_percent_one_core": 89.54, + "peak_process_rss_mib": 538.86 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 36.421, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 112.463, + "latency_ms": { + "mean": 284.244, + "p50": 205.933, + "p95": 732.896, + "p99": 1066.21 + }, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 4096, + "WITH:messages": 4096 + }, + "process_cpu_percent_one_core": 81.25, + "peak_process_rss_mib": 538.98 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": true + }, + "empty_cache_recovery": true, + "delayed_old_fill": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-strategy-buckets-no-redis-no-epochs.json b/evidence/cache-strategy-buckets-no-redis-no-epochs.json new file mode 100644 index 0000000..8806b2d --- /dev/null +++ b/evidence/cache-strategy-buckets-no-redis-no-epochs.json @@ -0,0 +1,258 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T15:33:56.329Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 32, + "duration_seconds": 60, + "warmup_seconds": 10, + "repetitions": 3, + "seed_messages": 100000, + "cold_burst_requests": 64, + "writes_per_repeat": 4096, + "history_control": false, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "8d5b8d2072c8d3f2ea5736a065782778f58cd8932ea69877a41e45b555b99536", + "cache/cache.service.js": "fa132f28aa07f0a7118d308a073c296dd319131b63c15bd9a700d8ac874cd7a1", + "Auth/auth.service.js": "75af4ff945f2c3af7a224ca773e0d4357e27e0fbe64cdc050bc6b1875c04d0e9", + "User/user.guard.js": "4c2b79845c3e83b84d0a219b233c0b7d6f3782ecd80758cd7be6e461ce87cdd7", + "Chat/chat.controller.js": "df7593892dcf458e23c7f85dde69b945b137c6226373e3ee4b75df5d82b45aba" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 64, + "elapsed_seconds": 7.001, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 9.141, + "latency_ms": { + "mean": 5440.542, + "p50": 5886.145, + "p95": 6793.244, + "p99": 6815.613 + }, + "sql_queries": 128, + "sql_per_request": 2, + "sql_calls": { + "SELECT:chat_members": 64, + "SELECT:messages": 64 + }, + "process_cpu_percent_one_core": 51.46, + "peak_process_rss_mib": 510.95 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 60.092, + "successes": 4279, + "errors": 0, + "error_ratio": 0, + "successful_rps": 71.208, + "latency_ms": { + "mean": 448.479, + "p50": 320.114, + "p95": 1342.793, + "p99": 2414.964 + }, + "sql_queries": 8558, + "sql_per_request": 2, + "sql_calls": { + "SELECT:chat_members": 4279, + "SELECT:messages": 4279 + }, + "process_cpu_percent_one_core": 88.25, + "peak_process_rss_mib": 537.16 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 35.757, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 114.551, + "latency_ms": { + "mean": 278.841, + "p50": 236.409, + "p95": 590.17, + "p99": 1432.035 + }, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 4096, + "INSERT:messages": 4096 + }, + "process_cpu_percent_one_core": 96.82, + "peak_process_rss_mib": 535.46 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 64, + "elapsed_seconds": 0.276, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 231.506, + "latency_ms": { + "mean": 183.505, + "p50": 176.559, + "p95": 263.688, + "p99": 267.248 + }, + "sql_queries": 128, + "sql_per_request": 2, + "sql_calls": { + "SELECT:chat_members": 64, + "SELECT:messages": 64 + }, + "process_cpu_percent_one_core": 135.45, + "peak_process_rss_mib": 535.71 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 60.091, + "successes": 9271, + "errors": 0, + "error_ratio": 0, + "successful_rps": 154.284, + "latency_ms": { + "mean": 207.269, + "p50": 150.569, + "p95": 474.167, + "p99": 718.176 + }, + "sql_queries": 18542, + "sql_per_request": 2, + "sql_calls": { + "SELECT:chat_members": 9271, + "SELECT:messages": 9271 + }, + "process_cpu_percent_one_core": 106.99, + "peak_process_rss_mib": 537.71 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 29.907, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 136.96, + "latency_ms": { + "mean": 233.316, + "p50": 172.903, + "p95": 521.985, + "p99": 1168.736 + }, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 4096, + "INSERT:messages": 4096 + }, + "process_cpu_percent_one_core": 94.66, + "peak_process_rss_mib": 537.71 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 64, + "elapsed_seconds": 0.312, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 205.101, + "latency_ms": { + "mean": 200.791, + "p50": 195.491, + "p95": 295.193, + "p99": 304.063 + }, + "sql_queries": 128, + "sql_per_request": 2, + "sql_calls": { + "SELECT:chat_members": 64, + "SELECT:messages": 64 + }, + "process_cpu_percent_one_core": 123.32, + "peak_process_rss_mib": 537.84 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 60.083, + "successes": 9923, + "errors": 0, + "error_ratio": 0, + "successful_rps": 165.155, + "latency_ms": { + "mean": 193.639, + "p50": 142.886, + "p95": 470.228, + "p99": 718.957 + }, + "sql_queries": 19846, + "sql_per_request": 2, + "sql_calls": { + "SELECT:chat_members": 9923, + "SELECT:messages": 9923 + }, + "process_cpu_percent_one_core": 100.11, + "peak_process_rss_mib": 537.96 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 30.127, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 135.958, + "latency_ms": { + "mean": 234.938, + "p50": 186.87, + "p95": 558.338, + "p99": 794.478 + }, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 4096, + "INSERT:messages": 4096 + }, + "process_cpu_percent_one_core": 97.46, + "peak_process_rss_mib": 539.09 + } + ], + "correctness": { + "no_redis_client": true, + "epochs_unchanged": true, + "read_after_write": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-strategy-experiment.json b/evidence/cache-strategy-experiment.json new file mode 100644 index 0000000..ec24415 --- /dev/null +++ b/evidence/cache-strategy-experiment.json @@ -0,0 +1,64 @@ +{ + "recorded_at": "2026-10-13T13:04:30.585Z", + "image": "sha256:a4799affbf3b82d4a120296b16306e7693c13007013061a911fb5d38ceb6d945", + "modified_sources": { + "Chat/chat.service.ts": { + "original_source": "11b6b6d361d5599667318540b2c83a1b8e397db6d4d3665bbfa526e0b349d430", + "experiment_source": "b2aaf10ea1994df9418e157f3d61747182f0dc7f8ac7b1faa70caf6e9b936395", + "experiment_js": "d8228f1bb09e50cba1dc604cf2494a43f5a36db35631bdc28cca55c8bb6ea013" + }, + "Auth/auth.service.ts": { + "original_source": "86599b6e89cd66483cb10aff0d85cc29fe092ab24bbb849960079dcae347b8bf", + "experiment_source": "09a6ee6599c1e4434fe1ad00cac973ea3b5c189e93aa72c3f9b353f5ff2695b2", + "experiment_js": "15b5e9104116f6eb4a214622f754fdd97b14f20f0c93c8b5644820392129671e" + }, + "User/user.guard.ts": { + "original_source": "b84d95633fbd89b4fdbc505c51dd64e657611651b757bed1aea8eee3f0eac3d9", + "experiment_source": "61542fe2b85fb5b83ba8bfb8ddee0d34a8f8216eb0283b0987489666bb4f87fd", + "experiment_js": "187bc710bb75421c098fcde7e2ee9004c2b01f6b569f639c20779f4d5ed47d99" + }, + "Chat/chat.controller.ts": { + "original_source": "700becb64112538a6551c5775ccc09ff9d750755dcffe6ec916782afed1dae11", + "experiment_source": "29f56fcb998e4fc115fbad3705e9c6c7738e528165c4c012fa662c1a7a0e35f5", + "experiment_js": "e6a9a63bf5a17d5f7e3138077ea4874f2c25b6e378f1d86691f08c87d2d23da0" + }, + "cache/cache.service.ts": { + "original_source": "f27ab6ff5a0f8da05936272bafbc7cea38198074e5c7d17c2e01ae0bf29986b3", + "experiment_source": "d9abf1e2b368010934214a8730ca99d085eda57c748bbc69ccd5a0a085d66a9a", + "experiment_js": "fa132f28aa07f0a7118d308a073c296dd319131b63c15bd9a700d8ac874cd7a1" + }, + "User/user.service.ts": { + "original_source": "de158e39c114c610cc7ea6c850108c8dd69c9bc3d643bac94557d272621f3cfb", + "experiment_source": "532bbba837fcbc9ad6b431316680dc0bdd7a910b9870fe0ec625c7d81fa53ddd", + "experiment_js": "90cfd8c45b02a6d4a5220a869d86ab5bac66b6b4c6a9f79685cd7c24a97fc2cb" + } + }, + "command": [ + "docker", + "compose", + "-f", + "compose.yaml", + "-f", + "test/compose.benchmark.yaml", + "-f", + "C:\\Users\\olpin\\AppData\\Local\\Temp\\lab2-no-epochs-fxZFbE\\compose.no-epochs.yaml", + "run", + "--rm", + "--no-deps", + "--pull", + "never", + "benchmark", + "node", + "/experiment/cache-benchmark.mjs", + "after", + "/results/cache-strategy-no-redis-no-epochs.json" + ], + "implementation": "Separate temporary source copies compiled with TypeScript and mounted over six application modules. Workspace sources and running backend remain unchanged.", + "schema": "Unused epoch columns remain; no migration, counter update or authoritative epoch read in the experiment API paths.", + "redis": "Application starts without CACHE_URL. Observer/proxy are retained only for benchmark setup and cleanup.", + "full_result": "cache-strategy-full.json", + "experiment_result": "cache-strategy-no-redis-no-epochs.json", + "exit_code": 0, + "signal": null, + "sources_unchanged": true +} diff --git a/evidence/cache-strategy-full.json b/evidence/cache-strategy-full.json new file mode 100644 index 0000000..f4adad8 --- /dev/null +++ b/evidence/cache-strategy-full.json @@ -0,0 +1,338 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T13:00:23.771Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 10, + "warmup_seconds": 3, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 512, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "f0f8b0cd357dcbb2ba6f401e30dadfcf19ab0deb7c1a812b306126d0478289e2", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 2.018, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 15.856, + "latency_ms": { + "mean": 1796.174, + "p50": 1840.086, + "p95": 1916.159, + "p99": 1926.09 + }, + "sql_queries": 68, + "sql_per_request": 2.125, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 2, + "SELECT:users": 2 + }, + "process_cpu_percent_one_core": 72.84, + "peak_process_rss_mib": 330.04 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.08, + "successes": 1187, + "errors": 0, + "error_ratio": 0, + "successful_rps": 117.759, + "latency_ms": { + "mean": 135.17, + "p50": 93.299, + "p95": 314.09, + "p99": 1264.56 + }, + "sql_queries": 2377, + "sql_per_request": 2.0025, + "sql_calls": { + "SELECT:sessions": 1187, + "SELECT:chat_members": 1187, + "SELECT:users": 3 + }, + "process_cpu_percent_one_core": 120.31, + "peak_process_rss_mib": 350.43 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.049, + "successes": 1221, + "errors": 0, + "error_ratio": 0, + "successful_rps": 121.508, + "latency_ms": { + "mean": 131.408, + "p50": 94.183, + "p95": 315.506, + "p99": 465.341 + }, + "sql_queries": 3663, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 1221, + "SELECT:chat_members": 1221, + "SELECT:messages": 1221 + }, + "process_cpu_percent_one_core": 107.31, + "peak_process_rss_mib": 351.05 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 3.54, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 144.623, + "latency_ms": { + "mean": 109.902, + "p50": 87.761, + "p95": 244.052, + "p99": 343.535 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 121.51, + "peak_process_rss_mib": 351.68 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.126, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 253.886, + "latency_ms": { + "mean": 115.632, + "p50": 114.914, + "p95": 120.78, + "p99": 123.616 + }, + "sql_queries": 96, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 122.64, + "peak_process_rss_mib": 347.61 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.098, + "successes": 2181, + "errors": 0, + "error_ratio": 0, + "successful_rps": 215.98, + "latency_ms": { + "mean": 73.643, + "p50": 58.478, + "p95": 167.898, + "p99": 255.596 + }, + "sql_queries": 4362, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 2181, + "SELECT:chat_members": 2181 + }, + "process_cpu_percent_one_core": 114.09, + "peak_process_rss_mib": 348.86 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.041, + "successes": 1740, + "errors": 0, + "error_ratio": 0, + "successful_rps": 173.29, + "latency_ms": { + "mean": 92.117, + "p50": 74.146, + "p95": 195.93, + "p99": 429.858 + }, + "sql_queries": 5220, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 1740, + "SELECT:chat_members": 1740, + "SELECT:messages": 1740 + }, + "process_cpu_percent_one_core": 113.81, + "peak_process_rss_mib": 349.33 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 2.224, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 230.243, + "latency_ms": { + "mean": 68.974, + "p50": 61.759, + "p95": 113.761, + "p99": 210.209 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 119.03, + "peak_process_rss_mib": 349.33 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.21, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 152.051, + "latency_ms": { + "mean": 176.548, + "p50": 179.571, + "p95": 206.26, + "p99": 207.106 + }, + "sql_queries": 94, + "sql_per_request": 2.9375, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 30 + }, + "process_cpu_percent_one_core": 126.37, + "peak_process_rss_mib": 349.33 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.032, + "successes": 1653, + "errors": 0, + "error_ratio": 0, + "successful_rps": 164.773, + "latency_ms": { + "mean": 97.028, + "p50": 76.509, + "p95": 220.155, + "p99": 339.868 + }, + "sql_queries": 3306, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 1653, + "SELECT:chat_members": 1653 + }, + "process_cpu_percent_one_core": 106, + "peak_process_rss_mib": 349.83 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.142, + "successes": 1400, + "errors": 0, + "error_ratio": 0, + "successful_rps": 138.041, + "latency_ms": { + "mean": 115.078, + "p50": 94.485, + "p95": 224.867, + "p99": 389.849 + }, + "sql_queries": 4200, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 1400, + "SELECT:chat_members": 1400, + "SELECT:messages": 1400 + }, + "process_cpu_percent_one_core": 118.4, + "peak_process_rss_mib": 350.33 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 6.522, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 78.507, + "latency_ms": { + "mean": 202.008, + "p50": 149.193, + "p95": 508.243, + "p99": 1019.547 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 68.33, + "peak_process_rss_mib": 350.58 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": true + }, + "empty_cache_recovery": true, + "delayed_old_fill": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-strategy-long-averages.json b/evidence/cache-strategy-long-averages.json new file mode 100644 index 0000000..7c2480e --- /dev/null +++ b/evidence/cache-strategy-long-averages.json @@ -0,0 +1,98 @@ +[ + { + "workload": "cold-history-burst", + "variant": "Redis и эпохи", + "successes": 192, + "errors": 0, + "mean_rps": 65.91143151390318, + "mean_latency_ms": 754.3346666666666, + "mean_p95_ms": 933.4383333333334, + "sql_per_request": 2.5885416666666665, + "median_rps": 84.922, + "repeat_rps": [ + 84.922, + 174.993, + 35.695 + ] + }, + { + "workload": "cold-history-burst", + "variant": "Без Redis и эпох", + "successes": 192, + "errors": 0, + "mean_rps": 35.52923760177646, + "mean_latency_ms": 1207.2706666666666, + "mean_p95_ms": 1730.9593333333332, + "sql_per_request": 4, + "median_rps": 97.303, + "repeat_rps": [ + 14.688, + 164.482, + 97.303 + ] + }, + { + "workload": "warm-history", + "variant": "Redis и эпохи", + "successes": 20193, + "errors": 0, + "mean_rps": 111.93521028387076, + "mean_latency_ms": 285.5940715594513, + "mean_p95_ms": 921.5433333333334, + "sql_per_request": 2.0226811271232603, + "median_rps": 98.432, + "repeat_rps": [ + 98.432, + 171.599, + 65.786 + ] + }, + { + "workload": "warm-history", + "variant": "Без Redis и эпох", + "successes": 20812, + "errors": 0, + "mean_rps": 115.21130191206917, + "mean_latency_ms": 277.44751691331925, + "mean_p95_ms": 769.9786666666665, + "sql_per_request": 4, + "median_rps": 116.919, + "repeat_rps": [ + 116.919, + 87.18, + 141.665 + ] + }, + { + "workload": "writes-single-chat", + "variant": "Redis и эпохи", + "successes": 12288, + "errors": 0, + "mean_rps": 67.13213360867996, + "mean_latency_ms": 476.11233333333325, + "mean_p95_ms": 1289.0003333333334, + "sql_per_request": 2.05517578125, + "median_rps": 104.129, + "repeat_rps": [ + 104.129, + 37.944, + 114.545 + ] + }, + { + "workload": "writes-single-chat", + "variant": "Без Redis и эпох", + "successes": 12288, + "errors": 0, + "mean_rps": 98.20422450789998, + "mean_latency_ms": 325.492, + "mean_p95_ms": 790.6086666666666, + "sql_per_request": 3, + "median_rps": 93.775, + "repeat_rps": [ + 93.775, + 86.854, + 119.458 + ] + } +] diff --git a/evidence/cache-strategy-long-experiment.json b/evidence/cache-strategy-long-experiment.json new file mode 100644 index 0000000..edd3960 --- /dev/null +++ b/evidence/cache-strategy-long-experiment.json @@ -0,0 +1,79 @@ +{ + "recorded_at": "2026-10-13T13:24:50.458Z", + "image": "sha256:a4799affbf3b82d4a120296b16306e7693c13007013061a911fb5d38ceb6d945", + "modified_sources": { + "Chat/chat.service.ts": { + "original_source": "11b6b6d361d5599667318540b2c83a1b8e397db6d4d3665bbfa526e0b349d430", + "experiment_source": "b2aaf10ea1994df9418e157f3d61747182f0dc7f8ac7b1faa70caf6e9b936395", + "experiment_js": "d8228f1bb09e50cba1dc604cf2494a43f5a36db35631bdc28cca55c8bb6ea013" + }, + "Auth/auth.service.ts": { + "original_source": "86599b6e89cd66483cb10aff0d85cc29fe092ab24bbb849960079dcae347b8bf", + "experiment_source": "09a6ee6599c1e4434fe1ad00cac973ea3b5c189e93aa72c3f9b353f5ff2695b2", + "experiment_js": "15b5e9104116f6eb4a214622f754fdd97b14f20f0c93c8b5644820392129671e" + }, + "User/user.guard.ts": { + "original_source": "b84d95633fbd89b4fdbc505c51dd64e657611651b757bed1aea8eee3f0eac3d9", + "experiment_source": "61542fe2b85fb5b83ba8bfb8ddee0d34a8f8216eb0283b0987489666bb4f87fd", + "experiment_js": "187bc710bb75421c098fcde7e2ee9004c2b01f6b569f639c20779f4d5ed47d99" + }, + "Chat/chat.controller.ts": { + "original_source": "700becb64112538a6551c5775ccc09ff9d750755dcffe6ec916782afed1dae11", + "experiment_source": "29f56fcb998e4fc115fbad3705e9c6c7738e528165c4c012fa662c1a7a0e35f5", + "experiment_js": "e6a9a63bf5a17d5f7e3138077ea4874f2c25b6e378f1d86691f08c87d2d23da0" + }, + "cache/cache.service.ts": { + "original_source": "f27ab6ff5a0f8da05936272bafbc7cea38198074e5c7d17c2e01ae0bf29986b3", + "experiment_source": "d9abf1e2b368010934214a8730ca99d085eda57c748bbc69ccd5a0a085d66a9a", + "experiment_js": "fa132f28aa07f0a7118d308a073c296dd319131b63c15bd9a700d8ac874cd7a1" + }, + "User/user.service.ts": { + "original_source": "de158e39c114c610cc7ea6c850108c8dd69c9bc3d643bac94557d272621f3cfb", + "experiment_source": "532bbba837fcbc9ad6b431316680dc0bdd7a910b9870fe0ec625c7d81fa53ddd", + "experiment_js": "90cfd8c45b02a6d4a5220a869d86ab5bac66b6b4c6a9f79685cd7c24a97fc2cb" + } + }, + "command": [ + "docker", + "compose", + "-f", + "compose.yaml", + "-f", + "test/compose.benchmark.yaml", + "-f", + "C:\\Users\\olpin\\AppData\\Local\\Temp\\lab2-no-epochs-8CcNxV\\compose.no-epochs.yaml", + "run", + "--rm", + "--no-deps", + "--pull", + "never", + "benchmark", + "node", + "/experiment/cache-benchmark.mjs", + "after", + "/results/cache-strategy-long-no-redis-no-epochs.json", + "--concurrency", + "32", + "--duration-seconds", + "60", + "--warmup-seconds", + "10", + "--repetitions", + "3", + "--seed-messages", + "100000", + "--cold-burst", + "64", + "--writes-per-repeat", + "4096", + "--skip-history-control" + ], + "implementation": "Separate temporary source copies compiled with TypeScript and mounted over six application modules. Workspace sources and running backend remain unchanged.", + "schema": "Unused epoch columns remain; no migration, counter update or authoritative epoch read in the experiment API paths.", + "redis": "Application starts without CACHE_URL. Observer/proxy are retained only for benchmark setup and cleanup.", + "full_result": "cache-strategy-long-full.json", + "experiment_result": "cache-strategy-long-no-redis-no-epochs.json", + "exit_code": 0, + "signal": null, + "sources_unchanged": true +} diff --git a/evidence/cache-strategy-long-full.json b/evidence/cache-strategy-long-full.json new file mode 100644 index 0000000..88fb6cd --- /dev/null +++ b/evidence/cache-strategy-long-full.json @@ -0,0 +1,271 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T13:15:26.986Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 32, + "duration_seconds": 60, + "warmup_seconds": 10, + "repetitions": 3, + "seed_messages": 100000, + "cold_burst_requests": 64, + "writes_per_repeat": 4096, + "history_control": false, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "f0f8b0cd357dcbb2ba6f401e30dadfcf19ab0deb7c1a812b306126d0478289e2", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 64, + "elapsed_seconds": 0.754, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 84.922, + "latency_ms": { + "mean": 523.232, + "p50": 529.229, + "p95": 714.717, + "p99": 719.659 + }, + "sql_queries": 130, + "sql_per_request": 2.0313, + "sql_calls": { + "SELECT:sessions": 64, + "SELECT:chat_members": 64, + "SELECT:messages": 2 + }, + "process_cpu_percent_one_core": 179.07, + "peak_process_rss_mib": 508.06 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 60.052, + "successes": 5911, + "errors": 0, + "error_ratio": 0, + "successful_rps": 98.432, + "latency_ms": { + "mean": 324.995, + "p50": 178.39, + "p95": 924.623, + "p99": 2499.571 + }, + "sql_queries": 11971, + "sql_per_request": 2.0252, + "sql_calls": { + "SELECT:sessions": 5911, + "SELECT:chat_members": 5911, + "SELECT:messages": 58, + "SELECT:users": 91 + }, + "process_cpu_percent_one_core": 87.65, + "peak_process_rss_mib": 540.81 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 39.336, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 104.129, + "latency_ms": { + "mean": 306.991, + "p50": 238.36, + "p95": 709.191, + "p99": 1377.125 + }, + "sql_queries": 8239, + "sql_per_request": 2.0115, + "sql_calls": { + "SELECT:sessions": 4096, + "WITH:messages": 4096, + "SELECT:users": 47 + }, + "process_cpu_percent_one_core": 93.48, + "peak_process_rss_mib": 540.61 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 64, + "elapsed_seconds": 0.366, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 174.993, + "latency_ms": { + "mean": 321.618, + "p50": 321.769, + "p95": 357.118, + "p99": 358.633 + }, + "sql_queries": 183, + "sql_per_request": 2.8594, + "sql_calls": { + "SELECT:sessions": 64, + "SELECT:chat_members": 64, + "SELECT:messages": 55 + }, + "process_cpu_percent_one_core": 191.09, + "peak_process_rss_mib": 540.61 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 60.152, + "successes": 10322, + "errors": 0, + "error_ratio": 0, + "successful_rps": 171.599, + "latency_ms": { + "mean": 186.321, + "p50": 141.563, + "p95": 451.313, + "p99": 611.536 + }, + "sql_queries": 20653, + "sql_per_request": 2.0009, + "sql_calls": { + "SELECT:sessions": 10322, + "SELECT:chat_members": 10322, + "SELECT:messages": 9 + }, + "process_cpu_percent_one_core": 104.21, + "peak_process_rss_mib": 542.23 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 107.947, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 37.944, + "latency_ms": { + "mean": 842.343, + "p50": 609.049, + "p95": 2335.301, + "p99": 3656.624 + }, + "sql_queries": 8769, + "sql_per_request": 2.1409, + "sql_calls": { + "SELECT:sessions": 4096, + "WITH:messages": 4096, + "SELECT:users": 577 + }, + "process_cpu_percent_one_core": 78.49, + "peak_process_rss_mib": 542.23 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 64, + "elapsed_seconds": 1.793, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 35.695, + "latency_ms": { + "mean": 1418.154, + "p50": 1552.772, + "p95": 1728.48, + "p99": 1764.616 + }, + "sql_queries": 184, + "sql_per_request": 2.875, + "sql_calls": { + "SELECT:sessions": 64, + "SELECT:chat_members": 64, + "SELECT:messages": 50, + "SELECT:users": 6 + }, + "process_cpu_percent_one_core": 85.4, + "peak_process_rss_mib": 541.23 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 60.195, + "successes": 3960, + "errors": 0, + "error_ratio": 0, + "successful_rps": 65.786, + "latency_ms": { + "mean": 485.543, + "p50": 309.711, + "p95": 1388.694, + "p99": 2972.275 + }, + "sql_queries": 8220, + "sql_per_request": 2.0758, + "sql_calls": { + "SELECT:sessions": 3960, + "SELECT:chat_members": 3960, + "SELECT:messages": 96, + "SELECT:users": 204 + }, + "process_cpu_percent_one_core": 78.06, + "peak_process_rss_mib": 541.23 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 35.759, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 114.545, + "latency_ms": { + "mean": 279.003, + "p50": 181.143, + "p95": 822.509, + "p99": 1351.269 + }, + "sql_queries": 8246, + "sql_per_request": 2.0132, + "sql_calls": { + "SELECT:sessions": 4096, + "WITH:messages": 4096, + "SELECT:users": 54 + }, + "process_cpu_percent_one_core": 90.87, + "peak_process_rss_mib": 539.98 + } + ], + "correctness": { + "redis_reconnect": { + "old_keys_retained": true, + "read_after_write_during_outage": true, + "read_after_write_after_reconnect_other_replica": true + }, + "empty_cache_recovery": true, + "delayed_old_fill": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-strategy-long-no-redis-no-epochs.json b/evidence/cache-strategy-long-no-redis-no-epochs.json new file mode 100644 index 0000000..e0d301c --- /dev/null +++ b/evidence/cache-strategy-long-no-redis-no-epochs.json @@ -0,0 +1,270 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T13:25:17.453Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 32, + "duration_seconds": 60, + "warmup_seconds": 10, + "repetitions": 3, + "seed_messages": 100000, + "cold_burst_requests": 64, + "writes_per_repeat": 4096, + "history_control": false, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "d8228f1bb09e50cba1dc604cf2494a43f5a36db35631bdc28cca55c8bb6ea013", + "cache/cache.service.js": "fa132f28aa07f0a7118d308a073c296dd319131b63c15bd9a700d8ac874cd7a1" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 64, + "elapsed_seconds": 4.357, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 14.688, + "latency_ms": { + "mean": 2832.374, + "p50": 2680.746, + "p95": 4178.552, + "p99": 4204.4 + }, + "sql_queries": 256, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 64, + "SELECT:users": 64, + "SELECT:chat_members": 64, + "SELECT:messages": 64 + }, + "process_cpu_percent_one_core": 66.4, + "peak_process_rss_mib": 503.43 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 60.213, + "successes": 7040, + "errors": 0, + "error_ratio": 0, + "successful_rps": 116.919, + "latency_ms": { + "mean": 273.324, + "p50": 208.077, + "p95": 647.394, + "p99": 867.928 + }, + "sql_queries": 28160, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 7040, + "SELECT:users": 7040, + "SELECT:chat_members": 7040, + "SELECT:messages": 7040 + }, + "process_cpu_percent_one_core": 110.35, + "peak_process_rss_mib": 529.98 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 43.679, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 93.775, + "latency_ms": { + "mean": 340.995, + "p50": 273.072, + "p95": 867.22, + "p99": 1314.603 + }, + "sql_queries": 12288, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 4096, + "SELECT:users": 4096, + "INSERT:messages": 4096 + }, + "process_cpu_percent_one_core": 96.06, + "peak_process_rss_mib": 528.34 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 64, + "elapsed_seconds": 0.389, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 164.482, + "latency_ms": { + "mean": 302.238, + "p50": 295.632, + "p95": 378.2, + "p99": 380.864 + }, + "sql_queries": 256, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 64, + "SELECT:users": 64, + "SELECT:chat_members": 64, + "SELECT:messages": 64 + }, + "process_cpu_percent_one_core": 129.37, + "peak_process_rss_mib": 528.59 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 60.358, + "successes": 5262, + "errors": 0, + "error_ratio": 0, + "successful_rps": 87.18, + "latency_ms": { + "mean": 366.511, + "p50": 224.132, + "p95": 1186.254, + "p99": 2821.087 + }, + "sql_queries": 21048, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 5262, + "SELECT:users": 5262, + "SELECT:chat_members": 5262, + "SELECT:messages": 5262 + }, + "process_cpu_percent_one_core": 91.61, + "peak_process_rss_mib": 528.84 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 47.16, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 86.854, + "latency_ms": { + "mean": 368.096, + "p50": 301.578, + "p95": 828.432, + "p99": 1193.829 + }, + "sql_queries": 12288, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 4096, + "SELECT:users": 4096, + "INSERT:messages": 4096 + }, + "process_cpu_percent_one_core": 92.17, + "peak_process_rss_mib": 528.34 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 64, + "elapsed_seconds": 0.658, + "successes": 64, + "errors": 0, + "error_ratio": 0, + "successful_rps": 97.303, + "latency_ms": { + "mean": 487.2, + "p50": 499.068, + "p95": 636.126, + "p99": 646.102 + }, + "sql_queries": 256, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 64, + "SELECT:users": 64, + "SELECT:chat_members": 64, + "SELECT:messages": 64 + }, + "process_cpu_percent_one_core": 143.09, + "peak_process_rss_mib": 527.84 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 60.071, + "successes": 8510, + "errors": 0, + "error_ratio": 0, + "successful_rps": 141.665, + "latency_ms": { + "mean": 225.788, + "p50": 182.322, + "p95": 476.288, + "p99": 663.291 + }, + "sql_queries": 34040, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 8510, + "SELECT:users": 8510, + "SELECT:chat_members": 8510, + "SELECT:messages": 8510 + }, + "process_cpu_percent_one_core": 108.52, + "peak_process_rss_mib": 527.84 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 34.288, + "successes": 4096, + "errors": 0, + "error_ratio": 0, + "successful_rps": 119.458, + "latency_ms": { + "mean": 267.385, + "p50": 202.874, + "p95": 676.174, + "p99": 934.633 + }, + "sql_queries": 12288, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 4096, + "SELECT:users": 4096, + "INSERT:messages": 4096 + }, + "process_cpu_percent_one_core": 100.89, + "peak_process_rss_mib": 527.84 + } + ], + "correctness": { + "no_redis_client": true, + "epochs_unchanged": true, + "read_after_write": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/cache-strategy-no-redis-no-epochs.json b/evidence/cache-strategy-no-redis-no-epochs.json new file mode 100644 index 0000000..ad52d55 --- /dev/null +++ b/evidence/cache-strategy-no-redis-no-epochs.json @@ -0,0 +1,347 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T13:05:02.777Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 10, + "warmup_seconds": 3, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 512, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF" + }, + "dist_sha256": { + "Chat/chat.service.js": "d8228f1bb09e50cba1dc604cf2494a43f5a36db35631bdc28cca55c8bb6ea013", + "cache/cache.service.js": "fa132f28aa07f0a7118d308a073c296dd319131b63c15bd9a700d8ac874cd7a1" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 4.432, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 7.221, + "latency_ms": { + "mean": 3223.831, + "p50": 3472.532, + "p95": 4242.166, + "p99": 4291.418 + }, + "sql_queries": 128, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 76.08, + "peak_process_rss_mib": 322.23 + }, + { + "workload": "warm-history", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.483, + "successes": 110, + "errors": 0, + "error_ratio": 0, + "successful_rps": 10.493, + "latency_ms": { + "mean": 1498.767, + "p50": 1448.568, + "p95": 2199.117, + "p99": 2286.128 + }, + "sql_queries": 440, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 110, + "SELECT:users": 110, + "SELECT:chat_members": 110, + "SELECT:messages": 110 + }, + "process_cpu_percent_one_core": 69.42, + "peak_process_rss_mib": 325.3 + }, + { + "workload": "history-cache-bypassed", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.439, + "successes": 304, + "errors": 0, + "error_ratio": 0, + "successful_rps": 29.122, + "latency_ms": { + "mean": 542.086, + "p50": 390.773, + "p95": 1283.803, + "p99": 1945.359 + }, + "sql_queries": 1216, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 304, + "SELECT:users": 304, + "SELECT:chat_members": 304, + "SELECT:messages": 304 + }, + "process_cpu_percent_one_core": 98.33, + "peak_process_rss_mib": 348.39 + }, + { + "workload": "writes-single-chat", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 24.459, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 20.933, + "latency_ms": { + "mean": 760.483, + "p50": 598.938, + "p95": 1799.757, + "p99": 3162.945 + }, + "sql_queries": 1536, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 512, + "SELECT:users": 512, + "INSERT:messages": 512 + }, + "process_cpu_percent_one_core": 66.68, + "peak_process_rss_mib": 350.14 + }, + { + "workload": "cold-history-burst", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 2.206, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 14.503, + "latency_ms": { + "mean": 2020.556, + "p50": 1987.51, + "p95": 2166.607, + "p99": 2167.749 + }, + "sql_queries": 128, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 90.24, + "peak_process_rss_mib": 350.76 + }, + { + "workload": "warm-history", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.332, + "successes": 333, + "errors": 0, + "error_ratio": 0, + "successful_rps": 32.229, + "latency_ms": { + "mean": 488.166, + "p50": 378.127, + "p95": 1153.736, + "p99": 1400.961 + }, + "sql_queries": 1332, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 333, + "SELECT:users": 333, + "SELECT:chat_members": 333, + "SELECT:messages": 333 + }, + "process_cpu_percent_one_core": 88.94, + "peak_process_rss_mib": 351.14 + }, + { + "workload": "history-cache-bypassed", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.194, + "successes": 870, + "errors": 0, + "error_ratio": 0, + "successful_rps": 85.347, + "latency_ms": { + "mean": 186.44, + "p50": 159.038, + "p95": 411.49, + "p99": 565.075 + }, + "sql_queries": 3480, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 870, + "SELECT:users": 870, + "SELECT:chat_members": 870, + "SELECT:messages": 870 + }, + "process_cpu_percent_one_core": 109.42, + "peak_process_rss_mib": 351.26 + }, + { + "workload": "writes-single-chat", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 8.947, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 57.224, + "latency_ms": { + "mean": 278.524, + "p50": 232.781, + "p95": 528.251, + "p99": 758.496 + }, + "sql_queries": 1536, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 512, + "SELECT:users": 512, + "INSERT:messages": 512 + }, + "process_cpu_percent_one_core": 89.77, + "peak_process_rss_mib": 351.39 + }, + { + "workload": "cold-history-burst", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.584, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 54.771, + "latency_ms": { + "mean": 540.323, + "p50": 560.057, + "p95": 579.473, + "p99": 579.723 + }, + "sql_queries": 128, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 121.78, + "peak_process_rss_mib": 351.39 + }, + { + "workload": "warm-history", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.144, + "successes": 885, + "errors": 0, + "error_ratio": 0, + "successful_rps": 87.24, + "latency_ms": { + "mean": 182.207, + "p50": 138.17, + "p95": 476.708, + "p99": 686.502 + }, + "sql_queries": 3540, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 885, + "SELECT:users": 885, + "SELECT:chat_members": 885, + "SELECT:messages": 885 + }, + "process_cpu_percent_one_core": 111.32, + "peak_process_rss_mib": 351.51 + }, + { + "workload": "history-cache-bypassed", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.145, + "successes": 1136, + "errors": 0, + "error_ratio": 0, + "successful_rps": 111.971, + "latency_ms": { + "mean": 142.145, + "p50": 119.222, + "p95": 261.548, + "p99": 493.224 + }, + "sql_queries": 4544, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 1136, + "SELECT:users": 1136, + "SELECT:chat_members": 1136, + "SELECT:messages": 1136 + }, + "process_cpu_percent_one_core": 113.63, + "peak_process_rss_mib": 347.39 + }, + { + "workload": "writes-single-chat", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 6.233, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 82.146, + "latency_ms": { + "mean": 193.673, + "p50": 182.46, + "p95": 382.204, + "p99": 437.929 + }, + "sql_queries": 1536, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 512, + "SELECT:users": 512, + "INSERT:messages": 512 + }, + "process_cpu_percent_one_core": 102.54, + "peak_process_rss_mib": 347.64 + } + ], + "correctness": { + "no_redis_client": true, + "epochs_unchanged": true, + "read_after_write": true + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +} diff --git a/evidence/checks-rerun.json b/evidence/checks-rerun.json new file mode 100644 index 0000000..a062ece --- /dev/null +++ b/evidence/checks-rerun.json @@ -0,0 +1,37 @@ +{ + "recorded_on": "2026-10-13", + "backend_image": "sha256:02a5d9ca3816781e5931a82926b6a62858b1abf1eb9a0244da79d45e5787b020", + "scope": "Current built image; no rebuild, no changes to tests or HTTP deadlines.", + "checks": [ + { + "command": "python -X utf8 scripts/test-persistence.py --scenario public --base-url http://127.0.0.1:8080 --output evidence/persistence-public.json", + "result": "PASS", + "evidence": "persistence-public.json", + "http_deadline_seconds": 2, + "elapsed_seconds": 34.502 + }, + { + "command": "docker compose -f compose.yaml -f test/compose.benchmark.yaml run --rm --no-deps --pull never benchmark node --test test/passwords.mjs test/persistence.mjs test/resilience.mjs test/cache.mjs test/cache-epochs.mjs test/message-pagination.mjs", + "result": "PASS", + "exit_code": 0, + "tests": 15, + "passed": 15, + "failed": 0, + "skipped": 0, + "duration_ms": 48905.3297, + "output_extract": "checks-rerun.txt" + }, + { + "command": "python -X utf8 tests/smoke.py --base-url http://127.0.0.1:8080", + "result": "PASS", + "exit_code": 0, + "stdout": "PASS: lab2 public API scenario; infrastructure and grading evidence remain separate." + } + ], + "removed_superseded_failed_reports": [ + "argon2-public-persistence.json", + "cache-epochs-public-persistence.json" + ], + "historical_before_fix_cache_results_retained": true, + "clean_clone_not_checked": true +} diff --git a/evidence/checks-rerun.txt b/evidence/checks-rerun.txt new file mode 100644 index 0000000..ea27e83 --- /dev/null +++ b/evidence/checks-rerun.txt @@ -0,0 +1,24 @@ +Extract of node --test output; application HTTP logs omitted. +✔ DB cache epochs: two replicas, retained Redis keys, concurrent writes and atomic rollback (6434.557331ms) +✔ Redis cache: hits, expiry, invalidation race and unavailable-server fallback (1292.252866ms) +✔ API cache: fewer SQL reads, write invalidation, permissions, logout and Redis fallback (3126.628974ms) +✔ message keyset pagination: timestamp ties, chat isolation and deleted cursor row (3942.163363ms) +✔ Argon2id only: PHC format, independent derivation, unique salts, Unicode and invalid hashes (934.867797ms) +✔ PostgreSQL storage: constraints, pagination, access and application restart (16185.472827ms) +▶ Auth and dependency failures remain bounded and fail closed + ✔ incorrect password is 401 with Basic challenge (427.894703ms) + ✔ SESSION_TTL_SECONDS=2 expires without renewing on reads (2817.902277ms) + ✔ Redis disconnect: SQL fallback and anonymous callers remain unauthorized (2220.317988ms) + ✔ Redis hangs: command timeout bypasses cache (2547.996445ms) + ✔ PostgreSQL disconnect: bounded 503, no cached authorization bypass (564.359592ms) + ✔ PostgreSQL hangs on an established connection: client query timeout (5310.926248ms) + ✔ both services unavailable: fail closed and recover confirmed data (319.237936ms) +✔ Auth and dependency failures remain bounded and fail closed (22602.846427ms) +ℹ tests 15 +ℹ suites 0 +ℹ pass 15 +ℹ fail 0 +ℹ cancelled 0 +ℹ skipped 0 +ℹ todo 0 +ℹ duration_ms 48905.3297 diff --git a/evidence/epoch-variants-averages.json b/evidence/epoch-variants-averages.json new file mode 100644 index 0000000..b241702 --- /dev/null +++ b/evidence/epoch-variants-averages.json @@ -0,0 +1,122 @@ +[ + { + "variant": "baseline", + "workload": "warm-history", + "successes": 40749, + "errors": 0, + "rps": 226.07561929595826, + "mean_latency_ms": 141.4230803946109, + "mean_p95_ms": 338.26133333333337, + "sql_per_request": 2.0037056124076664, + "repeat_rps": [ + 188.018, + 243.914, + 246.313 + ] + }, + { + "variant": "profile-join", + "workload": "warm-history", + "successes": 30756, + "errors": 0, + "rps": 170.52277906222452, + "mean_latency_ms": 187.38915626219273, + "mean_p95_ms": 516.1243333333333, + "sql_per_request": 2.0104695018858108, + "repeat_rps": [ + 135.713, + 209.749, + 166.141 + ] + }, + { + "variant": "access-join", + "workload": "warm-history", + "successes": 44662, + "errors": 0, + "rps": 246.93419437594684, + "mean_latency_ms": 129.50623859209173, + "mean_p95_ms": 331.749, + "sql_per_request": 1.0056199901482243, + "repeat_rps": [ + 282.567, + 271.362, + 186.487 + ] + }, + { + "variant": "striped", + "workload": "warm-history", + "successes": 43795, + "errors": 0, + "rps": 242.54826596958387, + "mean_latency_ms": 131.7491905468661, + "mean_p95_ms": 313.2903333333333, + "sql_per_request": 1.0040187235985842, + "repeat_rps": [ + 264.672, + 238.233, + 224.738 + ] + }, + { + "variant": "baseline", + "workload": "writes-single-chat", + "successes": 12288, + "errors": 0, + "rps": 90.77209467245811, + "mean_latency_ms": 352.00066666666663, + "mean_p95_ms": 985.9113333333333, + "sql_per_request": 2.0240885416666665, + "repeat_rps": [ + 51.084, + 133.969, + 166.398 + ] + }, + { + "variant": "profile-join", + "workload": "writes-single-chat", + "successes": 12288, + "errors": 0, + "rps": 141.47391689788964, + "mean_latency_ms": 225.99266666666665, + "mean_p95_ms": 524.0226666666666, + "sql_per_request": 2, + "repeat_rps": [ + 114.318, + 137.555, + 192.755 + ] + }, + { + "variant": "access-join", + "workload": "writes-single-chat", + "successes": 12288, + "errors": 0, + "rps": 117.7767341109716, + "mean_latency_ms": 271.309, + "mean_p95_ms": 624.231, + "sql_per_request": 2, + "repeat_rps": [ + 78.403, + 181, + 139.035 + ] + }, + { + "variant": "striped", + "workload": "writes-single-chat", + "successes": 12288, + "errors": 0, + "rps": 165.06145476526297, + "mean_latency_ms": 193.265, + "mean_p95_ms": 475.6803333333334, + "sql_per_request": 2, + "repeat_rps": [ + 182.806, + 160.668, + 154.303 + ] + } +] diff --git a/evidence/epoch-variants-code.json b/evidence/epoch-variants-code.json new file mode 100644 index 0000000..c0bef15 --- /dev/null +++ b/evidence/epoch-variants-code.json @@ -0,0 +1,111 @@ +{ + "variants": [ + { + "name": "baseline", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "86599b6e89cd66483cb10aff0d85cc29fe092ab24bbb849960079dcae347b8bf", + "js_sha256": "70e4c149faff62a38f3009816994c349096a8300495ecd57128a07af2acfb78f" + }, + "User/user.service.ts": { + "source_sha256": "de158e39c114c610cc7ea6c850108c8dd69c9bc3d643bac94557d272621f3cfb", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "b84d95633fbd89b4fdbc505c51dd64e657611651b757bed1aea8eee3f0eac3d9", + "js_sha256": "16bc70f6d4df0809637b16f569dda973085128775f29c29d6154aecf9a45be52" + }, + "Chat/chat.service.ts": { + "source_sha256": "11b6b6d361d5599667318540b2c83a1b8e397db6d4d3665bbfa526e0b349d430", + "js_sha256": "42cc729f6f8f6da1a4b6b66746d7ea8299c4a26cfc29f6cfcb436d865107dfad" + }, + "Chat/chat.controller.ts": { + "source_sha256": "700becb64112538a6551c5775ccc09ff9d750755dcffe6ec916782afed1dae11", + "js_sha256": "32ebfcf009fce603c8637da701e33756868a3a4b1dda3e93cf7007b3a8b14ec7" + } + }, + "striped": false + }, + { + "name": "profile-join", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "63e6ad3117bf8adda51bab735ee7b975179e68a6af060aafe63416a8c9b90107", + "js_sha256": "5da0f49def86501c34c2f8d02dbd86dde37b9b7d1d98b57df3e334fc557dcffd" + }, + "User/user.service.ts": { + "source_sha256": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "b84d95633fbd89b4fdbc505c51dd64e657611651b757bed1aea8eee3f0eac3d9", + "js_sha256": "16bc70f6d4df0809637b16f569dda973085128775f29c29d6154aecf9a45be52" + }, + "Chat/chat.service.ts": { + "source_sha256": "11b6b6d361d5599667318540b2c83a1b8e397db6d4d3665bbfa526e0b349d430", + "js_sha256": "42cc729f6f8f6da1a4b6b66746d7ea8299c4a26cfc29f6cfcb436d865107dfad" + }, + "Chat/chat.controller.ts": { + "source_sha256": "700becb64112538a6551c5775ccc09ff9d750755dcffe6ec916782afed1dae11", + "js_sha256": "32ebfcf009fce603c8637da701e33756868a3a4b1dda3e93cf7007b3a8b14ec7" + } + }, + "striped": false + }, + { + "name": "access-join", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "c577b5c9d8ad52eae065359f1614de2d74b1bc7588ac2676d513f4aba2fc9c6f", + "js_sha256": "8fc180339017f373771a1abeed9f6dc978ee8a1c051df9f6fb69f054ca45bf0f" + }, + "User/user.service.ts": { + "source_sha256": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "20b05a0e5272a4ee1ccbddef83494e62621ffb0236e56a15c17e7f8f0083f6d7", + "js_sha256": "a078cc3065d6f87ee441f2bc0ff43af25094e66db4bd661d74cf3cd1c501fc2a" + }, + "Chat/chat.service.ts": { + "source_sha256": "11a44d19390d1e605fb72fabbc6111a25917e292a1aab4132e26390887128219", + "js_sha256": "3759d025e679f2b1694e486c460361a96979f8b67a1a8e811e589c722e8fb55f" + }, + "Chat/chat.controller.ts": { + "source_sha256": "1e3b1e0a5abc053625c5b1a6dc14f5b5b3e87676b1af0bdd73e78ad95d1eb325", + "js_sha256": "6ac78b848b82f03a4134a9e19e2b802fef59d06b938f2e747fa361c2293fd5c7" + } + }, + "striped": false + }, + { + "name": "striped", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "f99168697aa79d7c5c1fd9f35083448c97f68a0bfecdbfbca49fa279445d79b1", + "js_sha256": "73fe21965e7f1fc421b501c5760ee8dfc4ca7edb606477db1682dd04a9c885d1" + }, + "User/user.service.ts": { + "source_sha256": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "20b05a0e5272a4ee1ccbddef83494e62621ffb0236e56a15c17e7f8f0083f6d7", + "js_sha256": "a078cc3065d6f87ee441f2bc0ff43af25094e66db4bd661d74cf3cd1c501fc2a" + }, + "Chat/chat.service.ts": { + "source_sha256": "b43a57b6e6e17a3133f2061d5660f8e36b62e049975b0d6d800517f99d942699", + "js_sha256": "208e1298e119284bb587ba80b8ef650e7c8fd9031a17ff5079f50732902a62c7" + }, + "Chat/chat.controller.ts": { + "source_sha256": "1e3b1e0a5abc053625c5b1a6dc14f5b5b3e87676b1af0bdd73e78ad95d1eb325", + "js_sha256": "6ac78b848b82f03a4134a9e19e2b802fef59d06b938f2e747fa361c2293fd5c7" + } + }, + "striped": true + } + ], + "schema": "epoch_variants_0302fea1e5264f72a02693f65cb217b7", + "exit_code": 0, + "implementation": "TypeScript source snapshots; variant methods activated sequentially before HTTP workloads. Separate cache prefixes and API instances, shared fixtures and Node process." +} \ No newline at end of file diff --git a/evidence/epoch-variants-sources.json b/evidence/epoch-variants-sources.json new file mode 100644 index 0000000..283a460 --- /dev/null +++ b/evidence/epoch-variants-sources.json @@ -0,0 +1,30 @@ +{ + "baseline": { + "Auth/auth.service.ts": "import { Injectable } from '@nestjs/common';\nimport { createHash, randomBytes } from 'node:crypto';\nimport { TextDecoder } from 'node:util';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { Prisma } from '../generated/prisma/client';\nimport { UserService } from '../User/user.service';\nimport type { User } from '../User/user.schema';\nimport { invalidRequest } from '../common/validation';\nimport { AuthException } from './auth.exception';\nimport { PasswordService, validPassword } from './password.service';\nimport type { Session } from './auth.schema';\n\n@Injectable()\nexport class AuthService {\n private readonly ttlSeconds: number;\n\n constructor(\n private readonly prisma: PrismaService,\n private readonly users: UserService,\n private readonly passwords: PasswordService,\n ) {\n this.ttlSeconds = Number(process.env.SESSION_TTL_SECONDS ?? 3600);\n if (\n !Number.isSafeInteger(this.ttlSeconds) ||\n this.ttlSeconds <= 0 ||\n Number.isNaN(new Date(Date.now() + this.ttlSeconds * 1000).getTime())\n ) {\n throw new Error(\n 'SESSION_TTL_SECONDS must be a positive integer representing a valid expiry',\n );\n }\n }\n\n async login(authorization: unknown, body: unknown): Promise {\n const { username, password } = this.basicCredentials(authorization);\n const user = await this.prisma.user.findUnique({ where: { username } });\n const verified = await this.passwords.verify(\n password,\n user?.passwordHash ?? null,\n );\n if (!user || !verified) throw new AuthException('Basic');\n if (body !== undefined)\n return invalidRequest('Вход через Basic не принимает тело запроса');\n const token = randomBytes(32).toString('base64url');\n const session = await this.prisma.session.create({\n data: {\n userId: user.id,\n tokenHash: this.tokenHash(token),\n expiresAt: new Date(Date.now() + this.ttlSeconds * 1000),\n },\n });\n return {\n token,\n token_type: 'Bearer',\n expires_at: session.expiresAt.toISOString(),\n user: this.users.serialize(user),\n };\n }\n\n async authenticate(\n authorization: unknown,\n ): Promise<{ user: User; sessionId: string; chatsEpoch: string }> {\n const match =\n typeof authorization === 'string' &&\n /^Bearer +([A-Za-z0-9_-]{43})$/i.exec(authorization);\n if (!match) throw new AuthException('Bearer');\n const [session] = await this.prisma.$queryRaw<\n { id: string; userId: string; chatsEpoch: bigint }[]\n >(Prisma.sql`\n SELECT s.id, s.user_id AS \"userId\", u.chats_epoch AS \"chatsEpoch\"\n FROM sessions AS s\n JOIN users AS u ON u.id = s.user_id\n WHERE s.token_hash = ${this.tokenHash(match[1])}\n AND s.revoked_at IS NULL AND s.expires_at > ${new Date()}\n LIMIT 1\n `);\n if (!session) throw new AuthException('Bearer');\n const user = await this.users.get(session.userId);\n if (!user) throw new AuthException('Bearer');\n return {\n user,\n sessionId: session.id,\n chatsEpoch: session.chatsEpoch.toString(),\n };\n }\n\n async logout(sessionId: string): Promise {\n const now = new Date();\n const result = await this.prisma.session.updateMany({\n where: { id: sessionId, revokedAt: null, expiresAt: { gt: now } },\n data: { revokedAt: now },\n });\n if (result.count !== 1) throw new AuthException('Bearer');\n }\n\n private tokenHash(token: string): string {\n return createHash('sha256').update(token).digest('hex');\n }\n\n private basicCredentials(authorization: unknown): {\n username: string;\n password: string;\n } {\n const match =\n typeof authorization === 'string' &&\n /^Basic +([A-Za-z0-9+/]+={0,2})$/i.exec(authorization);\n if (!match) throw new AuthException('Basic');\n try {\n const bytes = Buffer.from(match[1], 'base64');\n if (\n bytes.toString('base64').replace(/=+$/, '') !==\n match[1].replace(/=+$/, '')\n )\n throw new AuthException('Basic');\n const value = new TextDecoder('utf-8', { fatal: true }).decode(bytes);\n const colon = value.indexOf(':');\n const username = value.slice(0, colon);\n const password = value.slice(colon + 1);\n if (\n colon < 0 ||\n !/^[a-z0-9_]{3,32}$/.test(username) ||\n !validPassword(password)\n )\n throw new AuthException('Basic');\n return { username, password };\n } catch {\n throw new AuthException('Basic');\n }\n }\n}\n", + "User/user.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { Prisma, type User as StoredUser } from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport { objectBody, requiredText } from '../common/validation';\nimport {\n PasswordService,\n registrationPassword,\n} from '../Auth/password.service';\nimport type { User } from './user.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\n@Injectable()\nexport class UserService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly passwords: PasswordService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown): Promise {\n const body = objectBody(value, ['username', 'display_name', 'password']);\n const username = body.username;\n if (typeof username !== 'string' || !/^[a-z0-9_]{3,32}$/.test(username)) {\n throw new ApiException(\n HttpStatus.BAD_REQUEST,\n 'invalid_request',\n 'Некорректный username',\n );\n }\n const displayName = requiredText(body.display_name, 'display_name', 100);\n const password = registrationPassword(body.password);\n const passwordHash = await this.passwords.hash(password);\n try {\n return this.serialize(\n await this.prisma.user.create({\n data: { username, displayName, passwordHash },\n }),\n );\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2002'\n ) {\n throw new ApiException(\n HttpStatus.CONFLICT,\n 'conflict',\n 'Username уже занят',\n );\n }\n throw error;\n }\n }\n\n async get(id: string): Promise {\n return this.cache.remember(\n `user:${id}`,\n 'profile',\n CACHE_TTL.entity,\n async () => {\n const user = await this.prisma.user.findUnique({ where: { id } });\n return user ? this.serialize(user) : undefined;\n },\n );\n }\n\n serialize(user: StoredUser): User {\n return {\n id: user.id,\n username: user.username,\n display_name: user.displayName,\n created_at: user.createdAt.toISOString(),\n };\n }\n}\n", + "User/user.guard.ts": "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\nimport type { FastifyRequest } from 'fastify';\nimport { AuthService } from '../Auth/auth.service';\nimport type { User } from './user.schema';\n\nexport type AuthenticatedRequest = FastifyRequest & {\n currentUser: User;\n currentSessionId: string;\n currentChatsEpoch: string;\n};\n\n@Injectable()\nexport class UserGuard implements CanActivate {\n constructor(private readonly auth: AuthService) {}\n\n async canActivate(context: ExecutionContext): Promise {\n const request = context.switchToHttp().getRequest();\n const session = await this.auth.authenticate(request.headers.authorization);\n request.currentUser = session.user;\n request.currentSessionId = session.sessionId;\n request.currentChatsEpoch = session.chatsEpoch;\n return true;\n }\n}\n", + "Chat/chat.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { randomUUID } from 'node:crypto';\nimport {\n Prisma,\n type Message as StoredMessage,\n} from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport {\n invalidRequest,\n objectBody,\n pageLimit,\n requiredText,\n uuid,\n} from '../common/validation';\nimport type { Chat, Message, Page } from './chat.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\ninterface Cursor {\n scope: string;\n created_at: string;\n id: string;\n}\n\nconst chatInclude = {\n members: { orderBy: { position: 'asc' as const } },\n} satisfies Prisma.ChatInclude;\ntype StoredChat = Prisma.ChatGetPayload<{ include: typeof chatInclude }>;\n\n@Injectable()\nexport class ChatService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown, userId: string): Promise {\n const body = objectBody(value, ['title', 'member_ids']);\n const title = requiredText(body.title, 'title', 100);\n if (\n !Array.isArray(body.member_ids) ||\n body.member_ids.length < 1 ||\n body.member_ids.length > 100\n ) {\n return invalidRequest('Некорректный member_ids');\n }\n const memberIds = body.member_ids.map((id: unknown) =>\n uuid(id, 'member_ids'),\n );\n if (\n new Set(memberIds).size !== memberIds.length ||\n !memberIds.includes(userId)\n ) {\n return invalidRequest(\n 'Список участников содержит дубликат или не содержит вызывающего',\n );\n }\n try {\n const chat = await this.prisma.$transaction(async (tx) => {\n const count = await tx.user.count({ where: { id: { in: memberIds } } });\n if (count !== memberIds.length)\n return invalidRequest('Неизвестный участник чата');\n const created = await tx.chat.create({\n data: {\n title,\n members: {\n create: memberIds.map((userId, position) => ({\n userId,\n position,\n })),\n },\n },\n include: chatInclude,\n });\n await tx.$executeRaw(Prisma.sql`\n WITH locked AS MATERIALIZED (\n SELECT id FROM users\n WHERE id IN (${Prisma.join(memberIds.map((id) => Prisma.sql`${id}::uuid`))})\n ORDER BY id FOR UPDATE\n )\n UPDATE users AS u SET chats_epoch = u.chats_epoch + 1\n FROM locked WHERE u.id = locked.id\n `);\n return created;\n });\n return this.serializeChat(chat);\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2003'\n ) {\n return invalidRequest('Неизвестный участник чата');\n }\n throw error;\n }\n }\n\n async list(\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n epoch: string,\n ): Promise> {\n const limit = pageLimit(limitValue);\n const scope = `chats:${userId}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const chats = await this.prisma.chat.findMany({\n where: { members: { some: { userId } }, ...this.after(cursor) },\n include: chatInclude,\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n chats.map((chat) => this.serializeChat(chat)),\n limit,\n scope,\n );\n },\n epoch,\n );\n }\n\n async get(value: unknown, userId: string): Promise {\n const { id } = await this.authorizeChat(value, userId);\n return this.getMetadata(id);\n }\n\n private async authorizeChat(value: unknown, userId: string) {\n const id = uuid(value, 'chat_id');\n const [membership] = await this.prisma.$queryRaw<\n { id: string; messagesEpoch: bigint }[]\n >(Prisma.sql`\n SELECT c.id, c.messages_epoch AS \"messagesEpoch\"\n FROM chat_members AS cm JOIN chats AS c ON c.id = cm.chat_id\n WHERE cm.chat_id = ${id}::uuid AND cm.user_id = ${userId}::uuid\n `);\n if (!membership) {\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n }\n return membership;\n }\n\n private getMetadata(id: string): Promise {\n return this.cache.remember(\n `chat:${id}`,\n 'metadata',\n CACHE_TTL.entity,\n async () => {\n const chat = await this.prisma.chat.findUnique({\n where: { id },\n include: chatInclude,\n });\n if (!chat)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeChat(chat);\n },\n );\n }\n\n async createMessage(\n chatId: unknown,\n value: unknown,\n userId: string,\n ): Promise {\n const id = uuid(chatId, 'chat_id');\n const body = objectBody(value, ['text']);\n const text = requiredText(body.text, 'text', 4000);\n const [message] = await this.prisma.$queryRaw(Prisma.sql`\n WITH updated AS (\n UPDATE chats AS c\n SET messages_epoch = c.messages_epoch + 1\n WHERE c.id = ${id}::uuid\n AND EXISTS (\n SELECT 1 FROM chat_members AS cm\n WHERE cm.chat_id = c.id AND cm.user_id = ${userId}::uuid\n )\n RETURNING c.id\n )\n INSERT INTO messages (id, chat_id, sender_id, text)\n SELECT ${randomUUID()}::uuid, updated.id, ${userId}::uuid, ${text}\n FROM updated\n RETURNING id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n `);\n if (!message)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeMessage(message);\n }\n\n async listMessages(\n chatId: unknown,\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n ): Promise> {\n const chat = await this.authorizeChat(chatId, userId);\n const limit = pageLimit(limitValue);\n const scope = `messages:${chat.id}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const messages = cursor\n ? await this.prisma.$queryRaw(Prisma.sql`\n SELECT id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n FROM \"public\".\"messages\"\n WHERE chat_id = ${chat.id}::uuid\n AND (created_at, id) >\n (${new Date(cursor.created_at)}::timestamptz, ${cursor.id}::uuid)\n ORDER BY created_at ASC, id ASC\n LIMIT ${limit + 1}\n `)\n : await this.prisma.message.findMany({\n where: { chatId: chat.id },\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n messages.map((message) => this.serializeMessage(message)),\n limit,\n scope,\n );\n },\n chat.messagesEpoch.toString(),\n );\n }\n\n private after(cursor: Cursor | null) {\n if (!cursor) return {};\n const createdAt = new Date(cursor.created_at);\n return {\n OR: [\n { createdAt: { gt: createdAt } },\n { createdAt, id: { gt: cursor.id } },\n ],\n };\n }\n\n private serializeChat(chat: StoredChat): Chat {\n return {\n id: chat.id,\n title: chat.title,\n member_ids: chat.members.map((member) => member.userId),\n created_at: chat.createdAt.toISOString(),\n };\n }\n\n private serializeMessage(message: StoredMessage): Message {\n return {\n id: message.id,\n chat_id: message.chatId,\n sender_id: message.senderId,\n text: message.text,\n created_at: message.createdAt.toISOString(),\n };\n }\n\n private page(\n items: T[],\n limit: number,\n scope: string,\n ): Page {\n const result = items.slice(0, limit);\n const last = result.at(-1);\n return {\n items: result,\n next_cursor:\n items.length > limit && last\n ? Buffer.from(\n JSON.stringify({\n scope,\n created_at: last.created_at,\n id: last.id,\n }),\n ).toString('base64url')\n : null,\n };\n }\n\n private decodeCursor(value: unknown, scope: string): Cursor | null {\n if (value === undefined) return null;\n if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/.test(value))\n return invalidRequest('Некорректный cursor');\n try {\n const cursor: unknown = JSON.parse(\n Buffer.from(value, 'base64url').toString('utf8'),\n );\n if (\n typeof cursor !== 'object' ||\n cursor === null ||\n Array.isArray(cursor)\n )\n return invalidRequest('Некорректный cursor');\n const data = cursor as Record;\n if (\n data.scope !== scope ||\n typeof data.created_at !== 'string' ||\n Number.isNaN(Date.parse(data.created_at)) ||\n typeof data.id !== 'string'\n ) {\n return invalidRequest('Некорректный cursor');\n }\n return {\n scope,\n created_at: data.created_at,\n id: uuid(data.id, 'cursor'),\n };\n } catch {\n return invalidRequest('Некорректный cursor');\n }\n }\n}\n", + "Chat/chat.controller.ts": "import {\n Body,\n Controller,\n Get,\n HttpCode,\n HttpStatus,\n Param,\n Post,\n Query,\n Req,\n UseGuards,\n} from '@nestjs/common';\nimport {\n ApiBody,\n ApiBearerAuth,\n ApiCreatedResponse,\n ApiOkResponse,\n ApiOperation,\n ApiQuery,\n ApiTags,\n} from '@nestjs/swagger';\nimport { UserGuard, type AuthenticatedRequest } from '../User/user.guard';\nimport {\n CreateChatDto,\n CreateMessageDto,\n Chat,\n Message,\n ChatPage,\n MessagePage,\n} from './chat.schema';\nimport { ChatService } from './chat.service';\n\n@ApiTags('chats')\n@ApiBearerAuth('bearerAuth')\n@UseGuards(UserGuard)\n@Controller('api/v1/chats')\nexport class ChatController {\n constructor(private readonly chats: ChatService) {}\n\n @Post()\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateChatDto })\n @ApiOperation({ operationId: 'createChat' })\n @ApiCreatedResponse({ type: Chat })\n create(@Req() request: AuthenticatedRequest, @Body() body: unknown) {\n return this.chats.create(body, request.currentUser.id);\n }\n\n @Get()\n @ApiOperation({ operationId: 'listChats' })\n @ApiOkResponse({ type: ChatPage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n list(\n @Req() request: AuthenticatedRequest,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.list(\n request.currentUser.id,\n limit,\n cursor,\n request.currentChatsEpoch,\n );\n }\n\n @Get(':chat_id')\n @ApiOperation({ operationId: 'getChat' })\n @ApiOkResponse({ type: Chat })\n get(@Req() request: AuthenticatedRequest, @Param('chat_id') chatId: string) {\n return this.chats.get(chatId, request.currentUser.id);\n }\n\n @Post(':chat_id/messages')\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateMessageDto })\n @ApiOperation({ operationId: 'createMessage' })\n @ApiCreatedResponse({ type: Message })\n createMessage(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Body() body: unknown,\n ) {\n return this.chats.createMessage(chatId, body, request.currentUser.id);\n }\n\n @Get(':chat_id/messages')\n @ApiOperation({ operationId: 'listMessages' })\n @ApiOkResponse({ type: MessagePage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n listMessages(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.listMessages(\n chatId,\n request.currentUser.id,\n limit,\n cursor,\n );\n }\n}\n" + }, + "profile-join": { + "Auth/auth.service.ts": "import { Injectable } from '@nestjs/common';\nimport { createHash, randomBytes } from 'node:crypto';\nimport { TextDecoder } from 'node:util';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { Prisma } from '../generated/prisma/client';\nimport { UserService } from '../User/user.service';\nimport type { User } from '../User/user.schema';\nimport { invalidRequest } from '../common/validation';\nimport { AuthException } from './auth.exception';\nimport { PasswordService, validPassword } from './password.service';\nimport type { Session } from './auth.schema';\n\n@Injectable()\nexport class AuthService {\n private readonly ttlSeconds: number;\n\n constructor(\n private readonly prisma: PrismaService,\n private readonly users: UserService,\n private readonly passwords: PasswordService,\n ) {\n this.ttlSeconds = Number(process.env.SESSION_TTL_SECONDS ?? 3600);\n if (\n !Number.isSafeInteger(this.ttlSeconds) ||\n this.ttlSeconds <= 0 ||\n Number.isNaN(new Date(Date.now() + this.ttlSeconds * 1000).getTime())\n ) {\n throw new Error(\n 'SESSION_TTL_SECONDS must be a positive integer representing a valid expiry',\n );\n }\n }\n\n async login(authorization: unknown, body: unknown): Promise {\n const { username, password } = this.basicCredentials(authorization);\n const user = await this.prisma.user.findUnique({ where: { username } });\n const verified = await this.passwords.verify(\n password,\n user?.passwordHash ?? null,\n );\n if (!user || !verified) throw new AuthException('Basic');\n if (body !== undefined)\n return invalidRequest('Вход через Basic не принимает тело запроса');\n const token = randomBytes(32).toString('base64url');\n const session = await this.prisma.session.create({\n data: {\n userId: user.id,\n tokenHash: this.tokenHash(token),\n expiresAt: new Date(Date.now() + this.ttlSeconds * 1000),\n },\n });\n return {\n token,\n token_type: 'Bearer',\n expires_at: session.expiresAt.toISOString(),\n user: this.users.serialize(user),\n };\n }\n\n async authenticate(\n authorization: unknown,\n ): Promise<{ user: User; sessionId: string; chatsEpoch: string }> {\n const match =\n typeof authorization === 'string' &&\n /^Bearer +([A-Za-z0-9_-]{43})$/i.exec(authorization);\n if (!match) throw new AuthException('Bearer');\n const [session] = await this.prisma.$queryRaw<\n {\n id: string;\n userId: string;\n username: string;\n displayName: string;\n createdAt: Date;\n chatsEpoch: bigint;\n }[]\n >(Prisma.sql`\n SELECT s.id, s.user_id AS \"userId\", u.chats_epoch AS \"chatsEpoch\",\n u.username, u.display_name AS \"displayName\", u.created_at AS \"createdAt\"\n FROM sessions AS s\n JOIN users AS u ON u.id = s.user_id\n WHERE s.token_hash = ${this.tokenHash(match[1])}\n AND s.revoked_at IS NULL AND s.expires_at > ${new Date()}\n LIMIT 1\n `);\n if (!session) throw new AuthException('Bearer');\n return {\n user: this.users.serialize({ ...session, id: session.userId }),\n sessionId: session.id,\n chatsEpoch: session.chatsEpoch.toString(),\n };\n }\n\n async logout(sessionId: string): Promise {\n const now = new Date();\n const result = await this.prisma.session.updateMany({\n where: { id: sessionId, revokedAt: null, expiresAt: { gt: now } },\n data: { revokedAt: now },\n });\n if (result.count !== 1) throw new AuthException('Bearer');\n }\n\n private tokenHash(token: string): string {\n return createHash('sha256').update(token).digest('hex');\n }\n\n private basicCredentials(authorization: unknown): {\n username: string;\n password: string;\n } {\n const match =\n typeof authorization === 'string' &&\n /^Basic +([A-Za-z0-9+/]+={0,2})$/i.exec(authorization);\n if (!match) throw new AuthException('Basic');\n try {\n const bytes = Buffer.from(match[1], 'base64');\n if (\n bytes.toString('base64').replace(/=+$/, '') !==\n match[1].replace(/=+$/, '')\n )\n throw new AuthException('Basic');\n const value = new TextDecoder('utf-8', { fatal: true }).decode(bytes);\n const colon = value.indexOf(':');\n const username = value.slice(0, colon);\n const password = value.slice(colon + 1);\n if (\n colon < 0 ||\n !/^[a-z0-9_]{3,32}$/.test(username) ||\n !validPassword(password)\n )\n throw new AuthException('Basic');\n return { username, password };\n } catch {\n throw new AuthException('Basic');\n }\n }\n}\n", + "User/user.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { Prisma, type User as StoredUser } from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport { objectBody, requiredText } from '../common/validation';\nimport {\n PasswordService,\n registrationPassword,\n} from '../Auth/password.service';\nimport type { User } from './user.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\n@Injectable()\nexport class UserService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly passwords: PasswordService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown): Promise {\n const body = objectBody(value, ['username', 'display_name', 'password']);\n const username = body.username;\n if (typeof username !== 'string' || !/^[a-z0-9_]{3,32}$/.test(username)) {\n throw new ApiException(\n HttpStatus.BAD_REQUEST,\n 'invalid_request',\n 'Некорректный username',\n );\n }\n const displayName = requiredText(body.display_name, 'display_name', 100);\n const password = registrationPassword(body.password);\n const passwordHash = await this.passwords.hash(password);\n try {\n return this.serialize(\n await this.prisma.user.create({\n data: { username, displayName, passwordHash },\n }),\n );\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2002'\n ) {\n throw new ApiException(\n HttpStatus.CONFLICT,\n 'conflict',\n 'Username уже занят',\n );\n }\n throw error;\n }\n }\n\n async get(id: string): Promise {\n return this.cache.remember(\n `user:${id}`,\n 'profile',\n CACHE_TTL.entity,\n async () => {\n const user = await this.prisma.user.findUnique({ where: { id } });\n return user ? this.serialize(user) : undefined;\n },\n );\n }\n\n serialize(\n user: Pick,\n ): User {\n return {\n id: user.id,\n username: user.username,\n display_name: user.displayName,\n created_at: user.createdAt.toISOString(),\n };\n }\n}\n", + "User/user.guard.ts": "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\nimport type { FastifyRequest } from 'fastify';\nimport { AuthService } from '../Auth/auth.service';\nimport type { User } from './user.schema';\n\nexport type AuthenticatedRequest = FastifyRequest & {\n currentUser: User;\n currentSessionId: string;\n currentChatsEpoch: string;\n};\n\n@Injectable()\nexport class UserGuard implements CanActivate {\n constructor(private readonly auth: AuthService) {}\n\n async canActivate(context: ExecutionContext): Promise {\n const request = context.switchToHttp().getRequest();\n const session = await this.auth.authenticate(request.headers.authorization);\n request.currentUser = session.user;\n request.currentSessionId = session.sessionId;\n request.currentChatsEpoch = session.chatsEpoch;\n return true;\n }\n}\n", + "Chat/chat.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { randomUUID } from 'node:crypto';\nimport {\n Prisma,\n type Message as StoredMessage,\n} from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport {\n invalidRequest,\n objectBody,\n pageLimit,\n requiredText,\n uuid,\n} from '../common/validation';\nimport type { Chat, Message, Page } from './chat.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\ninterface Cursor {\n scope: string;\n created_at: string;\n id: string;\n}\n\nconst chatInclude = {\n members: { orderBy: { position: 'asc' as const } },\n} satisfies Prisma.ChatInclude;\ntype StoredChat = Prisma.ChatGetPayload<{ include: typeof chatInclude }>;\n\n@Injectable()\nexport class ChatService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown, userId: string): Promise {\n const body = objectBody(value, ['title', 'member_ids']);\n const title = requiredText(body.title, 'title', 100);\n if (\n !Array.isArray(body.member_ids) ||\n body.member_ids.length < 1 ||\n body.member_ids.length > 100\n ) {\n return invalidRequest('Некорректный member_ids');\n }\n const memberIds = body.member_ids.map((id: unknown) =>\n uuid(id, 'member_ids'),\n );\n if (\n new Set(memberIds).size !== memberIds.length ||\n !memberIds.includes(userId)\n ) {\n return invalidRequest(\n 'Список участников содержит дубликат или не содержит вызывающего',\n );\n }\n try {\n const chat = await this.prisma.$transaction(async (tx) => {\n const count = await tx.user.count({ where: { id: { in: memberIds } } });\n if (count !== memberIds.length)\n return invalidRequest('Неизвестный участник чата');\n const created = await tx.chat.create({\n data: {\n title,\n members: {\n create: memberIds.map((userId, position) => ({\n userId,\n position,\n })),\n },\n },\n include: chatInclude,\n });\n await tx.$executeRaw(Prisma.sql`\n WITH locked AS MATERIALIZED (\n SELECT id FROM users\n WHERE id IN (${Prisma.join(memberIds.map((id) => Prisma.sql`${id}::uuid`))})\n ORDER BY id FOR UPDATE\n )\n UPDATE users AS u SET chats_epoch = u.chats_epoch + 1\n FROM locked WHERE u.id = locked.id\n `);\n return created;\n });\n return this.serializeChat(chat);\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2003'\n ) {\n return invalidRequest('Неизвестный участник чата');\n }\n throw error;\n }\n }\n\n async list(\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n epoch: string,\n ): Promise> {\n const limit = pageLimit(limitValue);\n const scope = `chats:${userId}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const chats = await this.prisma.chat.findMany({\n where: { members: { some: { userId } }, ...this.after(cursor) },\n include: chatInclude,\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n chats.map((chat) => this.serializeChat(chat)),\n limit,\n scope,\n );\n },\n epoch,\n );\n }\n\n async get(value: unknown, userId: string): Promise {\n const { id } = await this.authorizeChat(value, userId);\n return this.getMetadata(id);\n }\n\n private async authorizeChat(value: unknown, userId: string) {\n const id = uuid(value, 'chat_id');\n const [membership] = await this.prisma.$queryRaw<\n { id: string; messagesEpoch: bigint }[]\n >(Prisma.sql`\n SELECT c.id, c.messages_epoch AS \"messagesEpoch\"\n FROM chat_members AS cm JOIN chats AS c ON c.id = cm.chat_id\n WHERE cm.chat_id = ${id}::uuid AND cm.user_id = ${userId}::uuid\n `);\n if (!membership) {\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n }\n return membership;\n }\n\n private getMetadata(id: string): Promise {\n return this.cache.remember(\n `chat:${id}`,\n 'metadata',\n CACHE_TTL.entity,\n async () => {\n const chat = await this.prisma.chat.findUnique({\n where: { id },\n include: chatInclude,\n });\n if (!chat)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeChat(chat);\n },\n );\n }\n\n async createMessage(\n chatId: unknown,\n value: unknown,\n userId: string,\n ): Promise {\n const id = uuid(chatId, 'chat_id');\n const body = objectBody(value, ['text']);\n const text = requiredText(body.text, 'text', 4000);\n const [message] = await this.prisma.$queryRaw(Prisma.sql`\n WITH updated AS (\n UPDATE chats AS c\n SET messages_epoch = c.messages_epoch + 1\n WHERE c.id = ${id}::uuid\n AND EXISTS (\n SELECT 1 FROM chat_members AS cm\n WHERE cm.chat_id = c.id AND cm.user_id = ${userId}::uuid\n )\n RETURNING c.id\n )\n INSERT INTO messages (id, chat_id, sender_id, text)\n SELECT ${randomUUID()}::uuid, updated.id, ${userId}::uuid, ${text}\n FROM updated\n RETURNING id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n `);\n if (!message)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeMessage(message);\n }\n\n async listMessages(\n chatId: unknown,\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n ): Promise> {\n const chat = await this.authorizeChat(chatId, userId);\n const limit = pageLimit(limitValue);\n const scope = `messages:${chat.id}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const messages = cursor\n ? await this.prisma.$queryRaw(Prisma.sql`\n SELECT id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n FROM \"public\".\"messages\"\n WHERE chat_id = ${chat.id}::uuid\n AND (created_at, id) >\n (${new Date(cursor.created_at)}::timestamptz, ${cursor.id}::uuid)\n ORDER BY created_at ASC, id ASC\n LIMIT ${limit + 1}\n `)\n : await this.prisma.message.findMany({\n where: { chatId: chat.id },\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n messages.map((message) => this.serializeMessage(message)),\n limit,\n scope,\n );\n },\n chat.messagesEpoch.toString(),\n );\n }\n\n private after(cursor: Cursor | null) {\n if (!cursor) return {};\n const createdAt = new Date(cursor.created_at);\n return {\n OR: [\n { createdAt: { gt: createdAt } },\n { createdAt, id: { gt: cursor.id } },\n ],\n };\n }\n\n private serializeChat(chat: StoredChat): Chat {\n return {\n id: chat.id,\n title: chat.title,\n member_ids: chat.members.map((member) => member.userId),\n created_at: chat.createdAt.toISOString(),\n };\n }\n\n private serializeMessage(message: StoredMessage): Message {\n return {\n id: message.id,\n chat_id: message.chatId,\n sender_id: message.senderId,\n text: message.text,\n created_at: message.createdAt.toISOString(),\n };\n }\n\n private page(\n items: T[],\n limit: number,\n scope: string,\n ): Page {\n const result = items.slice(0, limit);\n const last = result.at(-1);\n return {\n items: result,\n next_cursor:\n items.length > limit && last\n ? Buffer.from(\n JSON.stringify({\n scope,\n created_at: last.created_at,\n id: last.id,\n }),\n ).toString('base64url')\n : null,\n };\n }\n\n private decodeCursor(value: unknown, scope: string): Cursor | null {\n if (value === undefined) return null;\n if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/.test(value))\n return invalidRequest('Некорректный cursor');\n try {\n const cursor: unknown = JSON.parse(\n Buffer.from(value, 'base64url').toString('utf8'),\n );\n if (\n typeof cursor !== 'object' ||\n cursor === null ||\n Array.isArray(cursor)\n )\n return invalidRequest('Некорректный cursor');\n const data = cursor as Record;\n if (\n data.scope !== scope ||\n typeof data.created_at !== 'string' ||\n Number.isNaN(Date.parse(data.created_at)) ||\n typeof data.id !== 'string'\n ) {\n return invalidRequest('Некорректный cursor');\n }\n return {\n scope,\n created_at: data.created_at,\n id: uuid(data.id, 'cursor'),\n };\n } catch {\n return invalidRequest('Некорректный cursor');\n }\n }\n}\n", + "Chat/chat.controller.ts": "import {\n Body,\n Controller,\n Get,\n HttpCode,\n HttpStatus,\n Param,\n Post,\n Query,\n Req,\n UseGuards,\n} from '@nestjs/common';\nimport {\n ApiBody,\n ApiBearerAuth,\n ApiCreatedResponse,\n ApiOkResponse,\n ApiOperation,\n ApiQuery,\n ApiTags,\n} from '@nestjs/swagger';\nimport { UserGuard, type AuthenticatedRequest } from '../User/user.guard';\nimport {\n CreateChatDto,\n CreateMessageDto,\n Chat,\n Message,\n ChatPage,\n MessagePage,\n} from './chat.schema';\nimport { ChatService } from './chat.service';\n\n@ApiTags('chats')\n@ApiBearerAuth('bearerAuth')\n@UseGuards(UserGuard)\n@Controller('api/v1/chats')\nexport class ChatController {\n constructor(private readonly chats: ChatService) {}\n\n @Post()\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateChatDto })\n @ApiOperation({ operationId: 'createChat' })\n @ApiCreatedResponse({ type: Chat })\n create(@Req() request: AuthenticatedRequest, @Body() body: unknown) {\n return this.chats.create(body, request.currentUser.id);\n }\n\n @Get()\n @ApiOperation({ operationId: 'listChats' })\n @ApiOkResponse({ type: ChatPage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n list(\n @Req() request: AuthenticatedRequest,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.list(\n request.currentUser.id,\n limit,\n cursor,\n request.currentChatsEpoch,\n );\n }\n\n @Get(':chat_id')\n @ApiOperation({ operationId: 'getChat' })\n @ApiOkResponse({ type: Chat })\n get(@Req() request: AuthenticatedRequest, @Param('chat_id') chatId: string) {\n return this.chats.get(chatId, request.currentUser.id);\n }\n\n @Post(':chat_id/messages')\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateMessageDto })\n @ApiOperation({ operationId: 'createMessage' })\n @ApiCreatedResponse({ type: Message })\n createMessage(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Body() body: unknown,\n ) {\n return this.chats.createMessage(chatId, body, request.currentUser.id);\n }\n\n @Get(':chat_id/messages')\n @ApiOperation({ operationId: 'listMessages' })\n @ApiOkResponse({ type: MessagePage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n listMessages(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.listMessages(\n chatId,\n request.currentUser.id,\n limit,\n cursor,\n );\n }\n}\n" + }, + "access-join": { + "Auth/auth.service.ts": "import { Injectable } from '@nestjs/common';\nimport { createHash, randomBytes } from 'node:crypto';\nimport { TextDecoder } from 'node:util';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { Prisma } from '../generated/prisma/client';\nimport { UserService } from '../User/user.service';\nimport type { User } from '../User/user.schema';\nimport { invalidRequest, uuid, uuidPattern } from '../common/validation';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport { AuthException } from './auth.exception';\nimport { PasswordService, validPassword } from './password.service';\nimport type { Session } from './auth.schema';\n\nexport interface ChatAccess {\n chatId: string;\n userId: string;\n messagesEpoch: string;\n}\n\n@Injectable()\nexport class AuthService {\n private readonly ttlSeconds: number;\n\n constructor(\n private readonly prisma: PrismaService,\n private readonly users: UserService,\n private readonly passwords: PasswordService,\n ) {\n this.ttlSeconds = Number(process.env.SESSION_TTL_SECONDS ?? 3600);\n if (\n !Number.isSafeInteger(this.ttlSeconds) ||\n this.ttlSeconds <= 0 ||\n Number.isNaN(new Date(Date.now() + this.ttlSeconds * 1000).getTime())\n ) {\n throw new Error(\n 'SESSION_TTL_SECONDS must be a positive integer representing a valid expiry',\n );\n }\n }\n\n async login(authorization: unknown, body: unknown): Promise {\n const { username, password } = this.basicCredentials(authorization);\n const user = await this.prisma.user.findUnique({ where: { username } });\n const verified = await this.passwords.verify(\n password,\n user?.passwordHash ?? null,\n );\n if (!user || !verified) throw new AuthException('Basic');\n if (body !== undefined)\n return invalidRequest('Вход через Basic не принимает тело запроса');\n const token = randomBytes(32).toString('base64url');\n const session = await this.prisma.session.create({\n data: {\n userId: user.id,\n tokenHash: this.tokenHash(token),\n expiresAt: new Date(Date.now() + this.ttlSeconds * 1000),\n },\n });\n return {\n token,\n token_type: 'Bearer',\n expires_at: session.expiresAt.toISOString(),\n user: this.users.serialize(user),\n };\n }\n\n async authenticate(\n authorization: unknown,\n chatId?: unknown,\n ): Promise<{\n user: User;\n sessionId: string;\n chatsEpoch: string;\n chatAccess?: ChatAccess;\n }> {\n const match =\n typeof authorization === 'string' &&\n /^Bearer +([A-Za-z0-9_-]{43})$/i.exec(authorization);\n if (!match) throw new AuthException('Bearer');\n const requestedChat =\n typeof chatId === 'string' && uuidPattern.test(chatId)\n ? chatId.toLowerCase()\n : null;\n const [session] = await this.prisma.$queryRaw<\n {\n id: string;\n userId: string;\n username: string;\n displayName: string;\n createdAt: Date;\n chatsEpoch: bigint;\n chatId: string | null;\n messagesEpoch: bigint | null;\n }[]\n >(Prisma.sql`\n SELECT s.id, s.user_id AS \"userId\", u.chats_epoch AS \"chatsEpoch\",\n u.username, u.display_name AS \"displayName\", u.created_at AS \"createdAt\",\n ${\n chatId === undefined\n ? Prisma.sql`NULL::uuid AS \"chatId\", NULL::bigint AS \"messagesEpoch\"`\n : Prisma.sql`c.id AS \"chatId\", c.messages_epoch AS \"messagesEpoch\"`\n }\n FROM sessions AS s\n JOIN users AS u ON u.id = s.user_id\n ${\n chatId === undefined\n ? Prisma.empty\n : Prisma.sql`\n LEFT JOIN chat_members AS cm\n ON cm.user_id = s.user_id AND cm.chat_id = ${requestedChat}::uuid\n LEFT JOIN chats AS c ON c.id = cm.chat_id\n `\n }\n WHERE s.token_hash = ${this.tokenHash(match[1])}\n AND s.revoked_at IS NULL AND s.expires_at > ${new Date()}\n LIMIT 1\n `);\n if (!session) throw new AuthException('Bearer');\n if (chatId !== undefined) {\n uuid(chatId, 'chat_id');\n if (session.chatId === null || session.messagesEpoch === null)\n throw new ApiException(404, 'not_found', 'Объект не найден');\n }\n return {\n user: this.users.serialize({ ...session, id: session.userId }),\n sessionId: session.id,\n chatsEpoch: session.chatsEpoch.toString(),\n chatAccess:\n session.chatId !== null && session.messagesEpoch !== null\n ? {\n chatId: session.chatId,\n userId: session.userId,\n messagesEpoch: session.messagesEpoch.toString(),\n }\n : undefined,\n };\n }\n\n async logout(sessionId: string): Promise {\n const now = new Date();\n const result = await this.prisma.session.updateMany({\n where: { id: sessionId, revokedAt: null, expiresAt: { gt: now } },\n data: { revokedAt: now },\n });\n if (result.count !== 1) throw new AuthException('Bearer');\n }\n\n private tokenHash(token: string): string {\n return createHash('sha256').update(token).digest('hex');\n }\n\n private basicCredentials(authorization: unknown): {\n username: string;\n password: string;\n } {\n const match =\n typeof authorization === 'string' &&\n /^Basic +([A-Za-z0-9+/]+={0,2})$/i.exec(authorization);\n if (!match) throw new AuthException('Basic');\n try {\n const bytes = Buffer.from(match[1], 'base64');\n if (\n bytes.toString('base64').replace(/=+$/, '') !==\n match[1].replace(/=+$/, '')\n )\n throw new AuthException('Basic');\n const value = new TextDecoder('utf-8', { fatal: true }).decode(bytes);\n const colon = value.indexOf(':');\n const username = value.slice(0, colon);\n const password = value.slice(colon + 1);\n if (\n colon < 0 ||\n !/^[a-z0-9_]{3,32}$/.test(username) ||\n !validPassword(password)\n )\n throw new AuthException('Basic');\n return { username, password };\n } catch {\n throw new AuthException('Basic');\n }\n }\n}\n", + "User/user.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { Prisma, type User as StoredUser } from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport { objectBody, requiredText } from '../common/validation';\nimport {\n PasswordService,\n registrationPassword,\n} from '../Auth/password.service';\nimport type { User } from './user.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\n@Injectable()\nexport class UserService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly passwords: PasswordService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown): Promise {\n const body = objectBody(value, ['username', 'display_name', 'password']);\n const username = body.username;\n if (typeof username !== 'string' || !/^[a-z0-9_]{3,32}$/.test(username)) {\n throw new ApiException(\n HttpStatus.BAD_REQUEST,\n 'invalid_request',\n 'Некорректный username',\n );\n }\n const displayName = requiredText(body.display_name, 'display_name', 100);\n const password = registrationPassword(body.password);\n const passwordHash = await this.passwords.hash(password);\n try {\n return this.serialize(\n await this.prisma.user.create({\n data: { username, displayName, passwordHash },\n }),\n );\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2002'\n ) {\n throw new ApiException(\n HttpStatus.CONFLICT,\n 'conflict',\n 'Username уже занят',\n );\n }\n throw error;\n }\n }\n\n async get(id: string): Promise {\n return this.cache.remember(\n `user:${id}`,\n 'profile',\n CACHE_TTL.entity,\n async () => {\n const user = await this.prisma.user.findUnique({ where: { id } });\n return user ? this.serialize(user) : undefined;\n },\n );\n }\n\n serialize(\n user: Pick,\n ): User {\n return {\n id: user.id,\n username: user.username,\n display_name: user.displayName,\n created_at: user.createdAt.toISOString(),\n };\n }\n}\n", + "User/user.guard.ts": "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\nimport type { FastifyRequest } from 'fastify';\nimport { AuthService, type ChatAccess } from '../Auth/auth.service';\nimport type { User } from './user.schema';\n\nexport type AuthenticatedRequest = FastifyRequest & {\n currentUser: User;\n currentSessionId: string;\n currentChatsEpoch: string;\n currentChatAccess?: ChatAccess;\n};\n\n@Injectable()\nexport class UserGuard implements CanActivate {\n constructor(private readonly auth: AuthService) {}\n\n async canActivate(context: ExecutionContext): Promise {\n const request = context.switchToHttp().getRequest();\n const chatId =\n request.method === 'GET' &&\n request.routeOptions.url === '/api/v1/chats/:chat_id/messages'\n ? (request.params as { chat_id: string }).chat_id\n : undefined;\n const session = await this.auth.authenticate(\n request.headers.authorization,\n chatId,\n );\n request.currentUser = session.user;\n request.currentSessionId = session.sessionId;\n request.currentChatsEpoch = session.chatsEpoch;\n request.currentChatAccess = session.chatAccess;\n return true;\n }\n}\n", + "Chat/chat.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { randomUUID } from 'node:crypto';\nimport type { ChatAccess } from '../Auth/auth.service';\nimport {\n Prisma,\n type Message as StoredMessage,\n} from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport {\n invalidRequest,\n objectBody,\n pageLimit,\n requiredText,\n uuid,\n} from '../common/validation';\nimport type { Chat, Message, Page } from './chat.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\ninterface Cursor {\n scope: string;\n created_at: string;\n id: string;\n}\n\nconst chatInclude = {\n members: { orderBy: { position: 'asc' as const } },\n} satisfies Prisma.ChatInclude;\ntype StoredChat = Prisma.ChatGetPayload<{ include: typeof chatInclude }>;\n\n@Injectable()\nexport class ChatService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown, userId: string): Promise {\n const body = objectBody(value, ['title', 'member_ids']);\n const title = requiredText(body.title, 'title', 100);\n if (\n !Array.isArray(body.member_ids) ||\n body.member_ids.length < 1 ||\n body.member_ids.length > 100\n ) {\n return invalidRequest('Некорректный member_ids');\n }\n const memberIds = body.member_ids.map((id: unknown) =>\n uuid(id, 'member_ids'),\n );\n if (\n new Set(memberIds).size !== memberIds.length ||\n !memberIds.includes(userId)\n ) {\n return invalidRequest(\n 'Список участников содержит дубликат или не содержит вызывающего',\n );\n }\n try {\n const chat = await this.prisma.$transaction(async (tx) => {\n const count = await tx.user.count({ where: { id: { in: memberIds } } });\n if (count !== memberIds.length)\n return invalidRequest('Неизвестный участник чата');\n const created = await tx.chat.create({\n data: {\n title,\n members: {\n create: memberIds.map((userId, position) => ({\n userId,\n position,\n })),\n },\n },\n include: chatInclude,\n });\n await tx.$executeRaw(Prisma.sql`\n WITH locked AS MATERIALIZED (\n SELECT id FROM users\n WHERE id IN (${Prisma.join(memberIds.map((id) => Prisma.sql`${id}::uuid`))})\n ORDER BY id FOR UPDATE\n )\n UPDATE users AS u SET chats_epoch = u.chats_epoch + 1\n FROM locked WHERE u.id = locked.id\n `);\n return created;\n });\n return this.serializeChat(chat);\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2003'\n ) {\n return invalidRequest('Неизвестный участник чата');\n }\n throw error;\n }\n }\n\n async list(\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n epoch: string,\n ): Promise> {\n const limit = pageLimit(limitValue);\n const scope = `chats:${userId}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const chats = await this.prisma.chat.findMany({\n where: { members: { some: { userId } }, ...this.after(cursor) },\n include: chatInclude,\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n chats.map((chat) => this.serializeChat(chat)),\n limit,\n scope,\n );\n },\n epoch,\n );\n }\n\n async get(value: unknown, userId: string): Promise {\n const { id } = await this.authorizeChat(value, userId);\n return this.getMetadata(id);\n }\n\n private async authorizeChat(value: unknown, userId: string) {\n const id = uuid(value, 'chat_id');\n const [membership] = await this.prisma.$queryRaw<\n { id: string; messagesEpoch: bigint }[]\n >(Prisma.sql`\n SELECT c.id, c.messages_epoch AS \"messagesEpoch\"\n FROM chat_members AS cm JOIN chats AS c ON c.id = cm.chat_id\n WHERE cm.chat_id = ${id}::uuid AND cm.user_id = ${userId}::uuid\n `);\n if (!membership) {\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n }\n return membership;\n }\n\n private getMetadata(id: string): Promise {\n return this.cache.remember(\n `chat:${id}`,\n 'metadata',\n CACHE_TTL.entity,\n async () => {\n const chat = await this.prisma.chat.findUnique({\n where: { id },\n include: chatInclude,\n });\n if (!chat)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeChat(chat);\n },\n );\n }\n\n async createMessage(\n chatId: unknown,\n value: unknown,\n userId: string,\n ): Promise {\n const id = uuid(chatId, 'chat_id');\n const body = objectBody(value, ['text']);\n const text = requiredText(body.text, 'text', 4000);\n const [message] = await this.prisma.$queryRaw(Prisma.sql`\n WITH updated AS (\n UPDATE chats AS c\n SET messages_epoch = c.messages_epoch + 1\n WHERE c.id = ${id}::uuid\n AND EXISTS (\n SELECT 1 FROM chat_members AS cm\n WHERE cm.chat_id = c.id AND cm.user_id = ${userId}::uuid\n )\n RETURNING c.id\n )\n INSERT INTO messages (id, chat_id, sender_id, text)\n SELECT ${randomUUID()}::uuid, updated.id, ${userId}::uuid, ${text}\n FROM updated\n RETURNING id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n `);\n if (!message)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeMessage(message);\n }\n\n async listMessages(\n chatId: unknown,\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n access?: ChatAccess,\n ): Promise> {\n const id = uuid(chatId, 'chat_id');\n const chat =\n access?.chatId === id && access.userId === userId\n ? { id, messagesEpoch: access.messagesEpoch }\n : await this.authorizeChat(id, userId);\n const limit = pageLimit(limitValue);\n const scope = `messages:${chat.id}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const messages = cursor\n ? await this.prisma.$queryRaw(Prisma.sql`\n SELECT id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n FROM \"public\".\"messages\"\n WHERE chat_id = ${chat.id}::uuid\n AND (created_at, id) >\n (${new Date(cursor.created_at)}::timestamptz, ${cursor.id}::uuid)\n ORDER BY created_at ASC, id ASC\n LIMIT ${limit + 1}\n `)\n : await this.prisma.message.findMany({\n where: { chatId: chat.id },\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n messages.map((message) => this.serializeMessage(message)),\n limit,\n scope,\n );\n },\n chat.messagesEpoch.toString(),\n );\n }\n\n private after(cursor: Cursor | null) {\n if (!cursor) return {};\n const createdAt = new Date(cursor.created_at);\n return {\n OR: [\n { createdAt: { gt: createdAt } },\n { createdAt, id: { gt: cursor.id } },\n ],\n };\n }\n\n private serializeChat(chat: StoredChat): Chat {\n return {\n id: chat.id,\n title: chat.title,\n member_ids: chat.members.map((member) => member.userId),\n created_at: chat.createdAt.toISOString(),\n };\n }\n\n private serializeMessage(message: StoredMessage): Message {\n return {\n id: message.id,\n chat_id: message.chatId,\n sender_id: message.senderId,\n text: message.text,\n created_at: message.createdAt.toISOString(),\n };\n }\n\n private page(\n items: T[],\n limit: number,\n scope: string,\n ): Page {\n const result = items.slice(0, limit);\n const last = result.at(-1);\n return {\n items: result,\n next_cursor:\n items.length > limit && last\n ? Buffer.from(\n JSON.stringify({\n scope,\n created_at: last.created_at,\n id: last.id,\n }),\n ).toString('base64url')\n : null,\n };\n }\n\n private decodeCursor(value: unknown, scope: string): Cursor | null {\n if (value === undefined) return null;\n if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/.test(value))\n return invalidRequest('Некорректный cursor');\n try {\n const cursor: unknown = JSON.parse(\n Buffer.from(value, 'base64url').toString('utf8'),\n );\n if (\n typeof cursor !== 'object' ||\n cursor === null ||\n Array.isArray(cursor)\n )\n return invalidRequest('Некорректный cursor');\n const data = cursor as Record;\n if (\n data.scope !== scope ||\n typeof data.created_at !== 'string' ||\n Number.isNaN(Date.parse(data.created_at)) ||\n typeof data.id !== 'string'\n ) {\n return invalidRequest('Некорректный cursor');\n }\n return {\n scope,\n created_at: data.created_at,\n id: uuid(data.id, 'cursor'),\n };\n } catch {\n return invalidRequest('Некорректный cursor');\n }\n }\n}\n", + "Chat/chat.controller.ts": "import {\n Body,\n Controller,\n Get,\n HttpCode,\n HttpStatus,\n Param,\n Post,\n Query,\n Req,\n UseGuards,\n} from '@nestjs/common';\nimport {\n ApiBody,\n ApiBearerAuth,\n ApiCreatedResponse,\n ApiOkResponse,\n ApiOperation,\n ApiQuery,\n ApiTags,\n} from '@nestjs/swagger';\nimport { UserGuard, type AuthenticatedRequest } from '../User/user.guard';\nimport {\n CreateChatDto,\n CreateMessageDto,\n Chat,\n Message,\n ChatPage,\n MessagePage,\n} from './chat.schema';\nimport { ChatService } from './chat.service';\n\n@ApiTags('chats')\n@ApiBearerAuth('bearerAuth')\n@UseGuards(UserGuard)\n@Controller('api/v1/chats')\nexport class ChatController {\n constructor(private readonly chats: ChatService) {}\n\n @Post()\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateChatDto })\n @ApiOperation({ operationId: 'createChat' })\n @ApiCreatedResponse({ type: Chat })\n create(@Req() request: AuthenticatedRequest, @Body() body: unknown) {\n return this.chats.create(body, request.currentUser.id);\n }\n\n @Get()\n @ApiOperation({ operationId: 'listChats' })\n @ApiOkResponse({ type: ChatPage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n list(\n @Req() request: AuthenticatedRequest,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.list(\n request.currentUser.id,\n limit,\n cursor,\n request.currentChatsEpoch,\n );\n }\n\n @Get(':chat_id')\n @ApiOperation({ operationId: 'getChat' })\n @ApiOkResponse({ type: Chat })\n get(@Req() request: AuthenticatedRequest, @Param('chat_id') chatId: string) {\n return this.chats.get(chatId, request.currentUser.id);\n }\n\n @Post(':chat_id/messages')\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateMessageDto })\n @ApiOperation({ operationId: 'createMessage' })\n @ApiCreatedResponse({ type: Message })\n createMessage(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Body() body: unknown,\n ) {\n return this.chats.createMessage(chatId, body, request.currentUser.id);\n }\n\n @Get(':chat_id/messages')\n @ApiOperation({ operationId: 'listMessages' })\n @ApiOkResponse({ type: MessagePage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n listMessages(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.listMessages(\n chatId,\n request.currentUser.id,\n limit,\n cursor,\n request.currentChatAccess,\n );\n }\n}\n" + }, + "striped": { + "Auth/auth.service.ts": "import { Injectable } from '@nestjs/common';\nimport { createHash, randomBytes } from 'node:crypto';\nimport { TextDecoder } from 'node:util';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { Prisma } from '../generated/prisma/client';\nimport { UserService } from '../User/user.service';\nimport type { User } from '../User/user.schema';\nimport { invalidRequest, uuid, uuidPattern } from '../common/validation';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport { AuthException } from './auth.exception';\nimport { PasswordService, validPassword } from './password.service';\nimport type { Session } from './auth.schema';\n\nexport interface ChatAccess {\n chatId: string;\n userId: string;\n messagesEpoch: string;\n}\n\n@Injectable()\nexport class AuthService {\n private readonly ttlSeconds: number;\n\n constructor(\n private readonly prisma: PrismaService,\n private readonly users: UserService,\n private readonly passwords: PasswordService,\n ) {\n this.ttlSeconds = Number(process.env.SESSION_TTL_SECONDS ?? 3600);\n if (\n !Number.isSafeInteger(this.ttlSeconds) ||\n this.ttlSeconds <= 0 ||\n Number.isNaN(new Date(Date.now() + this.ttlSeconds * 1000).getTime())\n ) {\n throw new Error(\n 'SESSION_TTL_SECONDS must be a positive integer representing a valid expiry',\n );\n }\n }\n\n async login(authorization: unknown, body: unknown): Promise {\n const { username, password } = this.basicCredentials(authorization);\n const user = await this.prisma.user.findUnique({ where: { username } });\n const verified = await this.passwords.verify(\n password,\n user?.passwordHash ?? null,\n );\n if (!user || !verified) throw new AuthException('Basic');\n if (body !== undefined)\n return invalidRequest('Вход через Basic не принимает тело запроса');\n const token = randomBytes(32).toString('base64url');\n const session = await this.prisma.session.create({\n data: {\n userId: user.id,\n tokenHash: this.tokenHash(token),\n expiresAt: new Date(Date.now() + this.ttlSeconds * 1000),\n },\n });\n return {\n token,\n token_type: 'Bearer',\n expires_at: session.expiresAt.toISOString(),\n user: this.users.serialize(user),\n };\n }\n\n async authenticate(\n authorization: unknown,\n chatId?: unknown,\n ): Promise<{\n user: User;\n sessionId: string;\n chatsEpoch: string;\n chatAccess?: ChatAccess;\n }> {\n const match =\n typeof authorization === 'string' &&\n /^Bearer +([A-Za-z0-9_-]{43})$/i.exec(authorization);\n if (!match) throw new AuthException('Bearer');\n const requestedChat =\n typeof chatId === 'string' && uuidPattern.test(chatId)\n ? chatId.toLowerCase()\n : null;\n const [session] = await this.prisma.$queryRaw<\n {\n id: string;\n userId: string;\n username: string;\n displayName: string;\n createdAt: Date;\n chatsEpoch: bigint;\n chatId: string | null;\n messagesEpoch: bigint | null;\n }[]\n >(Prisma.sql`\n SELECT s.id, s.user_id AS \"userId\", u.chats_epoch AS \"chatsEpoch\",\n u.username, u.display_name AS \"displayName\", u.created_at AS \"createdAt\",\n ${\n chatId === undefined\n ? Prisma.sql`NULL::uuid AS \"chatId\", NULL::bigint AS \"messagesEpoch\"`\n : Prisma.sql`c.id AS \"chatId\", COALESCE((SELECT SUM(e.epoch) FROM \"epoch_variants_0302fea1e5264f72a02693f65cb217b7\".chat_message_epochs AS e WHERE e.chat_id = c.id), 0)::bigint AS \"messagesEpoch\"`\n }\n FROM sessions AS s\n JOIN users AS u ON u.id = s.user_id\n ${\n chatId === undefined\n ? Prisma.empty\n : Prisma.sql`\n LEFT JOIN chat_members AS cm\n ON cm.user_id = s.user_id AND cm.chat_id = ${requestedChat}::uuid\n LEFT JOIN chats AS c ON c.id = cm.chat_id\n `\n }\n WHERE s.token_hash = ${this.tokenHash(match[1])}\n AND s.revoked_at IS NULL AND s.expires_at > ${new Date()}\n LIMIT 1\n `);\n if (!session) throw new AuthException('Bearer');\n if (chatId !== undefined) {\n uuid(chatId, 'chat_id');\n if (session.chatId === null || session.messagesEpoch === null)\n throw new ApiException(404, 'not_found', 'Объект не найден');\n }\n return {\n user: this.users.serialize({ ...session, id: session.userId }),\n sessionId: session.id,\n chatsEpoch: session.chatsEpoch.toString(),\n chatAccess:\n session.chatId !== null && session.messagesEpoch !== null\n ? {\n chatId: session.chatId,\n userId: session.userId,\n messagesEpoch: session.messagesEpoch.toString(),\n }\n : undefined,\n };\n }\n\n async logout(sessionId: string): Promise {\n const now = new Date();\n const result = await this.prisma.session.updateMany({\n where: { id: sessionId, revokedAt: null, expiresAt: { gt: now } },\n data: { revokedAt: now },\n });\n if (result.count !== 1) throw new AuthException('Bearer');\n }\n\n private tokenHash(token: string): string {\n return createHash('sha256').update(token).digest('hex');\n }\n\n private basicCredentials(authorization: unknown): {\n username: string;\n password: string;\n } {\n const match =\n typeof authorization === 'string' &&\n /^Basic +([A-Za-z0-9+/]+={0,2})$/i.exec(authorization);\n if (!match) throw new AuthException('Basic');\n try {\n const bytes = Buffer.from(match[1], 'base64');\n if (\n bytes.toString('base64').replace(/=+$/, '') !==\n match[1].replace(/=+$/, '')\n )\n throw new AuthException('Basic');\n const value = new TextDecoder('utf-8', { fatal: true }).decode(bytes);\n const colon = value.indexOf(':');\n const username = value.slice(0, colon);\n const password = value.slice(colon + 1);\n if (\n colon < 0 ||\n !/^[a-z0-9_]{3,32}$/.test(username) ||\n !validPassword(password)\n )\n throw new AuthException('Basic');\n return { username, password };\n } catch {\n throw new AuthException('Basic');\n }\n }\n}\n", + "User/user.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { Prisma, type User as StoredUser } from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport { objectBody, requiredText } from '../common/validation';\nimport {\n PasswordService,\n registrationPassword,\n} from '../Auth/password.service';\nimport type { User } from './user.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\n@Injectable()\nexport class UserService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly passwords: PasswordService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown): Promise {\n const body = objectBody(value, ['username', 'display_name', 'password']);\n const username = body.username;\n if (typeof username !== 'string' || !/^[a-z0-9_]{3,32}$/.test(username)) {\n throw new ApiException(\n HttpStatus.BAD_REQUEST,\n 'invalid_request',\n 'Некорректный username',\n );\n }\n const displayName = requiredText(body.display_name, 'display_name', 100);\n const password = registrationPassword(body.password);\n const passwordHash = await this.passwords.hash(password);\n try {\n return this.serialize(\n await this.prisma.user.create({\n data: { username, displayName, passwordHash },\n }),\n );\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2002'\n ) {\n throw new ApiException(\n HttpStatus.CONFLICT,\n 'conflict',\n 'Username уже занят',\n );\n }\n throw error;\n }\n }\n\n async get(id: string): Promise {\n return this.cache.remember(\n `user:${id}`,\n 'profile',\n CACHE_TTL.entity,\n async () => {\n const user = await this.prisma.user.findUnique({ where: { id } });\n return user ? this.serialize(user) : undefined;\n },\n );\n }\n\n serialize(\n user: Pick,\n ): User {\n return {\n id: user.id,\n username: user.username,\n display_name: user.displayName,\n created_at: user.createdAt.toISOString(),\n };\n }\n}\n", + "User/user.guard.ts": "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\nimport type { FastifyRequest } from 'fastify';\nimport { AuthService, type ChatAccess } from '../Auth/auth.service';\nimport type { User } from './user.schema';\n\nexport type AuthenticatedRequest = FastifyRequest & {\n currentUser: User;\n currentSessionId: string;\n currentChatsEpoch: string;\n currentChatAccess?: ChatAccess;\n};\n\n@Injectable()\nexport class UserGuard implements CanActivate {\n constructor(private readonly auth: AuthService) {}\n\n async canActivate(context: ExecutionContext): Promise {\n const request = context.switchToHttp().getRequest();\n const chatId =\n request.method === 'GET' &&\n request.routeOptions.url === '/api/v1/chats/:chat_id/messages'\n ? (request.params as { chat_id: string }).chat_id\n : undefined;\n const session = await this.auth.authenticate(\n request.headers.authorization,\n chatId,\n );\n request.currentUser = session.user;\n request.currentSessionId = session.sessionId;\n request.currentChatsEpoch = session.chatsEpoch;\n request.currentChatAccess = session.chatAccess;\n return true;\n }\n}\n", + "Chat/chat.service.ts": "import { HttpStatus, Injectable } from '@nestjs/common';\nimport { randomUUID } from 'node:crypto';\nimport type { ChatAccess } from '../Auth/auth.service';\nimport {\n Prisma,\n type Message as StoredMessage,\n} from '../generated/prisma/client';\nimport { PrismaService } from '../prisma/prisma.service';\nimport { ApiException } from '../common/exceptions/api.exception';\nimport {\n invalidRequest,\n objectBody,\n pageLimit,\n requiredText,\n uuid,\n} from '../common/validation';\nimport type { Chat, Message, Page } from './chat.schema';\nimport { CacheService, CACHE_TTL } from '../cache/cache.service';\n\ninterface Cursor {\n scope: string;\n created_at: string;\n id: string;\n}\n\nconst chatInclude = {\n members: { orderBy: { position: 'asc' as const } },\n} satisfies Prisma.ChatInclude;\ntype StoredChat = Prisma.ChatGetPayload<{ include: typeof chatInclude }>;\n\n@Injectable()\nexport class ChatService {\n constructor(\n private readonly prisma: PrismaService,\n private readonly cache: CacheService,\n ) {}\n\n async create(value: unknown, userId: string): Promise {\n const body = objectBody(value, ['title', 'member_ids']);\n const title = requiredText(body.title, 'title', 100);\n if (\n !Array.isArray(body.member_ids) ||\n body.member_ids.length < 1 ||\n body.member_ids.length > 100\n ) {\n return invalidRequest('Некорректный member_ids');\n }\n const memberIds = body.member_ids.map((id: unknown) =>\n uuid(id, 'member_ids'),\n );\n if (\n new Set(memberIds).size !== memberIds.length ||\n !memberIds.includes(userId)\n ) {\n return invalidRequest(\n 'Список участников содержит дубликат или не содержит вызывающего',\n );\n }\n try {\n const chat = await this.prisma.$transaction(async (tx) => {\n const count = await tx.user.count({ where: { id: { in: memberIds } } });\n if (count !== memberIds.length)\n return invalidRequest('Неизвестный участник чата');\n const created = await tx.chat.create({\n data: {\n title,\n members: {\n create: memberIds.map((userId, position) => ({\n userId,\n position,\n })),\n },\n },\n include: chatInclude,\n });\n await tx.$executeRaw(Prisma.sql`\n WITH locked AS MATERIALIZED (\n SELECT id FROM users\n WHERE id IN (${Prisma.join(memberIds.map((id) => Prisma.sql`${id}::uuid`))})\n ORDER BY id FOR UPDATE\n )\n UPDATE users AS u SET chats_epoch = u.chats_epoch + 1\n FROM locked WHERE u.id = locked.id\n `);\n return created;\n });\n return this.serializeChat(chat);\n } catch (error) {\n if (\n error instanceof Prisma.PrismaClientKnownRequestError &&\n error.code === 'P2003'\n ) {\n return invalidRequest('Неизвестный участник чата');\n }\n throw error;\n }\n }\n\n async list(\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n epoch: string,\n ): Promise> {\n const limit = pageLimit(limitValue);\n const scope = `chats:${userId}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const chats = await this.prisma.chat.findMany({\n where: { members: { some: { userId } }, ...this.after(cursor) },\n include: chatInclude,\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n chats.map((chat) => this.serializeChat(chat)),\n limit,\n scope,\n );\n },\n epoch,\n );\n }\n\n async get(value: unknown, userId: string): Promise {\n const { id } = await this.authorizeChat(value, userId);\n return this.getMetadata(id);\n }\n\n private async authorizeChat(value: unknown, userId: string) {\n const id = uuid(value, 'chat_id');\n const [membership] = await this.prisma.$queryRaw<\n { id: string; messagesEpoch: bigint }[]\n >(Prisma.sql`\n SELECT c.id, COALESCE((SELECT SUM(e.epoch) FROM \"epoch_variants_0302fea1e5264f72a02693f65cb217b7\".chat_message_epochs AS e WHERE e.chat_id = c.id), 0)::bigint AS \"messagesEpoch\"\n FROM chat_members AS cm JOIN chats AS c ON c.id = cm.chat_id\n WHERE cm.chat_id = ${id}::uuid AND cm.user_id = ${userId}::uuid\n `);\n if (!membership) {\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n }\n return membership;\n }\n\n private getMetadata(id: string): Promise {\n return this.cache.remember(\n `chat:${id}`,\n 'metadata',\n CACHE_TTL.entity,\n async () => {\n const chat = await this.prisma.chat.findUnique({\n where: { id },\n include: chatInclude,\n });\n if (!chat)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeChat(chat);\n },\n );\n }\n\n async createMessage(\n chatId: unknown,\n value: unknown,\n userId: string,\n ): Promise {\n const id = uuid(chatId, 'chat_id');\n const body = objectBody(value, ['text']);\n const text = requiredText(body.text, 'text', 4000);\n const messageId = randomUUID();\n const bucket = parseInt(messageId.slice(0, 2), 16) % 16;\n const [message] = await this.prisma.$queryRaw(Prisma.sql`\n WITH updated AS (\n INSERT INTO \"epoch_variants_0302fea1e5264f72a02693f65cb217b7\".chat_message_epochs AS e (chat_id, bucket, epoch)\n SELECT cm.chat_id, ${bucket}::smallint, 1 FROM chat_members AS cm\n WHERE cm.chat_id = ${id}::uuid AND cm.user_id = ${userId}::uuid\n ON CONFLICT (chat_id, bucket) DO UPDATE SET epoch = e.epoch + 1\n RETURNING chat_id\n )\n INSERT INTO messages (id, chat_id, sender_id, text)\n SELECT ${messageId}::uuid, updated.chat_id, ${userId}::uuid, ${text} FROM updated\n RETURNING id, chat_id AS \"chatId\", sender_id AS \"senderId\", text, created_at AS \"createdAt\"\n `);\n if (!message)\n throw new ApiException(\n HttpStatus.NOT_FOUND,\n 'not_found',\n 'Объект не найден',\n );\n return this.serializeMessage(message);\n }\n\n async listMessages(\n chatId: unknown,\n userId: string,\n limitValue: unknown,\n cursorValue: unknown,\n access?: ChatAccess,\n ): Promise> {\n const id = uuid(chatId, 'chat_id');\n const chat =\n access?.chatId === id && access.userId === userId\n ? { id, messagesEpoch: access.messagesEpoch }\n : await this.authorizeChat(id, userId);\n const limit = pageLimit(limitValue);\n const scope = `messages:${chat.id}`;\n const cursor = this.decodeCursor(cursorValue, scope);\n return this.cache.remember(\n scope,\n { limit, cursor },\n CACHE_TTL.page,\n async () => {\n const messages = cursor\n ? await this.prisma.$queryRaw(Prisma.sql`\n SELECT id, chat_id AS \"chatId\", sender_id AS \"senderId\",\n text, created_at AS \"createdAt\"\n FROM \"public\".\"messages\"\n WHERE chat_id = ${chat.id}::uuid\n AND (created_at, id) >\n (${new Date(cursor.created_at)}::timestamptz, ${cursor.id}::uuid)\n ORDER BY created_at ASC, id ASC\n LIMIT ${limit + 1}\n `)\n : await this.prisma.message.findMany({\n where: { chatId: chat.id },\n orderBy: [{ createdAt: 'asc' }, { id: 'asc' }],\n take: limit + 1,\n });\n return this.page(\n messages.map((message) => this.serializeMessage(message)),\n limit,\n scope,\n );\n },\n chat.messagesEpoch.toString(),\n );\n }\n\n private after(cursor: Cursor | null) {\n if (!cursor) return {};\n const createdAt = new Date(cursor.created_at);\n return {\n OR: [\n { createdAt: { gt: createdAt } },\n { createdAt, id: { gt: cursor.id } },\n ],\n };\n }\n\n private serializeChat(chat: StoredChat): Chat {\n return {\n id: chat.id,\n title: chat.title,\n member_ids: chat.members.map((member) => member.userId),\n created_at: chat.createdAt.toISOString(),\n };\n }\n\n private serializeMessage(message: StoredMessage): Message {\n return {\n id: message.id,\n chat_id: message.chatId,\n sender_id: message.senderId,\n text: message.text,\n created_at: message.createdAt.toISOString(),\n };\n }\n\n private page(\n items: T[],\n limit: number,\n scope: string,\n ): Page {\n const result = items.slice(0, limit);\n const last = result.at(-1);\n return {\n items: result,\n next_cursor:\n items.length > limit && last\n ? Buffer.from(\n JSON.stringify({\n scope,\n created_at: last.created_at,\n id: last.id,\n }),\n ).toString('base64url')\n : null,\n };\n }\n\n private decodeCursor(value: unknown, scope: string): Cursor | null {\n if (value === undefined) return null;\n if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/.test(value))\n return invalidRequest('Некорректный cursor');\n try {\n const cursor: unknown = JSON.parse(\n Buffer.from(value, 'base64url').toString('utf8'),\n );\n if (\n typeof cursor !== 'object' ||\n cursor === null ||\n Array.isArray(cursor)\n )\n return invalidRequest('Некорректный cursor');\n const data = cursor as Record;\n if (\n data.scope !== scope ||\n typeof data.created_at !== 'string' ||\n Number.isNaN(Date.parse(data.created_at)) ||\n typeof data.id !== 'string'\n ) {\n return invalidRequest('Некорректный cursor');\n }\n return {\n scope,\n created_at: data.created_at,\n id: uuid(data.id, 'cursor'),\n };\n } catch {\n return invalidRequest('Некорректный cursor');\n }\n }\n}\n", + "Chat/chat.controller.ts": "import {\n Body,\n Controller,\n Get,\n HttpCode,\n HttpStatus,\n Param,\n Post,\n Query,\n Req,\n UseGuards,\n} from '@nestjs/common';\nimport {\n ApiBody,\n ApiBearerAuth,\n ApiCreatedResponse,\n ApiOkResponse,\n ApiOperation,\n ApiQuery,\n ApiTags,\n} from '@nestjs/swagger';\nimport { UserGuard, type AuthenticatedRequest } from '../User/user.guard';\nimport {\n CreateChatDto,\n CreateMessageDto,\n Chat,\n Message,\n ChatPage,\n MessagePage,\n} from './chat.schema';\nimport { ChatService } from './chat.service';\n\n@ApiTags('chats')\n@ApiBearerAuth('bearerAuth')\n@UseGuards(UserGuard)\n@Controller('api/v1/chats')\nexport class ChatController {\n constructor(private readonly chats: ChatService) {}\n\n @Post()\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateChatDto })\n @ApiOperation({ operationId: 'createChat' })\n @ApiCreatedResponse({ type: Chat })\n create(@Req() request: AuthenticatedRequest, @Body() body: unknown) {\n return this.chats.create(body, request.currentUser.id);\n }\n\n @Get()\n @ApiOperation({ operationId: 'listChats' })\n @ApiOkResponse({ type: ChatPage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n list(\n @Req() request: AuthenticatedRequest,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.list(\n request.currentUser.id,\n limit,\n cursor,\n request.currentChatsEpoch,\n );\n }\n\n @Get(':chat_id')\n @ApiOperation({ operationId: 'getChat' })\n @ApiOkResponse({ type: Chat })\n get(@Req() request: AuthenticatedRequest, @Param('chat_id') chatId: string) {\n return this.chats.get(chatId, request.currentUser.id);\n }\n\n @Post(':chat_id/messages')\n @HttpCode(HttpStatus.CREATED)\n @ApiBody({ type: CreateMessageDto })\n @ApiOperation({ operationId: 'createMessage' })\n @ApiCreatedResponse({ type: Message })\n createMessage(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Body() body: unknown,\n ) {\n return this.chats.createMessage(chatId, body, request.currentUser.id);\n }\n\n @Get(':chat_id/messages')\n @ApiOperation({ operationId: 'listMessages' })\n @ApiOkResponse({ type: MessagePage })\n @ApiQuery({\n name: 'limit',\n required: false,\n schema: { type: 'integer', minimum: 1, maximum: 100, default: 50 },\n })\n @ApiQuery({ name: 'cursor', required: false, type: String })\n listMessages(\n @Req() request: AuthenticatedRequest,\n @Param('chat_id') chatId: string,\n @Query('limit') limit: unknown,\n @Query('cursor') cursor: unknown,\n ) {\n return this.chats.listMessages(\n chatId,\n request.currentUser.id,\n limit,\n cursor,\n request.currentChatAccess,\n );\n }\n}\n" + } +} diff --git a/evidence/epoch-variants-validation.json b/evidence/epoch-variants-validation.json new file mode 100644 index 0000000..9116c12 --- /dev/null +++ b/evidence/epoch-variants-validation.json @@ -0,0 +1,15 @@ +{ + "recorded_on": "2026-10-13", + "selected_variant": "profile join + combined session/membership/epoch check + 16 message epoch buckets", + "backend_image": "sha256:02a5d9ca3816781e5931a82926b6a62858b1abf1eb9a0244da79d45e5787b020", + "migration": "20261013150000_message_epoch_buckets", + "checks": [ + { "command": "docker compose build backend migrate", "result": "PASS" }, + { "command": "docker compose up -d backend", "result": "PASS", "migration_applied": true }, + { "command": "docker compose -f compose.yaml -f test/compose.benchmark.yaml run --rm --no-deps --pull never benchmark node --test test/cache-epochs.mjs test/cache.mjs", "result": "PASS", "tests": 3, "failed": 0 }, + { "command": "pnpm.cmd lint", "result": "PASS" } + ], + "backend_status": "running healthy", + "experiment_schema_removed": true, + "previous_epoch_values_preserved_by_migration": true +} diff --git a/evidence/epoch-variants.json b/evidence/epoch-variants.json new file mode 100644 index 0000000..7f5dad8 --- /dev/null +++ b/evidence/epoch-variants.json @@ -0,0 +1,617 @@ +{ + "recorded_at": "2026-10-13T14:18:08.573Z", + "methodology": { + "concurrency": 32, + "duration_seconds": 60, + "warmup_seconds": 10, + "repetitions": 3, + "seed_messages": 100000, + "writes_per_repeat": 4096, + "order": [ + [ + "baseline", + "profile-join", + "access-join", + "striped" + ], + [ + "striped", + "access-join", + "profile-join", + "baseline" + ], + [ + "profile-join", + "striped", + "baseline", + "access-join" + ] + ], + "requests": "Real loopback HTTP; shared read fixtures, separate write chats and cache prefixes", + "resources": "Four idle/active API instances and HTTP generator share one Node process; only one workload active at a time", + "sql": "pg.Client.query; transaction-control commands excluded; no changes to database pool size" + }, + "variants": [ + { + "name": "baseline", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "86599b6e89cd66483cb10aff0d85cc29fe092ab24bbb849960079dcae347b8bf", + "js_sha256": "70e4c149faff62a38f3009816994c349096a8300495ecd57128a07af2acfb78f" + }, + "User/user.service.ts": { + "source_sha256": "de158e39c114c610cc7ea6c850108c8dd69c9bc3d643bac94557d272621f3cfb", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "b84d95633fbd89b4fdbc505c51dd64e657611651b757bed1aea8eee3f0eac3d9", + "js_sha256": "16bc70f6d4df0809637b16f569dda973085128775f29c29d6154aecf9a45be52" + }, + "Chat/chat.service.ts": { + "source_sha256": "11b6b6d361d5599667318540b2c83a1b8e397db6d4d3665bbfa526e0b349d430", + "js_sha256": "42cc729f6f8f6da1a4b6b66746d7ea8299c4a26cfc29f6cfcb436d865107dfad" + }, + "Chat/chat.controller.ts": { + "source_sha256": "700becb64112538a6551c5775ccc09ff9d750755dcffe6ec916782afed1dae11", + "js_sha256": "32ebfcf009fce603c8637da701e33756868a3a4b1dda3e93cf7007b3a8b14ec7" + } + }, + "striped": false + }, + { + "name": "profile-join", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "63e6ad3117bf8adda51bab735ee7b975179e68a6af060aafe63416a8c9b90107", + "js_sha256": "5da0f49def86501c34c2f8d02dbd86dde37b9b7d1d98b57df3e334fc557dcffd" + }, + "User/user.service.ts": { + "source_sha256": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "b84d95633fbd89b4fdbc505c51dd64e657611651b757bed1aea8eee3f0eac3d9", + "js_sha256": "16bc70f6d4df0809637b16f569dda973085128775f29c29d6154aecf9a45be52" + }, + "Chat/chat.service.ts": { + "source_sha256": "11b6b6d361d5599667318540b2c83a1b8e397db6d4d3665bbfa526e0b349d430", + "js_sha256": "42cc729f6f8f6da1a4b6b66746d7ea8299c4a26cfc29f6cfcb436d865107dfad" + }, + "Chat/chat.controller.ts": { + "source_sha256": "700becb64112538a6551c5775ccc09ff9d750755dcffe6ec916782afed1dae11", + "js_sha256": "32ebfcf009fce603c8637da701e33756868a3a4b1dda3e93cf7007b3a8b14ec7" + } + }, + "striped": false + }, + { + "name": "access-join", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "c577b5c9d8ad52eae065359f1614de2d74b1bc7588ac2676d513f4aba2fc9c6f", + "js_sha256": "8fc180339017f373771a1abeed9f6dc978ee8a1c051df9f6fb69f054ca45bf0f" + }, + "User/user.service.ts": { + "source_sha256": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "20b05a0e5272a4ee1ccbddef83494e62621ffb0236e56a15c17e7f8f0083f6d7", + "js_sha256": "a078cc3065d6f87ee441f2bc0ff43af25094e66db4bd661d74cf3cd1c501fc2a" + }, + "Chat/chat.service.ts": { + "source_sha256": "11a44d19390d1e605fb72fabbc6111a25917e292a1aab4132e26390887128219", + "js_sha256": "3759d025e679f2b1694e486c460361a96979f8b67a1a8e811e589c722e8fb55f" + }, + "Chat/chat.controller.ts": { + "source_sha256": "1e3b1e0a5abc053625c5b1a6dc14f5b5b3e87676b1af0bdd73e78ad95d1eb325", + "js_sha256": "6ac78b848b82f03a4134a9e19e2b802fef59d06b938f2e747fa361c2293fd5c7" + } + }, + "striped": false + }, + { + "name": "striped", + "modules": { + "Auth/auth.service.ts": { + "source_sha256": "f99168697aa79d7c5c1fd9f35083448c97f68a0bfecdbfbca49fa279445d79b1", + "js_sha256": "73fe21965e7f1fc421b501c5760ee8dfc4ca7edb606477db1682dd04a9c885d1" + }, + "User/user.service.ts": { + "source_sha256": "0737e88c408510bc17ec0597c3812be855c03499dfc2ad5ba6a4b1e85bb1c5e7", + "js_sha256": "e71c703979ae29963546f88602d4c98735562163749af06c966474e1670e4b7c" + }, + "User/user.guard.ts": { + "source_sha256": "20b05a0e5272a4ee1ccbddef83494e62621ffb0236e56a15c17e7f8f0083f6d7", + "js_sha256": "a078cc3065d6f87ee441f2bc0ff43af25094e66db4bd661d74cf3cd1c501fc2a" + }, + "Chat/chat.service.ts": { + "source_sha256": "b43a57b6e6e17a3133f2061d5660f8e36b62e049975b0d6d800517f99d942699", + "js_sha256": "208e1298e119284bb587ba80b8ef650e7c8fd9031a17ff5079f50732902a62c7" + }, + "Chat/chat.controller.ts": { + "source_sha256": "1e3b1e0a5abc053625c5b1a6dc14f5b5b3e87676b1af0bdd73e78ad95d1eb325", + "js_sha256": "6ac78b848b82f03a4134a9e19e2b802fef59d06b938f2e747fa361c2293fd5c7" + } + }, + "striped": true + } + ], + "samples": [ + { + "variant": "baseline", + "workload": "warm-history", + "repeat": 1, + "successes": 11300, + "errors": 0, + "elapsed_seconds": 60.101, + "rps": 188.018, + "mean_latency_ms": 170.03, + "p95_ms": 437.91, + "sql_queries": 22651, + "sql_per_request": 2.0045, + "sql_calls": { + "SELECT": 22651 + }, + "cpu_percent_one_core": 110.44, + "rss_mib": 572.86 + }, + { + "variant": "baseline", + "workload": "writes-single-chat", + "repeat": 1, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 80.182, + "rps": 51.084, + "mean_latency_ms": 625.658, + "p95_ms": 1960.791, + "sql_queries": 8470, + "sql_per_request": 2.0679, + "sql_calls": { + "SELECT": 4374, + "WITH": 4096 + }, + "cpu_percent_one_core": 81.41, + "rss_mib": 567.86 + }, + { + "variant": "profile-join", + "workload": "warm-history", + "repeat": 1, + "successes": 8162, + "errors": 0, + "elapsed_seconds": 60.142, + "rps": 135.713, + "mean_latency_ms": 235.249, + "p95_ms": 646.713, + "sql_queries": 16463, + "sql_per_request": 2.017, + "sql_calls": { + "SELECT": 16463 + }, + "cpu_percent_one_core": 90.2, + "rss_mib": 571.11 + }, + { + "variant": "profile-join", + "workload": "writes-single-chat", + "repeat": 1, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 35.83, + "rps": 114.318, + "mean_latency_ms": 279.681, + "p95_ms": 723.32, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 94.92, + "rss_mib": 571.23 + }, + { + "variant": "access-join", + "workload": "warm-history", + "repeat": 1, + "successes": 17153, + "errors": 0, + "elapsed_seconds": 60.704, + "rps": 282.567, + "mean_latency_ms": 113.157, + "p95_ms": 243.983, + "sql_queries": 17206, + "sql_per_request": 1.0031, + "sql_calls": { + "SELECT": 17206 + }, + "cpu_percent_one_core": 106.31, + "rss_mib": 576.19 + }, + { + "variant": "access-join", + "workload": "writes-single-chat", + "repeat": 1, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 52.243, + "rps": 78.403, + "mean_latency_ms": 407.523, + "p95_ms": 987.832, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 80.45, + "rss_mib": 576.19 + }, + { + "variant": "striped", + "workload": "warm-history", + "repeat": 1, + "successes": 15925, + "errors": 0, + "elapsed_seconds": 60.169, + "rps": 264.672, + "mean_latency_ms": 120.746, + "p95_ms": 268.879, + "sql_queries": 15977, + "sql_per_request": 1.0033, + "sql_calls": { + "SELECT": 15977 + }, + "cpu_percent_one_core": 105.46, + "rss_mib": 576.48 + }, + { + "variant": "striped", + "workload": "writes-single-chat", + "repeat": 1, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 22.406, + "rps": 182.806, + "mean_latency_ms": 174.946, + "p95_ms": 414.242, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 103.49, + "rss_mib": 576.33 + }, + { + "variant": "striped", + "workload": "warm-history", + "repeat": 2, + "successes": 14354, + "errors": 0, + "elapsed_seconds": 60.252, + "rps": 238.233, + "mean_latency_ms": 134.067, + "p95_ms": 305.055, + "sql_queries": 14406, + "sql_per_request": 1.0036, + "sql_calls": { + "SELECT": 14406 + }, + "cpu_percent_one_core": 103.01, + "rss_mib": 576.27 + }, + { + "variant": "striped", + "workload": "writes-single-chat", + "repeat": 2, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 25.494, + "rps": 160.668, + "mean_latency_ms": 198.958, + "p95_ms": 427.198, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 99.91, + "rss_mib": 576.27 + }, + { + "variant": "access-join", + "workload": "warm-history", + "repeat": 2, + "successes": 16307, + "errors": 0, + "elapsed_seconds": 60.093, + "rps": 271.362, + "mean_latency_ms": 117.835, + "p95_ms": 277.764, + "sql_queries": 16339, + "sql_per_request": 1.002, + "sql_calls": { + "SELECT": 16339 + }, + "cpu_percent_one_core": 103.54, + "rss_mib": 576.77 + }, + { + "variant": "access-join", + "workload": "writes-single-chat", + "repeat": 2, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 22.63, + "rps": 181, + "mean_latency_ms": 176.596, + "p95_ms": 359.748, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 102.17, + "rss_mib": 576.38 + }, + { + "variant": "profile-join", + "workload": "warm-history", + "repeat": 2, + "successes": 12604, + "errors": 0, + "elapsed_seconds": 60.091, + "rps": 209.749, + "mean_latency_ms": 152.428, + "p95_ms": 398.121, + "sql_queries": 25278, + "sql_per_request": 2.0056, + "sql_calls": { + "SELECT": 25278 + }, + "cpu_percent_one_core": 104.2, + "rss_mib": 576.5 + }, + { + "variant": "profile-join", + "workload": "writes-single-chat", + "repeat": 2, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 29.777, + "rps": 137.555, + "mean_latency_ms": 232.438, + "p95_ms": 530.581, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 96.07, + "rss_mib": 576.5 + }, + { + "variant": "baseline", + "workload": "warm-history", + "repeat": 2, + "successes": 14650, + "errors": 0, + "elapsed_seconds": 60.062, + "rps": 243.914, + "mean_latency_ms": 131.102, + "p95_ms": 298.279, + "sql_queries": 29335, + "sql_per_request": 2.0024, + "sql_calls": { + "SELECT": 29335 + }, + "cpu_percent_one_core": 106, + "rss_mib": 576.5 + }, + { + "variant": "baseline", + "workload": "writes-single-chat", + "repeat": 2, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 30.574, + "rps": 133.969, + "mean_latency_ms": 238.29, + "p95_ms": 521.311, + "sql_queries": 8210, + "sql_per_request": 2.0044, + "sql_calls": { + "SELECT": 4114, + "WITH": 4096 + }, + "cpu_percent_one_core": 91.63, + "rss_mib": 576.63 + }, + { + "variant": "profile-join", + "workload": "warm-history", + "repeat": 3, + "successes": 9990, + "errors": 0, + "elapsed_seconds": 60.13, + "rps": 166.141, + "mean_latency_ms": 192.396, + "p95_ms": 503.539, + "sql_queries": 20093, + "sql_per_request": 2.0113, + "sql_calls": { + "SELECT": 20093 + }, + "cpu_percent_one_core": 92.44, + "rss_mib": 576.6 + }, + { + "variant": "profile-join", + "workload": "writes-single-chat", + "repeat": 3, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 21.25, + "rps": 192.755, + "mean_latency_ms": 165.859, + "p95_ms": 318.167, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 107.92, + "rss_mib": 576.6 + }, + { + "variant": "striped", + "workload": "warm-history", + "repeat": 3, + "successes": 13516, + "errors": 0, + "elapsed_seconds": 60.141, + "rps": 224.738, + "mean_latency_ms": 142.252, + "p95_ms": 365.937, + "sql_queries": 13588, + "sql_per_request": 1.0053, + "sql_calls": { + "SELECT": 13588 + }, + "cpu_percent_one_core": 98.43, + "rss_mib": 576.85 + }, + { + "variant": "striped", + "workload": "writes-single-chat", + "repeat": 3, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 26.545, + "rps": 154.303, + "mean_latency_ms": 205.891, + "p95_ms": 585.601, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 102.74, + "rss_mib": 576.66 + }, + { + "variant": "baseline", + "workload": "warm-history", + "repeat": 3, + "successes": 14799, + "errors": 0, + "elapsed_seconds": 60.082, + "rps": 246.313, + "mean_latency_ms": 129.797, + "p95_ms": 278.595, + "sql_queries": 29663, + "sql_per_request": 2.0044, + "sql_calls": { + "SELECT": 29663 + }, + "cpu_percent_one_core": 105.5, + "rss_mib": 577.03 + }, + { + "variant": "baseline", + "workload": "writes-single-chat", + "repeat": 3, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 24.616, + "rps": 166.398, + "mean_latency_ms": 192.054, + "p95_ms": 475.632, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 94.84, + "rss_mib": 576.8 + }, + { + "variant": "access-join", + "workload": "warm-history", + "repeat": 3, + "successes": 11202, + "errors": 0, + "elapsed_seconds": 60.069, + "rps": 186.487, + "mean_latency_ms": 171.531, + "p95_ms": 473.5, + "sql_queries": 11368, + "sql_per_request": 1.0148, + "sql_calls": { + "SELECT": 11368 + }, + "cpu_percent_one_core": 89.43, + "rss_mib": 577.13 + }, + { + "variant": "access-join", + "workload": "writes-single-chat", + "repeat": 3, + "successes": 4096, + "errors": 0, + "elapsed_seconds": 29.46, + "rps": 139.035, + "mean_latency_ms": 229.808, + "p95_ms": 525.113, + "sql_queries": 8192, + "sql_per_request": 2, + "sql_calls": { + "SELECT": 4096, + "WITH": 4096 + }, + "cpu_percent_one_core": 94.07, + "rss_mib": 577.13 + } + ], + "correctness": { + "baseline": { + "access_statuses": true, + "redis_outage_and_retained_keys": true, + "rollback": true, + "delayed_old_fill": true, + "empty_cache": true + }, + "profile-join": { + "access_statuses": true, + "redis_outage_and_retained_keys": true, + "rollback": true, + "delayed_old_fill": true, + "empty_cache": true + }, + "access-join": { + "access_statuses": true, + "redis_outage_and_retained_keys": true, + "rollback": true, + "delayed_old_fill": true, + "empty_cache": true + }, + "striped": { + "access_statuses": true, + "redis_outage_and_retained_keys": true, + "rollback": true, + "delayed_old_fill": true, + "empty_cache": true + } + }, + "completed": true +} diff --git a/evidence/history-index-explain.json b/evidence/history-index-explain.json new file mode 100644 index 0000000..84d38e9 --- /dev/null +++ b/evidence/history-index-explain.json @@ -0,0 +1,7277 @@ +{ + "recorded_at": "2026-10-12T08:45:43.120Z", + "command": "node scripts/explain-history.mjs", + "node_version": "v24.20.0", + "docker": { + "cpus": 4, + "memory_bytes": 3008614400, + "server_version": "28.3.2", + "os": "Docker Desktop", + "arch": "x86_64", + "postgres_container": { + "image": "postgres:17.6-bookworm", + "memory_limit_bytes": 0, + "nano_cpus": 0, + "cpu_quota": 0, + "cpu_period": 0, + "cpuset_cpus": "" + } + }, + "settings": [ + { + "name": "block_size", + "setting": "8192", + "unit": null + }, + { + "name": "effective_cache_size", + "setting": "524288", + "unit": "8kB" + }, + { + "name": "jit", + "setting": "on", + "unit": null + }, + { + "name": "max_parallel_workers_per_gather", + "setting": "2", + "unit": null + }, + { + "name": "random_page_cost", + "setting": "4", + "unit": null + }, + { + "name": "server_version", + "setting": "17.6 (Debian 17.6-2.pgdg12+1)", + "unit": null + }, + { + "name": "shared_buffers", + "setting": "16384", + "unit": "8kB" + }, + { + "name": "work_mem", + "setting": "4096", + "unit": "kB" + } + ], + "source_table_indexes_before": [ + { + "indexname": "messages_chat_id_created_at_id_idx", + "indexdef": "CREATE INDEX messages_chat_id_created_at_id_idx ON public.messages USING btree (chat_id, created_at, id)" + }, + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON public.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON public.messages USING btree (sender_id)" + } + ], + "dataset": { + "total_messages": 60000, + "target_chat_messages": 20000, + "chats": 5, + "distribution": [ + { + "chat_id": "fb372790-4b73-5a45-c97c-7e4287fa05be", + "messages": 20000 + }, + { + "chat_id": "096d532a-b923-0f13-8dc9-243f47b54ac3", + "messages": 10000 + }, + { + "chat_id": "118c4ce4-f95c-c2a2-0ecf-f2aeb0cc0b49", + "messages": 10000 + }, + { + "chat_id": "35bbad77-7634-ca61-4fd8-5d37539c23b8", + "messages": 10000 + }, + { + "chat_id": "a3c16613-13f1-93e3-af30-521782e6eb21", + "messages": 10000 + } + ], + "text_length": 256, + "timestamp_ties": 10, + "insertion_order": "interleaved chats" + }, + "method": { + "warmup_runs_per_query_per_phase": 1, + "measured_runs": 5, + "page_size": 50, + "fetched_rows": 51, + "cursor_positions": [ + 10000, + 18000 + ], + "cache": "warm PostgreSQL buffers; Redis is bypassed", + "cleanup": "ROLLBACK the experiment schema; live tables and indexes unchanged", + "planner": "default scan settings; no forced index or disabled sequential scans", + "schema_difference": "copied columns/checks/defaults; foreign keys omitted equally in all phases", + "tuple_variant": "proposed equivalent SQL, not currently used by Prisma listMessages" + }, + "source_table_indexes_after": [ + { + "indexname": "messages_chat_id_created_at_id_idx", + "indexdef": "CREATE INDEX messages_chat_id_created_at_id_idx ON public.messages USING btree (chat_id, created_at, id)" + }, + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON public.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON public.messages USING btree (sender_id)" + } + ], + "experiment_schema_absent": true, + "cleanup_completed": true, + "runs": [ + { + "phase": "no_indexes", + "query": "first_page", + "indexes": [], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + 51 + ], + "result_sha256": "138ed492cb091c27b09f072b1658e219e66907e30679526b9b475db438b40c6a", + "execution_ms": [ + 24.433, + 23.558, + 35.517, + 28.718, + 43.21 + ], + "median_execution_ms": 28.718, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4027.9, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 28.676, + "Actual Total Time": 28.686, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4077.89, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 28.675, + "Actual Total Time": 28.679, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 0.014, + "Actual Total Time": 19.873, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.076, + "Triggers": [], + "Execution Time": 28.718 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 40000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4027.9, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 24.389, + "Actual Total Time": 24.401, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4077.89, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 24.388, + "Actual Total Time": 24.393, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 0.013, + "Actual Total Time": 17.477, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.131, + "Triggers": [], + "Execution Time": 24.433 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4027.9, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 23.516, + "Actual Total Time": 23.529, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4077.89, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 23.515, + "Actual Total Time": 23.521, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 0.016, + "Actual Total Time": 17.133, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.073, + "Triggers": [], + "Execution Time": 23.558 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4027.9, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 35.472, + "Actual Total Time": 35.483, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4077.89, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 35.471, + "Actual Total Time": 35.476, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 0.019, + "Actual Total Time": 27.687, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.093, + "Triggers": [], + "Execution Time": 35.517 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4027.9, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 28.676, + "Actual Total Time": 28.686, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4077.89, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 28.675, + "Actual Total Time": 28.679, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 0.014, + "Actual Total Time": 19.873, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.076, + "Triggers": [], + "Execution Time": 28.718 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4027.9, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 43.07, + "Actual Total Time": 43.179, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4027.78, + "Total Cost": 4077.89, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 43.069, + "Actual Total Time": 43.074, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 20046, + "Plan Width": 316, + "Actual Startup Time": 0.019, + "Actual Total Time": 24.581, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.114, + "Triggers": [], + "Execution Time": 43.21 + } + ] + }, + { + "phase": "no_indexes", + "query": "middle_page_or", + "indexes": [], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid\n AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:16:39.000Z", + "f47542f1-8089-6114-80cd-9f75fcae23e0", + 51 + ], + "result_sha256": "0e8cef00f3d683111579ca25950a3f21ecd8225ae703020f0ba49b5303ce0921", + "execution_ms": [ + 20.653, + 50.299, + 20.652, + 23.885, + 21.733 + ], + "median_execution_ms": 21.733, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3922.53, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 21.694, + "Actual Total Time": 21.702, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3930.9, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 21.692, + "Actual Total Time": 21.696, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 9.327, + "Actual Total Time": 18.539, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.12, + "Triggers": [], + "Execution Time": 21.733 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 50000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3922.53, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 20.554, + "Actual Total Time": 20.609, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3930.9, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 20.552, + "Actual Total Time": 20.587, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 9.678, + "Actual Total Time": 17.635, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.872, + "Triggers": [], + "Execution Time": 20.653 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3922.53, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 50.245, + "Actual Total Time": 50.257, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3930.9, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 50.244, + "Actual Total Time": 50.25, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 15.516, + "Actual Total Time": 23.855, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.302, + "Triggers": [], + "Execution Time": 50.299 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3922.53, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 20.613, + "Actual Total Time": 20.621, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3930.9, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 20.612, + "Actual Total Time": 20.616, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 7.28, + "Actual Total Time": 16.101, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.326, + "Triggers": [], + "Execution Time": 20.652 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3922.53, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 23.845, + "Actual Total Time": 23.854, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3930.9, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 23.844, + "Actual Total Time": 23.848, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 12.075, + "Actual Total Time": 20.032, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.095, + "Triggers": [], + "Execution Time": 23.885 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3922.53, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 21.694, + "Actual Total Time": 21.702, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.4, + "Total Cost": 3930.9, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 21.692, + "Actual Total Time": 21.696, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3399, + "Plan Width": 316, + "Actual Startup Time": 9.327, + "Actual Total Time": 18.539, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.12, + "Triggers": [], + "Execution Time": 21.733 + } + ] + }, + { + "phase": "no_indexes", + "query": "late_page_or", + "indexes": [], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid\n AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:29:59.000Z", + "fd35e333-189b-af5a-fdcf-c376bd20e02b", + 51 + ], + "result_sha256": "68c26a91a60dd54adb6bfeec93181c3d7d9669095c2ed0a04481a27d08475d65", + "execution_ms": [ + 17.752, + 25.704, + 10.384, + 22.61, + 16.779 + ], + "median_execution_ms": 17.752, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3831.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 17.702, + "Actual Total Time": 17.715, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3833.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 17.7, + "Actual Total Time": 17.706, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 16.019, + "Actual Total Time": 17.183, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.316, + "Triggers": [], + "Execution Time": 17.752 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 58000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3831.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 17.702, + "Actual Total Time": 17.715, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3833.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 17.7, + "Actual Total Time": 17.706, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 16.019, + "Actual Total Time": 17.183, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.316, + "Triggers": [], + "Execution Time": 17.752 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3831.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 25.662, + "Actual Total Time": 25.671, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3833.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 25.66, + "Actual Total Time": 25.665, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 23.949, + "Actual Total Time": 25.119, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.101, + "Triggers": [], + "Execution Time": 25.704 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3831.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 10.347, + "Actual Total Time": 10.357, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3833.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 10.345, + "Actual Total Time": 10.35, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 8.703, + "Actual Total Time": 9.72, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.093, + "Triggers": [], + "Execution Time": 10.384 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3831.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 22.558, + "Actual Total Time": 22.576, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3833.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 22.557, + "Actual Total Time": 22.565, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 19.407, + "Actual Total Time": 21.905, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.104, + "Triggers": [], + "Execution Time": 22.61 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3831.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 16.741, + "Actual Total Time": 16.75, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.45, + "Total Cost": 3833.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 16.739, + "Actual Total Time": 16.744, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 9.807, + "Actual Total Time": 15.753, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.181, + "Triggers": [], + "Execution Time": 16.779 + } + ] + }, + { + "phase": "no_indexes", + "query": "late_page_tuple", + "indexes": [], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid)\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:29:59.000Z", + "fd35e333-189b-af5a-fdcf-c376bd20e02b", + 51 + ], + "result_sha256": "68c26a91a60dd54adb6bfeec93181c3d7d9669095c2ed0a04481a27d08475d65", + "execution_ms": [ + 12.468, + 22.145, + 22.897, + 22.697, + 12.853 + ], + "median_execution_ms": 22.145, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3681.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 22.09, + "Actual Total Time": 22.1, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3683.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 22.088, + "Actual Total Time": 22.092, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 19.54, + "Actual Total Time": 21.483, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.106, + "Triggers": [], + "Execution Time": 22.145 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 58000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3681.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 12.428, + "Actual Total Time": 12.436, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3683.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 12.427, + "Actual Total Time": 12.43, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 10.752, + "Actual Total Time": 11.989, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.102, + "Triggers": [], + "Execution Time": 12.468 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3681.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 22.09, + "Actual Total Time": 22.1, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3683.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 22.088, + "Actual Total Time": 22.092, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 19.54, + "Actual Total Time": 21.483, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.106, + "Triggers": [], + "Execution Time": 22.145 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3681.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 22.86, + "Actual Total Time": 22.87, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3683.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 22.859, + "Actual Total Time": 22.863, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 20.021, + "Actual Total Time": 22.173, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.084, + "Triggers": [], + "Execution Time": 22.897 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3681.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 22.655, + "Actual Total Time": 22.664, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3683.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 22.653, + "Actual Total Time": 22.657, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 16.697, + "Actual Total Time": 21.99, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.096, + "Triggers": [], + "Execution Time": 22.697 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3681.58, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 12.816, + "Actual Total Time": 12.824, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.45, + "Total Cost": 3683.14, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 12.814, + "Actual Total Time": 12.818, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 673, + "Plan Width": 316, + "Actual Startup Time": 10.546, + "Actual Total Time": 11.861, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.072, + "Triggers": [], + "Execution Time": 12.853 + } + ] + }, + { + "phase": "without_history_index", + "query": "first_page", + "indexes": [ + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + 51 + ], + "result_sha256": "138ed492cb091c27b09f072b1658e219e66907e30679526b9b475db438b40c6a", + "execution_ms": [ + 16.619, + 17.94, + 13.889, + 12.897, + 48.033 + ], + "median_execution_ms": 16.619, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4025.44, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 16.588, + "Actual Total Time": 16.597, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4075.24, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 16.587, + "Actual Total Time": 16.591, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 0.012, + "Actual Total Time": 10.485, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.074, + "Triggers": [], + "Execution Time": 16.619 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 40000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4025.44, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 16.588, + "Actual Total Time": 16.597, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4075.24, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 16.587, + "Actual Total Time": 16.591, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 0.012, + "Actual Total Time": 10.485, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.074, + "Triggers": [], + "Execution Time": 16.619 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4025.44, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 17.908, + "Actual Total Time": 17.916, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4075.24, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 17.906, + "Actual Total Time": 17.91, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 0.02, + "Actual Total Time": 12.207, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.097, + "Triggers": [], + "Execution Time": 17.94 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4025.44, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 13.853, + "Actual Total Time": 13.861, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4075.24, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 13.851, + "Actual Total Time": 13.855, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 0.018, + "Actual Total Time": 9.364, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.097, + "Triggers": [], + "Execution Time": 13.889 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4025.44, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 12.857, + "Actual Total Time": 12.865, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4075.24, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 12.856, + "Actual Total Time": 12.859, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 0.016, + "Actual Total Time": 8.773, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.102, + "Triggers": [], + "Execution Time": 12.897 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4025.44, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 47.967, + "Actual Total Time": 47.98, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 4025.31, + "Total Cost": 4075.24, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 47.966, + "Actual Total Time": 47.971, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 52, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3359, + "Plan Rows": 19972, + "Plan Width": 316, + "Actual Startup Time": 0.015, + "Actual Total Time": 32.15, + "Actual Rows": 20000, + "Actual Loops": 1, + "Filter": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Filter": 40000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.094, + "Triggers": [], + "Execution Time": 48.033 + } + ] + }, + { + "phase": "without_history_index", + "query": "middle_page_or", + "indexes": [ + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid\n AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:16:39.000Z", + "f47542f1-8089-6114-80cd-9f75fcae23e0", + 51 + ], + "result_sha256": "0e8cef00f3d683111579ca25950a3f21ecd8225ae703020f0ba49b5303ce0921", + "execution_ms": [ + 13.029, + 11.602, + 11.838, + 9.89, + 29.564 + ], + "median_execution_ms": 11.838, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3922.33, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 11.8, + "Actual Total Time": 11.808, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3930.68, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 11.798, + "Actual Total Time": 11.802, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 5.784, + "Actual Total Time": 10.064, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.132, + "Triggers": [], + "Execution Time": 11.838 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 50000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3922.33, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 12.996, + "Actual Total Time": 13.004, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3930.68, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 12.994, + "Actual Total Time": 12.997, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 5, + "Actual Total Time": 10.988, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.113, + "Triggers": [], + "Execution Time": 13.029 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3922.33, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 11.566, + "Actual Total Time": 11.576, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3930.68, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 11.565, + "Actual Total Time": 11.569, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 5.094, + "Actual Total Time": 9.765, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.096, + "Triggers": [], + "Execution Time": 11.602 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3922.33, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 11.8, + "Actual Total Time": 11.808, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3930.68, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 11.798, + "Actual Total Time": 11.802, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 5.784, + "Actual Total Time": 10.064, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.132, + "Triggers": [], + "Execution Time": 11.838 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3922.33, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.861, + "Actual Total Time": 9.868, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3930.68, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 9.859, + "Actual Total Time": 9.862, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 3.325, + "Actual Total Time": 8.124, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.142, + "Triggers": [], + "Execution Time": 9.89 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3922.33, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 29.522, + "Actual Total Time": 29.532, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3922.2, + "Total Cost": 3930.68, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 29.52, + "Actual Total Time": 29.524, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 3393, + "Plan Width": 316, + "Actual Startup Time": 6.796, + "Actual Total Time": 21.488, + "Actual Rows": 10000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))))", + "Rows Removed by Filter": 50000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.16, + "Triggers": [], + "Execution Time": 29.564 + } + ] + }, + { + "phase": "without_history_index", + "query": "late_page_or", + "indexes": [ + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid\n AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:29:59.000Z", + "fd35e333-189b-af5a-fdcf-c376bd20e02b", + 51 + ], + "result_sha256": "68c26a91a60dd54adb6bfeec93181c3d7d9669095c2ed0a04481a27d08475d65", + "execution_ms": [ + 10.002, + 8.746, + 9.652, + 9.041, + 37.533 + ], + "median_execution_ms": 9.652, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3831.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.623, + "Actual Total Time": 9.631, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3833.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 9.622, + "Actual Total Time": 9.625, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.477, + "Actual Total Time": 9.291, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.12, + "Triggers": [], + "Execution Time": 9.652 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 58000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3831.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.964, + "Actual Total Time": 9.973, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3833.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 9.962, + "Actual Total Time": 9.966, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.659, + "Actual Total Time": 9.615, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.166, + "Triggers": [], + "Execution Time": 10.002 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3831.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 8.715, + "Actual Total Time": 8.723, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3833.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.714, + "Actual Total Time": 8.718, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 7.159, + "Actual Total Time": 8.25, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.126, + "Triggers": [], + "Execution Time": 8.746 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3831.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.623, + "Actual Total Time": 9.631, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3833.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 9.622, + "Actual Total Time": 9.625, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.477, + "Actual Total Time": 9.291, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.12, + "Triggers": [], + "Execution Time": 9.652 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3831.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 8.999, + "Actual Total Time": 9.013, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3833.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.997, + "Actual Total Time": 9.003, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 7.133, + "Actual Total Time": 8.367, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.123, + "Triggers": [], + "Execution Time": 9.041 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3831.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 37.493, + "Actual Total Time": 37.503, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3831.75, + "Total Cost": 3833.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 37.491, + "Actual Total Time": 37.495, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3809, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 27.785, + "Actual Total Time": 29.553, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.165, + "Triggers": [], + "Execution Time": 37.533 + } + ] + }, + { + "phase": "without_history_index", + "query": "late_page_tuple", + "indexes": [ + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid)\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:29:59.000Z", + "fd35e333-189b-af5a-fdcf-c376bd20e02b", + 51 + ], + "result_sha256": "68c26a91a60dd54adb6bfeec93181c3d7d9669095c2ed0a04481a27d08475d65", + "execution_ms": [ + 9.253, + 8.872, + 9.809, + 21.15, + 25.266 + ], + "median_execution_ms": 9.809, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3681.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.776, + "Actual Total Time": 9.784, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3683.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 9.774, + "Actual Total Time": 9.778, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.472, + "Actual Total Time": 9.399, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.087, + "Triggers": [], + "Execution Time": 9.809 + }, + "scan_type": "Seq Scan", + "index_name": null, + "rows_removed_by_filter": 58000, + "scanned_rows": 60000, + "sort": true, + "shared_buffer_hits": 2609, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3681.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.212, + "Actual Total Time": 9.22, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3683.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 9.21, + "Actual Total Time": 9.214, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 7.92, + "Actual Total Time": 8.835, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.127, + "Triggers": [], + "Execution Time": 9.253 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3681.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 8.839, + "Actual Total Time": 8.848, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3683.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.838, + "Actual Total Time": 8.842, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 7.598, + "Actual Total Time": 8.464, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.087, + "Triggers": [], + "Execution Time": 8.872 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3681.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 9.776, + "Actual Total Time": 9.784, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3683.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 9.774, + "Actual Total Time": 9.778, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 8.472, + "Actual Total Time": 9.399, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.087, + "Triggers": [], + "Execution Time": 9.809 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3681.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 21.102, + "Actual Total Time": 21.116, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3683.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 21.1, + "Actual Total Time": 21.107, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 19.135, + "Actual Total Time": 20.538, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.121, + "Triggers": [], + "Execution Time": 21.15 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3681.88, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 25.22, + "Actual Total Time": 25.232, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Sort", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 3681.75, + "Total Cost": 3683.46, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 25.218, + "Actual Total Time": 25.223, + "Actual Rows": 51, + "Actual Loops": 1, + "Sort Key": [ + "created_at", + "id" + ], + "Sort Method": "top-N heapsort", + "Sort Space Used": 51, + "Sort Space Type": "Memory", + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Seq Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0, + "Total Cost": 3659, + "Plan Rows": 682, + "Plan Width": 316, + "Actual Startup Time": 23.106, + "Actual Total Time": 24.62, + "Actual Rows": 2000, + "Actual Loops": 1, + "Filter": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 58000, + "Shared Hit Blocks": 2609, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.107, + "Triggers": [], + "Execution Time": 25.266 + } + ] + }, + { + "phase": "with_history_index", + "query": "first_page", + "indexes": [ + { + "indexname": "messages_chat_id_created_at_id_idx", + "indexdef": "CREATE INDEX messages_chat_id_created_at_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (chat_id, created_at, id)" + }, + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + 51 + ], + "result_sha256": "138ed492cb091c27b09f072b1658e219e66907e30679526b9b475db438b40c6a", + "execution_ms": [ + 0.1, + 0.089, + 0.07, + 0.131, + 0.094 + ], + "median_execution_ms": 0.094, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 28.95, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.024, + "Actual Total Time": 0.071, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11101.66, + "Plan Rows": 19840, + "Plan Width": 316, + "Actual Startup Time": 0.023, + "Actual Total Time": 0.064, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.111, + "Triggers": [], + "Execution Time": 0.094 + }, + "scan_type": "Index Scan", + "index_name": "messages_chat_id_created_at_id_idx", + "rows_removed_by_filter": 0, + "scanned_rows": 51, + "sort": false, + "shared_buffer_hits": 31, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 28.95, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.031, + "Actual Total Time": 0.073, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11101.66, + "Plan Rows": 19840, + "Plan Width": 316, + "Actual Startup Time": 0.029, + "Actual Total Time": 0.067, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.114, + "Triggers": [], + "Execution Time": 0.1 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 28.95, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.027, + "Actual Total Time": 0.065, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11101.66, + "Plan Rows": 19840, + "Plan Width": 316, + "Actual Startup Time": 0.026, + "Actual Total Time": 0.059, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.622, + "Triggers": [], + "Execution Time": 0.089 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 28.95, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.022, + "Actual Total Time": 0.053, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11101.66, + "Plan Rows": 19840, + "Plan Width": 316, + "Actual Startup Time": 0.021, + "Actual Total Time": 0.047, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.082, + "Triggers": [], + "Execution Time": 0.07 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 28.95, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.021, + "Actual Total Time": 0.112, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11101.66, + "Plan Rows": 19840, + "Plan Width": 316, + "Actual Startup Time": 0.02, + "Actual Total Time": 0.088, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.09, + "Triggers": [], + "Execution Time": 0.131 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 28.95, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.024, + "Actual Total Time": 0.071, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11101.66, + "Plan Rows": 19840, + "Plan Width": 316, + "Actual Startup Time": 0.023, + "Actual Total Time": 0.064, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 31, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.111, + "Triggers": [], + "Execution Time": 0.094 + } + ] + }, + { + "phase": "with_history_index", + "query": "middle_page_or", + "indexes": [ + { + "indexname": "messages_chat_id_created_at_id_idx", + "indexdef": "CREATE INDEX messages_chat_id_created_at_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (chat_id, created_at, id)" + }, + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid\n AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:16:39.000Z", + "f47542f1-8089-6114-80cd-9f75fcae23e0", + 51 + ], + "result_sha256": "0e8cef00f3d683111579ca25950a3f21ecd8225ae703020f0ba49b5303ce0921", + "execution_ms": [ + 4.782, + 6.997, + 5.595, + 5.111, + 6.055 + ], + "median_execution_ms": 5.595, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 172.25, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 5.535, + "Actual Total Time": 5.567, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 3339, + "Plan Width": 316, + "Actual Startup Time": 5.534, + "Actual Total Time": 5.559, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))", + "Rows Removed by Filter": 10000, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.129, + "Triggers": [], + "Execution Time": 5.595 + }, + "scan_type": "Index Scan", + "index_name": "messages_chat_id_created_at_id_idx", + "rows_removed_by_filter": 10000, + "scanned_rows": 10051, + "sort": false, + "shared_buffer_hits": 5203, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 172.25, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 4.712, + "Actual Total Time": 4.748, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 3339, + "Plan Width": 316, + "Actual Startup Time": 4.709, + "Actual Total Time": 4.738, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))", + "Rows Removed by Filter": 10000, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.144, + "Triggers": [], + "Execution Time": 4.782 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 172.25, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 6.933, + "Actual Total Time": 6.968, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 3339, + "Plan Width": 316, + "Actual Startup Time": 6.931, + "Actual Total Time": 6.96, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))", + "Rows Removed by Filter": 10000, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.139, + "Triggers": [], + "Execution Time": 6.997 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 172.25, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 5.535, + "Actual Total Time": 5.567, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 3339, + "Plan Width": 316, + "Actual Startup Time": 5.534, + "Actual Total Time": 5.559, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))", + "Rows Removed by Filter": 10000, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.129, + "Triggers": [], + "Execution Time": 5.595 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 172.25, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 5.059, + "Actual Total Time": 5.084, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 3339, + "Plan Width": 316, + "Actual Startup Time": 5.057, + "Actual Total Time": 5.078, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))", + "Rows Removed by Filter": 10000, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.116, + "Triggers": [], + "Execution Time": 5.111 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 172.25, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 5.987, + "Actual Total Time": 6.026, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 3339, + "Plan Width": 316, + "Actual Startup Time": 5.985, + "Actual Total Time": 6.016, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))", + "Rows Removed by Filter": 10000, + "Shared Hit Blocks": 5203, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.116, + "Triggers": [], + "Execution Time": 6.055 + } + ] + }, + { + "phase": "with_history_index", + "query": "late_page_or", + "indexes": [ + { + "indexname": "messages_chat_id_created_at_id_idx", + "indexdef": "CREATE INDEX messages_chat_id_created_at_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (chat_id, created_at, id)" + }, + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid\n AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid))\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:29:59.000Z", + "fd35e333-189b-af5a-fdcf-c376bd20e02b", + 51 + ], + "result_sha256": "68c26a91a60dd54adb6bfeec93181c3d7d9669095c2ed0a04481a27d08475d65", + "execution_ms": [ + 7.771, + 8.029, + 12.242, + 10.479, + 10.829 + ], + "median_execution_ms": 10.479, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 905.39, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 10.421, + "Actual Total Time": 10.452, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 10.419, + "Actual Total Time": 10.444, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 18000, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.241, + "Triggers": [], + "Execution Time": 10.479 + }, + "scan_type": "Index Scan", + "index_name": "messages_chat_id_created_at_id_idx", + "rows_removed_by_filter": 18000, + "scanned_rows": 18051, + "sort": false, + "shared_buffer_hits": 9355, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 905.39, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 7.723, + "Actual Total Time": 7.748, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 7.722, + "Actual Total Time": 7.742, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 18000, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.143, + "Triggers": [], + "Execution Time": 7.771 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 905.39, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 7.978, + "Actual Total Time": 8.004, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 7.977, + "Actual Total Time": 7.997, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 18000, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.146, + "Triggers": [], + "Execution Time": 8.029 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 905.39, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 12.174, + "Actual Total Time": 12.2, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 12.172, + "Actual Total Time": 12.193, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 18000, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.187, + "Triggers": [], + "Execution Time": 12.242 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 905.39, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 10.421, + "Actual Total Time": 10.452, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 10.419, + "Actual Total Time": 10.444, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 18000, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.241, + "Triggers": [], + "Execution Time": 10.479 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 905.39, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 10.768, + "Actual Total Time": 10.798, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 11250.46, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 10.766, + "Actual Total Time": 10.79, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "(chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Filter": 18000, + "Shared Hit Blocks": 9355, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 4, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.214, + "Triggers": [], + "Execution Time": 10.829 + } + ] + }, + { + "phase": "with_history_index", + "query": "late_page_tuple", + "indexes": [ + { + "indexname": "messages_chat_id_created_at_id_idx", + "indexdef": "CREATE INDEX messages_chat_id_created_at_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (chat_id, created_at, id)" + }, + { + "indexname": "messages_pkey", + "indexdef": "CREATE UNIQUE INDEX messages_pkey ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (id)" + }, + { + "indexname": "messages_sender_id_idx", + "indexdef": "CREATE INDEX messages_sender_id_idx ON explain_history_0e94bd9d82394e1497f4949dc0f81a1c.messages USING btree (sender_id)" + } + ], + "sql": "SELECT id, chat_id, sender_id, text, created_at FROM \"explain_history_0e94bd9d82394e1497f4949dc0f81a1c\".\"messages\"\nWHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid)\nORDER BY created_at ASC, id ASC LIMIT $4", + "parameters": [ + "fb372790-4b73-5a45-c97c-7e4287fa05be", + "2026-01-01T00:29:59.000Z", + "fd35e333-189b-af5a-fdcf-c376bd20e02b", + 51 + ], + "result_sha256": "68c26a91a60dd54adb6bfeec93181c3d7d9669095c2ed0a04481a27d08475d65", + "execution_ms": [ + 0.082, + 0.08, + 0.165, + 0.08, + 0.079 + ], + "median_execution_ms": 0.08, + "representative_plan": { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 180.32, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.029, + "Actual Total Time": 0.058, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 2236.91, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 0.028, + "Actual Total Time": 0.051, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.113, + "Triggers": [], + "Execution Time": 0.08 + }, + "scan_type": "Index Scan", + "index_name": "messages_chat_id_created_at_id_idx", + "rows_removed_by_filter": 0, + "scanned_rows": 51, + "sort": false, + "shared_buffer_hits": 29, + "shared_buffer_reads": 0, + "raw_plans": [ + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 180.32, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.03, + "Actual Total Time": 0.058, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 2236.91, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 0.029, + "Actual Total Time": 0.052, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.116, + "Triggers": [], + "Execution Time": 0.082 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 180.32, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.029, + "Actual Total Time": 0.058, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 2236.91, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 0.028, + "Actual Total Time": 0.051, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.113, + "Triggers": [], + "Execution Time": 0.08 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 180.32, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.041, + "Actual Total Time": 0.091, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 2236.91, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 0.039, + "Actual Total Time": 0.073, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.166, + "Triggers": [], + "Execution Time": 0.165 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 180.32, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.029, + "Actual Total Time": 0.057, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 2236.91, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 0.028, + "Actual Total Time": 0.051, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.168, + "Triggers": [], + "Execution Time": 0.08 + }, + { + "Plan": { + "Node Type": "Limit", + "Parallel Aware": false, + "Async Capable": false, + "Startup Cost": 0.41, + "Total Cost": 180.32, + "Plan Rows": 51, + "Plan Width": 316, + "Actual Startup Time": 0.029, + "Actual Total Time": 0.057, + "Actual Rows": 51, + "Actual Loops": 1, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0, + "Plans": [ + { + "Node Type": "Index Scan", + "Parent Relationship": "Outer", + "Parallel Aware": false, + "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_chat_id_created_at_id_idx", + "Relation Name": "messages", + "Alias": "messages", + "Startup Cost": 0.41, + "Total Cost": 2236.91, + "Plan Rows": 634, + "Plan Width": 316, + "Actual Startup Time": 0.028, + "Actual Total Time": 0.051, + "Actual Rows": 51, + "Actual Loops": 1, + "Index Cond": "((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))", + "Rows Removed by Index Recheck": 0, + "Shared Hit Blocks": 29, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + } + ] + }, + "Planning": { + "Shared Hit Blocks": 0, + "Shared Read Blocks": 0, + "Shared Dirtied Blocks": 0, + "Shared Written Blocks": 0, + "Local Hit Blocks": 0, + "Local Read Blocks": 0, + "Local Dirtied Blocks": 0, + "Local Written Blocks": 0, + "Temp Read Blocks": 0, + "Temp Written Blocks": 0 + }, + "Planning Time": 0.108, + "Triggers": [], + "Execution Time": 0.079 + } + ] + } + ] +} diff --git a/evidence/history-index-plans.txt b/evidence/history-index-plans.txt new file mode 100644 index 0000000..1a8ba1d --- /dev/null +++ b/evidence/history-index-plans.txt @@ -0,0 +1,242 @@ +=== no_indexes / first_page === +Indexes: (none) +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be",51] + +Limit (cost=4027.78..4027.90 rows=51 width=316) (actual time=17.915..17.960 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=4027.78..4077.89 rows=20046 width=316) (actual time=17.913..17.953 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 52kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3359.00 rows=20046 width=316) (actual time=0.015..11.329 rows=20000 loops=1) + Filter: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) + Rows Removed by Filter: 40000 + Buffers: shared hit=2609 +Planning Time: 0.082 ms +Execution Time: 17.989 ms + +=== no_indexes / middle_page_or === +Indexes: (none) +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid + AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid)) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:16:39.000Z","f47542f1-8089-6114-80cd-9f75fcae23e0",51] + +Limit (cost=3922.40..3922.53 rows=51 width=316) (actual time=18.519..18.529 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=3922.40..3930.90 rows=3399 width=316) (actual time=18.517..18.521 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 51kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3809.00 rows=3399 width=316) (actual time=6.148..13.726 rows=10000 loops=1) + Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))) + Rows Removed by Filter: 50000 + Buffers: shared hit=2609 +Planning Time: 0.112 ms +Execution Time: 18.559 ms + +=== no_indexes / late_page_or === +Indexes: (none) +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid + AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid)) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51] + +Limit (cost=3831.45..3831.58 rows=51 width=316) (actual time=16.897..16.908 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=3831.45..3833.14 rows=673 width=316) (actual time=16.895..16.900 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 51kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3809.00 rows=673 width=316) (actual time=15.036..16.370 rows=2000 loops=1) + Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))) + Rows Removed by Filter: 58000 + Buffers: shared hit=2609 +Planning Time: 0.114 ms +Execution Time: 16.993 ms + +=== no_indexes / late_page_tuple === +Indexes: (none) +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51] + +Limit (cost=3681.45..3681.58 rows=51 width=316) (actual time=21.195..21.205 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=3681.45..3683.14 rows=673 width=316) (actual time=21.194..21.198 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 51kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3659.00 rows=673 width=316) (actual time=13.066..16.387 rows=2000 loops=1) + Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))) + Rows Removed by Filter: 58000 + Buffers: shared hit=2609 +Planning Time: 0.163 ms +Execution Time: 21.242 ms + +=== without_history_index / first_page === +Indexes: messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be",51] + +Limit (cost=4025.31..4025.44 rows=51 width=316) (actual time=39.169..39.182 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=4025.31..4075.24 rows=19972 width=316) (actual time=39.167..39.174 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 52kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3359.00 rows=19972 width=316) (actual time=0.017..30.929 rows=20000 loops=1) + Filter: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) + Rows Removed by Filter: 40000 + Buffers: shared hit=2609 +Planning Time: 0.104 ms +Execution Time: 39.214 ms + +=== without_history_index / middle_page_or === +Indexes: messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid + AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid)) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:16:39.000Z","f47542f1-8089-6114-80cd-9f75fcae23e0",51] + +Limit (cost=3922.20..3922.33 rows=51 width=316) (actual time=22.514..22.524 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=3922.20..3930.68 rows=3393 width=316) (actual time=22.512..22.517 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 51kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3809.00 rows=3393 width=316) (actual time=7.398..15.354 rows=10000 loops=1) + Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid)))) + Rows Removed by Filter: 50000 + Buffers: shared hit=2609 +Planning Time: 0.168 ms +Execution Time: 22.562 ms + +=== without_history_index / late_page_or === +Indexes: messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid + AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid)) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51] + +Limit (cost=3831.75..3831.88 rows=51 width=316) (actual time=13.129..13.138 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=3831.75..3833.46 rows=682 width=316) (actual time=13.127..13.131 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 51kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3809.00 rows=682 width=316) (actual time=10.949..12.462 rows=2000 loops=1) + Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid)))) + Rows Removed by Filter: 58000 + Buffers: shared hit=2609 +Planning: + Buffers: shared hit=4 +Planning Time: 0.170 ms +Execution Time: 13.163 ms + +=== without_history_index / late_page_tuple === +Indexes: messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51] + +Limit (cost=3681.75..3681.88 rows=51 width=316) (actual time=18.320..18.331 rows=51 loops=1) + Buffers: shared hit=2609 + -> Sort (cost=3681.75..3683.46 rows=682 width=316) (actual time=18.318..18.323 rows=51 loops=1) + Sort Key: created_at, id + Sort Method: top-N heapsort Memory: 51kB + Buffers: shared hit=2609 + -> Seq Scan on messages (cost=0.00..3659.00 rows=682 width=316) (actual time=14.704..16.910 rows=2000 loops=1) + Filter: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))) + Rows Removed by Filter: 58000 + Buffers: shared hit=2609 +Planning Time: 0.169 ms +Execution Time: 18.368 ms + +=== with_history_index / first_page === +Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid ORDER BY created_at ASC, id ASC LIMIT $2 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be",51] + +Limit (cost=0.41..28.95 rows=51 width=316) (actual time=0.024..0.060 rows=51 loops=1) + Buffers: shared hit=31 + -> Index Scan using messages_chat_id_created_at_id_idx on messages (cost=0.41..11101.66 rows=19840 width=316) (actual time=0.022..0.054 rows=51 loops=1) + Index Cond: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) + Buffers: shared hit=31 +Planning Time: 0.100 ms +Execution Time: 0.081 ms + +=== with_history_index / middle_page_or === +Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid + AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid)) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:16:39.000Z","f47542f1-8089-6114-80cd-9f75fcae23e0",51] + +Limit (cost=0.41..172.25 rows=51 width=316) (actual time=6.295..6.365 rows=51 loops=1) + Buffers: shared hit=5203 + -> Index Scan using messages_chat_id_created_at_id_idx on messages (cost=0.41..11250.46 rows=3339 width=316) (actual time=6.293..6.355 rows=51 loops=1) + Index Cond: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) + Filter: ((created_at > '2026-01-01 00:16:39+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:16:39+00'::timestamp with time zone) AND (id > 'f47542f1-8089-6114-80cd-9f75fcae23e0'::uuid))) + Rows Removed by Filter: 10000 + Buffers: shared hit=5203 +Planning Time: 0.136 ms +Execution Time: 6.397 ms + +=== with_history_index / late_page_or === +Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid + AND (created_at > $2::timestamptz OR (created_at = $2::timestamptz AND id > $3::uuid)) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51] + +Limit (cost=0.41..905.39 rows=51 width=316) (actual time=15.793..15.831 rows=51 loops=1) + Buffers: shared hit=9355 + -> Index Scan using messages_chat_id_created_at_id_idx on messages (cost=0.41..11250.46 rows=634 width=316) (actual time=15.791..15.822 rows=51 loops=1) + Index Cond: (chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) + Filter: ((created_at > '2026-01-01 00:29:59+00'::timestamp with time zone) OR ((created_at = '2026-01-01 00:29:59+00'::timestamp with time zone) AND (id > 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))) + Rows Removed by Filter: 18000 + Buffers: shared hit=9355 +Planning: + Buffers: shared hit=4 +Planning Time: 0.194 ms +Execution Time: 16.039 ms + +=== with_history_index / late_page_tuple === +Indexes: messages_chat_id_created_at_id_idx, messages_pkey, messages_sender_id_idx +SQL: +SELECT id, chat_id, sender_id, text, created_at FROM "explain_history_0e94bd9d82394e1497f4949dc0f81a1c"."messages" +WHERE chat_id = $1::uuid AND (created_at, id) > ($2::timestamptz, $3::uuid) +ORDER BY created_at ASC, id ASC LIMIT $4 +Parameters: ["fb372790-4b73-5a45-c97c-7e4287fa05be","2026-01-01T00:29:59.000Z","fd35e333-189b-af5a-fdcf-c376bd20e02b",51] + +Limit (cost=0.41..180.32 rows=51 width=316) (actual time=0.029..0.066 rows=51 loops=1) + Buffers: shared hit=29 + -> Index Scan using messages_chat_id_created_at_id_idx on messages (cost=0.41..2236.91 rows=634 width=316) (actual time=0.028..0.059 rows=51 loops=1) + Index Cond: ((chat_id = 'fb372790-4b73-5a45-c97c-7e4287fa05be'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:29:59+00'::timestamp with time zone, 'fd35e333-189b-af5a-fdcf-c376bd20e02b'::uuid))) + Buffers: shared hit=29 +Planning Time: 0.132 ms +Execution Time: 0.090 ms diff --git a/evidence/persistence-full-restart.json b/evidence/persistence-full-restart.json new file mode 100644 index 0000000..ad758e5 --- /dev/null +++ b/evidence/persistence-full-restart.json @@ -0,0 +1,79 @@ +{ + "recorded_at": "2026-10-12T06:25:43.133804+00:00", + "scenario": "full-restart", + "command": "python scripts/test-persistence.py --scenario full-restart --base-url http://127.0.0.1:8080", + "hook": "scripts/restart.cmd", + "elapsed_seconds": 40.779, + "result": "PASS", + "test_output": "Restarting backend, PostgreSQL and Redis; hook output suppressed.\nPASS: users, chat, membership, confirmed message and all existing sessions survived; access control, new writes and logout work after restart.", + "before": { + "backend": { + "id": "e65385c8d35f102e3e50ff45e965ce720a952cc3bce6781c666379a30280037b", + "started_at": "2026-10-12T06:21:19.516993813Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_backend_data", + "destination": "/app/data" + } + ] + }, + "postgres": { + "id": "c2fbbfded445fbedeff7ae87dcc06b05bedb0d2b2c89050e4a1a2236b06398f5", + "started_at": "2026-10-12T06:20:41.596732919Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_postgres_data", + "destination": "/var/lib/postgresql/data" + } + ] + }, + "redis": { + "id": "547184576f5e04a076d8c41e504cb0669c4f7c17daed437a6ae1db41ee5d1435", + "started_at": "2026-10-12T06:20:41.592548143Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_redis_data", + "destination": "/data" + } + ] + } + }, + "after": { + "backend": { + "id": "e65385c8d35f102e3e50ff45e965ce720a952cc3bce6781c666379a30280037b", + "started_at": "2026-10-12T06:25:33.943246182Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_backend_data", + "destination": "/app/data" + } + ] + }, + "postgres": { + "id": "c2fbbfded445fbedeff7ae87dcc06b05bedb0d2b2c89050e4a1a2236b06398f5", + "started_at": "2026-10-12T06:25:26.025429573Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_postgres_data", + "destination": "/var/lib/postgresql/data" + } + ] + }, + "redis": { + "id": "547184576f5e04a076d8c41e504cb0669c4f7c17daed437a6ae1db41ee5d1435", + "started_at": "2026-10-12T06:25:26.023339878Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_redis_data", + "destination": "/data" + } + ] + } + } +} diff --git a/evidence/persistence-public.json b/evidence/persistence-public.json new file mode 100644 index 0000000..695b2ef --- /dev/null +++ b/evidence/persistence-public.json @@ -0,0 +1,79 @@ +{ + "recorded_at": "2026-10-13T16:23:55.211338+00:00", + "scenario": "public", + "command": "python scripts/test-persistence.py --scenario public --base-url http://127.0.0.1:8080", + "hook": "scripts/restart.cmd", + "elapsed_seconds": 34.502, + "result": "PASS", + "test_output": "Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.\nPASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.", + "before": { + "backend": { + "id": "ce5c956eb323254c98154e780e8a8f69e9937404e11c878d0c7ea6fcc37ed2ca", + "started_at": "2026-10-13T14:54:54.227123416Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_backend_data", + "destination": "/app/data" + } + ] + }, + "postgres": { + "id": "c2fbbfded445fbedeff7ae87dcc06b05bedb0d2b2c89050e4a1a2236b06398f5", + "started_at": "2026-10-13T11:49:19.784511713Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_postgres_data", + "destination": "/var/lib/postgresql/data" + } + ] + }, + "redis": { + "id": "547184576f5e04a076d8c41e504cb0669c4f7c17daed437a6ae1db41ee5d1435", + "started_at": "2026-10-13T11:49:19.787195443Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_redis_data", + "destination": "/data" + } + ] + } + }, + "after": { + "backend": { + "id": "ce5c956eb323254c98154e780e8a8f69e9937404e11c878d0c7ea6fcc37ed2ca", + "started_at": "2026-10-13T16:23:45.40376979Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_backend_data", + "destination": "/app/data" + } + ] + }, + "postgres": { + "id": "c2fbbfded445fbedeff7ae87dcc06b05bedb0d2b2c89050e4a1a2236b06398f5", + "started_at": "2026-10-13T16:23:37.596580347Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_postgres_data", + "destination": "/var/lib/postgresql/data" + } + ] + }, + "redis": { + "id": "547184576f5e04a076d8c41e504cb0669c4f7c17daed437a6ae1db41ee5d1435", + "started_at": "2026-10-13T16:23:37.593428721Z", + "running": true, + "volumes": [ + { + "name": "mtusi2026lab2-fork_redis_data", + "destination": "/data" + } + ] + } + } +} diff --git a/evidence/redis-comparison-averages.json b/evidence/redis-comparison-averages.json new file mode 100644 index 0000000..f629d96 --- /dev/null +++ b/evidence/redis-comparison-averages.json @@ -0,0 +1,68 @@ +[ + { + "workload": "cold-history-burst", + "mode": "redis", + "successes": 96, + "errors": 0, + "rps": 31.88309531717038, + "mean_latency_ms": 861.2799999999999, + "mean_p95_ms": 974.8576666666668, + "sql_per_request": 2.59375, + "cpu_percent_one_core": 81.53158419129858 + }, + { + "workload": "cold-history-burst", + "mode": "no-redis", + "successes": 96, + "errors": 0, + "rps": 71.53502235469448, + "mean_latency_ms": 391.2333333333333, + "mean_p95_ms": 441.25466666666665, + "sql_per_request": 4, + "cpu_percent_one_core": 96.23474664679583 + }, + { + "workload": "warm-history", + "mode": "redis", + "successes": 3789, + "errors": 0, + "rps": 122.20215442172483, + "mean_latency_ms": 129.60684771707574, + "mean_p95_ms": 1052.4756666666667, + "sql_per_request": 2.0084455001319608, + "cpu_percent_one_core": 94.85495742759466 + }, + { + "workload": "warm-history", + "mode": "no-redis", + "successes": 1711, + "errors": 0, + "rps": 55.36141849479065, + "mean_latency_ms": 287.3598059614261, + "mean_p95_ms": 622.4456666666666, + "sql_per_request": 4, + "cpu_percent_one_core": 91.36944962143274 + }, + { + "workload": "writes-single-chat", + "mode": "redis", + "successes": 1536, + "errors": 0, + "rps": 64.84569595136574, + "mean_latency_ms": 245.36233333333334, + "mean_p95_ms": 688.5626666666667, + "sql_per_request": 2.0364583333333335, + "cpu_percent_one_core": 88.20568201967323 + }, + { + "workload": "writes-single-chat", + "mode": "no-redis", + "successes": 1536, + "errors": 0, + "rps": 90.58206050598572, + "mean_latency_ms": 174.03833333333333, + "mean_p95_ms": 421.7203333333334, + "sql_per_request": 3, + "cpu_percent_one_core": 102.17294037860471 + } +] diff --git a/evidence/redis-comparison.json b/evidence/redis-comparison.json new file mode 100644 index 0000000..e118f73 --- /dev/null +++ b/evidence/redis-comparison.json @@ -0,0 +1,509 @@ +{ + "stage": "after", + "recorded_at": "2026-10-13T12:52:54.446Z", + "node": "v24.20.0", + "methodology": { + "requests": "real loopback HTTP; instrumented API process in measured backend image", + "sql": "pg.Client.query calls; transaction control counted separately", + "concurrency": 16, + "duration_seconds": 10, + "warmup_seconds": 3, + "repetitions": 3, + "seed_messages": 10000, + "cold_burst_requests": 32, + "writes_per_repeat": 512, + "resources": "process CPU/RSS includes HTTP generator and instrumentation; not container CPU", + "limitations": "closed loop, client and API share process/CPU; other Docker workloads share host resources; no capacity/SLA claim; fixtures bypass password KDF", + "comparison": { + "modes": [ + "redis", + "no-redis" + ], + "no_redis": "API started without CACHE_URL; all application Redis caches disabled", + "epochs": "PostgreSQL epochs and atomic CTE writes retained in both modes", + "order": "redis first in repeats 1/3, no-redis first in repeat 2", + "processes": "both API instances and HTTP generator share one measured Node process" + } + }, + "dist_sha256": { + "Chat/chat.service.js": "f0f8b0cd357dcbb2ba6f401e30dadfcf19ab0deb7c1a812b306126d0478289e2", + "cache/cache.service.js": "ec7c09ef55f9054176ace8c62a3690df6e717b54c36db9ef66b91bc34a761693" + }, + "dependencies": { + "@nestjs/core": "package metadata not exported", + "@prisma/adapter-pg": "package metadata not exported", + "pg": "8.23.1", + "ioredis": "6.0.0", + "fastify": "5.12.1" + }, + "samples": [ + { + "workload": "cold-history-burst:redis", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 1.837, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 17.42, + "latency_ms": { + "mean": 1530.045, + "p50": 1546.818, + "p95": 1755.189, + "p99": 1770.661 + }, + "sql_queries": 71, + "sql_per_request": 2.2188, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 5, + "SELECT:chat_members": 32, + "SELECT:messages": 2 + }, + "process_cpu_percent_one_core": 86.19, + "peak_process_rss_mib": 319.89 + }, + { + "workload": "warm-history:redis", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.873, + "successes": 191, + "errors": 0, + "error_ratio": 0, + "successful_rps": 17.566, + "latency_ms": { + "mean": 890.11, + "p50": 663.435, + "p95": 2777.896, + "p99": 2907.685 + }, + "sql_queries": 414, + "sql_per_request": 2.1675, + "sql_calls": { + "SELECT:sessions": 191, + "SELECT:chat_members": 191, + "SELECT:messages": 14, + "SELECT:users": 18 + }, + "process_cpu_percent_one_core": 66.76, + "peak_process_rss_mib": 315.13 + }, + { + "workload": "writes-single-chat:redis", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 17.874, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 28.645, + "latency_ms": { + "mean": 555.497, + "p50": 399.725, + "p95": 1666.381, + "p99": 2243.938 + }, + "sql_queries": 1080, + "sql_per_request": 2.1094, + "sql_calls": { + "SELECT:sessions": 512, + "WITH:messages": 512, + "SELECT:users": 56 + }, + "process_cpu_percent_one_core": 81.97, + "peak_process_rss_mib": 336.75 + }, + { + "workload": "cold-history-burst:no-redis", + "repeat": 1, + "concurrency": 32, + "elapsed_seconds": 0.841, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 38.059, + "latency_ms": { + "mean": 763.242, + "p50": 770.663, + "p95": 829.822, + "p99": 830.022 + }, + "sql_queries": 128, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 91.64, + "peak_process_rss_mib": 337 + }, + { + "workload": "warm-history:no-redis", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 10.345, + "successes": 381, + "errors": 0, + "error_ratio": 0, + "successful_rps": 36.828, + "latency_ms": { + "mean": 430.415, + "p50": 421.069, + "p95": 734.11, + "p99": 820.689 + }, + "sql_queries": 1524, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 381, + "SELECT:users": 381, + "SELECT:chat_members": 381, + "SELECT:messages": 381 + }, + "process_cpu_percent_one_core": 85.89, + "peak_process_rss_mib": 337.75 + }, + { + "workload": "writes-single-chat:no-redis", + "repeat": 1, + "concurrency": 16, + "elapsed_seconds": 4.754, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 107.691, + "latency_ms": { + "mean": 147.905, + "p50": 100.917, + "p95": 466.346, + "p99": 610.975 + }, + "sql_queries": 1536, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 512, + "SELECT:users": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 128.47, + "peak_process_rss_mib": 338.37 + }, + { + "workload": "cold-history-burst:no-redis", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 0.286, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 112.082, + "latency_ms": { + "mean": 205.996, + "p50": 195.439, + "p95": 280.506, + "p99": 281.494 + }, + "sql_queries": 128, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 90.64, + "peak_process_rss_mib": 338.5 + }, + { + "workload": "warm-history:no-redis", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.489, + "successes": 393, + "errors": 0, + "error_ratio": 0, + "successful_rps": 37.468, + "latency_ms": { + "mean": 425.185, + "p50": 392.661, + "p95": 791.784, + "p99": 958.484 + }, + "sql_queries": 1572, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 393, + "SELECT:users": 393, + "SELECT:chat_members": 393, + "SELECT:messages": 393 + }, + "process_cpu_percent_one_core": 89.12, + "peak_process_rss_mib": 338.5 + }, + { + "workload": "writes-single-chat:no-redis", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 5.905, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 86.709, + "latency_ms": { + "mean": 182.799, + "p50": 137.282, + "p95": 388.273, + "p99": 791.35 + }, + "sql_queries": 1536, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 512, + "SELECT:users": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 82.53, + "peak_process_rss_mib": 338.75 + }, + { + "workload": "cold-history-burst:redis", + "repeat": 2, + "concurrency": 32, + "elapsed_seconds": 1.029, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 31.09, + "latency_ms": { + "mean": 918.771, + "p50": 972.749, + "p95": 1025.929, + "p99": 1026.358 + }, + "sql_queries": 92, + "sql_per_request": 2.875, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 5, + "SELECT:chat_members": 32, + "SELECT:messages": 23 + }, + "process_cpu_percent_one_core": 61.08, + "peak_process_rss_mib": 338.75 + }, + { + "workload": "warm-history:redis", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 10.105, + "successes": 1978, + "errors": 0, + "error_ratio": 0, + "successful_rps": 195.742, + "latency_ms": { + "mean": 81.312, + "p50": 65.517, + "p95": 165.58, + "p99": 255.442 + }, + "sql_queries": 3956, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 1978, + "SELECT:chat_members": 1978 + }, + "process_cpu_percent_one_core": 117.29, + "peak_process_rss_mib": 340.5 + }, + { + "workload": "writes-single-chat:redis", + "repeat": 2, + "concurrency": 16, + "elapsed_seconds": 2.802, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 182.731, + "latency_ms": { + "mean": 86.914, + "p50": 72.205, + "p95": 174.511, + "p99": 249.039 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 116.33, + "peak_process_rss_mib": 339.81 + }, + { + "workload": "cold-history-burst:redis", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.145, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 220.143, + "latency_ms": { + "mean": 135.024, + "p50": 137.463, + "p95": 143.455, + "p99": 143.876 + }, + "sql_queries": 86, + "sql_per_request": 2.6875, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 2, + "SELECT:chat_members": 32, + "SELECT:messages": 20 + }, + "process_cpu_percent_one_core": 167.65, + "peak_process_rss_mib": 339.81 + }, + { + "workload": "warm-history:redis", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.028, + "successes": 1620, + "errors": 0, + "error_ratio": 0, + "successful_rps": 161.555, + "latency_ms": { + "mean": 98.91, + "p50": 76.732, + "p95": 213.951, + "p99": 404.794 + }, + "sql_queries": 3240, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 1620, + "SELECT:chat_members": 1620 + }, + "process_cpu_percent_one_core": 102.71, + "peak_process_rss_mib": 340.31 + }, + { + "workload": "writes-single-chat:redis", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 3.011, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 170.063, + "latency_ms": { + "mean": 93.676, + "p50": 67.99, + "p95": 224.796, + "p99": 264.354 + }, + "sql_queries": 1024, + "sql_per_request": 2, + "sql_calls": { + "SELECT:sessions": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 99.05, + "peak_process_rss_mib": 340.43 + }, + { + "workload": "cold-history-burst:no-redis", + "repeat": 3, + "concurrency": 32, + "elapsed_seconds": 0.215, + "successes": 32, + "errors": 0, + "error_ratio": 0, + "successful_rps": 149.175, + "latency_ms": { + "mean": 204.462, + "p50": 206.7, + "p95": 213.436, + "p99": 213.79 + }, + "sql_queries": 128, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 32, + "SELECT:users": 32, + "SELECT:chat_members": 32, + "SELECT:messages": 32 + }, + "process_cpu_percent_one_core": 121.65, + "peak_process_rss_mib": 340.43 + }, + { + "workload": "warm-history:no-redis", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 10.072, + "successes": 937, + "errors": 0, + "error_ratio": 0, + "successful_rps": 93.032, + "latency_ms": { + "mean": 171.384, + "p50": 154.642, + "p95": 341.443, + "p99": 697.848 + }, + "sql_queries": 3748, + "sql_per_request": 4, + "sql_calls": { + "SELECT:sessions": 937, + "SELECT:users": 937, + "SELECT:chat_members": 937, + "SELECT:messages": 937 + }, + "process_cpu_percent_one_core": 99.34, + "peak_process_rss_mib": 340.93 + }, + { + "workload": "writes-single-chat:no-redis", + "repeat": 3, + "concurrency": 16, + "elapsed_seconds": 6.298, + "successes": 512, + "errors": 0, + "error_ratio": 0, + "successful_rps": 81.295, + "latency_ms": { + "mean": 191.411, + "p50": 155.363, + "p95": 410.542, + "p99": 517.121 + }, + "sql_queries": 1536, + "sql_per_request": 3, + "sql_calls": { + "SELECT:sessions": 512, + "SELECT:users": 512, + "WITH:messages": 512 + }, + "process_cpu_percent_one_core": 100.74, + "peak_process_rss_mib": 340.93 + } + ], + "correctness": { + "read_after_write": { + "redis:1": true, + "no-redis:1": true, + "no-redis:2": true, + "redis:2": true, + "redis:3": true, + "no-redis:3": true + } + }, + "completed": true, + "cleanup": "only experiment chats/user/cache prefix removed" +}