SchemaGate checks SQL rewrites against today’s rows, not tomorrow’s
Version 1.20.0 compares result fingerprints and measures whether a rewrite runs faster. On a live PostgreSQL database, the two queries need not see the same snapshot.
SchemaGate v1.20.0, published Nov. 26, adds a query optimizer that asks a model to rewrite a slow read, then checks the rewrite against the original on the database. By default, the optimizer requires a matching fingerprint and a measured speedup of at least 1.1× to keep a rewrite; if none qualifies, it returns the original SQL. The practical change is that the model proposes candidates, but the database supplies evidence for accepting them.
What the comparison measures
On PostgreSQL, SchemaGate checks a row count and an order-insensitive sum of row hashes inside the database. It also checks an order-sensitive digest when the original has a top-level ORDER BY. For timing it uses the server’s EXPLAIN ANALYZE execution time, taking the best of two timed runs after a warm-up. On SQLite, MySQL, SQL Server and Oracle, the optimizer guide describes a different path: wall-clock timing including fetch, and comparison in Python, with no verified match above 200,000 rows. Those timings are not directly interchangeable with PostgreSQL’s server-side measurement.
The release exposes the checks over MCP as well. explain_query and compare_queries let a client bring its own rewrite without configuring a server-side model. optimize_query runs the model-driven loop on the server. The guide says all three use the same caller-scope checks as run_query. On PostgreSQL, the comparison uses read-only transactions, but it still executes the queries; the maintainers recommend a replica for expensive originals.
A match is evidence, not a proof
The optimizer rejects rewrites that add literals its scanner flags, with 0 and 1 exempted. That helps catch a model hard-coding a boundary it saw in the data. It cannot show that a rewrite handles rows that were absent from the test. A rewrite that changes a LEFT JOIN to an INNER JOIN, for example, could return the same rows when every order has a matching customer and quietly drop orders once an unmatched customer appears. No new literal is needed to make that mistake.
There’s a separate issue on a database receiving writes. The tagged implementation fingerprints the original and candidate in separate transactions. Under PostgreSQL’s default Read Committed isolation, a commit between those reads can change what the second query sees. For a production change, compare against a stable copy, include cases that exercise the query’s assumptions—such as unmatched rows—and review the SQL before swapping it in. A passing comparison is a useful filter, not a substitute for that review.
sources
- SchemaGate v1.20.0 releasegithub.com
- Optimizer documentation at v1.20.0raw.githubusercontent.com
- Optimizer implementation at v1.20.0github.com
- PostgreSQL transaction isolation documentationwww.postgresql.org
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026