Lab 2 U5 history index evidence
Base commit at measurement: d59d3f4; local Colima Docker: 2 CPUs, 2054840320 bytes memory.
Command: docker compose --env-file .env exec -T api python - --count 10000 --deep-offset 8000 < scripts/seed_history.py
Each run creates a new synthetic user/chat and appends its own messages to the disposable test database.
UTC: 2026-10-02T08:41:04.204691+00:00
PostgreSQL: 17.6 (Debian 17.6-2.pgdg12+1)
Synthetic chat messages: 10000
Deep cursor ordinal: 8000
History index: CREATE INDEX messages_history_idx ON public.messages USING btree (chat_id, created_at, id)
Verified: first/deep pages each have 51 ordered rows with no shared IDs

First page: EXPLAIN (ANALYZE, BUFFERS)
Limit  (cost=0.29..6.76 rows=51 width=70) (actual time=0.003..0.007 rows=51 loops=1)
  Buffers: shared hit=3
  ->  Index Scan using messages_history_idx on messages  (cost=0.29..1269.95 rows=10000 width=70) (actual time=0.003..0.005 rows=51 loops=1)
        Index Cond: (chat_id = '86684ee0-6818-4f81-ad7f-e7bf9069b8e8'::uuid)
        Buffers: shared hit=3
Planning Time: 0.014 ms
Execution Time: 0.010 ms

Deep page: EXPLAIN (ANALYZE, BUFFERS)
Limit  (cost=0.29..11.51 rows=51 width=70) (actual time=0.003..0.010 rows=51 loops=1)
  Buffers: shared hit=4
  ->  Index Scan using messages_history_idx on messages  (cost=0.29..439.78 rows=1996 width=70) (actual time=0.003..0.007 rows=51 loops=1)
        Index Cond: ((chat_id = '86684ee0-6818-4f81-ad7f-e7bf9069b8e8'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 08:41:04.152402+00'::timestamp with time zone, '492d2f70-1f2b-4e98-a87d-5bab4668d05c'::uuid)))
        Buffers: shared hit=4
Planning Time: 0.016 ms
Execution Time: 0.014 ms
