sql-review

sql-review is a skill for Claude Code, Codex from guyulong/cn-agent-skills. It costs 9 tokens per session (667 once invoked), scanned A, original, MIT.

A guide for reviewing SQL, the language used to query databases, and finding ways to make queries clearer and faster. It covers issues such as selecting unnecessary columns, missing filters, inefficient joins, and missing indexes.

In plain words
What is it for?
Use it to review SQL, diagnose slow database queries, improve pagination and batch inserts, and suggest indexes or query rewrites.
Why use it?
It helps identify queries that scan too much data or prevent the database from using indexes. It also explains common fixes and how to inspect a query plan with EXPLAIN.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/guyulong/cn-agent-skills/sql-review
Any agent
npx skills add guyulong/cn-agent-skills --skill sql-review
Clone the repo
git clone --depth 1 https://github.com/guyulong/cn-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for sql-review

README.md
[![agentmods](https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/sql-review.svg)](https://agentmods.dev/skills/guyulong/cn-agent-skills/sql-review)
Your own site
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/sql-review"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/sql-review.svg" alt="Measured on agentmods" height="20"></a>
Per session 9 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 667 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00009 $0.00667
Opus 5 $0.00005 $0.00333
Sonnet 5 $0.00002 $0.00133
Haiku 4.5 $0.00001 $0.00067

Measured 6d ago against content hash 73654791111b, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

sql-review scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/sql-review/SKILL.md · 94 lines

What it actually says

SQL审查与优化

使用场景

审查SQL语句,发现性能问题并提供优化建议。

审查规则

🔴 严重问题

  1. **SELECT ***

    • 问题:查询所有字段,浪费资源
    • 修复:只查询需要的字段
  2. 缺少WHERE条件

    • 问题:全表扫描
    • 修复:添加必要的过滤条件
  3. 隐式类型转换

    • 问题:字段类型不匹配导致索引失效
    • 示例:WHERE phone = 13800138000(phone是varchar)
    • 修复:WHERE phone = '13800138000'
  4. 前导通配符

    • 问题:LIKE '%keyword' 无法使用索引
    • 修复:考虑全文索引

🟡 性能问题

  1. N+1查询

    • 问题:循环中执行查询
    • 修复:使用JOIN或批量查询
  2. 子查询效率低

    • 问题:相关子查询
    • 修复:改用JOIN
  3. 缺少索引

    • 问题:WHERE/JOIN字段未建索引
    • 修复:添加合适索引
  4. 排序未使用索引

    • 问题:ORDER BY字段无索引
    • 修复:添加联合索引

🟢 优化建议

  1. 分页优化

    -- 慢:OFFSET大时性能差
    SELECT * FROM orders LIMIT 10 OFFSET 10000;
    
    -- 快:使用游标分页
    SELECT * FROM orders WHERE id > 10000 LIMIT 10;
    
  2. 批量操作

    -- 慢
    INSERT INTO users (name) VALUES ('张三');
    INSERT INTO users (name) VALUES ('李四');
    
    -- 快
    INSERT INTO users (name) VALUES ('张三'), ('李四');
    
  3. EXPLAIN分析

    EXPLAIN SELECT * FROM users WHERE phone = '13800138000';
    -- 查看 type、key、rows 字段
    

输出格式

SQL审查报告
━━━━━━━━━━━━━━━━━━━━━━━━
原始SQL: SELECT * FROM users WHERE phone = 13800138000

问题:
🔴 [严重] SELECT * - 建议只查询需要的字段
🔴 [严重] 隐式类型转换 - phone字段应使用字符串
🟡 [建议] phone字段建议添加索引

优化后:
SELECT id, name, phone FROM users WHERE phone = '13800138000';

建议索引:
CREATE INDEX idx_phone ON users(phone);
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 94 lines · 9 tokens per session scan A 73654791111b

Subscribe to this mod's changes

sql-review is a skill published in the GitHub repository guyulong/cn-agent-skills (2 stars, last pushed 3mo ago), licensed MIT. It adds 9 tokens to every session and 667 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

relational-database-design

Designs or reviews a relational database schema for a given domain. Covers table structure, normalization, indexes, constraints, and migration strategy. Invoked when the user asks to design a schema, review a database structure, or optimize a data model.

soulcodex/agentic · 55 tokens

SQL Query Optimizer

Reviews SQL queries for performance issues and rewrites them with optimized execution plans.

Notysoty/openagentskills · 20 tokens

database-safety

规则: 每个 migration 必须配 down 方法(回滚路径);对行数超过百万的表加列或建索引,必须评估锁表风险,使用在线 DDL 工具(pt-online-schema-change、gh-ost 或数据库自带的 ALGORITHM=INPLACE)而非直接 ALTER TABLE。.

Wade-DevCode/awesome-coding-skills-cn · 30 tokens

ascend-profiler-db-explorer

面向 Ascend PyTorch Profiler / msprof DB(如 ascendpytorchprofiler.db、msprof.db)的 SQL 分析技能。将自然语言问题(算子耗时、通信、下发、调度、schema/table 查询)转为安全可执行 SQL,并按需从官方文档提取表结构详情。.

little-planet/ascend-tune-lab · 82 tokens

review-prs

Review a GitHub pull request in the googleapis/mcp-toolbox repo against the team's reviewer checklist: PR title/description conventions, linked issue, logic errors and unhandled edge cases, breaking changes, test coverage, docs updates, security (input handling), and new dependencies. Use whenever a maintainer asks…

googleapis/mcp-toolbox · 162 tokens

migration-review

Review database migration files when a change adds or modifies paths under migrations/. Use it before merge to collect forward, rollback, locking, and data-safety evidence.

rohitg00/ai-engineering-from-scratch · 35 tokens