database-query-optimizer

database-query-optimizer is a skill for Claude Code, Codex from khalilbenaz/claude-skills-collection. It costs 99 tokens per session (2,006 once invoked), scanned A, original, MIT.

A guide to finding and improving slow SQL or NoSQL queries. It uses execution plans, such as EXPLAIN, to show how a database reads data and where time is spent.

In plain words
What is it for?
Use it to investigate slow queries in PostgreSQL, MySQL, SQL Server, SQLite, or MongoDB and choose changes based on measured plans and workload details.
Why use it?
It helps distinguish missing indexes, stale statistics, inefficient joins, and excessive repeated queries from problems elsewhere in the application.

Skill for Claude CodeCodex

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

Good fit Use it to investigate slow queries in PostgreSQL, MySQL, SQL Server, SQLite, or MongoDB and choose changes based on measured plans and workload details.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/khalilbenaz/claude-skills-collection/database-query-optimizer
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 khalilbenaz/claude-skills-collection --skill database-query-optimizer
Clone the repo
git clone --depth 1 https://github.com/khalilbenaz/claude-skills-collection

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 database-query-optimizer

README.md
[![agentmods](https://agentmods.dev/badge/skills/khalilbenaz/claude-skills-collection/database-query-optimizer.svg)](https://agentmods.dev/skills/khalilbenaz/claude-skills-collection/database-query-optimizer)
Your own site
<a href="https://agentmods.dev/skills/khalilbenaz/claude-skills-collection/database-query-optimizer"><img src="https://agentmods.dev/badge/skills/khalilbenaz/claude-skills-collection/database-query-optimizer.svg" alt="Measured on agentmods" height="20"></a>
Per session 99 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,006 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00099 $0.02006
Opus 5 $0.00049 $0.01003
Sonnet 5 $0.00020 $0.00401
Haiku 4.5 $0.00010 $0.00201

Measured 5d ago against content hash f7491377e958, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

database-query-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 5d 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.

dev-skills/database-query-optimizer/SKILL.md · 207 lines

How it starts

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

Database Query Optimizer

Étape 1 — Collecte d'informations

Demande systématiquement (ne suppose rien) :

  • SGBD et version : PostgreSQL 16, MySQL 8, SQL Server 2022, MongoDB 7, SQLite…
  • Requête complète (pas un résumé, le SQL brut)
  • Schéma : colonnes, types, index existants (\d table PG, SHOW CREATE TABLE MySQL)
  • Volume : lignes dans les tables concernées (ordre de grandeur suffit)
  • Temps mesuré : durée actuelle, cible souhaitée, outil de mesure
  • Contexte d'exécution : fréquence, OLTP vs OLAP, connexions concurrentes

Étape 2 — Diagnostic avec EXPLAIN

PostgreSQL / MySQL / SQLite

-- PostgreSQL : plan + exécution réelle
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) <requête>;

-- MySQL
EXPLAIN FORMAT=JSON <requête>;
SHOW STATUS LIKE 'Last_Query_Cost';

-- SQL Server
SET STATISTICS IO, TIME ON;
<requête>;
-- ou via SSMS : Query > Include Actual Execution Plan

Signaux d'alarme dans le plan

Signal Signification Priorité
Seq Scan sur grande table Pas d'index utilisable Critique
Hash Join + rows estimés très faux Statistiques obsolètes Élevée
Nested Loop × millions de rows Potentiel N+1 ou jointure cartésienne Critique
Sort sans Index Scan Manque d'index sur ORDER BY Modérée
cost=... très élevé vs actual rows faibles Mauvaise estimation selectivité Élevée
rows=1 partout mais slow Problème réseau / lock / cache miss Variable

Mettre à jour les statistiques

-- PostgreSQL
ANALYZE table_name;
-- MySQL
ANALYZE TABLE table_name;
-- SQL Server
UPDATE STATISTICS table_name;

Étape 3 — Optimisations concrètes

3.1 Index manquants

-- Créer un index couvrant (covering index) : évite un table lookup
CREATE INDEX CONCURRENTLY idx_orders_user_status
  ON orders (user_id, status)
  INCLUDE (created_at, total_amount);  -- PostgreSQL 11+

-- Index partiel : si requête filtre toujours sur une valeur
CREATE INDEX idx_orders_pending
  ON orders (created_at)
  WHERE status = 'pending';

-- Index composite : ordre des colonnes = sélectivité décroissante
-- Bon : (user_id, status)   -- user_id très sélectif
-- Mauvais : (status, user_id) -- status peu sélectif en tête

Read the full file on GitHub · 207 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. 5d ago First seen · 207 lines · 99 tokens per session scan A f7491377e958

Subscribe to this mod's changes

database-query-optimizer is a skill published in the GitHub repository khalilbenaz/claude-skills-collection (22 stars, last pushed 14d ago), licensed MIT. It adds 99 tokens to every session and 2,006 once invoked, about $0.0005 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.

Related

Other skills, from other repositories

frappe-errors-database

Use when handling database errors in Frappe/ERPNext. Covers DuplicateEntryError, LinkValidationError, MandatoryError, TimestampMismatchError, CharacterLengthExceededError, InReadOnlyMode, QueryTimeoutError, SQL injection errors, frappe.db.sql parameter format (% vs %s), getvalue returning None, transaction deadlocks…

Impertio-Studio/Frappe_Claude_Skill_Package · 142 tokens

sql-optimization-patterns

Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.

wshobson/agents · 44 tokens

database-patterns

DB schema design and query tuning: normalization, indexing, N+1, transactions, EXPLAIN. Triggers: schema, index, slow query, N+1, PostgreSQL, MySQL, EXPLAIN, deadlock, query plan.

softspark/ai-toolkit · 55 tokens

debug

Systematic debugging via logs, health checks, hypothesis-driven investigation. Triggers: debug, error, trace root cause, fix bug, reproduce symptom, investigation.

softspark/ai-toolkit · 34 tokens

introspect

Agent self-debugging and recovery. Use when stuck in loops, making repeated errors, or quality degrades. Triggers: introspect, self-debug, stuck, loop, why failing.

softspark/ai-toolkit · 42 tokens

migration-patterns

Zero-downtime DB migrations: expand-contract, double-write, backfill, blue-green. Triggers: migration, schema change, backfill, ALTER TABLE, online DDL.

softspark/ai-toolkit · 41 tokens