sql-safety-review

Analyzes SQL queries for risk factors and safer execution strategies.

5|1|Updated Feb 27, 2026
One-click install
npx skills add https://github.com/winhok/testkit --skill sql-safety-review
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-safety-review
Source: https://github.com/winhok/testkit/tree/main/skills/sql-safety-review
Command: npx skills add https://github.com/winhok/testkit --skill sql-safety-review

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

评估 SQL SELECT 查询是否存在炸库风险(全表扫描、大范围扫描、排序/临时表开销),并给出更安全的改写方案,同时引导用户通过 EXPLAIN 与表结构信息进行精确诊断。当用户贴出SQL问“能不能跑”时,也应触发。

Core Features & Use Cases

  • 静态诊断:识别扫描范围、索引命中、排序/分组、JOIN 与结果集等风险信号。
  • 安全改写:提供按范围缩小、返回字段限制、分页等的改写策略与具体示例。
  • 指引诊断:引导提供 EXPLAIN 计划、SHOW CREATE TABLE、数据量等信息以进行精确分析。
  • 流程化诊断:分阶段进行静态分析与后续的精确分析,提升诊断可重复性。

Quick Start

请对给定的 SELECT SQL 进行初步风险评估,提出安全改写与 EXPLAIN 指引。

Frequently Asked Questions about sql-safety-review

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I check if a SQL SELECT query is safe before running it?

To check if a SQL SELECT query is safe, perform a static risk assessment to identify full-table scans, broad range scans, and expensive sorts, ensuring your query avoids overwhelming the database.

What is the best way to rewrite a SQL query to prevent full-table scans?

The best way to rewrite a SQL query to prevent full-table scans is to narrow the scanning range, limit returned fields, and apply pagination, directly reducing the query's operational footprint.

How do I use EXPLAIN to diagnose expensive SQL sorts and temporary table overhead?

Use EXPLAIN to diagnose expensive SQL sorts by providing the execution plan output, which reveals temporary table overhead and index hits for precise, progressive query analysis.

Why does my SQL query request table structures and EXPLAIN output for diagnosis?

Your SQL query requires table structures and EXPLAIN output for precise diagnosis because static analysis alone cannot fully confirm index utilization without seeing the actual execution plan and schema.

Can I get a safety review for SQL queries with complex JOINs and broad range scans?

Yes, you can get a safety review for SQL queries with complex JOINs and broad range scans by applying static analysis to detect risk signals and providing safer execution strategies.