sql-review
Skill1 starsChanged 7 months agoMITView on GitHub
Systematic checklist for reviewing SQL queries and dbt models for correctness, performance, and maintainability.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- Smaui94/ClaudeSkillCollectiontheir own version, first seen Nov 8, 2026
- polardb/polardbx-skillstheir own version, first seen Nov 8, 2026
- Lanqiao-Luca/ai-java-workflowtheir own version, first seen Nov 8, 2026
- z-Zihan/Evirtheir own version, first seen Oct 13, 2026
- analyticsengineering/ae-toolkittheir own version, first seen Oct 12, 2026
- kyle-chalmers/streamsnowtheir own version, first seen Oct 11, 2026
Used with
Projects with it also use code-review.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
Also in 4 projects that use this
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- Lanqiao-Luca/ai-java-workflow★ 220same name
- kyle-chalmers/streamsnow★ 17same name
- z-Zihan/Evir★ 11same name
- polardb/polardbx-skills★ 8same name
- analyticsengineering/ae-toolkit★ 3same name
- gmanch94/claude-code-aidlc-template★ 2same name
- Jiplet/transformation-os★ 2same name
- dennisrongo/claude-skills★ 1same name
- bt2go/claude-skills★ 0same name
- Smaui94/ClaudeSkillCollection★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adr-writerSkill
- commit-styleSkill
- data-contractsSkill
The file
Files
SQL Review Skill
Systematic checklist for reviewing SQL queries and dbt models for correctness, performance, and maintainability.
Review Checklist
Correctness
- JOIN semantics are intentional. Is this INNER, LEFT, or FULL OUTER? Does NULL handling match the intent?
- Aggregation is at the right grain. Does GROUP BY match the intended unit of analysis?
- DISTINCT is not hiding a fan-out. If DISTINCT is used, understand why duplicates appeared.
- NULL handling is explicit.
COALESCE,NULLIF,IS NULL— are NULLs treated as meaningful or as data quality failures? - Date/time arithmetic is timezone-aware. Timestamps converted to local time before truncation? UTC vs. local?
- Division handles zero denominators.
NULLIF(denominator, 0)prevents division-by-zero. - CASE exhaustiveness. Does the CASE cover all possible values? Is an ELSE clause present?
Performance
- *No SELECT . Enumerate columns explicitly. SELECT * breaks downstream when the schema changes.
- Partition pruning is possible. The WHERE clause filters on a partition column.
- EXPLAIN plan reviewed. Look for: full table scans, Cartesian joins, nested loops on large tables, high estimated row counts.
- Joins on correct types. Joining VARCHAR to INT causes implicit casts and defeats indexes.
- Window functions over full scans. PARTITION BY on a high-cardinality column forces full shuffles in Spark.
- Subquery vs CTE. CTEs are more readable. In some engines (Snowflake, BigQuery), CTEs are materialized — use subqueries when the optimizer needs to inline.
- LIMIT on exploratory queries. Never run
SELECT * FROM billion_row_tablewithout LIMIT in development.
Readability & Maintainability
- CTEs are named after what they produce, not how.
customer_ordersnotcte1orstep1. - One logical transformation per CTE. Each CTE does one thing.
- Column aliases are descriptive.
revenue_usd, notrevorr. - No magic numbers.
WHERE status_code = 4→ what is status 4? Use a named constant or join to a lookup table. - Consistent capitalization. Keywords UPPER or lower — pick one. Column names snake_case.
dbt-Specific
- Primary key tested.
not_null+uniquetests on the model's grain column. - Foreign key relationships documented.
relationshipstest or description references the upstream model. ref()andsource()used, not hardcoded table names. NeverFROM prod.orders.order_events— use{{ ref('order_events') }}.- Incremental models have a filter.
{% if is_incremental() %} WHERE updated_at > (SELECT MAX(updated_at) FROM {{ this }}) {% endif %}. - No business logic in staging models. Staging = rename + cast + deduplicate. Business logic belongs in mart/reporting models.
Common SQL Anti-Patterns
The N+1 equivalent in SQL: correlated subquery in SELECT
-- BAD: executes once per row in the outer query
SELECT
o.order_id,
(SELECT COUNT(*) FROM order_items oi WHERE oi.order_id = o.order_id) AS item_count
FROM orders o;
-- GOOD: single pass with window function or JOIN
SELECT
o.order_id,
COUNT(oi.item_id) AS item_count
FROM orders o
LEFT JOIN order_items oi ON o.order_id = oi.order_id
GROUP BY o.order_id;Fan-out from unintended many-to-many join
-- BAD: if orders has multiple payments, revenue is double-counted
SELECT
SUM(p.amount) AS total_revenue
FROM orders o
JOIN payments p ON o.order_id = p.order_id;
-- GOOD: aggregate payments before joining
WITH payment_totals AS (
SELECT order_id, SUM(amount) AS total_amount
FROM payments
GROUP BY order_id
)
SELECT SUM(pt.total_amount) AS total_revenue
FROM orders o
JOIN payment_totals pt ON o.order_id = pt.order_id;Filtering after aggregation when filtering before is possible
-- BAD: aggregates all rows, then filters
SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
HAVING customer_id IN (SELECT customer_id FROM vip_customers);
-- GOOD: filter before aggregating reduces scan size
SELECT o.customer_id, COUNT(*) AS order_count
FROM orders o
INNER JOIN vip_customers v ON o.customer_id = v.customer_id
GROUP BY o.customer_id;Implicit type coercion in JOIN
-- BAD: customer_id is VARCHAR, user_id is INT — full scan on both
SELECT * FROM orders o JOIN users u ON o.customer_id = u.user_id;
-- GOOD: cast explicitly and document why the types differ
SELECT * FROM orders o
JOIN users u ON o.customer_id = CAST(u.user_id AS VARCHAR);
-- Note: customer_id stores legacy string IDs; user_id is the new integer PK.
-- Tracked in ADR-0008.EXPLAIN Output Reading Guide
| Pattern | Risk | Action |
Seq Scan on large table | High | Add index, verify partition pruning |
Hash Join on very large tables | Medium | Check join cardinality, consider bucketing |
Nested Loop on large tables | Very High | Rewrite as hash join or add index |
Sort with large estimated rows | Medium | Index if query runs frequently |
| Estimated rows << Actual rows | High | Run ANALYZE to update statistics |
Broadcast in Spark on large DF | High | Use sort-merge join instead |
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.

