An agent-generated SQLite PR that claims a faster query should not be merged on a green test run and a plausible diff. Review it as three separate claims: the result set is unchanged, the query plan changed in the intended way, and the migration can be reversed. If any claim lacks evidence, send the PR back.
This review targets a common edge case: an agent rewrites an EXISTS subquery into a join against a deduplicated set and adds a composite index. The rewrite can be correct. It can also change row multiplicity or add a temporary b-tree for DISTINCT, ORDER BY, or GROUP BY. No executable example is included; the checks below describe inputs to prepare, observations to make, and how to interpret a mismatch.
Prerequisites and scope
- A disposable copy of the schema and data you are allowed to use.
- The SQLite version pinned by the application, so plan evidence is reproducible.
- The original and proposed SQL, not just the generated migration.
- A test fixture that contains duplicate orders rows and a NULL case where the schema permits it.
- Query-plan output from the pinned SQLite version for both statements.
What to trust
Trust artifacts you can reproduce, not the PR narrative.
- Schema constraints and fixtures you control. They define the cases the query must handle.
- SQLite query-plan output for strategy. The SQLite query-plan documentation says each table read has a detail record beginning SCAN or SEARCH; SCAN is a full-table scan, while SEARCH visits a subset. It also documents temporary b-tree records for ORDER BY, GROUP BY, or DISTINCT: https://www.sqlite.org/eqp.html. This is not a timing benchmark.
- Bidirectional set comparison. If both queries return the same columns, compare both set-difference directions. A one-way comparison can miss rows added by the new query.
- A tested down migration. Test it on a disposable database, not in production.
A detail record beginning SEARCH is evidence that a subset of rows is visited. It is not evidence that the query is faster. The PR still needs a before/after measurement under the same SQLite version, schema, and data distribution.
| Agent claim | Evidence to require | If missing |
|---|---|---|
| faster | Before/after timing on the same data and SQLite version | Revert the claim; keep the PR in draft |
| uses an index | Query-plan detail from the pinned version | Block until the plan is attached |
| same results | Both set-difference directions plus duplicate and NULL fixtures | Block; green tests are not enough |
| safe migration | Tested down migration on a disposable copy | Block if the schema cannot be restored |
What to revert
Revert or block the PR when any of these appear:
- The agent edited the test expectations to match the new output. That is not a fix; it is a changed contract.
- DISTINCT was removed to avoid a sort. Verify row multiplicity first. Removing it can turn an existence check into a fan-out.
- An index migration has no rollback and no plan evidence. An index is a schema change; require plan and rollback evidence.
- The PR claims a speedup without a measurement. A plan diff is not a latency result.
- The rewrite changes ordering or pagination semantics. If order matters, require explicit ordering and tests; do not infer it from the rewrite.
If the PR includes build provenance, keep it in perspective: the SLSA 1.2 provenance specification describes production history of artifacts, not application behavior (https://slsa.dev/spec/v1.2/provenance). Provenance can support supply-chain review; it cannot prove that this query returns the same rows.
Observation-based test
1. Row-set equivalence in both directions
Inputs: the original existence query and the proposed join, on the same database copy. Observe both set differences and list the IDs only in the original and only in the proposed result. If the projection can collapse duplicates, also compare row counts. A nonempty difference or a count mismatch means the result-set claim is unsupported. An empty difference is necessary, not sufficient; it does not test ordering, and it does not test duplicate behavior if the projection collapses rows.
2. Duplicate and NULL cases
Inputs: a customer with zero open orders, a customer with one open order, a customer with multiple open orders, orders with non-open statuses, and a NULL join key if the schema permits it. Observe counts per customer and compare the full result, not only the first page. A mismatch is any customer appearing a different number of times, any NULL included or excluded differently, or any pagination boundary that changes.
3. Plan observation
Ask the PR author to attach query-plan output from the pinned SQLite version for the original and proposed statements on the same database file. Observe detail records beginning SCAN or SEARCH, and temporary b-tree records for ORDER BY, GROUP BY, or DISTINCT. Interpret a missing intended access path or a new temporary b-tree as a reason to demand an explanation, not as automatic proof of regression. Record the SQLite version with the output. The official reference is https://www.sqlite.org/eqp.html.
4. Migration up and down
Apply the index migration on a disposable copy, observe the schema before and after, then apply the down migration and confirm the schema returns to its prior state. If the down migration drops an index that other queries depend on, the PR is not reversible enough to merge as-is. SQLite transaction documentation notes one active write transaction and savepoints for nesting; keep the migration test isolated (https://www.sqlite.org/lang_transaction.html).
Failure modes
- Green tests, missing duplicate fixture. The suite passes because no customer has more than one open order.
- Plan output treated as a benchmark. A plan describes strategy; it does not establish latency.
- DISTINCT hides a fan-out but adds a temporary b-tree. The result may be correct while the plan gains a sort or materialization step.
- Plan output recorded without the SQLite version. The evidence is hard to reproduce.
- Index measured only for reads. The write workload remains unmeasured.
When this review does not apply
Do not use this playbook for a formatting-only change, a non-SQLite database, or a query with no performance or correctness claim. Do not claim a speedup from a plan alone. If you lack representative data, say so and keep the PR in draft.
The merge rule is simple: trust the plan for strategy, trust tests for the cases they actually cover, and revert any change that cannot show both semantic equivalence and a reversible migration.
AI assistance: This draft was generated with AI assistance. No query, migration, or plan was executed for it; the checks above describe observations a human reviewer should make. A human reviewer should verify the SQLite version, schema, plan output, fixtures, and DEV policy before publishing.
This article was created with AI assistance.