Proving a regression with tests and run history
Tests that say Inconclusive on partial data, exact diffs, run history with encrypted results, and a compare that says if the SQL or the data changed.
A number moved. Freight by country for last month doesn't match what you showed people two weeks ago. Either somebody edited the query, a parameter was different, you ran it against the wrong database, or the data really changed. Usually you find out by squinting at two screenshots.
SQLly notebooks now keep enough of a record to answer that without squinting. Tests cells, profiles, diffs and run history each do one part of that job, and together they can prove a regression. This is the sixth post in the notebooks series.
The order checks notebook: Run All, the profile, the failing ship region check and its rows, the year-over-year diff, and two runs compared. Recorded in the app. Watch the whole recording, with chapters.
Tests say what they saw, or that they can't tell
A Tests cell holds checks on another cell's result. Row count in a range, unique keys, a not-null limit, a value range, accepted values, a regular expression pattern, matching keys against another cell's result, drift from a baseline, freshness of the newest timestamp, query duration and KPI thresholds. Each check has a severity and an optional name like "one row per order", and each one reports Pass, Warning, Fail, Error or Inconclusive with the numbers it saw. A failing check has Show failing rows, which opens up to 20 of them in a grid.
Inconclusive is the important one. If the input was cut short by a row limit or sampled, a check doesn't pass or fail. It says it can't tell, unless you explicitly allow partial data for that check. I didn't want a test that says "unique" because the first 10,000 rows happened to be unique.
The notebook keeps count. The top bar shows "2 tests failing", Run All ends with "Run finished: 2 tests failing.", and every run's failures are kept with their evidence. Reopen the notebook and the top bar's count comes back from the newest run that checked each test. From a terminal, sqlly-cli notebook run exits with code 4 when a check fails, so a CI job can fail on it.
Profiles tell you when they're guessing
A Profile cell gives a card per column: type and likely meaning, missing and distinct values, range, average and spread, percentiles, outliers, a histogram, the most frequent values, and whether it could be a key. It works in a fixed amount of memory, so counts are exact up to a point and then estimated, and every estimate is marked ≈.
The banner says how much was read: "Profiled all 48,210 rows. Every figure is exact." or "Approximate: profiled 100,000 of 2,400,000 rows. Run the input in full for exact figures." A column is only called unique when every row was read. Same rule as the tests, for the same reason.
Diffs only call it when they've seen everything
A Diff cell compares a Before and an After. Each side is a cell's current result, its previous run, a snapshot you pinned, or the same SQL re-run read-only on another of the notebook's connections, which is how you compare dev with production. That other connection has to be one your trust lets the notebook use, and one that exists on this computer. Give it key columns to pair rows by key, or let it pair by position. Tolerance ignores small numeric differences, and text can be compared ignoring case or spacing.
The chips for added, removed, changed and unchanged rows are always exact, big integer ids and wide decimals included, and the grids show up to 2,000 changed rows with before, after and the difference. Each side is read up to 1,000,000 rows. Past that the diff refuses instead of comparing part of the data, and it only calls a comparison conclusive when both inputs are complete.
Every run leaves a record
Each time a notebook runs in the app, SQLly records what was asked for, which cells ran or failed, test results and the parameter values used, and sensitive values are never written. They show as hidden. The History tab on the left rail lists those runs, newest first. Open run shows a past run's results under the cells. Those results are kept encrypted for up to seven days. The run records themselves don't expire.
To keep a result longer, pin it as a named snapshot. A snapshot doesn't age out with the seven-day results, and Tests and Diff cells can use it as a baseline, as in "Snapshot: golden". Runs from sqlly-cli and from schedules are written to the same place, so they show up in the same History tab.
Compare runs says why a number moved
Click two runs and press Compare runs. For each cell that differs, SQLly gives the cause, worked out from what each run recorded. "The cell's SQL changed." "Parameters changed: region." "It ran on a different connection, database or sign-in." "Its safety settings (read-only, limits, cache) changed." "Cells it reads from changed: orders." Or, when none of those moved: "Same SQL, parameters and connection, but the data changed."
That last one is only said when both results were complete and checksummed. Together with the row-count and test-result changes per cell, it's usually enough to tell "someone edited the query" from "the data really changed" without running anything. The CLI does the same with sqlly-cli notebook runs compare latest~1 latest --notebook revenue.sqllynb.
What's missing
The command-line runner only runs SQL, Tests, KPI and data attachment cells. Profile, Diff, Plan, Entity detail, AI, transform and formula cells need the app. The History tab lists the newest 200 runs. Runs from the CLI record no query plans. Runs recorded before causes were tracked can only say "Something changed, but the older run does not record what." In the browser build, past results and snapshots aren't kept at all, because they're stored encrypted with a key from your system keychain and the browser doesn't have one SQLly can use.
One technical caveat on drift. Drift checks use PSI (the population stability index), KS distance or mean shift against the previous run or a snapshot. A stored baseline keeps a histogram, not the raw values, so KS distance is measured at the baseline's bin edges. That's coarser than a textbook KS test. It's fine for "this moved a lot", less so for small shifts.
Everything here is on Profiles, tests, diffs and plans and Run history and snapshots. The next post is the AI agent, which leans on all of this for its evidence. If a check ever says Pass when it shouldn't have, send me the notebook and the run.