sql-optimizer

GitHub

诊断慢SQL并生成具体优化方案。分析执行计划,定位主瓶颈(如全表扫描、非SARGable谓词),提供重写后的查询语句及具体的索引/分区建议,并评估预期性能提升效果。

plugins/pm-dataeng/skills/sql-optimizer/SKILL.md mohitagw15856/pm-claude-skills

Trigger Scenarios

用户请求优化SQL查询 解决查询超时或执行缓慢问题 降低查询成本或扫描量 审查查询执行计划

Install

npx skills add mohitagw15856/pm-claude-skills --skill sql-optimizer -g -y
More Options

Non-standard path

npx skills add https://github.com/mohitagw15856/pm-claude-skills/tree/main/plugins/pm-dataeng/skills/sql-optimizer -g -y

Use without installing

npx skills use mohitagw15856/pm-claude-skills@sql-optimizer

指定 Agent (Claude Code)

npx skills add mohitagw15856/pm-claude-skills --skill sql-optimizer -a claude-code -g -y

安装 repo 全部 skill

npx skills add mohitagw15856/pm-claude-skills --all -g -y

预览 repo 内 skill

npx skills add mohitagw15856/pm-claude-skills --list

SKILL.md

Frontmatter
{
    "name": "sql-optimizer",
    "description": "Diagnose a slow SQL query and produce a concrete optimization plan. Use when asked to optimize SQL, speed up a slow query, reduce a query's cost\/scan, fix a timeout, or review a query plan. Produces an analysis — the likely bottleneck, what the plan is doing wrong (full scans, bad joins, spills), the specific rewrite and index\/partition changes, and the expected impact, with the optimized query."
}

SQL Optimizer Skill

A slow query almost always has a specific, findable cause — a missing index, a non-sargable predicate, a join that explodes rows, a scan that should be a seek. This skill diagnoses it: read what the query (and plan, if given) is actually doing, name the bottleneck, and produce a concrete rewrite plus the index / partition / structural changes — with the expected impact, not vague "add indexes" advice.

Required Inputs

Ask for these only if they aren't already provided:

  • The query (and the engine — Postgres, BigQuery, Snowflake, MySQL… optimizations differ).
  • The symptom — slow, expensive (bytes scanned), timing out, or just under review.
  • Context if availableEXPLAIN/query plan, table sizes/row counts, existing indexes, partitioning/clustering.

Output Format

SQL Optimization: [query purpose]

1. What it's doing now — read the query (and plan): the scans, joins, sorts, and where the time/cost goes. Name the primary bottleneck (don't list ten micro-tweaks — find the one that matters).

2. The problems — ranked, each with why it's slow:

  • Non-sargable predicates (functions on indexed columns, leading wildcards) → can't use an index.
  • Missing/`wrong index or partition pruning; full scans where a seek is possible.
  • Join issues — fan-out, wrong join order, missing join keys, SELECT * pulling everything.
  • Sorts/spills, DISTINCT/GROUP BY on high-cardinality, correlated subqueries that should be joins.
  • Engine-specific: BigQuery/Snowflake → bytes scanned (partition/cluster pruning), not row counts.

3. The fix — the rewritten query, plus the index / partition / clustering / materialization changes. Be specific (CREATE INDEX … ON … (cols), partition on event_date).

4. Expected impact — roughly what each change buys (seek vs. scan, pruning N% of partitions, removing a sort) and how to verify (re-run EXPLAIN, compare bytes/rows).

Quality Checks

  • Names the single primary bottleneck, not a scattershot list
  • Predicates are checked for sargability (no functions on indexed columns, no leading %)
  • Index/partition recommendations are specific (exact columns), not "add an index"
  • For columnar/cloud engines, addresses bytes scanned & pruning, not just row counts
  • Provides the rewritten query and a way to verify the improvement

Anti-Patterns

  • Do not say "add indexes" generically — name the columns and explain which predicate/join they serve
  • Do not ignore the engine — Postgres index tuning and BigQuery partition pruning are different games
  • Do not optimize a query that should be a model — repeated heavy logic belongs in a materialized/dbt model
  • Do not wrap indexed columns in functions in the WHERE clause — it kills index usage (non-sargable)
  • Do not recommend changes without an expected impact or a way to measure it

Based On

Query-optimization practice — sargability, index/partition pruning, join-order and fan-out, plan reading, columnar bytes-scanned tuning.

Version History

  • a38bc30 Current 2026-07-05 11:15

Same Skill Collection

exports/openclaw/360-feedback-template/SKILL.md
exports/openclaw/401k-plan-decoder/SKILL.md
exports/openclaw/ab-test-planner/SKILL.md
exports/openclaw/ab-test-readout/SKILL.md
exports/openclaw/accessibility-audit/SKILL.md
exports/openclaw/account-plan/SKILL.md
exports/openclaw/acquirer-red-team/SKILL.md
exports/openclaw/ad-copy/SKILL.md
exports/openclaw/aeo-optimizer/SKILL.md
exports/openclaw/agenda-or-cancel/SKILL.md
exports/openclaw/agent-design-review/SKILL.md
exports/openclaw/agent-observability-spec/SKILL.md
exports/openclaw/agent-spec/SKILL.md
exports/openclaw/ai-ethics-review/SKILL.md
exports/openclaw/ai-eval-plan/SKILL.md
exports/openclaw/ai-feature-prd/SKILL.md
exports/openclaw/ai-product-canvas/SKILL.md
exports/openclaw/air-quality/SKILL.md
exports/openclaw/altitude-shifter/SKILL.md
exports/openclaw/ambiguity-resolver/SKILL.md
exports/openclaw/analyst-relations-brief/SKILL.md
exports/openclaw/announcement-card/SKILL.md
exports/openclaw/api-docs-writer/SKILL.md
exports/openclaw/api-test-plan/SKILL.md
exports/openclaw/api-versioning-strategy/SKILL.md
exports/openclaw/apology-letter/SKILL.md
exports/openclaw/architecture-decision-record/SKILL.md
exports/openclaw/architecture-diagram/SKILL.md
exports/openclaw/archive-strategy/SKILL.md
exports/openclaw/assumption-bounty/SKILL.md
exports/openclaw/assumption-mapper/SKILL.md
exports/openclaw/async-update-format/SKILL.md
exports/openclaw/auto-repair-estimate-decoder/SKILL.md
exports/openclaw/autopilot-charter/SKILL.md
exports/openclaw/benefits-decoder/SKILL.md
exports/openclaw/bid-tender-review/SKILL.md
exports/openclaw/board-deck-narrative/SKILL.md
exports/openclaw/board-minutes/SKILL.md
exports/openclaw/board-pre-read/SKILL.md
exports/openclaw/bom-cost-review/SKILL.md
exports/openclaw/bookkeeping-categorization/SKILL.md
exports/openclaw/boolean-search-builder/SKILL.md
exports/openclaw/brag-doc/SKILL.md
exports/openclaw/brainstorming/SKILL.md
exports/openclaw/brief-builder/SKILL.md
exports/openclaw/briefing-note/SKILL.md
exports/openclaw/budget-builder/SKILL.md
exports/openclaw/budget-variance-analysis/SKILL.md
exports/openclaw/bug-diagnosis/SKILL.md
exports/openclaw/bug-report/SKILL.md

Metadata

Files
0
Version
471c606
Hash
cf6b11a2
Indexed
2026-07-05 11:15

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-29 21:47
浙ICP备14020137号-1 $방문자$