DistillQL

The explain record

Every query returns an explain record with the rows: the checks the query passed, what ran on each engine and as whom, the policies that applied, where each output column came from, and what it cost. An agent reads it to check its own work. A person reads it to check the agent's.

query by ana across shop
  validated: one statement, read-only, read in the duckdb dialect
  validated: resolved 2 table(s) against the federated catalog
  validated: every column qualified and found in its table's schema
  validated: single engine 'shop': no local join needed
  validated: shop [*] estimate: rows=3 bytes=None (EXPLAIN)
  shop [*] as ana: 2 rows, 46 bytes, 2 ms
      pushdown: whole query ran on the engine; local plan is a pass-through
      policy: none: DuckDB has no session user
  local join: 2 rows, 1 ms
  lineage:
      region <- shop.main.customers.region (1.00)
      revenue <- shop.main.orders.amount (0.95)
  cost: bytes_pulled=46, remote_ms=2, local_ms=1, fragments=1

Get it

  • Command line: distillql sql prints it after the rows. --json prints all of it.
  • Python: res.explain().summary() for the text above, res.explain().to_dict() for all of it.
  • Agent tools: query returns it with every result.

Fields

Field What it holds
query, user, engines The SQL, who asked, and the engines it read.
validation Each check the query passed before anything ran.
warnings What the agent should read before it answers: a cap it could not check, a row count it does not know.
fragments One per engine part: its SQL, the identity it ran as, what the engine reported back (identity_seen), policies, pushdown, estimated and actual rows, bytes and time.
local_sql, local_rows, local_ms The join DuckDB ran over the parts.
lineage For each output column, the source engine.schema.table.column and how sure DistillQL is.
cost Bytes pulled, time on each side, number of fragments, and bytes the engine billed when it reports them.
metrics_expanded Each metric('name') the query used, and what it expanded to.

Identity

identity_seen is what the database itself reported (current_user on Postgres), so the record shows who the query really ran as. On Postgres it is read before and after the rows. If the query changed its role in between, the rows are thrown away and the query fails.

Limits

A query over a limit is refused before it runs, with a message that names the limit and the estimate. Set limits in the config:

caps: {rows: 1000000, bytes: 500000000}

When an engine gives no estimate, DistillQL warns and runs. With strict: true it refuses instead. See configuration.