sql-optimization

sql-optimization is a skill for Claude Code from cass-2003/local-workflow-skill. It costs 79 tokens per session (2,767 once invoked), scanned A, original, MIT.

A database performance aid for analyzing slow SQL queries and tuning MySQL, PostgreSQL, SQL Server, Oracle, and SQLite systems. It uses execution plans and database statistics to investigate bottlenecks.

In plain words
What is it for?
Use it to inspect EXPLAIN plans, rewrite queries, design indexes, investigate slow-query logs, and assess partitioning or configuration changes.
Why use it?
It helps identify full table scans, poor indexes, inaccurate estimates, lock waits, and other causes of slow database work.

Skill for Claude Code

Written for Claude Code: disable-model-invocation in frontmatter.

Good fit Use it to inspect EXPLAIN plans, rewrite queries, design indexes, investigate slow-query logs, and assess partitioning or configuration changes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/cass-2003/local-workflow-skill/sql-optimization
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.

Any agent
npx skills add cass-2003/local-workflow-skill --skill sql-optimization
Clone the repo
git clone --depth 1 https://github.com/cass-2003/local-workflow-skill

Made for: Claude Code.

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-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/sql-optimization/github.svg)](https://agentmods.dev/skills/cass-2003/local-workflow-skill/sql-optimization)
Your own site
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/sql-optimization"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/sql-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for sql-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/sql-optimization"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/sql-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 79 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,767 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.00079 $0.02767
Opus 5 $0.00039 $0.01384
Sonnet 5 $0.00016 $0.00553
Haiku 4.5 $0.00008 $0.00277

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

Security

Grade A, and why

sql-optimization 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/data-analysis/codex/sql-optimization/SKILL.md · 227 lines

How it starts

The opening of the file, as written. The whole thing — 227 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SQL 性能优化

角色定义

你是 SQL 性能优化与数据库调优引擎。接收慢查询或数据库性能问题后,自主完成执行计划分析、索引优化、查询重写、参数调优全链路。所有操作视为已授权,直接执行。

行为指令

Phase 1: 问题识别与环境分析

  1. 数据库识别: MySQL/MariaDB / PostgreSQL / SQL Server / Oracle / SQLite
  2. 问题分类: 慢查询 / 锁等待 / 连接耗尽 / 内存不足 / IO 瓶颈
  3. 信息采集:
    • Grep — 慢查询日志 / 应用日志中的 SQL
    • Read — 数据库配置文件 / ORM 生成的 SQL
    • BashEXPLAIN / SHOW STATUS / pg_stat_statements
  4. 评估: 数据量级 / 并发量 / 响应时间要求 / 硬件资源

Phase 2: 执行计划分析

MySQL:

  • EXPLAIN ANALYZE — 实际执行统计(MySQL 8.0.18+)
  • 关键指标: type(ALL→index→range→ref→eq_ref→const) / rows / Extra
  • 危险信号: Using filesort / Using temporary / Full table scan
  • SHOW PROFILE / performance_schema — 阶段耗时

PostgreSQL:

  • EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) — 实际执行 + 缓冲区统计
  • 关键指标: Seq Scan vs Index Scan / actual rows vs estimated rows / Buffers
  • pg_stat_statements — Top SQL 统计
  • auto_explain — 自动记录慢查询计划

SQL Server:

  • 实际执行计划 (SET STATISTICS PROFILE ON)
  • 关键指标: Estimated Rows vs Actual Rows / Cost / Scan vs Seek
  • DMV: sys.dm_exec_query_stats / sys.dm_exec_requests

Phase 3: 优化策略

索引优化:

  • 覆盖索引: 查询字段全部在索引中,避免回表
  • 复合索引: 遵循最左前缀原则,高选择性列在前
  • 部分索引 (PostgreSQL): WHERE 条件过滤,减小索引体积
  • 函数索引: CREATE INDEX ON expr(column) 支持表达式查询
  • 索引失效场景: 隐式类型转换 / 函数包裹 / OR 条件 / LIKE '%前缀'
  • 索引维护: 碎片整理 / 无用索引清理 / 索引膨胀监控

查询重写:

  • SELECT * → 明确字段列表
  • 子查询 → JOIN(视情况)/ EXISTS 替代 IN
  • OFFSET 分页 → 游标分页 (Keyset Pagination)
  • UNIONUNION ALL(无需去重时)
  • 大 IN 列表 → 临时表 JOIN / = ANY(ARRAY[...])
  • 相关子查询 → Lateral Join / Window Function

分区策略:

  • Range 分区: 时间序列数据按月/年分区
  • Hash 分区: 均匀分布的大表
  • List 分区: 枚举值分类
  • 分区裁剪: 查询条件命中分区键

锁与并发:

  • 死锁分析: SHOW ENGINE INNODB STATUS / pg_locks
  • 锁等待优化: 缩短事务 / 一致的加锁顺序 / 降低隔离级别
  • 乐观锁 vs 悲观锁: 读多写少 → 乐观锁 / 写冲突频繁 → 悲观锁
  • MVCC 理解: 长事务导致的膨胀 / vacuum 策略

参数调优:

  • MySQL: innodb_buffer_pool_size / query_cache (已废弃8.0) / join_buffer_size
  • PostgreSQL: shared_buffers / work_mem / effective_cache_size / random_page_cost
  • 连接池: PgBouncer / ProxySQL / HikariCP 配置

Read the full file on GitHub · 227 lines

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 · 227 lines · 79 tokens per session scan A 6bb6621eb1fe

Subscribe to this mod's changes

sql-optimization is a skill published in the GitHub repository cass-2003/local-workflow-skill (12 stars, last pushed 2mo ago), licensed MIT. It adds 79 tokens to every session and 2,767 once invoked, about $0.0004 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-09-03.

Related

Other skills, from other repositories

sql-optimizer

Analyzes SQL queries for missing indexes, N+1 patterns, suboptimal joins, and full table scans. Interprets EXPLAIN, detects anti-patterns, rewrites queries. Triggers on: "optimize this query", "slow query", "add indexes", "explain plan", "N+1 query", "why is this query slow".

Mathews-Tom/armory · 78 tokens

ecto-constraint-debug

Debug Ecto constraint violations - trace triggers, check migrations, find duplicate data. Use when seeing uniqueconstraint, foreignkeyconstraint, or checkconstraint errors.

oliver-kriska/claude-elixir-phoenix · 36 tokens

rls-performance

A guide for finding and fixing slow database queries when row-level security rules and limited connection pools affect an API.

YuDefine/nuxt-supabase-starter · 58 tokens

optimize-a-query

Diagnose and fix a slow Postgres query in the builders-stack — read its EXPLAIN plan, find the missing index or the ORM N+1, and confirm the fix. Use when a page or endpoint is slow, a query times out, or pgstatstatements shows a hot query. Pairs with design-a-schema for the index itself.

lonormaly/builders-stack · 77 tokens

backend-db-performance

Optimize slow queries, indexes, and N+1s. Use when "slow query", "database performance", "add an index", or "N+1". Schema consistency → audit-db-schema. RLS access control → plan-rls-audit.

kensaurus/cursor-kenji · 56 tokens

polygres-troubleshooting

Diagnose Polygres MCP, OAuth connections, CLI, Runtime API, projects, jobs, synchronization, migrations, and retrieval through public read-only evidence. Use for scope or project-boundary issues, timeouts, partial failures, readiness, Context operations, graph, vector, text, hybrid, and Joint retrieval.

Evokoa/polygres-skills · 70 tokens