Token导航 LogoToken导航

Agent Skill · 开发

sql-optimizer(SQL 优化器)

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

sql-optimizer 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 17,004。

总安装 447周安装 19GitHub Stars 217下载 157核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:sql-optimizer(SQL 优化器)
来源仓库:https://github.com/mathews-tom/praxis-skills
仓库路径:skills/sql-optimizer
安装命令:
npx skills add https://github.com/mathews-tom/praxis-skills --skill sql-optimizer
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/mathews-tom/praxis-skills --skill sql-optimizer

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

智能优化 SQL 查询语句,自动重写以提升运行速度。适合处理复杂联表查询或大数据量分页场景。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。结合统计信息推荐最佳连接顺序与过滤条件。建议配合 explain 分析结果人工复核优化建议合理性。

sql-optimizer 属于开发类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/sql-optimizer

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/mathews-tom/praxis-skills --skill sql-optimize…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

sql-optimizer 怎么安装?

在终端执行 npx skills add https://github.com/mathews-tom/praxis-skills --skill sql-optimizer。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

sql-optimizer 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

sql-optimizer 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

sql-optimizer 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

sql-optimizer 用的人多吗?

公开数据是累计安装 447 次,近一周安装 19 次,下载 157 次,GitHub 217 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

sql-optimizer 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
sql-optimizer

SQL 优化器 · 本页

447217需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

SQL Optimizer

Systematic SQL performance analysis: parse query structure, interpret EXPLAIN plans, detect anti-patterns (N+1, full scans, cartesian joins), recommend indexes, and rewrite queries — with explanations of WHY each change improves performance, not just WHAT changed.

Reference Files

FileContentsLoad When
references/anti-patterns.mdCommon SQL anti-patterns with detection rules and fixesAlways
references/index-strategies.mdIndex type selection, composite index ordering, covering indexesIndex recommendations needed
references/explain-guide.mdReading EXPLAIN output for PostgreSQL, MySQL, SQLiteEXPLAIN plan provided
references/join-optimization.mdJoin type selection, join order optimization, subquery-to-join conversionQuery contains joins or subqueries

Prerequisites

  • The SQL query to optimize
  • Database engine (PostgreSQL, MySQL, SQLite) — optimization differs by engine
  • Table schemas and approximate row counts (helpful but not required)
  • EXPLAIN output (highly valuable when available)

Workflow

Phase 1: Query Analysis

Parse the SQL to understand its structure:

  1. Identify operations — SELECT columns, FROM tables, JOIN conditions, WHERE filters, GROUP BY, ORDER BY, HAVING, subqueries.
  2. Map table relationships — Which tables are joined? On what keys? Are there implicit cartesian products?
  3. Detect immediate red flags:

- SELECT * — fetching unnecessary columns - Functions on indexed columns in WHERE — prevents index use - OR in WHERE — often prevents index use - Correlated subqueries — potential N+1 - Missing WHERE on DELETE/UPDATE — dangerous

Phase 2: EXPLAIN Interpretation

If an EXPLAIN plan is provided:

  1. Scan types — Sequential Scan (bad for large tables), Index Scan (good), Index Only Scan (best), Bitmap Index Scan (acceptable).
  2. Join methods — Nested Loop (good for small tables), Hash Join (good for equi-joins), Merge Join (good for sorted data).
  3. Row estimates — Compare estimated rows with actual rows. Large discrepancies indicate stale statistics (ANALYZE).
  4. Cost hotspots — Highest-cost node is the bottleneck. Optimize there first.
  5. Sort operations — External sorts (disk) are expensive. Consider indexes that match ORDER BY.

Phase 3: Anti-Pattern Detection

Check for known performance anti-patterns (see references/anti-patterns.md):

PatternDetectionImpact
SELECT *Star in select listTransfers unnecessary data
N+1 queriesLoop with query insideN additional roundtrips
Function on indexed columnWHERE UPPER(name) = 'X'Index bypass
Implicit type castString compared to integerIndex bypass
Missing join conditionCartesian productExponential rows
LIKE '%prefix'Leading wildcardFull scan
OR with different columnsWHERE a=1 OR b=2Index bypass
SELECT DISTINCT as band-aidHides duplicate-producing joinFix the join instead

Phase 4: Optimization

  1. Index recommendations — Based on WHERE, JOIN, ORDER BY, GROUP BY columns. Consider composite indexes for multi-column conditions.
  2. Query rewrite — Convert correlated subqueries to JOINs, replace IN (SELECT...) with EXISTS, use CTEs for readability without performance cost (PostgreSQL 12+ may inline CTEs).
  3. Schema suggestions — Denormalization, materialized views, partitioning (mention only when query-level optimization is insufficient).

Phase 5: Output

Present the original query, detected issues, recommended indexes, rewritten query, and explanation of each change.

Output Format

## SQL Optimization Analysis

### Original Query

{original SQL}


### Issues Detected

| #   | Issue   | Severity          | Location            | Impact           |
| --- | ------- | ----------------- | ------------------- | ---------------- |
| 1   | {issue} | {High/Medium/Low} | {WHERE/JOIN/SELECT} | {what it causes} |

### EXPLAIN Interpretation

{If EXPLAIN provided}

- **Bottleneck:** {node type} on `{table}` (cost: {N})
- **Rows scanned:** {N} (estimated {M})
- **Index used:** {name or "None"}
- **Key insight:** {what this reveals}

### Recommended Indexes

-- {Reason for this index} CREATE INDEX {name} ON {table}({columns});


### Optimized Query

{rewritten query}


### Change Explanation

1. **{Change}** — {Why this improves performance. Include estimated impact.}

### Expected Improvement

- Scan type: {before} → {after}
- Estimated rows scanned: {before} → {after}
- Index usage: {before} → {after}

Configuring Scope

ModeInputDepthWhen to Use
quickSingle queryAnti-pattern scan + index suggestionFast feedback during development
standardQuery + schemaFull analysis with rewritesDefault for optimization requests
deepQuery + EXPLAIN + schema + row countsFull analysis with statistics validationProduction performance investigation

Calibration Rules

  1. Measure before optimizing. Request EXPLAIN output before recommending changes. Intuition about query performance is unreliable — a "slow-looking" query may be fast with proper indexes, and a "simple" query may scan millions of rows.
  2. Index discipline. Every index has write overhead. Do not recommend indexes that won't be used by the actual query workload. Consider the read/write ratio.
  3. Explain WHY, not just WHAT. "Add an index on users.email" is incomplete. "Add an index on users.email because the WHERE clause filters by email, currently causing a sequential scan of 1M rows" is actionable.
  4. Preserve correctness. Query rewrites must return identical results. If a rewrite changes semantics (e.g., INNER JOIN vs LEFT JOIN), flag it explicitly.
  5. Database engine matters. PostgreSQL, MySQL, and SQLite have different optimizers, index types, and capabilities. Always target the specific engine.

Error Handling

ProblemResolution
No EXPLAIN output providedAnalyze query structure and anti-patterns. Note that recommendations are best-effort without EXPLAIN.
Unknown database engineAsk which engine. Default anti-pattern analysis applies to all engines.
Query uses ORM-generated SQLOptimize the SQL, then suggest ORM-level changes (e.g., select_related in Django, eager loading).
Schema not providedInfer table structure from the query. Note assumptions.
Query is already optimalState that no significant improvements are possible. Suggest non-query optimizations (caching, denormalization).
Complex multi-CTE queryAnalyze each CTE independently, then analyze the composition.

When NOT to Optimize

Push back if:

  • The query runs infrequently and performance is acceptable (one-time admin query)
  • The optimization requires schema changes that affect many consumers — suggest an ADR instead
  • The real problem is application-level (N+1 from ORM loop) — fix the application code, not the SQL
  • The query is auto-generated by a tool (ORM migration, BI tool) — optimize at the tool level

平台分布

Codex

32.76%
按下载量换算51

Claude

30.99%
按下载量换算49

Cursor

18.98%
按下载量换算30

Gemini CLI

8.77%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills