Profiles, tests, diffs and plans
功能的Profile a result, test it with checks that show their evidence, compare results and runs, and read, compare and time query plans.
Five cell kinds help you check a result rather than just look at it: 个人资料 describes every column, 测试 checks rules and shows the evidence, 差异 compares two results, Query plan explains and times a query, and Entity detail follows one record through its foreign keys. Each one reads another cell, picked with its Input picker, and runs when you run it.
Profile a result
A Profile cell shows a card for each column of its input: the type and its likely meaning (dates, emails, IDs, money and more), missing values, distinct values, the range, average and spread, percentiles (5th, median, 95th), outliers, a histogram, the five most frequent values, and whether the column could be a key. A summary grid lists every column with Missing %, Distinct, Min, Max, Average, Spread and Key, sortable by any of them.


Profiles work in a fixed amount of memory. Counts are exact up to a point and then estimated, and any 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 result that spilled to disk is profiled from the whole file. When the input is a table in the notebook's local data (an attachment, or a cell copied there) that holds more rows than its result shows, missing values, distinct values, ranges, averages and quartiles come from the whole table, computed by the local database: the banner says "Column statistics cover all 2400 rows of the local table (DuckDB). Histograms, top values and meanings cover the first 1000 rows." and each column card heads those figures Whole table (DuckDB) and the rest First 1000 rows. The summary grid uses the whole-table figures. A profile whose result already covers the whole table is profiled from its rows as before, because the local database's distinct count is an estimate. A column is only called 唯一 when every row was read.


测试
A Tests cell holds one or more checks on its input. Add checks of these kinds:
| 检查 | What it tests |
|---|---|
| Row count | The number of rows is between a minimum and a maximum. |
| 唯一 | One or more columns have no duplicate values (rows with a NULL key are skipped, as in a UNIQUE constraint). |
| Not null | A column's share of NULLs is at most a limit (zero by default). |
| Value range | A column's values are within a minimum and maximum. |
| Accepted values | A column only holds values from a list, optionally ignoring case. |
| 模式 | A column's text matches a regular expression (linear-time, size-limited). |
| Matching keys | Every value of a column exists in a column of another cell (a foreign-key check across results). |
| Drift from baseline | A column's distribution hasn't moved too far from the previous run or a pinned snapshot (PSI, KS distance or mean shift). |
| Freshness | The newest timestamp in a column is recent enough. Timestamps stored without a time zone are read in the check's 时区 (blank means UTC); a timestamp in the future gives a warning. |
| Query duration | The input query ran within a time limit. |
| KPI threshold | A value compares as expected with a threshold. |
Each check has a severity (error or warning) and an optional name, such as "one row per order". Press Run tests (or run the notebook). Each check shows 传入, 警告, Fail, 错误 或者 Inconclusive with the numbers it saw, and a failing check offers Show failing rows with up to 20 of them in a grid.


- No false alarms from partial data. When the input was cut short or sampled, a check reports Inconclusive instead of passing or failing, unless you allow partial data for that check.
- Baselines. Drift checks compare with the Previous run 或一个 快照 you pinned in the History tab; see Snapshots.
- The notebook keeps count. The top bar shows "2 tests failing" (or "need attention", or "passing"), and Run All ends with "Run finished: 2 tests failing." Every run's failures are kept with their evidence in the run history. When you open the notebook again, the top bar shows each Tests cell's outcome from the newest recorded run that checked it, until a new run replaces it.
- In CI.
sqlly-cli notebook runexits with code 4 when a check fails; see exit codes.


Diff two results
A Diff cell compares a 之前 和一个 之后. Each side is a cell and one of:
- Current result: the cell's result now.
- Previous run: the same cell in the last recorded run.
- Snapshot: …: a snapshot you pinned.
- Re-run on …: the same SQL run again, read-only, on another of the notebook's connections, to compare development with production. That connection must be one you allowed when you trusted the notebook, and it must be set up on this computer ("That connection is not set up on this computer.").
为 键列 的表(例如 id, region) to pair rows by key; without keys, rows are paired by position. Tolerance ignores numeric differences up to an amount (say 0.01 for rounding), and Ignore case 和 Ignore spacing compare text loosely. Large whole numbers and long decimals are compared digit for digit, never through floating point, unless you set a tolerance. Press 比较: chips summarize added, removed, changed and unchanged rows (always exact), column changes are listed, and grids show the added, removed and changed rows (each change with before, after and the difference), up to 2,000 rows.


Each side is read up to 1,000,000 rows; past that the diff refuses rather than compare part of the data. A comparison is called conclusive only when both inputs are complete.
查询计划
A Query plan cell shows the plan of another cell's query, through the same plan viewer as a query tab (findings and the operator tree; see 查询计划), on engines that support it.
- 估计计划 never runs the query. Actual plan (runs the query) runs it once after you confirm: "An actual plan runs this query once on its connection, read-only." with Run actual plan. Both always use the read-only session, and both refuse a query with more than one statement: "A plan can only be captured for a single statement. Split the query into one statement per cell."
- Compare with another cell's query (a rewrite) or the Previous run to see which operators got costlier or cheaper. The query you compare with goes through the same checks as running it, and must be on the same connection.
- Explain with AI, beside the plan, adds an AI cell that explains the plan's most expensive steps and how the query might be made faster. See The AI notebook agent.
- Session counters from the database are shown on SQL Server and MySQL, each figure labelled with the engine and where it came from.




Parameter sweeps
A plan cell can also time a query across a list of values for one parameter, a few runs each: at most 200 runs in all (values × repetitions, up to 20 repetitions). For each value it reports the mean, standard deviation, minimum, maximum and median, and says one value is faster or slower than another only when the difference is beyond two standard errors; otherwise "Within run-to-run noise". A sweep goes through the same permission checks as running the cell (trust, the connection, read-only), never runs a cell that changes data ("Sweeps only run read-only queries."), and on a production connection it asks first: "This sweep repeats the query on a production connection. Authorize this run?" with Authorize and run.
Entity detail
An Entity detail cell takes one record, a row from another cell's result (with Previous and Next to step through it) or a parameter value such as a customer ID. When the row comes from a Table cell, the Entity detail cell follows the row you select in that table's grid (through its sorting and filters) and fetches its related rows again once it has run. It shows the rows related to it through foreign keys, each in its own grid. Tick the relationships to follow under Relationships to follow: "Orders rows that point here (CustomerID)" or "Customers it points to (CustomerID)". Only ticked relationships are queried, read-only, at most 50 rows each by default (500 at most) and up to 12 relationships; rows with a NULL key are skipped. Open as detail on a related set adds a new Entity detail cell for it.


限制
- A diff side re-run on another connection uses the SQL as written for the cell's own engine.
- A plan can't compare with a query on a different connection.
- The CLI runs Tests cells but not Profile, Diff, Plan or Entity detail cells.
- Only profiles of a local table use the whole table for their column statistics; a profile of a remote result reads the rows the result holds.