diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..46526f6a
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+* text=auto eol=lf
+*.png binary
+*.jpg binary
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 8ceefa10..42dfe8c5 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -1,18 +1,11 @@
## Лабораторная 2
-Автор / группа: TODO
-Целевая оценка (3/4/5): TODO
-Трек 5, если заявлен: TODO
+Парамонов Глеб, БВТ2301. Цель: 5, трек 2 «План запроса и восстановление».
-Что реализовано и что перенесено: TODO
-Команды запуска из чистого clone: TODO
-Результаты проверок и ссылка на REPORT.md: TODO
-Ограничения / известные ошибки: TODO
-Источники и использование ИИ: TODO
+Перенесён собственный API ЛР1 в PostgreSQL: транзакции и миграции, Argon2id, Basic → opaque Bearer, expiry/logout, Valkey-кэш профилей. Источник истины — PostgreSQL; отказ кэша допускается, отказ БД возвращает ограниченную ошибку.
-- [ ] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами.
-- [ ] Контракт и публичные тесты не ослаблены.
-- [ ] make check и make test выполнены; приложен реальный вывод.
-- [ ] Сценарии отказов/безопасности своего уровня воспроизведены.
-- [ ] Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens.
-- [ ] README задания сохранён, REPORT.md содержит инструкцию именно моего решения.
+Проверено: public smoke/persistence, гонка регистрации (1×201,7×409), rollback чата, 100 конкурентных сообщений, короткий TTL, logout, cache/DB down и восстановление. На 120000 сообщений сравнены 3 индекса × 2 запроса и стоимость INSERT; backup восстановлен в новый volume со сверкой counts,20 сообщений и всей истории. Keyset+compound:0.049мс против19.717мс; цена записи5000:140.445мс против112.982мс. HTTP:136.35RPS,0% ошибок, p95=122.238мс.
+
+Запуск: `python3 scripts/bootstrap.py && docker compose up -d --build --wait`; затем `make test`, `make verify`, `make experiment` (зависимости/Windows-команды в REPORT.md).
+
+[Отчёт и доказательства](../src/branch/solution/bvt2301-paramonov/REPORT.md). Ограничения: один host/БД, HTTP только локально, backup без PITR, короткие closed-loop измерения. Исходные контракты/tests сохранены. Использована помощь OpenAI Codex; данные измерены реальным запуском.
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
new file mode 100644
index 00000000..d3f03664
--- /dev/null
+++ b/ARCHITECTURE.md
@@ -0,0 +1,32 @@
+# План хранения и транзакций
+
+PostgreSQL — источник истины для пользователей, сессий, чатов, членства и сообщений.
+Данные пользователей неизменяемы в обязательном API. Valkey кэширует именно их
+публичное представление на 60 секунд; действительность сессии проверяется в PostgreSQL
+при каждом запросе. Поэтому отказ кэша не отменяет logout/expiry и не даёт доступ
+анонимному клиенту. При отказе PostgreSQL защищённые запросы получают 503.
+
+users: UUID PK, UNIQUE username, display_name, password_hash (Argon2id), created_at.
+sessions: SHA-256 случайного 256-битного токена PK, user FK, expires_at, created_at.
+chats: UUID PK, title, created_at.
+members: (chat_id, user_id) PK и внешние ключи на chats/users.
+messages: UUID PK, chat FK, sender FK, text, created_at; составной FK на members
+не позволяет записать отправителя вне чата даже при ошибке в приложении.
+
+Создание чата и всех его участников — одна транзакция. Создание сообщения — одна
+транзакция после проверки доступа. Регистрация защищена UNIQUE, гонка завершается
+одним 201 и остальными 409. Logout удаляет сессию в транзакции; Valkey не хранит
+разрешение на вход. Ранее начавшийся запрос может завершиться одновременно с logout.
+
+История: индекс (chat_id, created_at, id), keyset по (created_at,id), LIMIT n+1.
+Отдельный индекс members(user_id,chat_id) ускоряет список доступных чатов. Часы БД
+единые, но страницы между запросами не являются snapshot: конкурентная незавершённая
+транзакция может стать видимой позднее курсора. Для неизменной истории пропусков нет.
+
+Пул ограничен 5 соединениями, ожидание 2 секунды; statement_timeout=2s,
+lock_timeout=1s. KDF ограничен четырьмя параллельными задачами. Cursor подписан
+общим локально генерируемым секретом, который сохраняется при рестарте.
+
+Миграции нумеруются, учитываются в schema_migrations, защищены advisory lock.
+Отдельный одноразовый сервис migrate запускается до API. Повторный запуск проверяет
+хеши применённых миграций, не пересоздаёт таблицы и не seed-ит данные.
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..b0c0c77f
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,16 @@
+# Google public mirror of the official Docker Python image; immutable digest.
+FROM mirror.gcr.io/library/python@sha256:34386ef0cb081344d7ec1c103ba398e6e9f64e9ab3a1509accc92a4e24a07258
+ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONUTF8=1 \
+ APP_HOST=0.0.0.0 APP_PORT=8080
+WORKDIR /app
+COPY requirements.txt .
+RUN pip install --no-cache-dir -r requirements.txt && \
+ groupadd --gid 10001 messenger && useradd --uid 10001 --gid 10001 --no-create-home messenger
+COPY src ./src
+COPY migrations ./migrations
+USER 10001:10001
+EXPOSE 8080
+STOPSIGNAL SIGTERM
+HEALTHCHECK --interval=5s --timeout=2s --start-period=5s --retries=3 \
+ CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=1)"
+CMD ["python", "-m", "src"]
diff --git a/Makefile b/Makefile
index 9ecb223e..f2f9c453 100644
--- a/Makefile
+++ b/Makefile
@@ -24,3 +24,19 @@ load:
test-persistence:
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
+
+.PHONY: up down verify experiment
+up:
+ $(PYTHON) scripts/bootstrap.py
+ docker compose up -d --build --wait
+
+down:
+ docker compose down
+
+verify:
+ $(PYTHON) scripts/verify_stack.py
+
+experiment:
+ $(PYTHON) scripts/index_experiment.py
+ $(PYTHON) scripts/load_experiment.py
+ $(PYTHON) scripts/plot_experiment.py
diff --git a/REPORT.md b/REPORT.md
index e42f2b05..a4f8470f 100644
--- a/REPORT.md
+++ b/REPORT.md
@@ -1,37 +1,87 @@
-# Отчёт — лабораторная 2
+# Лабораторная 2 — PostgreSQL, сессии и Valkey
-- Автор, группа: TODO
-- Целевая оценка; выбранный трек 5, если нужен: TODO
-- Commit/PR: TODO после публикации
-- Использованные источники, библиотеки и помощь ИИ: TODO
+Автор: **Парамонов Глеб, БВТ2301**. Цель: **5**, трек 2 «План запроса и восстановление».
+Ветка: `solution/bvt2301-paramonov`. Код собственной ЛР1 перенесён и переработан для SQL и Bearer. Работа подготовлена с помощью OpenAI Codex (реализация, тесты, диагностика и оформление); измерения получены запуском реального стенда, не моделированием результатов. README, COURSE, обязательные contracts и публичные tests сохранены.
-## Запуск из чистого clone
+## Чистый запуск
-TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
+Нужны Docker Engine с Linux containers, Compose v2, Python 3.12+; для make-целей GNU Make. На Windows используется Docker Desktop/WSL2, команды Python запускать с `-X utf8`. Команды выполняются из корня этого репозитория; соседние лабораторные не нужны.
-## Архитектура и решения
+```sh
+python3 -m venv .venv
+.venv/bin/python -m pip install -r requirements-test.txt -r requirements-dev.txt
+python3 scripts/bootstrap.py
+docker compose config --quiet
+docker compose up -d --build --wait
+make check validate test PYTHON=.venv/bin/python
+make test-persistence PYTHON=.venv/bin/python ACTION_SCRIPT=scripts/restart.sh
+make verify PYTHON=.venv/bin/python
+make experiment PYTHON=.venv/bin/python
+```
-TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab1, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
+Windows: вместо `.venv/bin/python` используйте `.venv/Scripts/python.exe -X utf8`. `python scripts/verify_stack.py` сам создаёт временный Windows hook для неизменённого public persistence test. На Linux используется исполняемый `scripts/restart.sh`. Тесты создают только синтетические данные и на короткое время останавливают зависимости учебного стенда.
-## Доказательства критериев
+Bootstrap один раз создаёт `.env` с случайным паролем БД и HMAC-secret, при повторе сохраняет существующий файл. Переменные из исходного `.env.example` сопоставлены так: `DATABASE_URL_FILE` → локальный `DATABASE_URL`, `CACHE_URL_FILE` → `REDIS_URL`, `SESSION_STORE=postgres` соответствует фактическому источнику сессий. `SESSION_TTL_SECONDS` используется прямо; `APP_HOST/APP_PORT` задаются Dockerfile. Файловые secrets в этой лабораторной не реализованы. `.env`, backups и volumes исключены из Git. `docker compose config` без `--quiet` может показать секреты — не публикуйте его вывод.
-| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
-| --- | --- | --- | --- |
-| Публичный smoke | make test | TODO | TODO |
-| Остальные пункты уровня 3 | TODO | TODO | TODO |
-| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
-| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
+Остановка с сохранением данных: `docker compose down`. **Намеренный сброс только учебного стенда**, если данные больше не нужны: `docker compose down -v`. Удалять volume для проверки сохранности нельзя.
-TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
+Python 3.12.15, PostgreSQL 17.11, Valkey 8.1 (точные образы закреплены digest в Dockerfile/compose). Docker Hub на машине возвращал 403, поэтому используется публичное зеркало официальных образов `mirror.gcr.io`. Python-зависимости закреплены в requirements.txt. API запускается непривилегированным UID 10001 с read-only FS и без capabilities; порт опубликован только на 127.0.0.1:8080. PostgreSQL и Valkey доступны только в Docker-сети.
-## Эксперименты и отказы
+## Архитектура и гарантии
-TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
+Клиент → FastAPI/Uvicorn (1 процесс) → PostgreSQL; Valkey хранит кэш **неизменяемого публичного профиля пользователя** на 60 секунд. Пользователи/чаты/участники/сообщения/сессии — только PostgreSQL. Перед каждым cache lookup проверяется сессия SQL-запросом; наличие профиля в кэше не даёт доступ после logout/expiry. История не кэшируется: подтверждённый COMMIT виден следующему чтению. Потеря кэша допустима, потеря БД возвращает 503. Readiness зависит от БД, liveness — от процесса.
-| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
-| --- | --- | --- | --- |
-| TODO | TODO | TODO | TODO |
+Схема и транзакционные решения предварительно описаны в [ARCHITECTURE.md](ARCHITECTURE.md). PK/FK/UNIQUE/CHECK защищают целостность. Чат и все его участники записываются в одной транзакции; ошибка FK откатывает чат. Миграции выполняются отдельным сервисом до API, сериализованы advisory lock, имя и SHA-256 применённого SQL фиксируются; изменение уже применённой миграции запрещено.
-## Ограничения и следующие шаги
+Argon2id: memory_cost=32768 KiB, time_cost=2, parallelism=1; одновременно до четырёх KDF в отдельных потоках. Пароль UTF-8 не усекается. Basic применяется только при входе, Bearer — на бизнес-маршрутах. Токен — 32 случайных байта; в БД хранится SHA-256, не сам токен. Expiry проверяется по времени БД, TTL не продлевается при чтении/рестарте. Logout удаляет строку сессии. Полные токены, пароли, тела и SQL не выводятся в журналы приложения.
-TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
+Пул: 1–5 соединений, ожидание 2 с, очередь до 32; connect 3 с, SQL statement 2 с, lock 1 с. HTTP deadline 8 с, inflight 32, body 32 KiB; Valkey connect/read 0.2 с. При отказе ограничены очередь и время ожидания. SQL параметризован. Динамические SQL-имена есть только в локальном эксперименте с фиксированными таблицами/сгенерированной БД.
+
+Keyset `(created_at,id)` опирается на индекс `(chat_id,created_at,id)`. HMAC cursor общий и связан с ресурсом. На неизменной истории нет повторов. Между HTTP-страницами нет общего snapshot: поздно завершённая конкурентная транзакция с более ранним timestamp может оказаться перед уже выданным cursor; часы не считаются уникальным ID.
+
+## Проверки критериев
+
+| Критерий | Команда / наблюдение | Доказательство |
+|---|---|---|
+| Контракт и API | `make check validate test`: структура, OpenAPI, публичный smoke | `evidence/checks.txt`, `integration.json` |
+| PostgreSQL, миграции с нуля/повторно | Compose migrate; повтор сообщает Already applied | `migrations/001_initial.sql`, `integration.json` |
+| Сохранность всех данных/действующей сессии | public persistence перезапускает api, db, cache без удаления volumes; тот же token читает те же данные | `integration.json`, `restart-processes.json` с изменившимися StartedAt всех трёх процессов |
+| KDF, Basic/Bearer/expiry/logout | неправильный пароль и X-User-Id →401; отдельный API TTL2: 200, затем401 через2.2с; logout204, затем401 | `scripts/verify_stack.py`, `integration.json` |
+| Составная транзакция/гонка username | неизвестный участник400 и неизменное число чатов; 8 конкурентных регистраций: одна201, семь409 | `integration.json` |
+| Конкурентные записи/пагинация | 100 сообщений/10 потоков, прочитаны все 100 уникальных ID страницами по17 | `integration.json` |
+| Осмысленный Valkey/TTL/отказ | 5 повторных обращений дали +5 cache hits; при stop cache запрос200 за0.211с | `integration.json`, `src/store.py` |
+| SQL pool/timeouts/отказ БД | при stop db запрос503 за0.009с, без credentials401; после start сессия снова работает | `integration.json` |
+| Индекс и EXPLAIN ≥10000 | 120000 сообщений; все EXPLAIN ANALYZE BUFFERS сохранены | `index-restore.json` |
+| Трек5: ≥2 индекса, запись, backup/new store | три варианта индекса × два запроса, пять повторов, restore в новый volume | `index-restore.json`, `indexes.png` |
+
+## Эксперимент: планы и восстановление
+
+Гипотеза: compound index позволяет читать глубокую страницу без перебора предыдущих строк; поддержка индекса повышает цену INSERT. `python scripts/index_experiment.py` создаёт отдельную synthetic database (основные таблицы приложения не меняются). 120000 сообщений: чаты 100000/15000/5000, текст около160 символов. Сравнивается страница 70001–70050 большого чата. Keyset использует сохранённый tuple предыдущей строки; OFFSET пропускает70000. Два прогрева + пять EXPLAIN на каждую комбинацию, тёплый cache. Для записи пять **зафиксированных** INSERT по5000, очистка только добавленных synthetic rows и VACUUM между повторами. Полные планы, buffers и каждый замер в JSON.
+
+| Индекс истории | Keyset, медиана мс | OFFSET, медиана мс | INSERT5000+COMMIT, медиана мс |
+|---|---:|---:|---:|
+| Только PK(id) | 19.717 | 171.559 | 112.982 |
+| (chat_id) | 14.577 | 172.957 | 134.971 |
+| (chat_id,created_at,id) | 0.049 | 14.827 | 140.445 |
+
+Выбран compound+keyset: примерно402× быстрее primary-only keyset в этом тёплом SQL-микротесте, при +24.3% медианной стоимости пакетной записи. Это не402× ускорение всего HTTP API: сеть, авторизация и сериализация здесь не измеряются. Простого chat_id недостаточно для упорядоченной глубокой страницы. Последовательный порядок вариантов и один ноутбук ограничивают причинные выводы; холодный cache и большие рабочие наборы не исследовались.
+
+
+
+`pg_dump -Fc` дал3592366 байт за1.247с. `pg_restore --exit-on-error` в **отдельный PostgreSQL-контейнер и новый именованный volume**:4.026с включая ожидание старта. Совпали counts пользователей1/чатов3/участников3/сообщений120000/сессий0,20 выбранных сообщений и агрегатный digest всех сообщений. Dump лежит локально в ignored `backups/`; restore-контейнер и его synthetic volume удаляются самим экспериментом, исходная synthetic database остаётся для осмотра. Это snapshot логической копии: записи после snapshot могут быть потеряны, WAL/PITR и репликация не настроены. MD5 здесь только проверка равенства синтетических строк, не защита паролей или подпись.
+
+## Нагрузка и ресурсы
+
+Машина: Windows10/WSL2/Docker28.0.1, i5-11400H,8GB RAM, WSL4CPU/3GB RAM. Лимиты: API1CPU/256MiB, PostgreSQL1CPU/256MiB (shared_buffers64MB,max_connections30), Valkey0.25CPU/64MiB (cache32MB). Restore1CPU/256MiB запускался отдельно от HTTP нагрузки.
+
+`python scripts/load_experiment.py`: прогрев2с,10 клиентов,10.033с, closed-loop — одна запись1000 символов, затем четыре чтения истории по50 сообщений. 1368 запросов:1088×200 и280×201,136.35 успешных RPS,0% ошибок; p50/p95/p99=66.607/122.238/181.218мс. Тест создаёт отдельный чат,120000 SQL-строк исследовательской БД не подмешиваются к HTTP-набору. Raw: `http-load.csv`, `http-summary.json`, `http-resources.json`.
+
+Docker stats: API максимум100.05% CPU и47.89MiB, БД23.73%/25.43MiB, cache2.53%/8.289MiB. Это три дискретных отсчёта working set, не непрерывные максимумы/RSS всей VM. Генератор на том же host, closed-loop скрывает coordinated omission; один10-секундный запуск не определяет production capacity.
+
+## Ограничения
+
+Один Docker-host/одна БД — SPOF; backup не обеспечивает непрерывную доступность. Локальный HTTP разрешён только для synthetic данных. DB-role учебно имеет права миграций (разделение ролей — следующий этап). Expired sessions перестают авторизовывать, но фоновая очистка строк пока не реализована. Кэш профилей не демонстрирует ускорение истории и не заявляется как трек1. Idempotency-Key и несколько реплик появятся в ЛР3; здесь повтор POST после неизвестного исхода может создать дубликат. Все результаты относятся к указанному стенду.
+
+## Повтор из чистого clone
+
+Коммит be6f10f собран в отдельном каталоге .setup/clean-lab2 с новым volume и новыми локальными секретами. Полная интеграционная проверка повторно прошла: 100/100 сообщений, гонка регистрации, cache hit +5, отказы cache/DB, expiry, logout, повтор миграции и persistence с прежней сессией. Результаты: evidence/clean-clone-verification.json, реальные времена рестартов: evidence/clean-clone-restart.json.
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 00000000..b153cb2d
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,54 @@
+x-app: &app
+ build: .
+ image: mtusi-messenger:lab2
+ env_file: .env
+ cpus: 1.0
+ mem_limit: 256m
+ pids_limit: 64
+ read_only: true
+ cap_drop: [ALL]
+ security_opt: [no-new-privileges:true]
+ stop_grace_period: 8s
+ logging:
+ driver: json-file
+ options: {max-size: 5m, max-file: "2"}
+services:
+ db:
+ image: mirror.gcr.io/library/postgres@sha256:3645570cccdfa447589da9f57dd740faa29b30938e861289a5574b6ca6b03826
+ environment:
+ POSTGRES_USER: messenger
+ POSTGRES_DB: messenger
+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Run python scripts/bootstrap.py}
+ command: [postgres, -c, shared_buffers=64MB, -c, max_connections=30]
+ volumes: [pgdata:/var/lib/postgresql/data]
+ cpus: 1.0
+ mem_limit: 256m
+ healthcheck:
+ test: [CMD-SHELL, "pg_isready -U messenger -d messenger"]
+ interval: 2s
+ timeout: 2s
+ retries: 20
+ cache:
+ image: mirror.gcr.io/valkey/valkey@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507
+ command: [valkey-server, --maxmemory, 32mb, --maxmemory-policy, allkeys-lru, --save, "", --appendonly, "no"]
+ cpus: 0.25
+ mem_limit: 64m
+ healthcheck:
+ test: [CMD, valkey-cli, ping]
+ interval: 2s
+ timeout: 1s
+ retries: 20
+ migrate:
+ <<: *app
+ command: [python, -m, src.migrate]
+ healthcheck: {disable: true}
+ depends_on:
+ db: {condition: service_healthy}
+ api:
+ <<: *app
+ ports: ["127.0.0.1:8080:8080"]
+ depends_on:
+ migrate: {condition: service_completed_successfully}
+ cache: {condition: service_healthy}
+volumes:
+ pgdata:
diff --git a/evidence/checks.txt b/evidence/checks.txt
new file mode 100644
index 00000000..fba78c95
--- /dev/null
+++ b/evidence/checks.txt
@@ -0,0 +1,4 @@
+python -X utf8 scripts/check_contract.py
+PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+python -X utf8 scripts/validate_openapi.py
+PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
diff --git a/evidence/clean-clone-restart.json b/evidence/clean-clone-restart.json
new file mode 100644
index 00000000..b2d308bb
--- /dev/null
+++ b/evidence/clean-clone-restart.json
@@ -0,0 +1,13 @@
+{
+ "before": {
+ "api": "2026-10-16T12:26:12.421719826Z",
+ "db": "2026-10-16T12:27:19.188705708Z",
+ "cache": "2026-10-16T12:27:17.815782719Z"
+ },
+ "after": {
+ "api": "2026-10-16T12:27:34.893221429Z",
+ "db": "2026-10-16T12:27:34.36080408Z",
+ "cache": "2026-10-16T12:27:34.173884108Z"
+ },
+ "volumes_removed": false
+}
diff --git a/evidence/clean-clone-verification.json b/evidence/clean-clone-verification.json
new file mode 100644
index 00000000..72f1e6d7
--- /dev/null
+++ b/evidence/clean-clone-verification.json
@@ -0,0 +1,34 @@
+{
+ "public_smoke": "PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.",
+ "authentication_negative": "wrong password, Basic on protected route, X-User-Id: 401",
+ "registration_race": [
+ 201,
+ 409,
+ 409,
+ 409,
+ 409,
+ 409,
+ 409,
+ 409
+ ],
+ "rollback": "missing member: 400; chats count unchanged",
+ "concurrent_messages": {
+ "sent": 100,
+ "read": 100,
+ "page_size": 17
+ },
+ "cache_hit_delta": 5,
+ "cache_down": {
+ "status": 200,
+ "seconds": 0.209
+ },
+ "database_down": {
+ "status": 503,
+ "seconds": 0.006
+ },
+ "logout": "204 then 401",
+ "short_ttl": "SESSION_TTL_SECONDS=2: 200 then 401 after 2.2s",
+ "migration_repeat": "Already applied: 001_initial.sql",
+ "public_persistence": "Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.\nPASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.",
+ "passed": true
+}
diff --git a/evidence/http-load.csv b/evidence/http-load.csv
new file mode 100644
index 00000000..08e360ae
--- /dev/null
+++ b/evidence/http-load.csv
@@ -0,0 +1,1369 @@
+worker,method,elapsed_s,latency_ms,status
+0,POST,0.00415,99.473,201
+1,POST,0.00578,108.551,201
+5,POST,0.015322,102.218,201
+2,POST,0.007225,112.014,201
+4,POST,0.009349,111.634,201
+3,POST,0.008632,113.049,201
+7,POST,0.018005,109.75,201
+9,POST,0.020841,115.852,201
+6,POST,0.016594,123.54,201
+8,POST,0.019242,122.525,201
+0,GET,0.103628,54.263,200
+5,GET,0.117544,48.052,200
+1,GET,0.114335,54.481,200
+4,GET,0.120989,53.626,200
+2,GET,0.119243,59.903,200
+7,GET,0.12776,56.283,200
+3,GET,0.121686,63.738,200
+9,GET,0.1367,50.846,200
+6,GET,0.140139,54.218,200
+8,GET,0.14177,56.663,200
+5,GET,0.1656,44.886,200
+0,GET,0.157894,57.179,200
+1,GET,0.168819,47.463,200
+4,GET,0.17462,44.577,200
+2,GET,0.179149,41.769,200
+3,GET,0.185427,91.644,200
+7,GET,0.184048,94.69,200
+9,GET,0.18755,94.539,200
+6,GET,0.194361,93.416,200
+8,GET,0.198438,92.385,200
+5,GET,0.21049,100.271,200
+0,GET,0.215079,99.4,200
+4,GET,0.219201,98.942,200
+1,GET,0.216286,102.811,200
+2,GET,0.220922,103.66,200
+3,GET,0.277075,101.154,200
+7,GET,0.27874,100.851,200
+9,GET,0.282093,107.344,200
+6,GET,0.287783,110.533,200
+8,GET,0.290827,109.647,200
+5,GET,0.310766,101.962,200
+0,GET,0.314482,106.17,200
+2,GET,0.324585,98.949,200
+1,GET,0.319101,106.057,200
+4,GET,0.318148,108.084,200
+7,GET,0.379595,102.003,200
+3,GET,0.378233,105.327,200
+9,GET,0.38944,106.415,200
+6,GET,0.398319,99.394,200
+8,GET,0.400478,101.745,200
+5,POST,0.412732,102.976,201
+0,POST,0.420656,97.2,201
+1,POST,0.42516,150.547,201
+4,POST,0.426236,158.12,201
+2,POST,0.423612,165.49,201
+7,POST,0.481601,110.77,201
+3,POST,0.483575,113.369,201
+9,POST,0.495858,108.831,201
+6,POST,0.497716,117.562,201
+8,POST,0.502232,114.389,201
+5,GET,0.515711,161.322,200
+0,GET,0.517859,163.19,200
+1,GET,0.575766,115.85,200
+4,GET,0.584361,112.403,200
+2,GET,0.589154,117.832,200
+7,GET,0.592375,121.063,200
+3,GET,0.596948,121.154,200
+9,GET,0.604695,165.53,200
+6,GET,0.615281,160.746,200
+8,GET,0.616627,163.191,200
+5,GET,0.677092,106.839,200
+0,GET,0.681054,112.652,200
+1,GET,0.69162,104.303,200
+4,GET,0.696767,103.822,200
+2,GET,0.706993,100.54,200
+7,GET,0.71345,98.914,200
+3,GET,0.718105,151.607,200
+9,GET,0.770229,109.834,200
+8,GET,0.779821,106.968,200
+5,GET,0.783937,106.765,200
+6,GET,0.776033,117.839,200
+1,GET,0.795927,108.229,200
+0,GET,0.79371,114.361,200
+4,GET,0.800592,112.113,200
+2,GET,0.807536,109.357,200
+7,GET,0.812368,155.025,200
+3,GET,0.869717,108.047,200
+9,GET,0.880066,111.094,200
+8,GET,0.886793,105.82,200
+5,GET,0.890709,114.42,200
+6,GET,0.893876,113.574,200
+1,GET,0.90416,155.199,200
+0,GET,0.908075,154.578,200
+2,GET,0.916895,156.952,200
+4,GET,0.912708,162.736,200
+7,GET,0.967396,124.603,200
+3,GET,0.977769,125.823,200
+9,GET,0.991164,173.402,200
+8,GET,0.992616,173.803,200
+5,POST,1.005133,168.867,201
+1,POST,1.059362,122.535,201
+6,GET,1.007452,175.882,200
+4,POST,1.075465,109.774,201
+2,POST,1.073892,117.193,201
+0,POST,1.062659,136.15,201
+7,POST,1.092002,113.041,201
+3,POST,1.103595,109.025,201
+8,POST,1.166424,95.373,201
+5,GET,1.174004,90.836,200
+9,POST,1.164575,101.565,201
+6,POST,1.183336,93.466,201
+1,GET,1.1819,96.18,200
+4,GET,1.185242,97.871,200
+2,GET,1.19116,99.581,200
+0,GET,1.198813,97.928,200
+7,GET,1.205047,99.788,200
+3,GET,1.212623,105.98,200
+8,GET,1.2618,66.495,200
+5,GET,1.264846,68.01,200
+9,GET,1.266143,70.145,200
+6,GET,1.276805,75.242,200
+1,GET,1.278082,86.881,200
+4,GET,1.283116,89.276,200
+2,GET,1.290744,92.766,200
+0,GET,1.296745,95.625,200
+7,GET,1.304839,91.491,200
+3,GET,1.318607,88.283,200
+8,GET,1.328299,83.666,200
+5,GET,1.33286,86.125,200
+9,GET,1.336293,85.301,200
+6,GET,1.35205,77.279,200
+1,GET,1.364969,67.537,200
+4,GET,1.372398,65.741,200
+2,GET,1.383515,60.232,200
+0,GET,1.392375,55.816,200
+7,GET,1.396333,56.648,200
+3,GET,1.406893,53.561,200
+8,GET,1.411968,55.288,200
+9,GET,1.421599,46.551,200
+5,GET,1.418989,50.7,200
+6,GET,1.429333,51.143,200
+4,GET,1.438142,43.613,200
+1,GET,1.43251,49.621,200
+2,GET,1.443755,50.036,200
+0,GET,1.448195,48.195,200
+7,GET,1.452985,52.259,200
+3,GET,1.460457,54.11,200
+9,GET,1.468153,49.39,200
+8,GET,1.46726,52.412,200
+5,POST,1.469693,57.632,201
+6,GET,1.48048,49.021,200
+4,POST,1.481759,48.19,201
+1,POST,1.48214,55.251,201
+2,POST,1.493795,48.541,201
+0,POST,1.496394,51.59,201
+7,POST,1.505248,56.055,201
+9,POST,1.517547,45.774,201
+3,POST,1.514571,50.137,201
+8,POST,1.519677,45.971,201
+6,POST,1.529505,41.794,201
+5,GET,1.527328,47.429,200
+4,GET,1.529953,48.46,200
+1,GET,1.537394,51.143,200
+2,GET,1.54234,48.05,200
+0,GET,1.547987,49.324,200
+7,GET,1.561306,44.826,200
+3,GET,1.564712,44.883,200
+9,GET,1.563324,48.341,200
+8,GET,1.565651,54.684,200
+6,GET,1.571301,51.489,200
+5,GET,1.57476,50.17,200
+4,GET,1.578416,53.048,200
+1,GET,1.58854,51.29,200
+2,GET,1.590394,50.948,200
+0,GET,1.597314,54.011,200
+7,GET,1.606135,57.747,200
+3,GET,1.609597,56.735,200
+9,GET,1.611668,56.272,200
+8,GET,1.620338,58.749,200
+6,GET,1.622793,57.73,200
+5,GET,1.624932,56.927,200
+4,GET,1.631467,59.771,200
+1,GET,1.639833,57.335,200
+2,GET,1.641344,59.999,200
+0,GET,1.651331,59.142,200
+7,GET,1.663885,54.822,200
+3,GET,1.666348,53.72,200
+9,GET,1.667941,59.466,200
+8,GET,1.679091,50.772,200
+6,GET,1.680527,54.775,200
+5,GET,1.681862,59.732,200
+1,GET,1.697173,55.141,200
+4,GET,1.691243,63.663,200
+2,GET,1.701346,58.887,200
+0,GET,1.710477,60.286,200
+7,GET,1.71871,56.495,200
+3,GET,1.720071,58.062,200
+8,GET,1.729866,57.564,200
+9,GET,1.72741,62.951,200
+6,GET,1.735304,62.449,200
+5,POST,1.741598,62.054,201
+1,POST,1.752317,53.813,201
+4,POST,1.754909,52.444,201
+2,POST,1.760238,48.364,201
+0,POST,1.770766,49.241,201
+7,POST,1.775208,47.585,201
+3,POST,1.778136,50.332,201
+8,POST,1.787432,43.067,201
+9,POST,1.790365,43.683,201
+6,POST,1.797755,45.67,201
+5,GET,1.803662,40.783,200
+1,GET,1.806132,39.785,200
+4,GET,1.807355,47.406,200
+2,GET,1.808612,48.221,200
+0,GET,1.82001,53.201,200
+7,GET,1.822796,53.343,200
+8,GET,1.830501,53.227,200
+3,GET,1.82847,60.493,200
+9,GET,1.834051,56.766,200
+6,GET,1.843428,56.574,200
+5,GET,1.844448,59.679,200
+1,GET,1.845919,61.12,200
+4,GET,1.854765,57.423,200
+2,GET,1.856836,65.325,200
+0,GET,1.873214,70.663,200
+7,GET,1.876142,80.211,200
+8,GET,1.883783,74.489,200
+3,GET,1.888966,78.453,200
+9,GET,1.890821,80.007,200
+6,GET,1.900005,73.027,200
+5,GET,1.904131,77.7,200
+1,GET,1.907048,76.512,200
+4,GET,1.912191,79.949,200
+2,GET,1.922164,81.397,200
+0,GET,1.94388,71.506,200
+8,GET,1.958275,63.59,200
+7,GET,1.956358,68.516,200
+3,GET,1.967422,61.413,200
+9,GET,1.970858,60.017,200
+6,GET,1.973036,68.377,200
+5,GET,1.981833,66.35,200
+1,GET,1.983577,66.049,200
+4,GET,1.992144,69.493,200
+2,GET,2.003565,67.304,200
+0,GET,2.015389,65.808,200
+8,GET,2.021868,61.424,200
+7,GET,2.024881,61.831,200
+3,GET,2.028838,66.353,200
+9,GET,2.030884,72.812,200
+6,GET,2.041416,64.251,200
+1,POST,2.04963,57.307,201
+5,POST,2.048189,67.266,201
+4,POST,2.061648,66.099,201
+2,POST,2.070872,59.99,201
+0,POST,2.081201,53.844,201
+8,POST,2.083327,54.566,201
+7,POST,2.086717,55.008,201
+3,POST,2.095194,49.799,201
+6,POST,2.10567,42.674,201
+9,POST,2.103699,48.646,201
+1,GET,2.106939,49.565,200
+5,GET,2.115458,50.95,200
+4,GET,2.127753,56.073,200
+0,GET,2.135047,62.625,200
+2,GET,2.130864,71.489,200
+7,GET,2.141728,62.743,200
+8,GET,2.137896,74.533,200
+3,GET,2.144998,73.367,200
+6,GET,2.148346,77.143,200
+9,GET,2.152348,75.606,200
+1,GET,2.156508,76.506,200
+5,GET,2.166411,77.877,200
+4,GET,2.183877,74.475,200
+0,GET,2.197676,63.801,200
+7,GET,2.204475,60.728,200
+2,GET,2.202356,74.674,200
+8,GET,2.212432,76.029,200
+3,GET,2.21837,75.27,200
+6,GET,2.225495,69.93,200
+9,GET,2.227956,77.3,200
+1,GET,2.233018,79.497,200
+5,GET,2.244292,90.713,200
+4,GET,2.258355,82.962,200
+0,GET,2.261481,86.941,200
+7,GET,2.265207,89.884,200
+2,GET,2.277035,88.708,200
+8,GET,2.288464,79.485,200
+3,GET,2.293643,78.174,200
+6,GET,2.295427,84.019,200
+9,GET,2.30526,79.245,200
+1,GET,2.312578,84.046,200
+5,GET,2.335009,79.82,200
+4,GET,2.341321,78.413,200
+0,GET,2.348424,73.756,200
+7,GET,2.355094,77.198,200
+2,GET,2.365748,75.696,200
+8,GET,2.367952,80.256,200
+3,GET,2.37182,79.694,200
+6,GET,2.379448,86.112,200
+9,GET,2.384508,87.509,200
+1,POST,2.396627,81.067,201
+5,POST,2.414832,76.419,201
+7,POST,2.432295,62.82,201
+0,POST,2.422184,75.444,201
+4,POST,2.419739,79.518,201
+2,POST,2.441448,59.348,201
+8,POST,2.448212,54.415,201
+3,POST,2.451517,58.671,201
+6,POST,2.465564,47.607,201
+9,POST,2.472021,48.26,201
+1,GET,2.477697,50.657,200
+7,GET,2.495118,47.158,200
+5,GET,2.491255,56.184,200
+0,GET,2.497631,52.959,200
+4,GET,2.499267,61.055,200
+8,GET,2.50263,63.83,200
+2,GET,2.5008,72.275,200
+3,GET,2.510191,72.665,200
+6,GET,2.513176,78.948,200
+9,GET,2.520289,78.629,200
+1,GET,2.528357,82.432,200
+7,GET,2.542281,72.441,200
+5,GET,2.547442,75.946,200
+0,GET,2.550593,77.207,200
+4,GET,2.560325,79.207,200
+8,GET,2.566464,78.813,200
+2,GET,2.57308,81.367,200
+3,GET,2.58286,81.134,200
+6,GET,2.592128,76.711,200
+9,GET,2.598922,81.646,200
+1,GET,2.610792,74.907,200
+7,GET,2.614726,79.909,200
+5,GET,2.623391,74.243,200
+0,GET,2.627803,77.604,200
+4,GET,2.639536,67.903,200
+8,GET,2.645285,74.454,200
+2,GET,2.654466,70.246,200
+3,GET,2.663999,73.702,200
+6,GET,2.668842,79.555,200
+9,GET,2.680571,74.02,200
+1,GET,2.685701,79.822,200
+7,GET,2.694639,79.547,200
+5,GET,2.697638,80.158,200
+0,GET,2.705411,84.325,200
+4,GET,2.707441,90.854,200
+8,GET,2.719743,89.404,200
+2,GET,2.724715,91.463,200
+3,GET,2.737704,88.318,200
+6,GET,2.748399,88.071,200
+9,GET,2.754595,83.55,200
+1,POST,2.765527,80.722,201
+7,POST,2.77419,75.699,201
+0,POST,2.789739,63.738,201
+5,POST,2.777804,77.679,201
+4,POST,2.798298,64.106,201
+8,POST,2.809151,56.374,201
+2,POST,2.816181,52.271,201
+3,POST,2.826025,50.935,201
+6,POST,2.836476,42.202,201
+9,POST,2.838149,45.608,201
+1,GET,2.846252,46.81,200
+7,GET,2.849894,45.203,200
+0,GET,2.85349,53.617,200
+5,GET,2.855528,53.747,200
+4,GET,2.862407,59.091,200
+8,GET,2.865533,57.903,200
+2,GET,2.868455,66.388,200
+6,GET,2.87868,70.04,200
+3,GET,2.876963,74.98,200
+9,GET,2.88376,85.37,200
+1,GET,2.893067,86.783,200
+7,GET,2.895102,92.232,200
+0,GET,2.907113,94.761,200
+5,GET,2.909278,98.677,200
+4,GET,2.921502,98.086,200
+8,GET,2.923439,108.683,200
+2,GET,2.934845,111.811,200
+6,GET,2.948724,108.277,200
+3,GET,2.951988,107.265,200
+9,GET,2.969134,100.571,200
+1,GET,2.979853,96.286,200
+7,GET,2.987338,91.609,200
+0,GET,3.001878,84.089,200
+5,GET,3.007958,86.431,200
+4,GET,3.019592,76.521,200
+8,GET,3.032125,72.056,200
+2,GET,3.04666,67.366,200
+6,GET,3.057004,62.541,200
+3,GET,3.059257,64.207,200
+9,GET,3.069738,66.624,200
+1,GET,3.076142,68.149,200
+7,GET,3.07895,68.083,200
+0,GET,3.086001,68.482,200
+5,GET,3.094394,69.555,200
+4,GET,3.096118,73.898,200
+8,GET,3.104186,81.976,200
+2,GET,3.11403,75.172,200
+6,GET,3.119548,82.401,200
+3,GET,3.123467,83.297,200
+1,POST,3.144294,67.533,201
+9,GET,3.136369,77.587,200
+7,POST,3.147038,71.932,201
+0,POST,3.154486,67.458,201
+5,POST,3.163953,60.591,201
+4,POST,3.17002,58.488,201
+2,POST,3.189247,51.345,201
+3,POST,3.206768,37.578,201
+8,POST,3.18617,59.109,201
+6,POST,3.201952,44.562,201
+1,GET,3.21183,40.243,200
+9,POST,3.213962,40.495,201
+7,GET,3.218974,45.892,200
+0,GET,3.221947,45.409,200
+5,GET,3.224555,54.356,200
+4,GET,3.228511,60.876,200
+2,GET,3.240594,63.402,200
+8,GET,3.245281,68.486,200
+3,GET,3.244349,71.733,200
+6,GET,3.246518,71.578,200
+1,GET,3.252077,81.747,200
+9,GET,3.254459,81.011,200
+7,GET,3.264869,73.305,200
+0,GET,3.267379,73.826,200
+5,GET,3.278914,79.019,200
+4,GET,3.289392,74.903,200
+2,GET,3.304,75.739,200
+8,GET,3.31377,72.389,200
+3,GET,3.316086,76.472,200
+6,GET,3.318099,78.323,200
+1,GET,3.333827,64.476,200
+9,GET,3.335473,65.226,200
+7,GET,3.33818,76.001,200
+0,GET,3.34121,75.215,200
+5,GET,3.357937,69.22,200
+4,GET,3.364299,72.82,200
+2,GET,3.379742,66.639,200
+8,GET,3.386163,65.242,200
+3,GET,3.392562,61.275,200
+6,GET,3.396427,63.452,200
+1,GET,3.398307,68.682,200
+9,GET,3.400703,73.235,200
+7,GET,3.414184,63.474,200
+0,GET,3.416428,67.571,200
+5,GET,3.427161,65.306,200
+4,GET,3.437123,67.364,200
+2,GET,3.446383,64.235,200
+8,GET,3.451408,61.08,200
+3,GET,3.453841,68.459,200
+6,GET,3.459881,65.254,200
+1,POST,3.466992,67.359,201
+7,POST,3.477661,59.629,201
+9,GET,3.473941,65.196,200
+0,POST,3.484002,61.151,201
+5,POST,3.492471,62.719,201
+4,POST,3.504491,56.341,201
+2,POST,3.510621,51.882,201
+8,POST,3.512491,51.395,201
+3,POST,3.522303,49.165,201
+1,GET,3.534354,39.092,200
+6,POST,3.525141,49.915,201
+9,POST,3.539141,44.163,201
+7,GET,3.537294,49.965,200
+0,GET,3.545158,52.872,200
+5,GET,3.555193,52.157,200
+4,GET,3.560836,51.57,200
+2,GET,3.562507,54.799,200
+8,GET,3.56389,56.187,200
+3,GET,3.57147,56.804,200
+1,GET,3.573449,58.474,200
+6,GET,3.575058,58.343,200
+9,GET,3.583308,56.38,200
+7,GET,3.587262,61.483,200
+0,GET,3.598034,57.936,200
+5,GET,3.607354,55.865,200
+4,GET,3.612446,61.199,200
+2,GET,3.617309,57.963,200
+8,GET,3.620079,60.93,200
+3,GET,3.628279,64.193,200
+1,GET,3.631928,64.02,200
+6,GET,3.633405,71.94,200
+9,GET,3.639691,70.383,200
+7,GET,3.648763,79.297,200
+0,GET,3.655974,88.66,200
+5,GET,3.66324,87.097,200
+4,GET,3.673649,83.115,200
+2,GET,3.675274,90.207,200
+8,GET,3.681012,92.352,200
+3,GET,3.692476,87.065,200
+1,GET,3.695955,96.675,200
+6,GET,3.705347,90.748,200
+9,GET,3.710078,100.236,200
+7,GET,3.728064,94.911,200
+4,GET,3.756767,72.371,200
+0,GET,3.744637,87.303,200
+5,GET,3.750346,88.946,200
+8,GET,3.77338,72.634,200
+3,GET,3.779543,67.661,200
+1,POST,3.792633,61.338,201
+2,GET,3.765483,91.915,200
+6,GET,3.796099,72.668,200
+9,GET,3.810318,74.205,200
+7,POST,3.822981,68.599,201
+4,POST,3.829143,68.033,201
+3,POST,3.847207,55.927,201
+0,POST,3.831944,73.282,201
+5,POST,3.839295,66.917,201
+2,POST,3.857403,54.023,201
+8,POST,3.846018,70.57,201
+1,GET,3.853975,68.724,200
+6,POST,3.868772,54.993,201
+9,POST,3.884528,48.705,201
+7,GET,3.891584,47.064,200
+4,GET,3.897183,52.829,200
+3,GET,3.903145,52.663,200
+5,GET,3.906214,53.605,200
+0,GET,3.905233,57.323,200
+2,GET,3.911444,59.636,200
+8,GET,3.916591,62.878,200
+6,GET,3.923769,61.1,200
+1,GET,3.922701,68.642,200
+9,GET,3.933243,61.76,200
+7,GET,3.938652,63.988,200
+4,GET,3.950015,58.022,200
+3,GET,3.955811,54.887,200
+5,GET,3.959822,60.127,200
+0,GET,3.962561,59.281,200
+2,GET,3.971084,60.269,200
+8,GET,3.979472,62.982,200
+6,GET,3.984872,59.529,200
+1,GET,3.991347,61.706,200
+9,GET,3.995011,61.152,200
+7,GET,4.002643,59.71,200
+4,GET,4.00804,60.583,200
+3,GET,4.0107,59.878,200
+0,GET,4.021846,56.772,200
+5,GET,4.019954,60.906,200
+8,GET,4.042458,50.279,200
+2,GET,4.031358,68.466,200
+6,GET,4.044405,63.654,200
+1,GET,4.053057,62.709,200
+9,GET,4.056165,65.975,200
+4,GET,4.068629,55.954,200
+7,GET,4.062356,72.948,200
+3,GET,4.070581,66.603,200
+0,GET,4.078621,64.989,200
+5,GET,4.080863,66.901,200
+8,GET,4.09274,72.396,200
+2,GET,4.099829,69.111,200
+6,GET,4.108062,71.212,200
+1,POST,4.11577,65.086,201
+4,POST,4.124587,61.142,201
+9,GET,4.122144,71.39,200
+7,POST,4.135308,59.85,201
+3,POST,4.137186,59.478,201
+0,POST,4.143613,55.994,201
+5,POST,4.147767,58.098,201
+8,POST,4.165141,52.313,201
+2,POST,4.168945,51.362,201
+6,POST,4.179277,46.495,201
+1,GET,4.180859,50.244,200
+4,GET,4.185739,47.795,200
+9,POST,4.193538,41.297,201
+7,GET,4.195161,46.972,200
+3,GET,4.196666,53.477,200
+0,GET,4.199616,55.722,200
+5,GET,4.205869,58.386,200
+8,GET,4.217457,60.873,200
+2,GET,4.22031,61.603,200
+6,GET,4.225775,59.186,200
+1,GET,4.231106,57.953,200
+4,GET,4.233537,70.458,200
+9,GET,4.234836,71.2,200
+7,GET,4.242137,65.36,200
+3,GET,4.250146,68.922,200
+0,GET,4.255341,74.959,200
+5,GET,4.264258,73.194,200
+8,GET,4.278333,64.248,200
+6,GET,4.284964,70.422,200
+2,GET,4.281916,77.919,200
+1,GET,4.289063,74.122,200
+4,GET,4.303999,75.585,200
+7,GET,4.3075,74.931,200
+9,GET,4.306039,78.331,200
+3,GET,4.31907,76.353,200
+0,GET,4.330303,73.663,200
+5,GET,4.337456,72.77,200
+8,GET,4.342585,71.366,200
+6,GET,4.355391,66.545,200
+2,GET,4.359838,63.568,200
+1,GET,4.363188,65.643,200
+4,GET,4.379586,51.921,200
+7,GET,4.382434,57.7,200
+9,GET,4.384373,60.049,200
+3,GET,4.395426,58.211,200
+0,GET,4.403969,58.181,200
+8,GET,4.413954,61.827,200
+5,GET,4.41023,67.437,200
+6,GET,4.421939,60.652,200
+2,GET,4.423409,64.146,200
+1,POST,4.428834,63.971,201
+4,POST,4.431511,63.273,201
+7,POST,4.440139,62.253,201
+9,GET,4.44443,64.208,200
+3,POST,4.45364,63.387,201
+0,POST,4.462153,62.425,201
+8,POST,4.475786,52.769,201
+5,POST,4.477669,53.031,201
+6,POST,4.482595,49.935,201
+2,POST,4.487557,47.51,201
+4,GET,4.494787,91.264,200
+1,GET,4.492808,95.289,200
+9,POST,4.508641,88.527,201
+7,GET,4.502405,98.434,200
+3,GET,4.517047,96.343,200
+0,GET,4.524586,100.305,200
+8,GET,4.528559,99.948,200
+5,GET,4.530705,101.521,200
+6,GET,4.532534,109.052,200
+2,GET,4.53507,111.372,200
+4,GET,4.586054,68.448,200
+1,GET,4.588099,72.343,200
+9,GET,4.597171,71.096,200
+7,GET,4.600908,70.618,200
+3,GET,4.613393,68.785,200
+8,GET,4.628553,56.033,200
+0,GET,4.624895,67.092,200
+5,GET,4.632229,66.906,200
+6,GET,4.641592,58.985,200
+2,GET,4.646446,64.229,200
+4,GET,4.654506,65.183,200
+1,GET,4.660446,61.052,200
+9,GET,4.66827,63.085,200
+7,GET,4.671528,63.187,200
+8,GET,4.684589,63.239,200
+3,GET,4.682181,71.271,200
+0,GET,4.691989,67.673,200
+5,GET,4.699139,68.935,200
+6,GET,4.70058,71.975,200
+2,GET,4.710678,70.639,200
+4,GET,4.719694,66.424,200
+1,GET,4.721502,68.956,200
+9,GET,4.731358,65.226,200
+7,GET,4.734717,72.387,200
+3,GET,4.753457,60.322,200
+8,GET,4.747832,72.681,200
+0,GET,4.759664,74.515,200
+5,GET,4.768128,68.164,200
+6,GET,4.772558,73.374,200
+2,GET,4.78132,71.832,200
+4,POST,4.786121,69.744,201
+1,POST,4.790461,67.184,201
+9,GET,4.796589,74.891,200
+7,POST,4.807108,71.647,201
+8,POST,4.820515,63.895,201
+3,POST,4.813782,74.056,201
+0,POST,4.834185,55.249,201
+5,POST,4.836302,60.452,201
+2,POST,4.853156,45.986,201
+1,GET,4.857647,46.381,200
+6,POST,4.845935,64.724,201
+4,GET,4.855874,57.347,200
+9,POST,4.871484,42.697,201
+7,GET,4.878759,50.345,200
+8,GET,4.884415,50.669,200
+3,GET,4.887841,56.226,200
+0,GET,4.889435,56.847,200
+5,GET,4.896757,58.58,200
+1,GET,4.904032,57.964,200
+6,GET,4.910662,54.424,200
+2,GET,4.899146,67.535,200
+4,GET,4.913224,63.538,200
+9,GET,4.914183,65.6,200
+7,GET,4.929106,64.153,200
+8,GET,4.935087,67.249,200
+3,GET,4.944073,62.523,200
+0,GET,4.946285,62.741,200
+5,GET,4.955341,56.726,200
+1,GET,4.961999,56.601,200
+6,GET,4.96509,59.128,200
+2,GET,4.966687,59.108,200
+4,GET,4.976765,53.977,200
+9,GET,4.979786,60.816,200
+7,GET,4.993272,58.509,200
+8,GET,5.002339,56.272,200
+0,GET,5.00903,52.834,200
+3,GET,5.006599,58.263,200
+5,GET,5.012069,60.643,200
+1,GET,5.018602,61.044,200
+6,GET,5.024222,58.461,200
+2,GET,5.025798,59.496,200
+4,GET,5.030746,67.537,200
+9,GET,5.040606,59.051,200
+7,GET,5.051784,63.822,200
+3,GET,5.064864,59.294,200
+8,GET,5.058632,67.217,200
+1,POST,5.079649,54.929,201
+0,GET,5.061865,78.13,200
+5,GET,5.072716,69.115,200
+2,GET,5.085297,75.085,200
+6,GET,5.082685,80.77,200
+4,POST,5.098286,73.314,201
+9,GET,5.099661,75.042,200
+8,POST,5.125853,67.088,201
+3,POST,5.124162,73.532,201
+7,POST,5.115609,83.482,201
+0,POST,5.139999,66.096,201
+5,POST,5.141835,69.476,201
+1,GET,5.134586,81.118,200
+6,POST,5.163459,66.029,201
+2,POST,5.160386,70.806,201
+4,GET,5.171605,65.87,200
+9,POST,5.174706,65.167,201
+8,GET,5.192943,68.261,200
+3,GET,5.197697,70.302,200
+7,GET,5.199094,71.221,200
+0,GET,5.206099,75.282,200
+5,GET,5.211315,75.573,200
+1,GET,5.215707,80.651,200
+6,GET,5.22949,73.44,200
+2,GET,5.231195,80.707,200
+4,GET,5.237478,76.928,200
+9,GET,5.239876,84.926,200
+8,GET,5.261207,81.611,200
+3,GET,5.268052,80.108,200
+7,GET,5.270369,85.545,200
+0,GET,5.281385,85.655,200
+5,GET,5.286892,86.919,200
+1,GET,5.296363,84.441,200
+6,GET,5.302934,83.158,200
+2,GET,5.311905,77.692,200
+4,GET,5.314412,82.163,200
+9,GET,5.324806,81.258,200
+8,GET,5.342822,68.896,200
+3,GET,5.348163,71.282,200
+7,GET,5.355918,65.272,200
+0,GET,5.367045,61.684,200
+5,GET,5.373814,62.965,200
+1,GET,5.380808,59.944,200
+6,GET,5.386095,63.311,200
+2,GET,5.389601,61.655,200
+4,GET,5.396579,63.902,200
+9,GET,5.406067,66.045,200
+8,GET,5.411723,64.964,200
+3,GET,5.41945,67.795,200
+7,GET,5.421193,67.621,200
+0,GET,5.428738,70.119,200
+5,GET,5.436783,68.122,200
+1,POST,5.440756,65.091,201
+6,GET,5.44941,64.155,200
+4,POST,5.460488,54.634,201
+2,GET,5.451261,66.447,200
+9,GET,5.472116,55.689,200
+8,POST,5.476691,59.869,201
+3,POST,5.487248,52.745,201
+7,POST,5.488818,51.997,201
+0,POST,5.49886,48.508,201
+1,GET,5.50585,48.911,200
+4,GET,5.515125,42.155,200
+5,POST,5.504909,54.684,201
+6,POST,5.513572,46.577,201
+2,POST,5.517711,43.606,201
+9,POST,5.527809,48.54,201
+3,GET,5.539996,48.936,200
+8,GET,5.536563,54.336,200
+7,GET,5.540818,52.883,200
+0,GET,5.547374,49.318,200
+1,GET,5.554764,51.666,200
+4,GET,5.557285,54.339,200
+5,GET,5.559597,54.887,200
+2,GET,5.561328,56.935,200
+6,GET,5.560151,60.162,200
+9,GET,5.576351,64.195,200
+3,GET,5.588935,58.132,200
+8,GET,5.590902,58.457,200
+0,GET,5.596695,54.048,200
+7,GET,5.593705,59.466,200
+1,GET,5.606433,55.794,200
+4,GET,5.611627,56.268,200
+5,GET,5.614489,55.792,200
+2,GET,5.618268,54.955,200
+6,GET,5.620316,58.207,200
+9,GET,5.64055,61.031,200
+3,GET,5.647071,62.513,200
+8,GET,5.649361,62.585,200
+0,GET,5.650748,64.8,200
+1,GET,5.662234,56.806,200
+7,GET,5.653173,72.257,200
+4,GET,5.667899,62.953,200
+5,GET,5.670284,63.397,200
+2,GET,5.673226,62.685,200
+6,GET,5.678526,63.443,200
+9,GET,5.701584,56.958,200
+8,GET,5.711949,52.944,200
+3,GET,5.709587,57.757,200
+1,POST,5.719043,49.452,201
+0,GET,5.715552,54.606,200
+7,GET,5.725435,53.204,200
+4,POST,5.730855,51.905,201
+5,GET,5.733685,51.392,200
+2,GET,5.735915,51.848,200
+6,GET,5.741972,49.167,200
+9,GET,5.758545,54.546,200
+8,POST,5.764897,49.471,201
+3,POST,5.767348,51.509,201
+1,GET,5.7685,52.857,200
+0,POST,5.77016,52.675,201
+7,POST,5.778642,46.186,201
+5,POST,5.785081,50.754,201
+4,GET,5.782764,54.435,200
+2,POST,5.787776,50.997,201
+6,POST,5.791142,49.545,201
+9,POST,5.813094,48.344,201
+8,GET,5.814372,52.37,200
+3,GET,5.81886,57.483,200
+1,GET,5.82136,68.977,200
+7,GET,5.824831,67.836,200
+0,GET,5.822838,72.408,200
+5,GET,5.835853,73.891,200
+4,GET,5.837203,76.214,200
+2,GET,5.838777,82.067,200
+6,GET,5.84069,82.89,200
+9,GET,5.861443,81.335,200
+8,GET,5.866747,82.133,200
+3,GET,5.87635,78.893,200
+1,GET,5.890341,72.298,200
+7,GET,5.892672,72.228,200
+0,GET,5.895249,79.082,200
+5,GET,5.909747,66.621,200
+4,GET,5.91342,67.558,200
+2,GET,5.920847,64.308,200
+6,GET,5.923583,67.921,200
+9,GET,5.942782,62.81,200
+8,GET,5.948886,60.558,200
+3,GET,5.955247,57.585,200
+1,GET,5.962643,61.27,200
+7,GET,5.964904,63.675,200
+0,GET,5.974335,58.481,200
+5,GET,5.976373,61.515,200
+4,GET,5.980983,68.22,200
+2,GET,5.985158,69.843,200
+6,GET,5.991507,72.053,200
+9,GET,6.005595,74.026,200
+8,GET,6.009449,71.862,200
+3,GET,6.012838,74.432,200
+7,GET,6.028589,68.309,200
+1,POST,6.023917,74.846,201
+0,GET,6.032855,71.074,200
+5,GET,6.037894,68.582,200
+2,GET,6.055005,61.223,200
+4,POST,6.049206,68.322,201
+6,GET,6.063564,61.322,200
+9,GET,6.079625,61.604,200
+8,POST,6.081314,61.469,201
+7,POST,6.096901,48.77,201
+3,POST,6.087274,59.993,201
+1,GET,6.098767,55.167,200
+0,POST,6.103933,51.553,201
+5,POST,6.106484,51.149,201
+2,POST,6.116231,44.0,201
+4,GET,6.117538,49.318,200
+6,POST,6.124889,46.948,201
+9,POST,6.141233,39.177,201
+8,GET,6.142787,41.931,200
+7,GET,6.145675,45.59,200
+1,GET,6.153939,41.151,200
+3,GET,6.147269,57.268,200
+0,GET,6.155492,51.788,200
+5,GET,6.157636,57.787,200
+2,GET,6.160235,59.885,200
+4,GET,6.166859,62.268,200
+6,GET,6.171853,65.904,200
+9,GET,6.180415,68.954,200
+8,GET,6.184722,66.611,200
+7,GET,6.191276,67.952,200
+3,GET,6.204542,84.382,200
+1,GET,6.1951,97.833,200
+0,GET,6.207283,93.886,200
+5,GET,6.215428,87.971,200
+2,GET,6.220158,95.088,200
+4,GET,6.229131,91.863,200
+6,GET,6.237761,97.037,200
+9,GET,6.249374,146.755,200
+8,GET,6.251336,148.479,200
+7,GET,6.259232,152.124,200
+3,GET,6.288928,124.535,200
+1,GET,6.292937,131.089,200
+0,GET,6.301174,128.991,200
+5,GET,6.303404,187.381,200
+2,GET,6.315269,178.648,200
+4,GET,6.320997,181.701,200
+6,GET,6.334802,185.202,200
+9,GET,6.396133,130.296,200
+8,GET,6.39982,129.2,200
+7,GET,6.411413,181.218,200
+3,GET,6.413468,181.411,200
+1,POST,6.42403,179.385,201
+0,GET,6.430168,180.916,200
+5,GET,6.490789,128.123,200
+2,GET,6.493922,127.072,200
+4,POST,6.502702,129.267,201
+6,GET,6.520009,116.952,200
+9,GET,6.526435,167.137,200
+8,POST,6.529024,167.404,201
+7,POST,6.592638,106.725,201
+3,POST,6.594883,114.317,201
+1,GET,6.603418,113.745,200
+0,POST,6.611088,107.819,201
+5,POST,6.618916,105.485,201
+2,POST,6.620998,105.481,201
+6,POST,6.636965,96.807,201
+4,GET,6.631973,105.588,200
+8,GET,6.696433,47.546,200
+9,POST,6.693577,100.657,201
+7,GET,6.699365,97.408,200
+3,GET,6.709204,98.578,200
+1,GET,6.717168,104.145,200
+0,GET,6.718911,104.471,200
+5,GET,6.724404,166.522,200
+2,GET,6.726482,171.852,200
+6,GET,6.733776,167.264,200
+4,GET,6.737565,176.564,200
+8,GET,6.743983,172.186,200
+9,GET,6.794241,138.917,200
+7,GET,6.796779,193.662,200
+3,GET,6.807785,185.293,200
+0,GET,6.823386,189.307,200
+1,GET,6.821321,194.617,200
+2,GET,6.898348,131.616,200
+5,GET,6.890931,191.594,200
+6,GET,6.901044,186.928,200
+4,GET,6.914133,186.91,200
+8,GET,6.916172,187.005,200
+9,GET,6.933162,182.796,200
+7,GET,6.990446,132.02,200
+3,GET,6.993081,136.642,200
+1,GET,7.015942,122.238,200
+0,GET,7.0127,128.267,200
+5,GET,7.082529,113.264,200
+2,GET,7.02997,167.455,200
+4,GET,7.101048,100.69,200
+6,GET,7.087978,115.793,200
+8,GET,7.103181,114.007,200
+9,GET,7.115963,115.299,200
+7,GET,7.122476,113.779,200
+1,POST,7.138183,152.958,201
+3,GET,7.129728,162.239,200
+0,GET,7.140971,152.632,200
+5,GET,7.195797,104.603,200
+2,GET,7.197428,107.592,200
+4,POST,7.201741,108.662,201
+6,GET,7.203776,112.925,200
+8,POST,7.217192,105.801,201
+9,GET,7.231269,102.314,200
+7,POST,7.236262,98.545,201
+1,GET,7.291145,48.295,200
+3,POST,7.29197,49.229,201
+0,POST,7.293605,48.856,201
+5,POST,7.300403,47.663,201
+2,POST,7.305025,47.615,201
+6,POST,7.316705,43.169,201
+4,GET,7.310406,51.375,200
+8,GET,7.322996,44.945,200
+7,GET,7.33481,44.245,200
+9,POST,7.333588,46.868,201
+1,GET,7.339446,46.284,200
+0,GET,7.342464,49.925,200
+3,GET,7.341203,53.0,200
+5,GET,7.34807,50.263,200
+2,GET,7.352643,57.94,200
+6,GET,7.359881,52.168,200
+4,GET,7.361785,57.994,200
+8,GET,7.367945,59.201,200
+7,GET,7.37906,65.181,200
+9,GET,7.380458,67.158,200
+1,GET,7.385734,69.587,200
+0,GET,7.392397,70.199,200
+3,GET,7.394206,71.691,200
+5,GET,7.398338,79.776,200
+2,GET,7.410587,75.997,200
+6,GET,7.412053,86.288,200
+4,GET,7.419783,87.408,200
+8,GET,7.427149,83.538,200
+7,GET,7.444292,73.089,200
+1,GET,7.455324,68.794,200
+9,GET,7.44762,78.865,200
+0,GET,7.4626,73.116,200
+3,GET,7.4659,78.467,200
+5,GET,7.478118,82.038,200
+2,GET,7.486587,87.108,200
+6,GET,7.498344,86.516,200
+4,GET,7.507229,79.369,200
+8,GET,7.510691,84.128,200
+7,GET,7.517424,83.987,200
+1,POST,7.524122,79.621,201
+9,GET,7.526489,85.141,200
+0,GET,7.53572,81.347,200
+3,GET,7.544372,82.31,200
+5,GET,7.56016,77.244,200
+2,GET,7.573698,71.075,200
+6,GET,7.584863,66.607,200
+4,POST,7.586601,66.445,201
+8,POST,7.594841,59.297,201
+7,POST,7.601414,56.215,201
+1,GET,7.603746,61.458,200
+9,GET,7.611634,55.088,200
+0,POST,7.61707,56.089,201
+3,POST,7.626686,53.577,201
+5,POST,7.637407,52.464,201
+6,POST,7.651473,45.913,201
+8,GET,7.65414,44.151,200
+2,POST,7.644777,54.511,201
+4,GET,7.653049,48.655,200
+7,GET,7.657632,57.453,200
+9,POST,7.666725,49.746,201
+1,GET,7.665208,53.35,200
+0,GET,7.673163,60.033,200
+3,GET,7.680266,57.65,200
+5,GET,7.689876,60.38,200
+6,GET,7.69739,59.858,200
+2,GET,7.69929,67.768,200
+8,GET,7.698294,75.702,200
+4,GET,7.701708,77.762,200
+7,GET,7.715088,66.11,200
+9,GET,7.716475,73.871,200
+1,GET,7.718561,74.171,200
+0,GET,7.7332,74.161,200
+3,GET,7.73792,76.965,200
+6,GET,7.757251,67.173,200
+5,GET,7.750258,75.25,200
+2,GET,7.767072,65.962,200
+8,GET,7.774,61.711,200
+4,GET,7.779473,61.55,200
+7,GET,7.781201,67.7,200
+9,GET,7.79035,62.599,200
+1,GET,7.792734,71.982,200
+0,GET,7.80737,67.589,200
+3,GET,7.814889,67.23,200
+5,GET,7.82551,59.539,200
+6,GET,7.824427,62.63,200
+2,GET,7.833037,63.97,200
+8,GET,7.835715,70.74,200
+4,GET,7.841027,68.1,200
+7,GET,7.848906,65.069,200
+9,GET,7.852952,71.439,200
+1,POST,7.86472,67.148,201
+0,GET,7.874962,64.402,200
+3,GET,7.882123,59.07,200
+5,GET,7.885054,63.92,200
+8,POST,7.906458,47.07,201
+6,GET,7.887059,69.355,200
+2,GET,7.897011,62.002,200
+4,POST,7.90913,51.435,201
+7,POST,7.913978,56.927,201
+9,GET,7.924395,59.022,200
+1,GET,7.931872,56.558,200
+0,POST,7.939368,54.147,201
+3,POST,7.941197,55.162,201
+8,GET,7.953531,45.341,200
+6,POST,7.956417,43.809,201
+5,POST,7.948977,52.378,201
+2,POST,7.959016,45.673,201
+4,GET,7.960569,54.233,200
+7,GET,7.970908,52.451,200
+9,POST,7.983422,48.808,201
+1,GET,7.988436,46.797,200
+0,GET,7.99352,43.817,200
+3,GET,7.996362,48.699,200
+8,GET,7.998876,48.172,200
+6,GET,8.000229,56.451,200
+5,GET,8.001358,57.422,200
+2,GET,8.004692,61.492,200
+4,GET,8.014806,64.75,200
+7,GET,8.023363,65.251,200
+9,GET,8.032233,59.526,200
+1,GET,8.035236,65.356,200
+0,GET,8.03734,65.16,200
+3,GET,8.045065,65.965,200
+8,GET,8.047052,66.511,200
+6,GET,8.056684,65.902,200
+5,GET,8.058784,68.5,200
+2,GET,8.066188,69.625,200
+4,GET,8.07956,69.81,200
+7,GET,8.088617,62.065,200
+9,GET,8.091763,69.276,200
+0,GET,8.102503,60.451,200
+1,GET,8.100597,64.669,200
+3,GET,8.111033,56.477,200
+8,GET,8.113567,62.979,200
+6,GET,8.122589,61.361,200
+5,GET,8.127295,60.38,200
+2,GET,8.135816,67.38,200
+4,GET,8.149374,69.429,200
+7,GET,8.150686,78.966,200
+9,GET,8.161043,70.661,200
+0,GET,8.162959,77.567,200
+1,POST,8.165269,77.714,201
+3,GET,8.167513,80.421,200
+8,POST,8.17655,72.538,201
+6,GET,8.183954,71.66,200
+5,GET,8.187694,78.574,200
+2,GET,8.203199,65.504,200
+9,GET,8.231707,50.968,200
+4,POST,8.218806,69.628,201
+7,POST,8.229655,61.567,201
+0,POST,8.240532,51.668,201
+3,POST,8.247937,53.951,201
+1,GET,8.242986,61.406,200
+8,GET,8.249092,62.054,200
+6,POST,8.255624,70.211,201
+4,GET,8.288437,39.021,200
+2,POST,8.26873,60.06,201
+9,POST,8.282679,48.02,201
+5,POST,8.266271,65.868,201
+7,GET,8.291224,52.473,200
+0,GET,8.292203,54.399,200
+3,GET,8.301895,54.357,200
+1,GET,8.304396,56.694,200
+8,GET,8.311151,60.063,200
+6,GET,8.325838,58.582,200
+4,GET,8.327461,59.175,200
+2,GET,8.328792,59.062,200
+9,GET,8.330703,59.613,200
+5,GET,8.33214,69.41,200
+7,GET,8.343702,60.905,200
+0,GET,8.346606,60.737,200
+3,GET,8.356257,59.373,200
+1,GET,8.361095,62.226,200
+8,GET,8.371217,63.038,200
+6,GET,8.384424,52.835,200
+4,GET,8.38664,57.842,200
+2,GET,8.387857,58.105,200
+9,GET,8.390319,61.633,200
+5,GET,8.401554,52.888,200
+7,GET,8.40461,57.572,200
+0,GET,8.407346,57.527,200
+3,GET,8.415634,58.61,200
+1,GET,8.423324,56.951,200
+8,GET,8.434259,54.536,200
+6,GET,8.437263,55.075,200
+4,GET,8.444486,49.682,200
+2,GET,8.445965,54.585,200
+9,GET,8.451955,55.737,200
+5,GET,8.454446,56.166,200
+7,GET,8.462186,51.365,200
+0,GET,8.464876,61.597,200
+3,GET,8.474248,60.078,200
+1,POST,8.480277,62.684,201
+8,POST,8.488798,60.437,201
+4,POST,8.494172,58.25,201
+6,GET,8.49234,63.582,200
+2,GET,8.500553,64.07,200
+5,GET,8.510616,56.612,200
+9,GET,8.507695,69.574,200
+7,POST,8.513552,69.224,201
+0,POST,8.526476,62.032,201
+3,POST,8.53433,63.749,201
+1,GET,8.542965,64.14,200
+8,GET,8.549237,62.07,200
+6,POST,8.555926,63.42,201
+4,GET,8.552425,72.636,200
+2,POST,8.564627,70.135,201
+5,POST,8.567232,75.413,201
+9,POST,8.577273,75.839,201
+7,GET,8.582779,73.431,200
+0,GET,8.588514,84.961,200
+3,GET,8.598082,92.087,200
+1,GET,8.607109,88.227,200
+8,GET,8.611311,95.146,200
+6,GET,8.619349,94.112,200
+4,GET,8.625064,94.284,200
+2,GET,8.634769,87.522,200
+5,GET,8.64265,94.178,200
+9,GET,8.653115,97.763,200
+7,GET,8.656214,98.069,200
+0,GET,8.673484,88.288,200
+3,GET,8.690174,82.627,200
+1,GET,8.69534,79.421,200
+8,GET,8.70646,70.969,200
+6,GET,8.713464,72.205,200
+4,GET,8.719351,75.202,200
+2,GET,8.722294,77.672,200
+5,GET,8.736833,76.441,200
+9,GET,8.750881,67.822,200
+7,GET,8.754287,74.11,200
+0,GET,8.761775,73.599,200
+3,GET,8.772805,71.19,200
+1,GET,8.774765,71.473,200
+8,GET,8.777433,72.659,200
+6,GET,8.785675,76.318,200
+4,GET,8.794559,72.233,200
+2,GET,8.799972,68.941,200
+5,GET,8.81328,66.777,200
+9,GET,8.818708,66.666,200
+7,GET,8.828402,69.332,200
+0,GET,8.835378,68.355,200
+1,POST,8.846246,71.777,201
+8,POST,8.850099,69.207,201
+3,GET,8.843998,76.569,200
+6,GET,8.861996,65.621,200
+4,POST,8.866795,63.262,201
+2,GET,8.868915,78.364,200
+5,GET,8.880059,72.029,200
+9,GET,8.885378,80.01,200
+7,POST,8.89774,68.983,201
+0,POST,8.903738,65.739,201
+1,GET,8.918035,63.098,200
+8,GET,8.919309,64.238,200
+3,POST,8.920571,65.789,201
+4,GET,8.930061,68.197,200
+6,POST,8.927622,81.324,201
+7,GET,8.966728,44.116,200
+9,POST,8.965392,46.527,201
+2,POST,8.947283,65.448,201
+5,POST,8.952094,61.381,201
+0,GET,8.96948,54.841,200
+1,GET,8.981141,48.249,200
+8,GET,8.983551,48.224,200
+3,GET,8.986364,47.947,200
+4,GET,8.998261,50.968,200
+6,GET,9.008958,58.101,200
+7,GET,9.010847,62.67,200
+9,GET,9.011922,64.142,200
+2,GET,9.012733,66.685,200
+5,GET,9.013477,74.698,200
+8,GET,9.031779,63.432,200
+0,GET,9.024326,73.866,200
+1,GET,9.029396,71.171,200
+3,GET,9.034315,76.44,200
+4,GET,9.049234,68.341,200
+6,GET,9.067063,64.405,200
+7,GET,9.07352,64.562,200
+9,GET,9.076068,63.641,200
+2,GET,9.079421,67.102,200
+8,GET,9.095214,53.156,200
+0,GET,9.098195,57.874,200
+5,GET,9.08818,70.102,200
+1,GET,9.100571,65.729,200
+3,GET,9.11076,58.901,200
+4,GET,9.117578,62.93,200
+6,GET,9.131473,61.377,200
+7,GET,9.138087,59.551,200
+9,GET,9.139712,61.668,200
+2,GET,9.146525,61.797,200
+8,POST,9.148374,62.689,201
+0,GET,9.156072,56.922,200
+5,GET,9.158284,57.382,200
+1,POST,9.166303,56.241,201
+3,GET,9.169664,64.546,200
+4,POST,9.180513,56.305,201
+6,GET,9.192854,61.368,200
+7,POST,9.19764,57.942,201
+9,GET,9.201384,61.23,200
+2,GET,9.208327,62.434,200
+0,POST,9.213002,58.983,201
+8,GET,9.211065,62.791,200
+5,GET,9.21567,73.936,200
+3,POST,9.234214,59.473,201
+1,GET,9.222548,76.38,200
+4,GET,9.236822,79.736,200
+6,POST,9.254226,78.25,201
+7,GET,9.255586,77.844,200
+9,POST,9.262619,75.47,201
+0,GET,9.271988,70.503,200
+2,POST,9.270766,74.618,201
+8,GET,9.27386,77.775,200
+5,POST,9.289611,70.64,201
+3,GET,9.293693,72.625,200
+1,GET,9.298934,71.452,200
+4,GET,9.316562,64.653,200
+6,GET,9.332479,66.033,200
+7,GET,9.33344,67.006,200
+9,GET,9.338094,71.59,200
+0,GET,9.342496,72.453,200
+2,GET,9.345388,74.207,200
+8,GET,9.351639,71.18,200
+5,GET,9.360257,75.623,200
+3,GET,9.366323,74.472,200
+1,GET,9.370394,75.365,200
+4,GET,9.381219,73.259,200
+6,GET,9.398516,73.86,200
+7,GET,9.400451,73.322,200
+9,GET,9.409689,71.316,200
+0,GET,9.414952,73.02,200
+2,GET,9.419599,72.196,200
+8,GET,9.422824,74.762,200
+5,GET,9.435883,63.544,200
+3,GET,9.440799,66.024,200
+1,GET,9.445762,67.488,200
+4,GET,9.454482,60.905,200
+6,GET,9.47238,56.713,200
+7,GET,9.473776,61.051,200
+0,GET,9.487976,50.113,200
+9,GET,9.481012,63.769,200
+2,GET,9.491798,56.55,200
+8,POST,9.49759,52.109,201
+3,GET,9.506826,52.099,200
+1,POST,9.513254,48.439,201
+5,GET,9.49943,63.184,200
+4,POST,9.51539,49.746,201
+6,GET,9.529098,51.628,200
+7,POST,9.53483,52.268,201
+9,GET,9.544784,46.165,200
+0,POST,9.538093,53.808,201
+2,GET,9.548351,51.485,200
+8,GET,9.549701,55.898,200
+1,GET,9.561696,46.557,200
+3,POST,9.558928,50.36,201
+5,GET,9.562619,56.209,200
+4,GET,9.56514,62.655,200
+6,POST,9.580729,62.516,201
+9,POST,9.590952,57.914,201
+7,GET,9.5871,65.626,200
+2,POST,9.599843,63.164,201
+0,GET,9.591904,74.61,200
+1,GET,9.608256,69.641,200
+8,GET,9.605603,74.147,200
+5,POST,9.618831,67.667,201
+3,GET,9.609293,79.45,200
+4,GET,9.627798,72.604,200
+6,GET,9.643248,75.985,200
+7,GET,9.652729,70.299,200
+9,GET,9.64887,83.781,200
+2,GET,9.66301,79.717,200
+0,GET,9.666518,87.083,200
+1,GET,9.6779,80.193,200
+8,GET,9.679754,81.682,200
+5,GET,9.686503,87.581,200
+3,GET,9.688756,89.619,200
+4,GET,9.700407,95.829,200
+6,GET,9.719237,93.238,200
+7,GET,9.723032,91.496,200
+9,GET,9.732655,83.836,200
+1,GET,9.758096,66.78,200
+2,GET,9.74273,87.365,200
+8,GET,9.76144,71.041,200
+0,GET,9.753606,83.414,200
+5,GET,9.774089,68.921,200
+3,GET,9.778384,71.665,200
+4,GET,9.796271,70.118,200
+6,GET,9.812479,66.106,200
+1,POST,9.824879,58.151,201
+7,GET,9.814535,69.482,200
+9,GET,9.816494,70.003,200
+2,GET,9.830099,68.665,200
+0,GET,9.837024,69.587,200
+8,POST,9.832484,76.865,201
+5,GET,9.843014,76.717,200
+3,GET,9.850053,79.51,200
+4,POST,9.866392,72.952,201
+7,POST,9.88402,57.419,201
+6,GET,9.878589,64.544,200
+1,GET,9.883034,69.749,200
+9,GET,9.8865,68.544,200
+2,GET,9.898805,63.462,200
+0,POST,9.906618,57.293,201
+8,GET,9.909354,67.593,200
+3,POST,9.929567,48.628,201
+5,GET,9.919735,60.688,200
+4,GET,9.939348,63.627,200
+6,POST,9.943136,61.802,201
+7,GET,9.941442,67.069,200
+9,POST,9.955047,61.822,201
+1,GET,9.952786,64.239,200
+2,POST,9.96227,61.257,201
+0,GET,9.963913,61.287,200
+3,GET,9.978198,49.563,200
+5,POST,9.980426,47.548,201
+8,GET,9.97695,55.011,200
diff --git a/evidence/http-resources.json b/evidence/http-resources.json
new file mode 100644
index 00000000..658d7ede
--- /dev/null
+++ b/evidence/http-resources.json
@@ -0,0 +1,110 @@
+[
+ {
+ "elapsed_s": 1.946,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "91.99%",
+ "Container": "708c0b14bcabe0bb0be47442021e3d8ec55216233ab670f9b65f29ebe87e86fd",
+ "ID": "708c0b14bcab",
+ "MemPerc": "18.54%",
+ "MemUsage": "47.47MiB / 256MiB",
+ "Name": "mtusi2026lab2-api-1",
+ "NetIO": "3.03MB / 2.85MB",
+ "PIDs": "3"
+ },
+ {
+ "elapsed_s": 1.946,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "2.44%",
+ "Container": "ac5c6c65019c906f0a2284b60a2bd70967d8a7e43525195fcaece09eef0c72d9",
+ "ID": "ac5c6c65019c",
+ "MemPerc": "12.76%",
+ "MemUsage": "8.164MiB / 64MiB",
+ "Name": "mtusi2026lab2-cache-1",
+ "NetIO": "52.7kB / 82kB",
+ "PIDs": "6"
+ },
+ {
+ "elapsed_s": 1.946,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "19.95%",
+ "Container": "85dd609cc3ea3334e57ca89675de2511a61335046299ec29594c78ad72cedec0",
+ "ID": "85dd609cc3ea",
+ "MemPerc": "9.77%",
+ "MemUsage": "25MiB / 256MiB",
+ "Name": "mtusi2026lab2-db-1",
+ "NetIO": "483kB / 2.76MB",
+ "PIDs": "11"
+ },
+ {
+ "elapsed_s": 5.872,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "97.06%",
+ "Container": "708c0b14bcabe0bb0be47442021e3d8ec55216233ab670f9b65f29ebe87e86fd",
+ "ID": "708c0b14bcab",
+ "MemPerc": "18.71%",
+ "MemUsage": "47.89MiB / 256MiB",
+ "Name": "mtusi2026lab2-api-1",
+ "NetIO": "32MB / 31.7MB",
+ "PIDs": "3"
+ },
+ {
+ "elapsed_s": 5.872,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "2.53%",
+ "Container": "ac5c6c65019c906f0a2284b60a2bd70967d8a7e43525195fcaece09eef0c72d9",
+ "ID": "ac5c6c65019c",
+ "MemPerc": "12.95%",
+ "MemUsage": "8.289MiB / 64MiB",
+ "Name": "mtusi2026lab2-cache-1",
+ "NetIO": "135kB / 218kB",
+ "PIDs": "6"
+ },
+ {
+ "elapsed_s": 5.872,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "22.76%",
+ "Container": "85dd609cc3ea3334e57ca89675de2511a61335046299ec29594c78ad72cedec0",
+ "ID": "85dd609cc3ea",
+ "MemPerc": "9.89%",
+ "MemUsage": "25.31MiB / 256MiB",
+ "Name": "mtusi2026lab2-db-1",
+ "NetIO": "1.14MB / 24MB",
+ "PIDs": "11"
+ },
+ {
+ "elapsed_s": 9.786,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "100.05%",
+ "Container": "708c0b14bcabe0bb0be47442021e3d8ec55216233ab670f9b65f29ebe87e86fd",
+ "ID": "708c0b14bcab",
+ "MemPerc": "18.68%",
+ "MemUsage": "47.83MiB / 256MiB",
+ "Name": "mtusi2026lab2-api-1",
+ "NetIO": "58.7MB / 58.4MB",
+ "PIDs": "3"
+ },
+ {
+ "elapsed_s": 9.786,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "1.82%",
+ "Container": "ac5c6c65019c906f0a2284b60a2bd70967d8a7e43525195fcaece09eef0c72d9",
+ "ID": "ac5c6c65019c",
+ "MemPerc": "12.95%",
+ "MemUsage": "8.289MiB / 64MiB",
+ "Name": "mtusi2026lab2-cache-1",
+ "NetIO": "189kB / 303kB",
+ "PIDs": "6"
+ },
+ {
+ "elapsed_s": 9.786,
+ "BlockIO": "0B / 0B",
+ "CPUPerc": "23.73%",
+ "Container": "85dd609cc3ea3334e57ca89675de2511a61335046299ec29594c78ad72cedec0",
+ "ID": "85dd609cc3ea",
+ "MemPerc": "9.93%",
+ "MemUsage": "25.43MiB / 256MiB",
+ "Name": "mtusi2026lab2-db-1",
+ "NetIO": "1.89MB / 50MB",
+ "PIDs": "11"
+ }
+]
diff --git a/evidence/http-summary.json b/evidence/http-summary.json
new file mode 100644
index 00000000..561b7293
--- /dev/null
+++ b/evidence/http-summary.json
@@ -0,0 +1,17 @@
+{
+ "warmup_s": 2,
+ "duration_s": 10.033,
+ "concurrency": 10,
+ "profile": "closed-loop: 1 write then 4 history reads per worker; 1000-character messages",
+ "requests": 1368,
+ "success_rps": 136.35,
+ "error_fraction": 0.0,
+ "p50_ms": 66.607,
+ "p95_ms": 122.238,
+ "p99_ms": 181.218,
+ "statuses": {
+ "200": 1088,
+ "201": 280
+ },
+ "resource_source": "Docker stats samples; CPU percent is host-core percentage, memory is cgroup working set"
+}
diff --git a/evidence/index-restore.json b/evidence/index-restore.json
new file mode 100644
index 00000000..43042744
--- /dev/null
+++ b/evidence/index-restore.json
@@ -0,0 +1,3948 @@
+{
+ "version": "PostgreSQL 17.11 (Debian 17.11-1.pgdg12+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit",
+ "rows": 120000,
+ "chat_sizes": [
+ 100000,
+ 15000,
+ 5000
+ ],
+ "repeats": 5,
+ "plans": [
+ {
+ "index": "primary_only",
+ "query": "keyset",
+ "execution_ms": [
+ 19.717,
+ 73.474,
+ 13.974,
+ 13.225,
+ 74.636
+ ],
+ "median_ms": 19.717,
+ "plans": [
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 6317.68,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 14.917,
+ "Actual Total Time": 19.544,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 10356.73,
+ "Plan Rows": 34668,
+ "Plan Width": 225,
+ "Actual Startup Time": 14.915,
+ "Actual Total Time": 19.537,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5311.82,
+ "Total Cost": 5355.16,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 11.424,
+ "Actual Total Time": 11.428,
+ "Actual Rows": 44,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4736.0,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 3.461,
+ "Actual Total Time": 9.44,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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": 19.717
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 6317.68,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.713,
+ "Actual Total Time": 73.441,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 10356.73,
+ "Plan Rows": 34668,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.711,
+ "Actual Total Time": 73.434,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5311.82,
+ "Total Cost": 5355.16,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 6.954,
+ "Actual Total Time": 6.956,
+ "Actual Rows": 40,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4736.0,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 3.649,
+ "Actual Total Time": 6.153,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.135,
+ "Triggers": [],
+ "Execution Time": 73.474
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 6317.68,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 11.211,
+ "Actual Total Time": 13.897,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 10356.73,
+ "Plan Rows": 34668,
+ "Plan Width": 225,
+ "Actual Startup Time": 11.209,
+ "Actual Total Time": 13.892,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5311.82,
+ "Total Cost": 5355.16,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 7.629,
+ "Actual Total Time": 7.632,
+ "Actual Rows": 44,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4736.0,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 3.991,
+ "Actual Total Time": 6.827,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.414,
+ "Triggers": [],
+ "Execution Time": 13.974
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 6317.68,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 10.389,
+ "Actual Total Time": 13.206,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 10356.73,
+ "Plan Rows": 34668,
+ "Plan Width": 225,
+ "Actual Startup Time": 10.388,
+ "Actual Total Time": 13.201,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5311.82,
+ "Total Cost": 5355.16,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 7.704,
+ "Actual Total Time": 7.706,
+ "Actual Rows": 44,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4736.0,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 4.052,
+ "Actual Total Time": 6.858,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.152,
+ "Triggers": [],
+ "Execution Time": 13.225
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 6317.68,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 71.8,
+ "Actual Total Time": 74.612,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6311.85,
+ "Total Cost": 10356.73,
+ "Plan Rows": 34668,
+ "Plan Width": 225,
+ "Actual Startup Time": 71.799,
+ "Actual Total Time": 74.607,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5311.82,
+ "Total Cost": 5355.16,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 47.208,
+ "Actual Total Time": 47.211,
+ "Actual Rows": 44,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 3891,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4736.0,
+ "Plan Rows": 17334,
+ "Plan Width": 225,
+ "Actual Startup Time": 43.141,
+ "Actual Total Time": 46.138,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.162,
+ "Triggers": [],
+ "Execution Time": 74.636
+ }
+ ]
+ },
+ {
+ "index": "primary_only",
+ "query": "offset",
+ "execution_ms": [
+ 128.966,
+ 184.693,
+ 110.659,
+ 178.235,
+ 171.559
+ ],
+ "median_ms": 171.559,
+ "plans": [
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21386.34,
+ "Total Cost": 21392.17,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 115.487,
+ "Actual Total Time": 124.548,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2595,
+ "Temp Written Blocks": 2961,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13219.1,
+ "Total Cost": 22912.44,
+ "Plan Rows": 83080,
+ "Plan Width": 225,
+ "Actual Startup Time": 78.595,
+ "Actual Total Time": 121.852,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2595,
+ "Temp Written Blocks": 2961,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12219.08,
+ "Total Cost": 12322.93,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 57.285,
+ "Actual Total Time": 63.136,
+ "Actual Rows": 23483,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 10288,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2595,
+ "Temp Written Blocks": 2961,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6728,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6632,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4486.0,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.012,
+ "Actual Total Time": 6.455,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.112,
+ "Triggers": [],
+ "Execution Time": 128.966
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21386.34,
+ "Total Cost": 21392.17,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 175.321,
+ "Actual Total Time": 183.158,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2368,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13219.1,
+ "Total Cost": 22912.44,
+ "Plan Rows": 83080,
+ "Plan Width": 225,
+ "Actual Startup Time": 73.494,
+ "Actual Total Time": 180.507,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2368,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12219.08,
+ "Total Cost": 12322.93,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 65.002,
+ "Actual Total Time": 70.766,
+ "Actual Rows": 23484,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 10024,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2368,
+ "Temp Written Blocks": 2963,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4486.0,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.031,
+ "Actual Total Time": 18.774,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.115,
+ "Triggers": [],
+ "Execution Time": 184.693
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21386.34,
+ "Total Cost": 21392.17,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 103.446,
+ "Actual Total Time": 108.434,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2495,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13219.1,
+ "Total Cost": 22912.44,
+ "Plan Rows": 83080,
+ "Plan Width": 225,
+ "Actual Startup Time": 65.872,
+ "Actual Total Time": 105.917,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2495,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12219.08,
+ "Total Cost": 12322.93,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 49.533,
+ "Actual Total Time": 56.887,
+ "Actual Rows": 23467,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 12328,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2495,
+ "Temp Written Blocks": 2963,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 4512,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4486.0,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.018,
+ "Actual Total Time": 6.581,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.124,
+ "Triggers": [],
+ "Execution Time": 110.659
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21386.34,
+ "Total Cost": 21392.17,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 168.071,
+ "Actual Total Time": 175.13,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2602,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13219.1,
+ "Total Cost": 22912.44,
+ "Plan Rows": 83080,
+ "Plan Width": 225,
+ "Actual Startup Time": 68.472,
+ "Actual Total Time": 172.41,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2602,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12219.08,
+ "Total Cost": 12322.93,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 63.676,
+ "Actual Total Time": 71.654,
+ "Actual Rows": 23499,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 11464,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2602,
+ "Temp Written Blocks": 2962,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 5368,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4486.0,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.011,
+ "Actual Total Time": 34.255,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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": 178.235
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21386.34,
+ "Total Cost": 21392.17,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 111.806,
+ "Actual Total Time": 169.057,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2610,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13219.1,
+ "Total Cost": 22912.44,
+ "Plan Rows": 83080,
+ "Plan Width": 225,
+ "Actual Startup Time": 72.626,
+ "Actual Total Time": 166.507,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2610,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12219.08,
+ "Total Cost": 12322.93,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 37.29,
+ "Actual Total Time": 43.569,
+ "Actual Rows": 23489,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 11072,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 3949,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2610,
+ "Temp Written Blocks": 2963,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 5768,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4486.0,
+ "Plan Rows": 41540,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.011,
+ "Actual Total Time": 6.339,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 3861,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.324,
+ "Triggers": [],
+ "Execution Time": 171.559
+ }
+ ]
+ },
+ {
+ "index": "chat_index",
+ "query": "keyset",
+ "execution_ms": [
+ 13.441,
+ 14.577,
+ 70.087,
+ 13.662,
+ 83.644
+ ],
+ "median_ms": 14.577,
+ "plans": [
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 6475.28,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.635,
+ "Actual Total Time": 13.414,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 10518.53,
+ "Plan Rows": 34704,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.633,
+ "Actual Total Time": 13.409,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5469.42,
+ "Total Cost": 5512.8,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 7.106,
+ "Actual Total Time": 7.114,
+ "Actual Rows": 34,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4893.0,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 4.085,
+ "Actual Total Time": 6.321,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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": 13.441
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 6475.28,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.733,
+ "Actual Total Time": 14.535,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 10518.53,
+ "Plan Rows": 34704,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.731,
+ "Actual Total Time": 14.529,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5469.42,
+ "Total Cost": 5512.8,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 7.013,
+ "Actual Total Time": 7.015,
+ "Actual Rows": 40,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4893.0,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 4.152,
+ "Actual Total Time": 6.279,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.23,
+ "Triggers": [],
+ "Execution Time": 14.577
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 6475.28,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 66.561,
+ "Actual Total Time": 69.897,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 10518.53,
+ "Plan Rows": 34704,
+ "Plan Width": 225,
+ "Actual Startup Time": 66.559,
+ "Actual Total Time": 69.891,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5469.42,
+ "Total Cost": 5512.8,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 63.233,
+ "Actual Total Time": 63.236,
+ "Actual Rows": 44,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4893.0,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 4.659,
+ "Actual Total Time": 62.023,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.323,
+ "Triggers": [],
+ "Execution Time": 70.087
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 6475.28,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 10.64,
+ "Actual Total Time": 13.635,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 10518.53,
+ "Plan Rows": 34704,
+ "Plan Width": 225,
+ "Actual Startup Time": 10.639,
+ "Actual Total Time": 13.63,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5469.42,
+ "Total Cost": 5512.8,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 7.67,
+ "Actual Total Time": 7.672,
+ "Actual Rows": 40,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4893.0,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 4.498,
+ "Actual Total Time": 6.888,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.254,
+ "Triggers": [],
+ "Execution Time": 13.662
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 6475.28,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 14.035,
+ "Actual Total Time": 83.613,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 6469.44,
+ "Total Cost": 10518.53,
+ "Plan Rows": 34704,
+ "Plan Width": 225,
+ "Actual Startup Time": 14.033,
+ "Actual Total Time": 83.6,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": 5469.42,
+ "Total Cost": 5512.8,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 9.531,
+ "Actual Total Time": 9.535,
+ "Actual Rows": 40,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory",
+ "Shared Hit Blocks": 4048,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "top-N heapsort",
+ "Sort Space Used": 37,
+ "Sort Space Type": "Memory"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4893.0,
+ "Plan Rows": 17352,
+ "Plan Width": 225,
+ "Actual Startup Time": 4.371,
+ "Actual Total Time": 8.113,
+ "Actual Rows": 10000,
+ "Actual Loops": 3,
+ "Filter": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Filter": 30000,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.212,
+ "Triggers": [],
+ "Execution Time": 83.644
+ }
+ ]
+ },
+ {
+ "index": "chat_index",
+ "query": "offset",
+ "execution_ms": [
+ 186.094,
+ 127.692,
+ 180.612,
+ 172.957,
+ 137.825
+ ],
+ "median_ms": 172.957,
+ "plans": [
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21570.35,
+ "Total Cost": 21576.18,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 179.759,
+ "Actual Total Time": 184.506,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2472,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13403.11,
+ "Total Cost": 23132.62,
+ "Plan Rows": 83390,
+ "Plan Width": 225,
+ "Actual Startup Time": 75.651,
+ "Actual Total Time": 181.264,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2472,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12403.09,
+ "Total Cost": 12507.33,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 67.613,
+ "Actual Total Time": 76.427,
+ "Actual Rows": 23427,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 13424,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2472,
+ "Temp Written Blocks": 2962,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6752,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 3472,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4643.0,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.011,
+ "Actual Total Time": 6.626,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.599,
+ "Triggers": [],
+ "Execution Time": 186.094
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21570.35,
+ "Total Cost": 21576.18,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 121.578,
+ "Actual Total Time": 125.884,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2429,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13403.11,
+ "Total Cost": 23132.62,
+ "Plan Rows": 83390,
+ "Plan Width": 225,
+ "Actual Startup Time": 75.407,
+ "Actual Total Time": 123.341,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2429,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12403.09,
+ "Total Cost": 12507.33,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 38.978,
+ "Actual Total Time": 47.258,
+ "Actual Rows": 23478,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 10584,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2429,
+ "Temp Written Blocks": 2962,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6248,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4643.0,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.036,
+ "Actual Total Time": 23.273,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.221,
+ "Triggers": [],
+ "Execution Time": 127.692
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21570.35,
+ "Total Cost": 21576.18,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 173.229,
+ "Actual Total Time": 178.848,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2366,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13403.11,
+ "Total Cost": 23132.62,
+ "Plan Rows": 83390,
+ "Plan Width": 225,
+ "Actual Startup Time": 66.691,
+ "Actual Total Time": 176.043,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2366,
+ "Temp Written Blocks": 2962,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12403.09,
+ "Total Cost": 12507.33,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 60.451,
+ "Actual Total Time": 69.222,
+ "Actual Rows": 23457,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 10080,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2366,
+ "Temp Written Blocks": 2962,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6752,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4643.0,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.009,
+ "Actual Total Time": 8.403,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.395,
+ "Triggers": [],
+ "Execution Time": 180.612
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21570.35,
+ "Total Cost": 21576.18,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 166.129,
+ "Actual Total Time": 171.345,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2699,
+ "Temp Written Blocks": 2960,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13403.11,
+ "Total Cost": 23132.62,
+ "Plan Rows": 83390,
+ "Plan Width": 225,
+ "Actual Startup Time": 73.732,
+ "Actual Total Time": 168.696,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2699,
+ "Temp Written Blocks": 2960,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12403.09,
+ "Total Cost": 12507.33,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 68.905,
+ "Actual Total Time": 75.136,
+ "Actual Rows": 23506,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 9592,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2699,
+ "Temp Written Blocks": 2960,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 8480,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 5568,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4643.0,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.009,
+ "Actual Total Time": 21.533,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.109,
+ "Triggers": [],
+ "Execution Time": 172.957
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 21570.35,
+ "Total Cost": 21576.18,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 129.959,
+ "Actual Total Time": 135.199,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2543,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Gather Merge",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 13403.11,
+ "Total Cost": 23132.62,
+ "Plan Rows": 83390,
+ "Plan Width": 225,
+ "Actual Startup Time": 88.783,
+ "Actual Total Time": 132.415,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Workers Planned": 2,
+ "Workers Launched": 2,
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2543,
+ "Temp Written Blocks": 2963,
+ "Plans": [
+ {
+ "Node Type": "Sort",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 12403.09,
+ "Total Cost": 12507.33,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 63.737,
+ "Actual Total Time": 71.064,
+ "Actual Rows": 23478,
+ "Actual Loops": 3,
+ "Sort Key": [
+ "created_at",
+ "id"
+ ],
+ "Sort Method": "external merge",
+ "Sort Space Used": 10512,
+ "Sort Space Type": "Disk",
+ "Shared Hit Blocks": 4106,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 2543,
+ "Temp Written Blocks": 2963,
+ "Workers": [
+ {
+ "Worker Number": 0,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6328,
+ "Sort Space Type": "Disk"
+ },
+ {
+ "Worker Number": 1,
+ "Sort Method": "external merge",
+ "Sort Space Used": 6816,
+ "Sort Space Type": "Disk"
+ }
+ ],
+ "Plans": [
+ {
+ "Node Type": "Seq Scan",
+ "Parent Relationship": "Outer",
+ "Parallel Aware": true,
+ "Async Capable": false,
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.0,
+ "Total Cost": 4643.0,
+ "Plan Rows": 41695,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.015,
+ "Actual Total Time": 26.824,
+ "Actual Rows": 33333,
+ "Actual Loops": 3,
+ "Filter": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Filter": 6667,
+ "Shared Hit Blocks": 4018,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "Local Hit Blocks": 0,
+ "Local Read Blocks": 0,
+ "Local Dirtied Blocks": 0,
+ "Local Written Blocks": 0,
+ "Temp Read Blocks": 0,
+ "Temp Written Blocks": 0,
+ "Workers": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "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.472,
+ "Triggers": [],
+ "Execution Time": 137.825
+ }
+ ]
+ },
+ {
+ "index": "compound",
+ "query": "keyset",
+ "execution_ms": [
+ 0.049,
+ 0.196,
+ 0.029,
+ 0.094,
+ 0.029
+ ],
+ "median_ms": 0.049,
+ "plans": [
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 0.42,
+ "Total Cost": 16.52,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.012,
+ "Actual Total Time": 0.035,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 13376.95,
+ "Plan Rows": 41523,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.011,
+ "Actual Total Time": 0.031,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Index Cond": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.049
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 0.42,
+ "Total Cost": 16.52,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.01,
+ "Actual Total Time": 0.112,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 13376.95,
+ "Plan Rows": 41523,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.01,
+ "Actual Total Time": 0.102,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Index Cond": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.083,
+ "Triggers": [],
+ "Execution Time": 0.196
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 0.42,
+ "Total Cost": 16.52,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.008,
+ "Actual Total Time": 0.02,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 13376.95,
+ "Plan Rows": 41523,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.007,
+ "Actual Total Time": 0.017,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Index Cond": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.063,
+ "Triggers": [],
+ "Execution Time": 0.029
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 0.42,
+ "Total Cost": 16.52,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.024,
+ "Actual Total Time": 0.064,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 13376.95,
+ "Plan Rows": 41523,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.023,
+ "Actual Total Time": 0.053,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Index Cond": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.216,
+ "Triggers": [],
+ "Execution Time": 0.094
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 0.42,
+ "Total Cost": 16.52,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.008,
+ "Actual Total Time": 0.02,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 13376.95,
+ "Plan Rows": 41523,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.007,
+ "Actual Total Time": 0.016,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Index Cond": "((chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:01:10+00'::timestamp with time zone, '696c0138-3d4f-bd16-e6b0-c1b6fff540ec'::uuid)))",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 6,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.052,
+ "Triggers": [],
+ "Execution Time": 0.029
+ }
+ ]
+ },
+ {
+ "index": "compound",
+ "query": "offset",
+ "execution_ms": [
+ 19.838,
+ 19.25,
+ 13.916,
+ 14.827,
+ 14.409
+ ],
+ "median_ms": 14.827,
+ "plans": [
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 11647.76,
+ "Total Cost": 11656.08,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 19.809,
+ "Actual Total Time": 19.82,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 16600.21,
+ "Plan Rows": 99764,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.011,
+ "Actual Total Time": 17.815,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Index Cond": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.1,
+ "Triggers": [],
+ "Execution Time": 19.838
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 11647.76,
+ "Total Cost": 11656.08,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 19.195,
+ "Actual Total Time": 19.208,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 16600.21,
+ "Plan Rows": 99764,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.069,
+ "Actual Total Time": 17.045,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Index Cond": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.44,
+ "Triggers": [],
+ "Execution Time": 19.25
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 11647.76,
+ "Total Cost": 11656.08,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 13.85,
+ "Actual Total Time": 13.892,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 16600.21,
+ "Plan Rows": 99764,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.032,
+ "Actual Total Time": 11.926,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Index Cond": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.218,
+ "Triggers": [],
+ "Execution Time": 13.916
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 11647.76,
+ "Total Cost": 11656.08,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 14.803,
+ "Actual Total Time": 14.812,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 16600.21,
+ "Plan Rows": 99764,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.018,
+ "Actual Total Time": 12.965,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Index Cond": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.234,
+ "Triggers": [],
+ "Execution Time": 14.827
+ },
+ {
+ "Plan": {
+ "Node Type": "Limit",
+ "Parallel Aware": false,
+ "Async Capable": false,
+ "Startup Cost": 11647.76,
+ "Total Cost": 11656.08,
+ "Plan Rows": 50,
+ "Plan Width": 225,
+ "Actual Startup Time": 14.375,
+ "Actual Total Time": 14.385,
+ "Actual Rows": 50,
+ "Actual Loops": 1,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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": "experiment_idx",
+ "Relation Name": "messages",
+ "Alias": "messages",
+ "Startup Cost": 0.42,
+ "Total Cost": 16600.21,
+ "Plan Rows": 99764,
+ "Plan Width": 225,
+ "Actual Startup Time": 0.028,
+ "Actual Total Time": 12.328,
+ "Actual Rows": 70050,
+ "Actual Loops": 1,
+ "Index Cond": "(chat_id = '64fbbeee-3c1b-b5be-9d4f-5bd05fe83171'::uuid)",
+ "Rows Removed by Index Recheck": 0,
+ "Shared Hit Blocks": 2754,
+ "Shared Read Blocks": 0,
+ "Shared Dirtied Blocks": 0,
+ "Shared Written Blocks": 0,
+ "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.187,
+ "Triggers": [],
+ "Execution Time": 14.409
+ }
+ ]
+ }
+ ],
+ "writes": [
+ {
+ "index": "primary_only",
+ "batch_rows": 5000,
+ "committed_ms": [
+ 194.955,
+ 130.708,
+ 105.758,
+ 112.982,
+ 107.794
+ ],
+ "median_ms": 112.982
+ },
+ {
+ "index": "chat_index",
+ "batch_rows": 5000,
+ "committed_ms": [
+ 134.971,
+ 163.012,
+ 176.464,
+ 132.247,
+ 119.119
+ ],
+ "median_ms": 134.971
+ },
+ {
+ "index": "compound",
+ "batch_rows": 5000,
+ "committed_ms": [
+ 165.151,
+ 123.352,
+ 125.609,
+ 140.445,
+ 145.072
+ ],
+ "median_ms": 140.445
+ }
+ ],
+ "snapshot": {
+ "counts": {
+ "users": 1,
+ "chats": 3,
+ "members": 3,
+ "messages": 120000,
+ "sessions": 0
+ },
+ "selected": [
+ [
+ "00007f59-a9d2-3b84-3ef6-091415782365",
+ "88255127-540c-95c6-cac6-18d9e4630a5b",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-109350",
+ "2026-01-01T00:01:49.350000+00:00"
+ ],
+ [
+ "0001e8fa-aaff-dcf0-e91a-76b3ce513a5a",
+ "88255127-540c-95c6-cac6-18d9e4630a5b",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-101333",
+ "2026-01-01T00:01:41.333000+00:00"
+ ],
+ [
+ "0001fe5c-dac5-95be-e3c2-98a08c99a1c5",
+ "88255127-540c-95c6-cac6-18d9e4630a5b",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-104987",
+ "2026-01-01T00:01:44.987000+00:00"
+ ],
+ [
+ "000209d4-d5f3-45da-b78b-66295ca75999",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-79772",
+ "2026-01-01T00:01:19.772000+00:00"
+ ],
+ [
+ "000251f9-16b9-e4e3-a885-72d4a8047563",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-16308",
+ "2026-01-01T00:00:16.308000+00:00"
+ ],
+ [
+ "0002b449-3bc2-28d4-c8a5-949664801557",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-29651",
+ "2026-01-01T00:00:29.651000+00:00"
+ ],
+ [
+ "000313b0-ff0e-d495-0396-6e648ab33022",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-76332",
+ "2026-01-01T00:01:16.332000+00:00"
+ ],
+ [
+ "000341d0-5544-f48f-fa05-f45f76dbc946",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-83651",
+ "2026-01-01T00:01:23.651000+00:00"
+ ],
+ [
+ "0003c8a7-b0d7-99c1-dabf-45599abb2dcf",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-3460",
+ "2026-01-01T00:00:03.460000+00:00"
+ ],
+ [
+ "00048192-4d3d-3489-843c-cdfe54d65984",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-53856",
+ "2026-01-01T00:00:53.856000+00:00"
+ ],
+ [
+ "0004b478-630d-6fc0-e9f7-10f8ef2f0ffb",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-15792",
+ "2026-01-01T00:00:15.792000+00:00"
+ ],
+ [
+ "0004e22f-10fc-ee50-40c6-a8fffc910cfc",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-60822",
+ "2026-01-01T00:01:00.822000+00:00"
+ ],
+ [
+ "00052d15-f4e7-d68b-269e-eeb7f90ab192",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-90960",
+ "2026-01-01T00:01:30.960000+00:00"
+ ],
+ [
+ "00061b8b-7e6c-7660-1881-a72e5c006355",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-53908",
+ "2026-01-01T00:00:53.908000+00:00"
+ ],
+ [
+ "00061f5e-d8e9-2727-ce0b-66d5c1f929c4",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-9014",
+ "2026-01-01T00:00:09.014000+00:00"
+ ],
+ [
+ "0007f005-203e-29ee-e42e-4f7bd8c8ce55",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-39009",
+ "2026-01-01T00:00:39.009000+00:00"
+ ],
+ [
+ "000894ce-771d-b0c5-4257-c0f11ba3738b",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-50802",
+ "2026-01-01T00:00:50.802000+00:00"
+ ],
+ [
+ "0009890d-722b-c19a-423a-4256dcd2f4d8",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-90624",
+ "2026-01-01T00:01:30.624000+00:00"
+ ],
+ [
+ "000a09f8-b6a1-5757-366d-e31e47f20ceb",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-32627",
+ "2026-01-01T00:00:32.627000+00:00"
+ ],
+ [
+ "000af189-7b90-0d83-02d6-a2a1b6f7cb7d",
+ "64fbbeee-3c1b-b5be-9d4f-5bd05fe83171",
+ "00000000-0000-0000-0000-000000000001",
+ "payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-payload-17917",
+ "2026-01-01T00:00:17.917000+00:00"
+ ]
+ ],
+ "all_messages_digest": "897c5828c0607c030860f5537915650a"
+ },
+ "backup": {
+ "seconds": 1.247,
+ "bytes": 3592366,
+ "sha256": "bb3aa237912e8427554885f7c3b183224b405a03a97a5a3f44acbc9d08fcd9a5"
+ },
+ "restore": {
+ "seconds_including_startup": 4.026,
+ "fresh_volume": "lab2-restore-2d6df06983",
+ "published_ports": false,
+ "counts": {
+ "users": 1,
+ "chats": 3,
+ "members": 3,
+ "messages": 120000,
+ "sessions": 0
+ },
+ "all_messages_digest": "897c5828c0607c030860f5537915650a",
+ "selected_20_match": true,
+ "verified": true
+ },
+ "limitations": "Warm-cache serial variants on one local host; logical backup snapshot, no WAL/PITR; synthetic DB retained for inspection.",
+ "database": "experiment_2d6df06983"
+}
diff --git a/evidence/indexes.png b/evidence/indexes.png
new file mode 100644
index 00000000..3a534e63
Binary files /dev/null and b/evidence/indexes.png differ
diff --git a/evidence/indexes.svg b/evidence/indexes.svg
new file mode 100644
index 00000000..0e184ce4
--- /dev/null
+++ b/evidence/indexes.svg
@@ -0,0 +1,2279 @@
+
+
+
diff --git a/evidence/integration.json b/evidence/integration.json
new file mode 100644
index 00000000..5b6601c9
--- /dev/null
+++ b/evidence/integration.json
@@ -0,0 +1,34 @@
+{
+ "public_smoke": "PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.",
+ "authentication_negative": "wrong password, Basic on protected route, X-User-Id: 401",
+ "registration_race": [
+ 201,
+ 409,
+ 409,
+ 409,
+ 409,
+ 409,
+ 409,
+ 409
+ ],
+ "rollback": "missing member: 400; chats count unchanged",
+ "concurrent_messages": {
+ "sent": 100,
+ "read": 100,
+ "page_size": 17
+ },
+ "cache_hit_delta": 5,
+ "cache_down": {
+ "status": 200,
+ "seconds": 0.211
+ },
+ "database_down": {
+ "status": 503,
+ "seconds": 0.009
+ },
+ "logout": "204 then 401",
+ "short_ttl": "SESSION_TTL_SECONDS=2: 200 then 401 after 2.2s",
+ "migration_repeat": "Already applied: 001_initial.sql",
+ "public_persistence": "Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.\nPASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.",
+ "passed": true
+}
diff --git a/evidence/restart-processes.json b/evidence/restart-processes.json
new file mode 100644
index 00000000..d1777e44
--- /dev/null
+++ b/evidence/restart-processes.json
@@ -0,0 +1,13 @@
+{
+ "before": {
+ "api": "2026-10-16T12:03:16.324917557Z",
+ "db": "2026-10-16T12:06:50.396973657Z",
+ "cache": "2026-10-16T12:06:47.794944116Z"
+ },
+ "after": {
+ "api": "2026-10-16T12:07:04.752894207Z",
+ "db": "2026-10-16T12:07:04.023045701Z",
+ "cache": "2026-10-16T12:07:03.931354369Z"
+ },
+ "volumes_removed": false
+}
diff --git a/migrations/001_initial.sql b/migrations/001_initial.sql
new file mode 100644
index 00000000..3b9cda97
--- /dev/null
+++ b/migrations/001_initial.sql
@@ -0,0 +1,35 @@
+CREATE TABLE users (
+ id uuid PRIMARY KEY,
+ username text NOT NULL UNIQUE CHECK (username ~ '^[a-z0-9_]{3,32}$'),
+ display_name text NOT NULL CHECK (char_length(display_name) BETWEEN 1 AND 100),
+ password_hash text NOT NULL,
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp()
+);
+CREATE TABLE sessions (
+ token_hash text PRIMARY KEY,
+ user_id uuid NOT NULL REFERENCES users(id),
+ expires_at timestamptz NOT NULL,
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp()
+);
+CREATE INDEX sessions_expiry ON sessions(expires_at);
+CREATE TABLE chats (
+ id uuid PRIMARY KEY,
+ title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 100),
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp()
+);
+CREATE TABLE members (
+ chat_id uuid NOT NULL REFERENCES chats(id),
+ user_id uuid NOT NULL REFERENCES users(id),
+ PRIMARY KEY(chat_id,user_id)
+);
+CREATE INDEX members_user_chat ON members(user_id,chat_id);
+CREATE INDEX chats_order ON chats(created_at,id);
+CREATE TABLE messages (
+ id uuid PRIMARY KEY,
+ chat_id uuid NOT NULL REFERENCES chats(id),
+ sender_id uuid NOT NULL REFERENCES users(id),
+ text text NOT NULL CHECK (char_length(text) BETWEEN 1 AND 4000),
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
+ FOREIGN KEY(chat_id,sender_id) REFERENCES members(chat_id,user_id)
+);
+CREATE INDEX messages_history ON messages(chat_id,created_at,id);
diff --git a/requirements-test.txt b/requirements-test.txt
new file mode 100644
index 00000000..9dff8880
--- /dev/null
+++ b/requirements-test.txt
@@ -0,0 +1,3 @@
+-r requirements.txt
+httpx==0.28.1
+matplotlib==3.10.8
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 00000000..13add4d9
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,23 @@
+annotated-doc==0.0.5
+annotated-types==0.8.0
+anyio==4.15.1
+argon2-cffi==25.1.0
+argon2-cffi-bindings==26.1.0
+cffi==2.1.1
+click==8.5.0
+fastapi==0.143.2
+h11==0.16.0
+idna==3.20
+opentelemetry-api==1.45.1
+psycopg==3.3.6
+psycopg-binary==3.3.6
+psycopg-pool==3.3.3
+pycparser==3.11
+pydantic==2.14.1
+pydantic_core==2.50.1
+redis==8.1.0
+starlette==1.8.0
+typing-inspection==0.4.4
+typing_extensions==4.16.0
+tzdata==2026.5
+uvicorn==0.54.0
diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py
new file mode 100644
index 00000000..7372ac02
--- /dev/null
+++ b/scripts/bootstrap.py
@@ -0,0 +1,15 @@
+"""Generate local synthetic credentials once. Never prints their values."""
+from pathlib import Path
+import secrets
+
+root=Path(__file__).resolve().parents[1]
+target=root/'.env'
+if target.exists():
+ print('Existing .env preserved')
+else:
+ password=secrets.token_hex(24)
+ content=f'POSTGRES_PASSWORD={password}\nDATABASE_URL=postgresql://messenger:{password}@db:5432/messenger\nREDIS_URL=redis://cache:6379/0\nCURSOR_SECRET={secrets.token_hex(32)}\nSESSION_TTL_SECONDS=3600\n'
+ with target.open('x',encoding='utf-8') as f: f.write(content)
+ try: target.chmod(0o600)
+ except OSError: pass
+ print('Created local .env; values not displayed')
diff --git a/scripts/index_experiment.py b/scripts/index_experiment.py
new file mode 100644
index 00000000..abd39621
--- /dev/null
+++ b/scripts/index_experiment.py
@@ -0,0 +1,109 @@
+"""120k skewed messages: query plans/write cost + real fresh-volume restore.
+
+Host orchestrates Docker; --inside runs synthetic SQL in an isolated database.
+No production table is changed and no credentials are printed.
+"""
+import hashlib
+from datetime import datetime
+import json
+import os
+from pathlib import Path
+import statistics
+import subprocess
+import sys
+import time
+import uuid
+
+def inside(dbname):
+ import psycopg
+ with psycopg.connect(os.environ['DATABASE_URL'],autocommit=True) as admin:
+ admin.execute(psycopg.sql.SQL('CREATE DATABASE {}').format(psycopg.sql.Identifier(dbname)))
+ with psycopg.connect(os.environ['DATABASE_URL'],dbname=dbname,autocommit=True) as c:
+ c.execute(Path('/app/migrations/001_initial.sql').read_text())
+ c.execute("INSERT INTO users(id,username,display_name,password_hash) VALUES ('00000000-0000-0000-0000-000000000001','benchmark','Synthetic','not-a-login-hash')")
+ c.execute("INSERT INTO chats(id,title) SELECT md5('chat'||n)::uuid,'chat'||n FROM generate_series(1,3) n")
+ c.execute("INSERT INTO members SELECT id,'00000000-0000-0000-0000-000000000001'::uuid FROM chats")
+ c.execute("INSERT INTO messages SELECT md5('message'||n)::uuid,md5('chat'||CASE WHEN n<=100000 THEN 1 WHEN n<=115000 THEN 2 ELSE 3 END)::uuid,'00000000-0000-0000-0000-000000000001'::uuid,repeat('payload-',20)||n,'2026-01-01'::timestamptz+n*interval '1 millisecond' FROM generate_series(1,120000) n")
+ c.execute('DROP INDEX messages_history')
+ c.execute('VACUUM ANALYZE messages')
+ cursor=c.execute("SELECT created_at,id FROM messages WHERE chat_id=md5('chat1')::uuid ORDER BY created_at,id OFFSET 69999 LIMIT 1").fetchone()
+ keyset="SELECT id,chat_id,sender_id,text,created_at FROM messages WHERE chat_id=md5('chat1')::uuid AND (created_at,id)>(%s,%s) ORDER BY created_at,id LIMIT 50"
+ offset="SELECT id,chat_id,sender_id,text,created_at FROM messages WHERE chat_id=md5('chat1')::uuid ORDER BY created_at,id OFFSET 70000 LIMIT 50"
+ result={'version':c.execute('SELECT version()').fetchone()[0],'rows':120000,'chat_sizes':[100000,15000,5000],'repeats':5,'plans':[],'writes':[]}
+ for variant,ddl in [('primary_only',None),('chat_index','CREATE INDEX experiment_idx ON messages(chat_id)'),('compound','CREATE INDEX experiment_idx ON messages(chat_id,created_at,id)')]:
+ if ddl: c.execute(ddl)
+ c.execute('ANALYZE messages')
+ for query_name,query,args in [('keyset',keyset,cursor),('offset',offset,())]:
+ for _ in range(2): c.execute(query,args).fetchall()
+ plans=[c.execute('EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) '+query,args).fetchone()[0][0] for _ in range(5)]
+ result['plans'].append({'index':variant,'query':query_name,'execution_ms':[p['Execution Time'] for p in plans],'median_ms':statistics.median(p['Execution Time'] for p in plans),'plans':plans})
+ # Five real committed batches, then remove only those synthetic rows.
+ measurements=[]
+ for rep in range(5):
+ start=time.perf_counter()
+ c.execute("INSERT INTO messages SELECT md5('write'||n)::uuid,md5('chat1')::uuid,'00000000-0000-0000-0000-000000000001'::uuid,repeat('payload-',20)||n,'2027-01-01'::timestamptz+n*interval '1 millisecond' FROM generate_series(1,5000) n")
+ measurements.append(round((time.perf_counter()-start)*1000,3))
+ c.execute("DELETE FROM messages WHERE created_at>='2027-01-01'")
+ c.execute('VACUUM ANALYZE messages')
+ result['writes'].append({'index':variant,'batch_rows':5000,'committed_ms':measurements,'median_ms':statistics.median(measurements)})
+ if ddl: c.execute('DROP INDEX experiment_idx')
+ c.execute('CREATE INDEX messages_history ON messages(chat_id,created_at,id)')
+ result['snapshot']=snapshot(c)
+ print(json.dumps(result,default=str))
+
+def snapshot(c):
+ counts={table:c.execute('SELECT count(*) FROM '+table).fetchone()[0] for table in ('users','chats','members','messages','sessions')}
+ selected=c.execute('SELECT id,chat_id,sender_id,text,created_at FROM messages ORDER BY id LIMIT 20').fetchall()
+ digest=c.execute("SELECT md5(string_agg(id::text||chat_id::text||sender_id::text||text||created_at::text,'' ORDER BY id)) FROM messages").fetchone()[0]
+ return {'counts':counts,'selected':[[str(v) for v in row] for row in selected],'all_messages_digest':digest}
+
+def host():
+ root=Path(__file__).resolve().parents[1]
+ def run(*args,input=None):
+ return subprocess.run(['docker',*args],cwd=root,input=input,stdout=subprocess.PIPE,stderr=subprocess.PIPE,check=True).stdout
+ unique=uuid.uuid4().hex[:10]; dbname='experiment_'+unique
+ cid=run('compose','ps','-q','db').decode().strip()
+ source=Path(__file__).read_bytes()
+ result=json.loads(run('compose','exec','-T','api','python','-','--inside',dbname,input=source))
+ start=time.perf_counter()
+ dump=run('exec',cid,'pg_dump','-U','messenger','-Fc',dbname)
+ result['backup']={'seconds':round(time.perf_counter()-start,3),'bytes':len(dump),'sha256':hashlib.sha256(dump).hexdigest()}
+ backup=root/'backups'/f'{dbname}.dump'; backup.parent.mkdir(exist_ok=True); backup.write_bytes(dump)
+ # Distinct container and brand-new named volume: no restore onto source storage.
+ image=run('inspect','--format','{{.Config.Image}}',cid).decode().strip()
+ volume='lab2-restore-'+unique; target='lab2-restore-'+unique
+ run('volume','create',volume)
+ try:
+ run('run','-d','--name',target,'--cpus','1','--memory','256m','-e','POSTGRES_USER=messenger','-e','POSTGRES_DB=messenger','-e','POSTGRES_HOST_AUTH_METHOD=trust','-v',volume+':/var/lib/postgresql/data',image)
+ start=time.perf_counter()
+ for _ in range(100):
+ try: run('exec',target,'pg_isready','-U','messenger'); break
+ except subprocess.CalledProcessError: time.sleep(.2)
+ else: raise AssertionError('restore PostgreSQL did not become ready')
+ run('exec','-i',target,'pg_restore','-U','messenger','-d','messenger','--exit-on-error',input=dump)
+ result['restore']={'seconds_including_startup':round(time.perf_counter()-start,3),'fresh_volume':volume,'published_ports':False}
+ # pg_restore schema/data includes all constraints and indexes.
+ query="SELECT json_build_object('users',(SELECT count(*) FROM users),'chats',(SELECT count(*) FROM chats),'members',(SELECT count(*) FROM members),'messages',(SELECT count(*) FROM messages),'sessions',(SELECT count(*) FROM sessions))"
+ counts=json.loads(run('exec',target,'psql','-U','messenger','-Atc',query))
+ digest=run('exec',target,'psql','-U','messenger','-Atc',"SELECT md5(string_agg(id::text||chat_id::text||sender_id::text||text||created_at::text,'' ORDER BY id)) FROM messages").decode().strip()
+ selected=json.loads(run('exec',target,'psql','-U','messenger','-Atc',"SELECT json_agg(row_to_json(t)) FROM (SELECT id,chat_id,sender_id,text,created_at::text FROM messages ORDER BY id LIMIT 20) t"))
+ selected=[[str(row[k]) for k in ('id','chat_id','sender_id','text','created_at')] for row in selected]
+ # Normalize equivalent precision/offset rendering, preserving actual instants.
+ for rows in (selected,result['snapshot']['selected']):
+ for row in rows: row[-1]=datetime.fromisoformat(row[-1]).isoformat(timespec='microseconds')
+ assert counts==result['snapshot']['counts']
+ assert digest==result['snapshot']['all_messages_digest']
+ assert selected==result['snapshot']['selected']
+ result['restore'].update(counts=counts,all_messages_digest=digest,selected_20_match=True,verified=True)
+ finally:
+ run('rm','-f',target)
+ run('volume','rm',volume)
+ result['limitations']='Warm-cache serial variants on one local host; logical backup snapshot, no WAL/PITR; synthetic DB retained for inspection.'
+ result['database']=dbname
+ (root/'evidence').mkdir(exist_ok=True)
+ (root/'evidence/index-restore.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
+ print(json.dumps({k:v for k,v in result.items() if k not in ('plans','snapshot')},indent=2))
+
+if __name__=='__main__':
+ if '--inside' in sys.argv: inside(sys.argv[-1])
+ else: host()
diff --git a/scripts/load_experiment.py b/scripts/load_experiment.py
new file mode 100644
index 00000000..cc41fa62
--- /dev/null
+++ b/scripts/load_experiment.py
@@ -0,0 +1,59 @@
+"""Bounded closed-loop HTTP load, raw latency and Docker resource samples."""
+from concurrent.futures import ThreadPoolExecutor
+import csv
+import json
+import math
+from pathlib import Path
+import subprocess
+import threading
+import time
+import uuid
+import httpx
+
+ROOT=Path(__file__).resolve().parents[1]
+def docker(*args):
+ return subprocess.check_output(['docker',*args],cwd=ROOT,text=True,encoding='utf-8').strip()
+rows=[]; samples=[]; done=threading.Event()
+def sample():
+ while not done.is_set():
+ data=docker('stats','--no-stream','--format','{{json .}}',*docker('compose','ps','-q').splitlines())
+ samples.extend({'elapsed_s':round(time.perf_counter()-start,3),**json.loads(line)} for line in data.splitlines())
+ done.wait(1)
+with httpx.Client(base_url='http://127.0.0.1:8080',timeout=10) as c:
+ body={'username':'load_'+uuid.uuid4().hex[:18],'display_name':'Load','password':'synthetic-password-123'}
+ user=c.post('/api/v1/users',json=body).json()
+ auth=c.post('/api/v1/auth/sessions',auth=(body['username'],body['password'])).json()
+ headers={'Authorization':'Bearer '+auth['token']}
+ chat=c.post('/api/v1/chats',headers=headers,json={'title':'load','member_ids':[user['id']]}).json()
+ path='/api/v1/chats/'+chat['id']+'/messages'
+ # Warm up the pool/cache for 2 seconds, outside measurement.
+ deadline=time.perf_counter()+2
+ while time.perf_counter()=5
+ docker('compose','stop','cache')
+ try:
+ start=time.perf_counter()
+ r=c.get('/api/v1/users/me',headers=headers)
+ evidence['cache_down']={'status':r.status_code,'seconds':round(time.perf_counter()-start,3)}
+ assert r.status_code==200
+ assert c.get('/api/v1/users/me',headers={'Authorization':'Bearer '+'x'*43}).status_code==401
+ finally: docker('compose','start','cache')
+ docker('compose','stop','db')
+ try:
+ start=time.perf_counter(); r=c.get('/api/v1/users/me',headers=headers)
+ evidence['database_down']={'status':r.status_code,'seconds':round(time.perf_counter()-start,3)}
+ assert r.status_code==503 and time.perf_counter()-start<10
+ assert c.get('/api/v1/users/me').status_code==401
+ finally: docker('compose','start','db')
+ wait_ready(c)
+ assert c.get('/api/v1/users/me',headers=headers).status_code==200
+ assert c.delete('/api/v1/auth/sessions/current',headers=headers).status_code==204
+ assert c.get('/api/v1/users/me',headers=headers).status_code==401
+ evidence['logout']='204 then 401'
+
+# A separate API process with short TTL uses the same persistent dependencies.
+name='lab2-expiry-'+uuid.uuid4().hex[:8]
+docker('compose','run','-d','--no-deps','--name',name,'-p','127.0.0.1::8080','-e','SESSION_TTL_SECONDS=2','api')
+try:
+ binding=docker('port',name,'8080/tcp').split(':')[-1]
+ with httpx.Client(base_url='http://127.0.0.1:'+binding,timeout=10) as c:
+ wait_ready(c); body,user=register(c); headers=login(c,body)
+ assert c.get('/api/v1/users/me',headers=headers).status_code==200
+ time.sleep(2.2)
+ assert c.get('/api/v1/users/me',headers=headers).status_code==401
+ evidence['short_ttl']='SESSION_TTL_SECONDS=2: 200 then 401 after 2.2s'
+finally: docker('rm','-f',name)
+
+evidence['migration_repeat']=docker('compose','run','--rm','--no-deps','migrate')
+if os.name=='nt':
+ with tempfile.TemporaryDirectory(prefix='lab2-hook-') as tmp:
+ hook=Path(tmp)/'restart.cmd'
+ hook.write_text('@echo off\n"'+sys.executable+'" "'+str(ROOT/'scripts/restart.py')+'"\n',encoding='utf-8')
+ evidence['public_persistence']=subprocess.check_output([sys.executable,'-X','utf8','tests/resilience.py','--mode','persistence','--action-script',str(hook)],cwd=ROOT,text=True,encoding='utf-8').strip()
+else:
+ evidence['public_persistence']=subprocess.check_output([sys.executable,'tests/resilience.py','--mode','persistence','--action-script','scripts/restart.sh'],cwd=ROOT,text=True).strip()
+evidence['passed']=True
+(OUT/'integration.json').write_text(json.dumps(evidence,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
+print(json.dumps(evidence,ensure_ascii=False,indent=2))
diff --git a/src/__init__.py b/src/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/__main__.py b/src/__main__.py
new file mode 100644
index 00000000..2e8fadcf
--- /dev/null
+++ b/src/__main__.py
@@ -0,0 +1,9 @@
+import logging
+import os
+import uvicorn
+
+logging.basicConfig(level=logging.INFO, format='%(message)s')
+uvicorn.run('src.app:app', host=os.environ.get('APP_HOST', '0.0.0.0'),
+ port=int(os.environ.get('APP_PORT', '8080')), workers=1,
+ access_log=False, server_header=False, timeout_keep_alive=2,
+ timeout_graceful_shutdown=5, backlog=64, h11_max_incomplete_event_size=16384)
diff --git a/src/app.py b/src/app.py
new file mode 100644
index 00000000..eccf04f0
--- /dev/null
+++ b/src/app.py
@@ -0,0 +1,173 @@
+import asyncio
+import base64
+from contextlib import asynccontextmanager
+from dataclasses import dataclass
+import os
+import re
+import secrets
+
+from argon2 import PasswordHasher
+from argon2.exceptions import VerificationError, InvalidHashError
+from fastapi import FastAPI, Request, Response
+import psycopg
+from psycopg_pool import PoolTimeout, TooManyRequests
+from starlette.exceptions import HTTPException
+
+from .common import ApiError, invalid, json_body, object_fields, pagination, string, uuid_value
+from .http import Boundaries, error_response
+from .store import Store, clean
+
+
+@dataclass
+class Settings:
+ database_url: str
+ redis_url: str
+ cursor_secret: str
+ session_ttl_seconds: int = 3600
+ db_pool_size: int = 5
+ max_body_bytes: int = 32768
+ max_inflight: int = 32
+ request_timeout: int = 8
+ write_rps: int = 100
+ write_burst: int = 100
+
+ @classmethod
+ def environment(cls):
+ result=cls(database_url=os.environ['DATABASE_URL'],redis_url=os.environ['REDIS_URL'],cursor_secret=os.environ['CURSOR_SECRET'],
+ **{name:int(os.environ.get(name.upper(),field.default)) for name,field in cls.__dataclass_fields__.items() if field.type is int})
+ if len(result.cursor_secret)<32 or any(getattr(result,name)<=0 for name,field in cls.__dataclass_fields__.items() if field.type is int):
+ raise ValueError('Invalid configuration')
+ return result
+
+
+def create_app(settings=None):
+ cfg=settings or Settings.environment()
+ store=Store(cfg)
+ hasher=PasswordHasher(time_cost=2,memory_cost=32768,parallelism=1)
+ dummy_hash=hasher.hash(secrets.token_urlsafe(32))
+ kdf_slots=asyncio.Semaphore(4)
+
+ @asynccontextmanager
+ async def lifespan(api):
+ await store.open()
+ try: yield
+ finally: await store.close()
+
+ api=FastAPI(lifespan=lifespan,openapi_url=None,docs_url=None,redoc_url=None)
+ api.state.store=store
+
+ @api.exception_handler(ApiError)
+ async def api_error(request,exc): return error_response(exc,request.state.request_id)
+
+ @api.exception_handler(HTTPException)
+ async def http_error(request,exc):
+ return error_response(ApiError(404,'not_found','Route not found'),request.state.request_id)
+
+ async def database_error(request,exc):
+ return error_response(ApiError(503,'unavailable','Database unavailable',{'Retry-After':'1'}),request.state.request_id)
+ for exception in (psycopg.Error,PoolTimeout,TooManyRequests): api.add_exception_handler(exception,database_error)
+
+ @api.exception_handler(psycopg.DataError)
+ async def data_error(request,exc):
+ return error_response(ApiError(400,'invalid_request','Unsupported field value'),request.state.request_id)
+
+ def unauthorized(basic=False):
+ scheme='Basic realm="messenger", charset="UTF-8"' if basic else 'Bearer realm="messenger"'
+ return ApiError(401,'unauthorized','Invalid credentials',{'WWW-Authenticate':scheme})
+
+ def bearer(request):
+ value=request.headers.get('authorization','')
+ parts=value.split()
+ if len(parts)!=2 or parts[0].lower()!='bearer' or not re.fullmatch(r'[A-Za-z0-9_-]{43}',parts[1]):
+ raise unauthorized()
+ return parts[1]
+
+ async def actor(request): return await store.authenticate(bearer(request))
+
+ @api.get('/health/live')
+ async def live(): return {'status':'ok'}
+
+ @api.get('/health/ready')
+ async def ready():
+ await store.ready()
+ return {'status':'ok'}
+
+ @api.post('/api/v1/users',status_code=201)
+ async def register(request:Request):
+ body=object_fields(await json_body(request),('username','display_name','password'))
+ username=string(body['username'],32)
+ if not re.fullmatch(r'[a-z0-9_]{3,32}',username): invalid('Invalid username')
+ name=string(body['display_name'],100)
+ password=string(body['password'],128)
+ if len(password)<12: invalid('Password must contain 12..128 code points')
+ async with kdf_slots: hashed=await asyncio.to_thread(hasher.hash,password)
+ return await store.register(username,name,hashed)
+
+ @api.post('/api/v1/auth/sessions',status_code=201)
+ async def login(request:Request):
+ try:
+ scheme,encoded=request.headers.get('authorization','').split(' ',1)
+ if scheme.lower()!='basic': raise ValueError()
+ username,password=base64.b64decode(encoded,validate=True).decode('utf-8').split(':',1)
+ if not re.fullmatch(r'[a-z0-9_]{3,32}',username) or not 12<=len(password)<=128: raise ValueError()
+ except (ValueError,UnicodeError): raise unauthorized(True) from None
+ if await request.body(): invalid('Session login does not accept a body')
+ row=await store.credentials(username)
+ try:
+ async with kdf_slots: await asyncio.to_thread(hasher.verify,row['password_hash'] if row else dummy_hash,password)
+ except (VerificationError,InvalidHashError): raise unauthorized(True) from None
+ if not row: raise unauthorized(True)
+ token=secrets.token_urlsafe(32)
+ expires=await store.create_session(row['id'],token)
+ return {'token':token,'token_type':'Bearer','expires_at':expires,
+ 'user':clean({k:v for k,v in row.items() if k!='password_hash'})}
+
+ @api.delete('/api/v1/auth/sessions/current',status_code=204)
+ async def logout(request:Request):
+ await actor(request)
+ await store.logout(bearer(request))
+ return Response(status_code=204)
+
+ @api.get('/api/v1/users/me')
+ async def me(request:Request): return await actor(request)
+
+ @api.post('/api/v1/chats',status_code=201)
+ async def create_chat(request:Request):
+ user=await actor(request)
+ body=object_fields(await json_body(request),('title','member_ids'))
+ title=string(body['title'],100)
+ if not isinstance(body['member_ids'],list) or not 1<=len(body['member_ids'])<=100: invalid('Invalid members')
+ members=[uuid_value(v) for v in body['member_ids']]
+ if len(set(members))!=len(members): invalid('Duplicate member')
+ return await store.create_chat(user['id'],title,members)
+
+ @api.get('/api/v1/chats')
+ async def list_chats(request:Request):
+ user=await actor(request)
+ limit,cursor=pagination(request,'chats:'+user['id'],store.secret)
+ return await store.page(user['id'],None,limit,cursor)
+
+ @api.get('/api/v1/chats/{chat_id}')
+ async def get_chat(chat_id:str,request:Request):
+ user=await actor(request)
+ return await store.chat(user['id'],uuid_value(chat_id))
+
+ @api.get('/api/v1/chats/{chat_id}/messages')
+ async def list_messages(chat_id:str,request:Request):
+ user=await actor(request); chat_id=uuid_value(chat_id)
+ await store.chat(user['id'],chat_id)
+ limit,cursor=pagination(request,'messages:'+chat_id,store.secret)
+ return await store.page(user['id'],chat_id,limit,cursor)
+
+ @api.post('/api/v1/chats/{chat_id}/messages',status_code=201)
+ async def create_message(chat_id:str,request:Request):
+ user=await actor(request); chat_id=uuid_value(chat_id)
+ await store.chat(user['id'],chat_id)
+ body=object_fields(await json_body(request),('text',))
+ return await store.create_message(user['id'],chat_id,string(body['text'],4000))
+
+ api.add_middleware(Boundaries,settings=cfg)
+ return api
+
+
+app=create_app()
diff --git a/src/common.py b/src/common.py
new file mode 100644
index 00000000..7d4e9e84
--- /dev/null
+++ b/src/common.py
@@ -0,0 +1,101 @@
+"""Strict contract validation and resource-bound cursors."""
+import base64
+import binascii
+import hashlib
+import hmac
+import json
+import re
+from datetime import datetime, timezone
+from uuid import UUID
+
+
+class ApiError(Exception):
+ def __init__(self, status, code, message, headers=None):
+ self.status, self.code, self.message = status, code, message
+ self.headers = headers or {}
+
+
+def invalid(message='Invalid request'):
+ raise ApiError(400, 'invalid_request', message)
+
+
+def uuid_value(value):
+ if not isinstance(value, str) or not re.fullmatch(
+ r'[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}', value
+ ):
+ invalid('Invalid UUID')
+ return str(UUID(value))
+
+
+def string(value, maximum, *, blank=False):
+ if not isinstance(value, str) or len(value) > maximum or (not blank and not value.strip()):
+ invalid('Invalid string')
+ # JSON can encode unpaired surrogates; they are not Unicode scalar values.
+ try:
+ value.encode('utf-8')
+ except UnicodeError:
+ invalid('Invalid Unicode')
+ return value
+
+
+def object_fields(value, required, optional=()):
+ if not isinstance(value, dict) or not set(required) <= value.keys() or value.keys() - set(required) - set(optional):
+ invalid('Invalid fields')
+ return value
+
+
+def timestamp():
+ return datetime.now(timezone.utc).isoformat(timespec='microseconds').replace('+00:00', 'Z')
+
+
+def encode_cursor(resource, key, secret):
+ data = json.dumps([resource, *key], separators=(',', ':')).encode()
+ return base64.urlsafe_b64encode(data + hmac.digest(secret, data, 'sha256')).decode().rstrip('=')
+
+
+def decode_cursor(value, resource, secret):
+ try:
+ if len(value) > 1024 or not re.fullmatch(r'[A-Za-z0-9_-]+', value):
+ raise ValueError()
+ raw = base64.b64decode(value + '=' * (-len(value) % 4), altchars=b'-_', validate=True)
+ data, signature = raw[:-32], raw[-32:]
+ if not hmac.compare_digest(hmac.digest(secret, data, 'sha256'), signature):
+ raise ValueError()
+ scope, created, identifier = json.loads(data)
+ if scope != resource or not isinstance(created, str) or not created.endswith('Z'):
+ raise ValueError()
+ datetime.fromisoformat(created.replace('Z', '+00:00'))
+ UUID(identifier)
+ return created, identifier
+ except (ValueError, TypeError, binascii.Error, UnicodeError):
+ invalid('Invalid cursor')
+
+
+def pagination(request, resource, secret):
+ if any(len(request.query_params.getlist(k)) != 1 for k in request.query_params):
+ invalid('Duplicate query parameter')
+ if set(request.query_params) - {'limit', 'cursor'}:
+ invalid('Unknown query parameter')
+ value = request.query_params.get('limit', '50')
+ if not re.fullmatch(r'[0-9]{1,3}', value) or not 1 <= int(value) <= 100:
+ invalid('Limit must be 1..100')
+ cursor = request.query_params.get('cursor')
+ return int(value), decode_cursor(cursor, resource, secret) if cursor is not None else None
+
+
+async def json_body(request):
+ if request.headers.get('content-type', '').split(';')[0].strip().lower() != 'application/json':
+ raise ApiError(415, 'unsupported_media_type', 'Expected application/json')
+ def unique_pairs(pairs):
+ result = {}
+ for key, value in pairs:
+ if key in result:
+ raise ValueError('duplicate key')
+ result[key] = value
+ return result
+ def no_constant(value):
+ raise ValueError('non-finite number')
+ try:
+ return json.loads((await request.body()).decode('utf-8'), object_pairs_hook=unique_pairs, parse_constant=no_constant)
+ except (ValueError, UnicodeError, RecursionError):
+ invalid('Invalid JSON')
diff --git a/src/http.py b/src/http.py
new file mode 100644
index 00000000..33eedad9
--- /dev/null
+++ b/src/http.py
@@ -0,0 +1,85 @@
+import asyncio
+import json
+import logging
+import time
+from uuid import uuid4
+from starlette.responses import JSONResponse
+from .common import ApiError
+logger=logging.getLogger("messenger")
+
+def error_response(exc, request_id):
+ return JSONResponse({'error': {'code': exc.code, 'message': exc.message, 'request_id': request_id}},
+ status_code=exc.status, headers={'X-Request-Id': request_id, **exc.headers})
+
+
+class Boundaries:
+ """Admission before body buffering; no unbounded application waiting queue."""
+ def __init__(self, app, settings):
+ self.app, self.cfg = app, settings
+ self.active, self.tokens, self.updated = 0, float(settings.write_burst), time.monotonic()
+
+ async def __call__(self, scope, receive, send):
+ if scope['type'] != 'http':
+ return await self.app(scope, receive, send)
+ request_id, started, status = uuid4().hex, time.monotonic(), 500
+ scope.setdefault('state', {})['request_id'] = request_id
+ started_response = False
+ async def tracked_send(message):
+ nonlocal status, started_response
+ if message['type'] == 'http.response.start':
+ status, started_response = message['status'], True
+ message['headers'] = [(k, v) for k, v in message.get('headers', []) if k.lower() != b'x-request-id'] + [(b'x-request-id', request_id.encode())]
+ await send(message)
+ admitted = False
+ try:
+ if self.active >= self.cfg.max_inflight:
+ raise ApiError(503, 'unavailable', 'Too many in-flight requests', {'Retry-After': '1'})
+ now = time.monotonic()
+ self.tokens = min(self.cfg.write_burst, self.tokens + (now - self.updated) * self.cfg.write_rps)
+ self.updated = now
+ if scope['method'] in ('POST', 'PUT', 'PATCH'):
+ if self.tokens < 1:
+ raise ApiError(429, 'rate_limited', 'Write rate exceeded', {'Retry-After': '1'})
+ self.tokens -= 1
+ self.active += 1
+ admitted = True
+ chunks, total = bytearray(), 0
+ async with asyncio.timeout(self.cfg.request_timeout):
+ while True:
+ message = await receive()
+ if message['type'] == 'http.disconnect':
+ return
+ chunk = message.get('body', b'')
+ total += len(chunk)
+ if total > self.cfg.max_body_bytes:
+ raise ApiError(413, 'payload_too_large', 'Request body exceeds byte limit')
+ chunks.extend(chunk)
+ if not message.get('more_body', False):
+ break
+ body = bytes(chunks)
+ delivered = False
+ async def replay():
+ nonlocal delivered
+ if delivered:
+ return await receive()
+ delivered = True
+ return {'type': 'http.request', 'body': body, 'more_body': False}
+ await self.app(scope, replay, tracked_send)
+ except TimeoutError:
+ if not started_response:
+ await error_response(ApiError(503, 'unavailable', 'Request timed out'), request_id)(scope, receive, tracked_send)
+ except ApiError as exc:
+ if not started_response:
+ await error_response(exc, request_id)(scope, receive, tracked_send)
+ except Exception as exc:
+ logger.error(json.dumps({'event': 'unexpected_error', 'request_id': request_id, 'type': type(exc).__name__}))
+ if not started_response:
+ await error_response(ApiError(500, 'internal_error', 'Internal error'), request_id)(scope, receive, tracked_send)
+ finally:
+ if admitted:
+ self.active -= 1
+ # No query, body, headers, usernames, or message content in logs.
+ route = scope.get('route')
+ logger.info(json.dumps({'event': 'http', 'request_id': request_id, 'method': scope['method'],
+ 'route': getattr(route, 'path', 'unmatched'), 'status': status,
+ 'duration_ms': round((time.monotonic() - started) * 1000, 3)}))
diff --git a/src/migrate.py b/src/migrate.py
new file mode 100644
index 00000000..a66ac916
--- /dev/null
+++ b/src/migrate.py
@@ -0,0 +1,28 @@
+"""Versioned, transactional migrations, serialized across deployers."""
+import hashlib
+import os
+from pathlib import Path
+import psycopg
+
+
+def main():
+ with psycopg.connect(os.environ['DATABASE_URL'],autocommit=True,connect_timeout=5) as conn:
+ conn.execute('SELECT pg_advisory_lock(23012026)')
+ try:
+ conn.execute('CREATE TABLE IF NOT EXISTS schema_migrations (name text PRIMARY KEY, sha256 text NOT NULL, applied_at timestamptz NOT NULL DEFAULT clock_timestamp())')
+ for file in sorted((Path(__file__).resolve().parents[1]/'migrations').glob('*.sql')):
+ data=file.read_bytes(); digest=hashlib.sha256(data).hexdigest()
+ row=conn.execute('SELECT sha256 FROM schema_migrations WHERE name=%s',(file.name,)).fetchone()
+ if row:
+ if row[0]!=digest: raise RuntimeError('An applied migration was modified: '+file.name)
+ print('Already applied:',file.name,flush=True)
+ continue
+ with conn.transaction():
+ conn.execute(data.decode('utf-8'))
+ conn.execute('INSERT INTO schema_migrations(name,sha256) VALUES (%s,%s)',(file.name,digest))
+ print('Applied:',file.name,flush=True)
+ finally:
+ conn.execute('SELECT pg_advisory_unlock(23012026)')
+
+
+if __name__=='__main__': main()
diff --git a/src/store.py b/src/store.py
new file mode 100644
index 00000000..ca81c016
--- /dev/null
+++ b/src/store.py
@@ -0,0 +1,130 @@
+import hashlib
+import json
+import logging
+from uuid import uuid4
+
+import psycopg
+from psycopg.rows import dict_row
+from psycopg_pool import AsyncConnectionPool
+from redis.asyncio import Redis
+from redis.exceptions import RedisError
+
+from .common import ApiError, encode_cursor, invalid
+
+
+def clean(row):
+ if row is None: return None
+ result={}
+ for k,v in row.items():
+ if hasattr(v,'isoformat'): v=v.isoformat(timespec='microseconds').replace('+00:00','Z')
+ elif isinstance(v,list): v=[str(x) for x in v]
+ elif type(v).__name__=='UUID': v=str(v)
+ result[k]=v
+ return result
+
+
+class Store:
+ def __init__(self,cfg):
+ self.cfg=cfg
+ self.secret=cfg.cursor_secret.encode()
+ self.pool=AsyncConnectionPool(cfg.database_url,min_size=1,max_size=cfg.db_pool_size,
+ timeout=2,max_waiting=32,open=False,
+ kwargs={'row_factory':dict_row,'connect_timeout':3,
+ 'options':'-c statement_timeout=2000 -c lock_timeout=1000 -c timezone=UTC'})
+ self.cache=Redis.from_url(cfg.redis_url,socket_timeout=.2,socket_connect_timeout=.2,
+ max_connections=8,decode_responses=True)
+
+ async def open(self): await self.pool.open(wait=True,timeout=20)
+ async def close(self):
+ await self.cache.aclose()
+ await self.pool.close()
+
+ async def ready(self):
+ async with self.pool.connection() as c: await c.execute('SELECT 1')
+
+ async def register(self,username,display_name,password_hash):
+ try:
+ async with self.pool.connection() as c:
+ row=await (await c.execute('INSERT INTO users(id,username,display_name,password_hash) VALUES (%s,%s,%s,%s) RETURNING id,username,display_name,created_at',
+ (uuid4(),username,display_name,password_hash))).fetchone()
+ return clean(row)
+ except psycopg.errors.UniqueViolation:
+ raise ApiError(409,'conflict','Username already exists') from None
+
+ async def credentials(self,username):
+ async with self.pool.connection() as c:
+ return await (await c.execute('SELECT * FROM users WHERE username=%s',(username,))).fetchone()
+
+ async def create_session(self,user_id,token):
+ async with self.pool.connection() as c:
+ row=await (await c.execute("INSERT INTO sessions(token_hash,user_id,expires_at) VALUES (%s,%s,clock_timestamp()+%s*interval '1 second') RETURNING expires_at",
+ (hashlib.sha256(token.encode()).hexdigest(),user_id,self.cfg.session_ttl_seconds))).fetchone()
+ return clean(row)['expires_at']
+
+ async def authenticate(self,token):
+ async with self.pool.connection() as c:
+ session=await (await c.execute('SELECT user_id FROM sessions WHERE token_hash=%s AND expires_at>clock_timestamp()',
+ (hashlib.sha256(token.encode()).hexdigest(),))).fetchone()
+ if session is None: raise ApiError(401,'unauthorized','Invalid session',{'WWW-Authenticate':'Bearer realm="messenger"'})
+ key='user:'+str(session['user_id'])
+ try:
+ cached=await self.cache.get(key)
+ if cached: return json.loads(cached)
+ except (RedisError,ValueError):
+ logging.getLogger('messenger').warning('{"event":"cache_bypass"}')
+ row=await (await c.execute('SELECT id,username,display_name,created_at FROM users WHERE id=%s',(session['user_id'],))).fetchone()
+ user=clean(row)
+ try: await self.cache.set(key,json.dumps(user),ex=60)
+ except RedisError: pass
+ return user
+
+ async def logout(self,token):
+ async with self.pool.connection() as c:
+ await c.execute('DELETE FROM sessions WHERE token_hash=%s',(hashlib.sha256(token.encode()).hexdigest(),))
+
+ async def _chat(self,c,actor,chat_id):
+ row=await (await c.execute('SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM members WHERE chat_id=c.id ORDER BY user_id) AS member_ids FROM chats c JOIN members m ON m.chat_id=c.id WHERE c.id=%s AND m.user_id=%s',(chat_id,actor))).fetchone()
+ if row is None: raise ApiError(404,'not_found','Object not found')
+ return clean(row)
+
+ async def chat(self,actor,chat_id):
+ async with self.pool.connection() as c: return await self._chat(c,actor,chat_id)
+
+ async def create_chat(self,actor,title,members):
+ if actor not in members: invalid('Members must include the current user')
+ try:
+ async with self.pool.connection() as c:
+ cid=uuid4()
+ await c.execute('INSERT INTO chats(id,title) VALUES (%s,%s)',(cid,title))
+ async with c.cursor() as cur:
+ await cur.executemany('INSERT INTO members(chat_id,user_id) VALUES (%s,%s)',[(cid,m) for m in members])
+ return await self._chat(c,actor,cid)
+ except psycopg.errors.ForeignKeyViolation:
+ invalid('All members must exist')
+
+ async def create_message(self,actor,chat_id,text):
+ async with self.pool.connection() as c:
+ await self._chat(c,actor,chat_id)
+ row=await (await c.execute('INSERT INTO messages(id,chat_id,sender_id,text) VALUES (%s,%s,%s,%s) RETURNING id,chat_id,sender_id,text,created_at',
+ (uuid4(),chat_id,actor,text))).fetchone()
+ return clean(row)
+
+ async def page(self,actor,chat_id,limit,cursor):
+ async with self.pool.connection() as c:
+ if chat_id:
+ await self._chat(c,actor,chat_id)
+ query='SELECT id,chat_id,sender_id,text,created_at FROM messages WHERE chat_id=%s'
+ args=[chat_id]; resource='messages:'+chat_id
+ if cursor:
+ query+=' AND (created_at,id)>(%s::timestamptz,%s::uuid)'; args.extend(cursor)
+ query+=' ORDER BY created_at,id LIMIT %s'; args.append(limit+1)
+ else:
+ query='SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM members WHERE chat_id=c.id ORDER BY user_id) AS member_ids FROM chats c JOIN members m ON m.chat_id=c.id WHERE m.user_id=%s'
+ args=[actor]; resource='chats:'+actor
+ if cursor:
+ query+=' AND (c.created_at,c.id)>(%s::timestamptz,%s::uuid)'; args.extend(cursor)
+ query+=' ORDER BY c.created_at,c.id LIMIT %s'; args.append(limit+1)
+ rows=[clean(row) for row in await (await c.execute(query,args)).fetchall()]
+ selected=rows[:limit]
+ next_cursor=encode_cursor(resource,(selected[-1]['created_at'],selected[-1]['id']),self.secret) if len(rows)>limit else None
+ return {'items':selected,'next_cursor':next_cursor}