DE//AGENT
Explore

Review SQL for fan-out joins

Follow the SQL Reviewer agent's four-step pass over a real query: read the diff and its context, establish the grain of every result set, apply the SQL Review skill's five rules while stopping at the first fan-out, and emit findings with file positions plus a rewritten clause you can verify against the twelve-case evaluation fixture.

At a glance

When A review must prove a join cannot fan out; Suspicion of NULL-unsafe NOT IN or = predicates
Where SQL
Why Fan-out doubles counts silently; this walkthrough turns the SQL Reviewer's four-step pass into a habit with a fixture that proves it worked.

Learning objectives

  • Prove a join cannot fan out before writing it
  • Spot NULL-unsafe `NOT IN` and `=` predicates
  • State the grain of a result set in one sentence

What you need

  • A pull request or a .sql file
  • The target dialect (postgres/duckdb/snowflake)
  • [object Object]

Steps

  1. Read the diff and the file context. (from agent-sql-reviewer )
  2. Establish the grain of every result set. (from agent-sql-reviewer )
  3. Apply the SQL review rules; stop at the first fan-out. (from agent-sql-reviewer )
  4. Emit findings with file:line and a rewritten clause. (from agent-sql-reviewer )

Check yourself

  • On a 12-case fixture of known-bad SQL, correctly identifies 11 correctness bugs and 0 false positives.
  • Reviewing a PR that joins orders to a non-unique customer snapshot — flags fan-out and proposes a dedupe CTE.

Worked example

Install the SQL review skill — from skill-sql-review

npx de-agent-platform add sql-review

The five review rules, applied in order — from skill-sql-review

1. Every join states its cardinality (1:1, N:1, N:N) and justifies it.
2. NOT IN (subquery) is banned where the subquery can return NULL — use NOT EXISTS.
3. Comparisons across types must be explicit casts, not implicit.
4. ORDER BY without LIMIT in a view is meaningless — drop it.
5. SELECT * in a persisted model freezes an unstable schema.

Sourced from

Security scan

Last sweep 2026-10-24: 0 finding(s), 0 marked as examples.

Common gotchas

  • Stop at the first fan-out — fixing five joins at once hides which fix worked.
  • NOT IN with a nullable column never compares as you think; use NOT EXISTS.
  • State the grain of every result set in one sentence before judging the query.

Production considerations

  • Keep the 12-case evaluation fixture in CI so regressions resurface.
  • Emit findings with file positions and a rewritten clause reviewers can verify.

Diagram

sql review pass
   |
   |- read diff + context --> state grain per result set
   |
   |- apply 5 rules --> first fan-out --> dedupe CTE
   |
   |- emit findings --> file:line + rewritten clause --> verify on fixture

Registry stats

Verification community · Oct 16, 2026
Completeness 81
Trust multiplier ×1.25
Composite 34.15 · adequate
Freshness 8 days since last source check
Difficulty beginner
Version 0.1.0
License Apache-2.0
Security flags none