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.
npx skills add cass-2003/local-workflow-skill --skill sql-optimizationgit clone --depth 1 https://github.com/cass-2003/local-workflow-skillWrote 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.
[](https://agentmods.dev/skills/cass-2003/local-workflow-skill/sql-optimization)<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.
<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>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.
| Model | Per session | Once 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 |
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.
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: 问题识别与环境分析
- 数据库识别: MySQL/MariaDB / PostgreSQL / SQL Server / Oracle / SQLite
- 问题分类: 慢查询 / 锁等待 / 连接耗尽 / 内存不足 / IO 瓶颈
- 信息采集:
Grep— 慢查询日志 / 应用日志中的 SQLRead— 数据库配置文件 / ORM 生成的 SQLBash—EXPLAIN/SHOW STATUS/pg_stat_statements
- 评估: 数据量级 / 并发量 / 响应时间要求 / 硬件资源
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 ScanvsIndex Scan/actual rowsvsestimated rows/Buffers pg_stat_statements— Top SQL 统计auto_explain— 自动记录慢查询计划
SQL Server:
- 实际执行计划 (SET STATISTICS PROFILE ON)
- 关键指标:
Estimated RowsvsActual Rows/Cost/ScanvsSeek - 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)UNION→UNION 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 配置
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.
- 6d ago First seen · 227 lines · 79 tokens per session scan A 6bb6621eb1fe
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.
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".
ecto-constraint-debug
Debug Ecto constraint violations - trace triggers, check migrations, find duplicate data. Use when seeing uniqueconstraint, foreignkeyconstraint, or checkconstraint errors.
rls-performance
A guide for finding and fixing slow database queries when row-level security rules and limited connection pools affect an API.
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.
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.
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.