sql-optimizer

sql-optimizer is a skill for Claude Code from Mathews-Tom/armory. It costs 78 tokens per session (1,888 once invoked), scanned A, original, MIT.

A SQL query performance analyzer that examines database queries, execution plans, indexes, joins, and common patterns that make queries slow.

In plain words
What is it for?
Use it to inspect EXPLAIN output, find missing indexes, full table scans, N+1 queries, inefficient joins, and rewrite SQL for PostgreSQL, MySQL, or SQLite.
Why use it?
It helps find causes of slow database access instead of relying on guesswork. It also explains why suggested index or query changes may improve performance.

Skill for Claude Code

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

Part of the armory plugin — 85 skills shipped together

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/mathews-tom/armory/sql-optimizer
Any agent
npx skills add Mathews-Tom/armory --skill sql-optimizer
Clone the repo
git clone --depth 1 https://github.com/Mathews-Tom/armory

Made for: Claude Code.

Or install armory, the plugin that ships this one along with the rest of its 85 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 sql-optimizer

README.md
[![agentmods](https://agentmods.dev/badge/skills/mathews-tom/armory/sql-optimizer.svg)](https://agentmods.dev/skills/mathews-tom/armory/sql-optimizer)
Your own site
<a href="https://agentmods.dev/skills/mathews-tom/armory/sql-optimizer"><img src="https://agentmods.dev/badge/skills/mathews-tom/armory/sql-optimizer.svg" alt="Measured on agentmods" height="20"></a>
Per session 78 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,888 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.00078 $0.01888
Opus 5 $0.00039 $0.00944
Sonnet 5 $0.00016 $0.00378
Haiku 4.5 $0.00008 $0.00189

Measured yesterday against content hash 77338978d5c6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, 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 yesterday.

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/sql-optimizer/SKILL.md · 191 lines

How it starts

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

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

File Contents Load When
references/anti-patterns.md Common SQL anti-patterns with detection rules and fixes Always
references/index-strategies.md Index type selection, composite index ordering, covering indexes Index recommendations needed
references/explain-guide.md Reading EXPLAIN output for PostgreSQL, MySQL, SQLite EXPLAIN plan provided
references/join-optimization.md Join type selection, join order optimization, subquery-to-join conversion Query 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

Read the full file on GitHub · 191 lines

Files

What ships with it

5 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. yesterday First seen · 191 lines · 78 tokens per session scan A 77338978d5c6

Subscribe to this mod's changes

sql-optimizer is a skill published in the GitHub repository Mathews-Tom/armory (316 stars, last pushed today), licensed MIT. It adds 78 tokens to every session and 1,888 once invoked, about $0.0004 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-05.

Related

Other skills, from other repositories

creating-oracle-to-postgres-migration-bug-report

Creates structured bug reports for defects found during Oracle-to-PostgreSQL migration. Use when documenting behavioral differences between Oracle and PostgreSQL as actionable bug reports with severity, root cause, and remediation steps.

boshi-xixixi/TraeSkill · 52 tokens

alloydb-basics

Manages clusters, instances, and backups for AlloyDB for PostgreSQL, and integrates with AlloyDB Model Context Protocol (MCP) tools for automated database operations. Use when creating, configuring, or administering AlloyDB databases. Do NOT use for general PostgreSQL instances (e.g. Cloud SQL) or other GCP databases.

google/skills · 72 tokens

cloud-sql-basics

This file generates or explains Cloud SQL resources. Use this file when the user asks to create a Cloud SQL instance or database for MySQL, PostgreSQL, or SQL Server. Cloud SQL manages third-party MySQL, PostgreSQL, and SQL Server instances as resources in Cloud SQL. For example, when Cloud SQL creates an open-source…

google/skills · 108 tokens

butterbase

AI-native, open-source backend-as-a-service with a built-in Model Context Protocol server. Postgres, auth, storage, functions, AI gateway.

butterbase-ai/butterbase · 34 tokens

supabase

Use when doing ANY task involving Supabase. Triggers: Supabase products (Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues); client libraries and SSR integrations (supabase-js, @supabase/ssr) in Next.js, React, SvelteKit, Astro, Remix; auth issues (login, logout, sessions, JWT, cookies…

supabase/agent-skills · 185 tokens

supabase-postgres-best-practices

Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the…

supabase/agent-skills · 182 tokens