← 返回
未分类 中文

SQL Query Reviewer

Reviews SQL queries for correctness, security risks, and performance issues; provides a structured report with severity ratings and optimized rewrites.
审查SQL查询的正确性、安全风险和性能问题,提供含严重等级和优化重写建议的结构化报告。
lnguyen1996
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 501
下载
💾 16
安装
1
版本
#latest

概述

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

  • NULL comparison using = instead of IS NULL
  • NOT IN with a subquery that can return NULLs — always false
  • UNION instead of UNION ALL when duplicates are acceptable (unnecessary dedup)
  • Wrong join type: INNER when LEFT needed, or vice versa
  • Cartesian join (missing ON clause or cross join without intent)
  • Aggregate without GROUP BY on non-aggregated columns
  • Incorrect use of HAVING vs WHERE
  • 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 WHERE clause 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.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-30 23:14 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Dockerfile & Container Reviewer

lnguyen1996
审查 Dockerfile 和 docker-compose 文件的安全、大小、构建及最佳实践问题,提供详细严重程度评级报告及修复建议。
★ 0 📥 523

Async & Concurrency Reviewer

lnguyen1996
审查多语言异步与并发代码,检测死锁、竞态条件、缺失取消处理及误用问题,并返回详细修复报告。
★ 0 📥 442

Commit Message Writer

lnguyen1996
从git差异、代码片段或变更描述生成规范化提交消息、PR标题和摘要,支持任何项目或编程语言。
★ 0 📥 451