β47 tokens always: the name and description. β501 when used: this file. β3.1k more on demand in 4 files.
When to use
- A SQL query is about to be promoted to a production dashboard or report
- A query is returning surprising or incorrect results
- A query is running slowly and needs performance review
- You want to catch anti-patterns (implicit conversions, SELECT *, unbounded CTEs) before they cause incidents
Process
- Lint the query β run
scripts/sql_lint.py (sqlglot-based) to catch syntax errors, unsupported functions for the target engine, and style violations. Fix hard errors before continuing.
- Review anti-patterns β compare the query structure against
references/sql_anti_patterns.md. Flag any present anti-patterns with a severity rating.
- Parse the explain plan β if an EXPLAIN or query profile output is available, run
scripts/explain_plan_parser.py to extract slow steps (full table scans, missing indexes, high row estimates).
- Estimate cardinality β run
scripts/cardinality_estimator.py if schema stats are available to flag joins that might fan-out unexpectedly.
- Check engine-specific behaviour β consult
references/engine_specific_guide.md for the target engine (Snowflake / BigQuery / Postgres / Redshift) to verify date functions, window behaviour, and clustering assumptions.
- Produce review output β fill in
assets/query_review_template.md with findings; for any performance issues found, complete assets/optimization_recommendations.md.
Inputs the skill needs
- Required: the SQL query text
- Required: target database engine (Snowflake / BigQuery / Postgres / Redshift / other)
- Optional: relevant table schemas (column names, types, approximate row counts)
- Optional: EXPLAIN / query profile output
- Optional: expected business logic β what should the query calculate?
Output
assets/query_review_template.md (filled) β categorised findings: correctness, performance, style
assets/optimization_recommendations.md (filled, if issues found) β ranked rewrite suggestions with expected impact