Plan regression
Overview
A plan regression test detects unexpected changes in a controlled workload, but must not confuse plan shape with correctness or latency. Verify results first, then record engine version, schema, statistics, parameters and plan evidence.
First example
SELECT id FROM pt_order INDEXED BY pt_cents WHERE cents=50 ORDER BY id;Observed SQLite result (rows in JSON):
[ [ 1 ], [ 2 ]]How it works
The host lab compares an explicitly forced index lookup with a forced scan, and checks equal results. SQLite EXPLAIN QUERY PLAN output format is not a stable API; keep any textual assertion limited to a pinned local version. A changed plan is a diagnostic signal, not necessarily a regression. Benchmark repeated workloads separately and avoid brittle fixed timing thresholds.
Practical example
SELECT id FROM pt_order NOT INDEXED WHERE cents=50 ORDER BY id;Observed SQLite result (rows in JSON):
[ [ 1 ], [ 2 ]]Practice and mistakes
Practice: execute EXPLAIN QUERY PLAN for both statements and compare output IDs. Hint 1: use the same predicate. Hint 2: inspect SEARCH versus SCAN, not elapsed time. Mistake: accepting a faster query with incorrect results.
PostgreSQL 17 example — NOT RUN
EXPLAIN (FORMAT JSON) SELECT id FROM pt_order WHERE cents=50 ORDER BY id;Expected result, not executed: "Environment-specific plan; no required node."