optimizing-sql

optimizing-sql is a skill for Claude Code from ancoleman/ai-design-components. It costs 47 tokens per session (2,862 once invoked), scanned A, original, MIT.

A guide to making SQL database queries run faster in PostgreSQL, MySQL, and SQL Server. SQL is the language commonly used to read and change data in databases.

In plain words
What is it for?
Use it to inspect EXPLAIN or execution plans, choose indexes, rewrite queries, and investigate problems such as repeated database requests or unnecessary data reads.
Why use it?
It helps identify expensive operations and avoid slow queries, timeouts, and inefficient database access.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the data-engineering-skills plugin — 6 skills shipped together

Good fit Use it to inspect EXPLAIN or execution plans, choose indexes, rewrite queries, and investigate problems such as repeated database requests or unnecessary data reads.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ancoleman/ai-design-components/optimizing-sql
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 ancoleman/ai-design-components --skill optimizing-sql
Clone the repo
git clone --depth 1 https://github.com/ancoleman/ai-design-components

Made for: Claude Code.

Or install data-engineering-skills, the plugin that ships this one along with the rest of its 6 skills.

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 optimizing-sql

README.md
[![agentmods](https://agentmods.dev/badge/skills/ancoleman/ai-design-components/optimizing-sql/github.svg)](https://agentmods.dev/skills/ancoleman/ai-design-components/optimizing-sql)
Your own site
<a href="https://agentmods.dev/skills/ancoleman/ai-design-components/optimizing-sql"><img src="https://agentmods.dev/badge/skills/ancoleman/ai-design-components/optimizing-sql/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 optimizing-sql

Your own site · 80×15
<a href="https://agentmods.dev/skills/ancoleman/ai-design-components/optimizing-sql"><img src="https://agentmods.dev/badge/skills/ancoleman/ai-design-components/optimizing-sql.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 47 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,862 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.00047 $0.02862
Opus 5.5 $0.00019 $0.01145
Sonnet 5.5 $0.00009 $0.00572
Haiku 4.5 $0.00005 $0.00286

Measured 1mo ago against content hash 7667d0a60d2b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

optimizing-sql 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 1mo 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/optimizing-sql/SKILL.md · 393 lines

How it starts

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

SQL Optimization

Provide tactical guidance for optimizing SQL query performance across PostgreSQL, MySQL, and SQL Server through execution plan analysis, strategic indexing, and query rewriting.

When to Use This Skill

Trigger this skill when encountering:

  • Slow query performance or database timeouts
  • Analyzing EXPLAIN plans or execution plans
  • Determining index requirements
  • Rewriting inefficient queries
  • Identifying query anti-patterns (N+1, SELECT *, correlated subqueries)
  • Database-specific optimization needs (PostgreSQL, MySQL, SQL Server)

Core Optimization Workflow

Step 1: Analyze Query Performance

Run execution plan analysis to identify bottlenecks:

PostgreSQL:

EXPLAIN ANALYZE SELECT * FROM users WHERE email = '[email protected]';

MySQL:

EXPLAIN FORMAT=JSON SELECT * FROM products WHERE category_id = 5;

SQL Server: Use SQL Server Management Studio: Display Estimated Execution Plan (Ctrl+L)

Key Metrics to Monitor:

  • Cost: Estimated resource consumption
  • Rows: Number of rows processed (estimated vs actual)
  • Scan Type: Sequential scan vs index scan
  • Execution Time: Actual time spent on operation

For detailed execution plan interpretation, see references/explain-guide.md.

Step 2: Identify Optimization Opportunities

Common Red Flags:

Indicator Problem Solution
Seq Scan / Table Scan Full table scan on large table Add index on filter columns
High row count Processing excessive rows Add WHERE filter or index
Nested Loop with large outer table Inefficient join algorithm Index join columns
Correlated subquery Subquery executes per row Rewrite as JOIN or EXISTS
Sort operation on large result set Expensive sorting Add index matching ORDER BY

For scan type interpretation, see references/scan-types.md.

Step 3: Apply Indexing Strategies

Index Decision Framework:

Is column used in WHERE, JOIN, ORDER BY, or GROUP BY?
├─ YES → Is column selective (many unique values)?
│  ├─ YES → Is table frequently queried?
│  │  ├─ YES → ADD INDEX
│  │  └─ NO → Consider based on query frequency
│  └─ NO (low selectivity) → Skip index
└─ NO → Skip index

Read the full file on GitHub · 393 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. 1mo ago First seen · 393 lines · 47 tokens per session scan A 7667d0a60d2b

Subscribe to this mod's changes

optimizing-sql is a skill published in the GitHub repository ancoleman/ai-design-components (525 stars, last pushed 10mo ago), licensed MIT. It adds 47 tokens to every session and 2,862 once invoked, about $0.0002 per session on Opus 5.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-08-30.