SQL Query Optimizer skill for Claude and Codex
Rewrites a slow SQL query and recommends indexes, with the reasoning behind each change and how the execution plan should differ afterward.
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when a developer has a slow SQL query and wants a faster rewrite plus index suggestions for their specific database engine. Do not use for choosing a join type or designing a schema from scratch. Related topics: sql, database, performance.
What it will ask you for
- Database engine (choose one: PostgreSQL, MySQL, SQL Server, SQLite, Oracle)
- Query type (choose one: SELECT, INSERT, UPDATE, DELETE, Complex JOIN)
- The slow query (longer free text)
- Approximate rows in the main table (number from 1000 to 100000000)
- Tables and current indexes (longer free text)
- Suspected bottlenecks (choose any: Missing indexes, Subqueries, JOIN order, N+1 pattern)
- Explain the execution plan changes (choose one: Yes, No)
How it works
- Scan the query for filters that defeat an index, correlated subqueries and over-wide selects.
- Propose the minimum set of indexes with exact CREATE INDEX statements and column order.
- Rewrite the query while preserving results, flagging any change in NULL or duplicate behaviour.
- Describe the expected plan change and the write cost of each new index.
What you get
The optimized query, CREATE INDEX statements, and a numbered list of changes with reasons, plus an execution plan comparison when requested.
What it watches out for
- Adding an index for every column, which slows writes and bloats storage.
- Wrapping an indexed column in a function so the index is ignored.
- Rewriting a subquery as a join in a way that duplicates rows.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.