reviewing-sql
Skill1 starsChanged 16 days agoMITView on GitHub
Use when writing or reviewing analytical SQL and correctness matters — catch join fan-out, NULL-semantics traps, GROUP BY grain mistakes, and window/dedup bugs before they ship wrong numbers. Triggers include "review this query", "the totals look too high/low", duplicated rows after a join, or any non-trivial aggregation or window function.
In this repository44 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- bigquery-superpowersSkill
- building-data-pipelinesSkill
- data-quality-checksSkill
- dbt-incremental-modelsSkill
- dimensional-modelingSkill
- writing-dbt-modelsSkill
- arenaSkill
- authority-boundarySkill
- beadflowSkill
- blast-radiusSkill
- control-uiSkill
- create-prSkill
- create-verification-skillSkill
- deslopSkill
- diagnosing-bugsSkill
- feedback-to-infrastructureSkill
- finding-concurrency-bugsSkill
- fixing-and-merging-prsSkill
- foundational-thinkingSkill
- grilling-frontend-prototypingSkill
- improve-harnessSkill
- maintain-verification-skillSkill
- make-operations-idempotentSkill
- metamorphic-testingSkill
- minimize-reader-loadSkill
- preflightSkill
- prototypeSkill
- recon-before-actionSkill
- redesign-from-first-principlesSkill
- resolve-merge-conflictsSkill
- tddSkill
- whySkill
- writing-great-skillsSkill
- catch-me-upSkill
- cross-critiqueSkill
- definition-of-doneSkill
- experience-firstSkill
- grillingSkill
- grill-with-docsSkill
- handoffSkill
- never-block-on-the-humanSkill
- show-me-your-workSkill
- unslopSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 48
Check row counts at each step: If a join changes your row count and you didn't expect it to, stop — that's fan-out.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Reviewing SQL
Analytical SQL fails quietly: the query runs, returns a number, and the number
is wrong. There's no stack trace — just a metric that's inflated by a fan-out
join or deflated by a NULL no one accounted for. Review for the handful of
traps that produce plausible wrong answers.
The traps, in order of how often they bite
- Join fan-out (the #1 cause of inflated metrics). Joining to a table that
has more than one matching row per key multiplies your rows — every
downstream
SUM/COUNTis now too high. Before trusting an aggregate after a join, confirm the grain: is the join one-to-one, or did it fan out? Aggregate the many-side to one row per key before joining, orCOUNT(DISTINCT ...). - NULL semantics.
NULL = NULLis not true — it's unknown. Equality andINsilently drop NULLs; useIS [NOT] DISTINCT FROMorCOALESCE.NOT IN (subquery)returns zero rows if the subquery contains a single NULL. PreferNOT EXISTS.- Aggregates skip NULLs:
AVGignores them,COUNT(col)≠COUNT(*).
- GROUP BY grain mistakes. The grain of the result = the
GROUP BYcolumns. Selecting a column that isn't in the group (and isn't aggregated) either errors or, worse, picks an arbitrary value. Be explicit about one row per what. - Window function pitfalls.
ROW_NUMBER()for dedup needs a deterministicORDER BYor you get nondeterministic results. Mind the frame: the default frame forSUM() OVER (ORDER BY ...)is a running total, not the group total — addROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWINGif you meant the whole partition. - Dedup that drops real rows.
DISTINCTandGROUP BYcollapse rows you may have wanted.QUALIFY ROW_NUMBER() OVER (PARTITION BY key ORDER BY ts DESC) = 1is the clean "latest row per key" — verify the partition and order are right. - Filtering an outer join in the WHERE clause. A
WHEREpredicate on the right table of aLEFT JOINsilently turns it into an inner join. Put the predicate in theONclause if you want to keep the unmatched left rows.
How to actually verify
- Check row counts at each step. If a join changes your row count and you didn't expect it to, stop — that's fan-out.
- Spot-check the grain with
select key, count(*) ... group by key having count(*) > 1. - Reconcile against a known total. Tie the result back to a number you trust from the source; a 2× discrepancy is usually fan-out, a slight shortfall is usually NULLs.
Pairs with
- diagnosing-bugs — when a number is wrong, reproduce and trace it rather than guessing.
- data-quality-checks — codify these checks as standing tests, not one-off reviews.
Original skill — distilled from Kevin's analytics-engineering practice.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

