Date: 2026-10-09
Command: py student-tests/explain-history.py
Messages: 12000

PASS: first_page: history index, 51 rows, no full scan; median SQL execution 0.111 ms
PASS: after_6000: history index, 51 rows, no full scan; median SQL execution 0.193 ms
PASS: 12000 messages; HTTP cursor after 6000 returns message 6001; plans saved in evidence

Control: py tests/smoke.py --base-url http://localhost:8080
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.

first_page
PREPARE history(uuid,integer) AS SELECT id::text,chat_id::text,sender_id::text,text,created_at FROM messages WHERE chat_id=$1 ORDER BY messages.created_at,messages.id LIMIT $2;
Limit  (cost=0.29..5.04 rows=51 width=143) (actual time=0.042..0.066 rows=51 loops=1)
  Buffers: shared hit=3
  ->  Index Scan using messages_chat_history_idx on messages  (cost=0.29..1118.17 rows=12000 width=143) (actual time=0.040..0.059 rows=51 loops=1)
        Index Cond: (chat_id = '06ecd609-697c-48aa-9150-8bce12447663'::uuid)
        Buffers: shared hit=3
Planning:
  Buffers: shared hit=113
Planning Time: 0.702 ms
Execution Time: 0.118 ms

after_6000
PREPARE history(uuid,integer,timestamptz,uuid) AS SELECT id::text,chat_id::text,sender_id::text,text,created_at FROM messages WHERE chat_id=$1 AND (created_at,id)>($3,$4::uuid) ORDER BY messages.created_at,messages.id LIMIT $2;
Limit  (cost=0.29..6.41 rows=51 width=143) (actual time=0.043..0.080 rows=51 loops=1)
  Buffers: shared hit=4
  ->  Index Scan using messages_chat_history_idx on messages  (cost=0.29..721.62 rows=6004 width=143) (actual time=0.042..0.074 rows=51 loops=1)
        Index Cond: ((chat_id = '06ecd609-697c-48aa-9150-8bce12447663'::uuid) AND (ROW(created_at, id) > ROW('2026-10-08 19:47:14.460524+00'::timestamp with time zone, 'fc066765-6778-4d9f-b1ed-60f49ecef3db'::uuid)))
        Buffers: shared hit=4
Planning:
  Buffers: shared hit=112
Planning Time: 0.629 ms
Execution Time: 0.152 ms
