sql-optimizer

sql-optimizer is a skill for Claude Code, Codex from JayRHa/AgentSkills. It costs 146 tokens per session (1,805 once invoked), scanned A, original, MIT.

A method for finding and fixing slow SQL queries by reading execution plans, changing queries or indexes, and measuring the result.

In plain words
What is it for?
Use it to investigate timeouts, expensive scans, missing indexes, inefficient queries, and database performance problems across common SQL engines.
Why use it?
It replaces guesswork with evidence about what is making a database query slow.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

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.

agentmods
npx agentmods add skills/jayrha/agentskills/sql-optimizer
Any agent
npx skills add JayRHa/AgentSkills --skill sql-optimizer
Clone the repo
git clone --depth 1 https://github.com/JayRHa/AgentSkills

Made for: Claude Code, Codex.

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/jayrha/agentskills/sql-optimizer.svg)](https://agentmods.dev/skills/jayrha/agentskills/sql-optimizer)
Your own site
<a href="https://agentmods.dev/skills/jayrha/agentskills/sql-optimizer"><img src="https://agentmods.dev/badge/skills/jayrha/agentskills/sql-optimizer.svg" alt="Measured on agentmods" height="20"></a>
Per session 146 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,805 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.00146 $0.01805
Opus 5 $0.00073 $0.00903
Sonnet 5 $0.00029 $0.00361
Haiku 4.5 $0.00015 $0.00180

Measured 2d ago against content hash 4e0171f419ed, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

sql-optimizer 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 2d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/explain_analyzer.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

sql-optimizer/SKILL.md · 109 lines

How it starts

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

SQL Optimizer

Overview

This skill turns "this query is slow" into a concrete, evidence-driven fix. It reads execution plans, identifies the dominant cost, proposes the smallest effective change (index, rewrite, schema, or config), and verifies the improvement with before/after measurements.

Keywords: slow query, EXPLAIN, EXPLAIN ANALYZE, query plan, seq scan, full table scan, index, covering index, composite index, query rewrite, sargable, N+1, timeout, high cost, cardinality, statistics, ANALYZE, query tuning, database performance, PostgreSQL, MySQL, SQL Server, Oracle, SQLite.

Golden rule: measure, change one thing, measure again. Never guess. Never add an index without reading the plan first.

Process

Follow these steps in order. Do not skip step 1 or 2.

  1. Gather context. Identify: the engine + version, the exact query (with real-ish parameters, not placeholders), table row counts, existing indexes, and how the query is run (ORM? prepared statement? batch?). If any are missing, ask or inspect the schema. See references/dialect-cheatsheet.md for how to collect each per engine.

  2. Capture the real plan. Run the engine's analyze form to get actual timing and row counts, not just estimates:

    • PostgreSQL: EXPLAIN (ANALYZE, BUFFERS, VERBOSE, FORMAT TEXT) <query>;
    • MySQL 8+/MariaDB: EXPLAIN ANALYZE <query>; (or EXPLAIN FORMAT=JSON)
    • SQL Server: SET STATISTICS IO, TIME ON; + Actual Execution Plan
    • Oracle: EXPLAIN PLAN FOR ...; SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); then DBMS_XPLAN.DISPLAY_CURSOR(FORMAT=>'ALLSTATS LAST')
    • SQLite: EXPLAIN QUERY PLAN <query>; Wrap writes (UPDATE/DELETE) in a transaction you roll back, or test on a SELECT-shaped copy.
  3. Find the dominant cost. Read the plan bottom-up / inner-most-first. Locate the node with the largest actual time × loops (PostgreSQL) or highest cost/rows. Compare estimated vs actual rows — a large mismatch (>10x) means stale statistics or a bad predicate estimate. Use the diagnosis table in references/plan-reading.md.

Read the full file on GitHub · 109 lines

Files

What ships with it

7 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 2d ago First seen · 109 lines · 146 tokens per session scan A 4e0171f419ed

Subscribe to this mod's changes

sql-optimizer is a skill published in the GitHub repository JayRHa/AgentSkills (4 stars, last pushed 1mo ago), licensed MIT. It adds 146 tokens to every session and 1,805 once invoked, about $0.0007 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.