SQL Query Reviewer
/install sql-query-reviewer
sql-query-reviewer
Description
Review SQL queries across any dialect for correctness, performance, and security. Finds N+1 patterns, missing indexes, injection risks, cartesian joins, and implicit type casts. Returns a structured report with severity ratings and optimized rewrites.
Use when
- "optimize this query"
- "is this SQL safe"
- "why is my query slow"
- "check my SQL"
- "is this injection-safe"
- Any raw SQL query, ORM-generated SQL, or migration file
Supported dialects
PostgreSQL, MySQL, SQLite, SQL Server (T-SQL), Oracle, BigQuery, Snowflake — and any ANSI SQL.
Input
Paste the SQL query or queries. Optionally specify:
- Dialect (defaults to generic ANSI SQL)
- Approximate table sizes (helps with index advice)
- Whether this is in a hot path (e.g., called on every request)
- ORM in use (if applicable)
Output format
## SQL Query Review
### Critical (fix before production)
- [Finding] — [why this causes bugs or data loss]
✗ Before: [problematic SQL]
✓ After: [corrected SQL]
### Performance (should fix)
- [Finding] — [estimated impact]
✗ Before: [slow SQL]
✓ After: [optimized SQL]
### Suggestions (nice to have)
- [Finding] — [explanation]
### What's correct
- [Specific patterns done right]
### Summary
[2–3 sentences: biggest risk, top fix, index recommendations if any]
Review checklist
Correctness
NULLcomparison using=instead ofIS NULLNOT INwith a subquery that can return NULLs — always falseUNIONinstead ofUNION ALLwhen duplicates are acceptable (unnecessary dedup)- Wrong join type:
INNERwhenLEFTneeded, or vice versa - Cartesian join (missing
ONclause or cross join without intent) - Aggregate without
GROUP BYon non-aggregated columns - Incorrect use of
HAVINGvsWHERE - Date/time arithmetic in wrong timezone
Security
- String interpolation into query — SQL injection risk
- User-supplied value in
ORDER BY,LIMIT, table/column name - Missing parameterisation in dynamic SQL
- Overly broad
SELECT *that exposes sensitive columns - Missing row-level security filter
Performance
SELECT *when only specific columns needed (excess data transfer)- Missing
WHEREclause on large table scan LIKE '%value%'— can't use index (leading wildcard)- Function applied to indexed column in
WHERE— defeats index - N+1: query inside a loop that could be a single JOIN
- Missing index on foreign key or frequently filtered column
- Subquery that re-executes per row — use CTE or JOIN instead
ORDER BY RAND()or equivalent — full table scan- Unbounded result set with no
LIMIT
Style
- Inconsistent case (keywords, identifiers)
- Ambiguous column reference without table alias
- Long query with no CTEs to break it into readable steps
- Magic number with no comment explaining it
Severity definitions
- Critical: Correctness bug (wrong results), injection risk, or data loss — fix before production
- Performance: Causes slow queries, full scans, or poor scalability — fix before release
- Suggestion: Readability, maintainability, or defensive coding improvement
Self-improvement instructions
After each review, note the most common finding. After 20 reviews, surface the top 3 SQL anti-patterns seen as "Most common SQL issues" at the top of the response.
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install sql-query-reviewer - 安装完成后,直接呼叫该 Skill 的名称或使用
/sql-query-reviewer触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
SQL Query Reviewer 是什么?
Reviews SQL queries for correctness, security risks, and performance issues; provides a structured report with severity ratings and optimized rewrites. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 186 次。
如何安装 SQL Query Reviewer?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install sql-query-reviewer」即可一键安装,无需额外配置。
SQL Query Reviewer 是免费的吗?
是的,SQL Query Reviewer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
SQL Query Reviewer 支持哪些平台?
SQL Query Reviewer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 SQL Query Reviewer?
由 Lnguyen1996(@lnguyen1996)开发并维护,当前版本 v1.0.0。