- How you use it
- Runs as a workflow step
- What it can do
- writes files · runs shell
- What's inside
The option
| Option | AWorkflow · v1.0.0Join grain fixture |
|---|---|
| How you use it | Runs as a workflow step |
| What it can do | writes files · runs shell |
| What's inside |
What this thread does
As of November 2026, declare table grain and reconcile a trusted total before accepting an agent’s SQL. Bruin and Basedash both discuss join multiplication, but differ on DISTINCT.
Do first: compare counts and sums before and after joins, then calculate the metric another way, following the review checklist.
The failure
A query written by an agent can run without any error and still be wrong. A silent failure is join fan-out: you join a table at order level to a table at order-line level and then sum an order-level column, so each order is counted once per line.
Bruin Academy's lesson "Join two tables without breaking the number" (updated 26 Aug 2026) shows it on a small dataset: the correct order-level total is 604,065.00; after joining to order lines the sum is 1,449,771.82, about 2.4 times too high. The query runs without an error. A second silent failure from the same lesson: putting a filter on the right-hand table in WHERE instead of ON (the lesson says to keep WHERE for the left table) turns a LEFT JOIN into an INNER JOIN, and an inner join to products dropped 15 orphan lines worth 3,637.89.
Checks from the two sources
From the Bruin lesson and the Basedash checklist ("How to review AI-generated SQL", Max Musing, 21 May 2026; Basedash sells a BI product, so read it as a vendor guide):
1. State the grain of each table (one row per what?) before reading the query, and state the grain the result should have. 2. Compare counts and sums before and after each join. The Bruin example gives an inflation factor of about 2.4. Do not assume the monetary inflation factor always equals the average child-row count; inspect the grain and reconcile the actual sums (worked example). 3. Total the same number a second way. Basedash suggests asking: "Write a query that totals the same numbers a different way", and comparing. 4. Do not accept DISTINCT as the repair. Bruin says DISTINCT does not fix fan-out and that any use of it should be justified rather than treated as a repair; Basedash calls join fan-out the most common AI SQL error and says it can inflate sums 3 to 10 times, but its cardinality section also lists DISTINCT among deduplication options. The two guides do not agree on a blanket DISTINCT rule; prefer aggregation at the intended grain and explain any deduplication (Basedash). 5. Look for orphans: LEFT JOIN, then filter where the right-side key is NULL (the Bruin lesson includes this anti-join pattern and the 15-line loss through an inner join to products). 6. Check the usual suspects (Basedash): wrong date column (created_at versus paid_at), soft-deleted rows, test or internal accounts, BETWEEN on dates, mixed types in a join, a window function without PARTITION BY, COUNT(column) versus COUNT(*), mixed currencies or time zones. 7. Spot-check the extremes: investigate the highest and lowest values, they often expose fan-out or a missing filter.
A prompt to start with
Suggested prompt: Before you run this query, write down the grain of every table and of the final result. After each join, run a COUNT(*) and a SUM of the key metric and tell me if either changed. Do not use DISTINCT to fix a count; explain the cause instead. Then give me a second query that totals the same metric by a different route.
Common mistakes
- Reading the result for plausibility instead of reconciling to a figure you trust.
- Letting the agent conceal a mismatch by adding DISTINCT or a GROUP BY.
- Reviewing only exploratory queries: the Basedash guide recommends full review for dashboards, reports, three-plus-table joins and contested metrics like revenue and churn.
Caveats
Both sources are teaching material, not studies of agent error rates. The Bruin lesson uses CLI queries rather than an AI prompt, and does not measure how often agents fall into fan-out. The point is that the checks are cheap compared with a wrong number in a report.
Sources
- Bruin’s join lesson: the 604,065.00 and 1,449,771.82 totals, approximately 2.4-fold inflation, 15 orphan lines and 3,637.89 lost revenue. Its remedies include aggregating before joining and avoiding DISTINCT as a blind repair.
- Basedash’s SQL review checklist: cardinality, filters, units, dates and a second computation of the same total. These are teaching examples and vendor guidance, not measured population error rates.
Started from a post by @Max Musing, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.