Query Optimization

Query Optimization is a skill for Claude Code from cyperx84/claude-code-plugin-examples. It costs 19 tokens per session (4,483 once invoked), scanned A, original, MIT.

A set of methods for making SQL database queries run more efficiently.

In plain words
What is it for?
Reading EXPLAIN plans, choosing indexes, rewriting queries, and tuning database performance.
Why use it?
It helps identify bottlenecks such as scanning large tables, missing indexes, expensive sorting, and inefficient joins.

Skill for Claude Code

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

Part of the database-manager plugin — 1 skill shipped together

Good fit Reading EXPLAIN plans, choosing indexes, rewriting queries, and tuning database performance.

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

Made for: Claude Code.

Or install database-manager, the plugin that ships this one along with the rest of its 1 skill.

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 Query Optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/cyperx84/claude-code-plugin-examples/query-optimization/github.svg)](https://agentmods.dev/skills/cyperx84/claude-code-plugin-examples/query-optimization)
Your own site
<a href="https://agentmods.dev/skills/cyperx84/claude-code-plugin-examples/query-optimization"><img src="https://agentmods.dev/badge/skills/cyperx84/claude-code-plugin-examples/query-optimization/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 Query Optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/cyperx84/claude-code-plugin-examples/query-optimization"><img src="https://agentmods.dev/badge/skills/cyperx84/claude-code-plugin-examples/query-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 19 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,483 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.00019 $0.04483
Opus 5.5 $0.00008 $0.01793
Sonnet 5.5 $0.00004 $0.00897
Haiku 4.5 $0.00002 $0.00448

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

Security

Grade A, and why

Query Optimization 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 3mo 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.

examples/04-real-world/database-plugin/skills/query-optimization/SKILL.md · 736 lines

How it starts

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

Query Optimization

You are a database performance expert specializing in query optimization, indexing strategies, and database performance tuning. You help identify and resolve performance bottlenecks in database queries and operations.

Understanding Query Execution

1. Reading EXPLAIN Plans

PostgreSQL EXPLAIN:

-- Basic EXPLAIN
EXPLAIN SELECT * FROM orders WHERE customer_id = 123;

-- Detailed analysis with ANALYZE
EXPLAIN ANALYZE SELECT * FROM orders WHERE customer_id = 123;

-- Visual format
EXPLAIN (FORMAT JSON) SELECT * FROM orders WHERE customer_id = 123;

Key Metrics to Watch:

EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT o.*, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE o.created_at > '2024-01-01'
  AND o.status = 'completed';

/*
Key indicators:
- Seq Scan: Table scan (usually slow for large tables)
- Index Scan: Using an index (good)
- Index Only Scan: Best - data from index only
- Nested Loop: Join strategy (good for small datasets)
- Hash Join: Join strategy (good for large datasets)
- Sort: Expensive operation, consider indexes
- Buffers: Memory usage
- Actual time: Real execution time
*/

Interpreting Costs:

Cost Structure: cost=0.42..8.44 rows=1 width=136
- First number (0.42): Startup cost
- Second number (8.44): Total cost
- rows: Estimated rows returned
- width: Average row size in bytes

LOWER COST = BETTER PERFORMANCE

2. Query Execution Order

SQL Execution Flow:

-- Written order (logical)
SELECT customer_name, SUM(total) as revenue
FROM orders
WHERE status = 'completed'
GROUP BY customer_name
HAVING SUM(total) > 1000
ORDER BY revenue DESC
LIMIT 10;

-- Actual execution order:
-- 1. FROM orders
-- 2. WHERE status = 'completed'
-- 3. GROUP BY customer_name
-- 4. HAVING SUM(total) > 1000
-- 5. SELECT customer_name, SUM(total)
-- 6. ORDER BY revenue DESC
-- 7. LIMIT 10

Indexing Strategies

1. When to Create Indexes

Good Index Candidates:

-- Foreign keys (for JOINs)
CREATE INDEX idx_orders_customer_id ON orders(customer_id);

-- Frequently filtered columns (WHERE clauses)
CREATE INDEX idx_orders_status ON orders(status);

-- Frequently sorted columns (ORDER BY)
CREATE INDEX idx_orders_created_at ON orders(created_at);

-- Columns used in GROUP BY
CREATE INDEX idx_sales_product_id ON sales(product_id);

-- Columns in JOIN conditions
CREATE INDEX idx_order_items_order_id ON order_items(order_id);

Read the full file on GitHub · 736 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. 3mo ago First seen · 736 lines · 19 tokens per session scan A 8d2b4a216d60

Subscribe to this mod's changes

Query Optimization is a skill published in the GitHub repository cyperx84/claude-code-plugin-examples (2 stars, last pushed 1y ago), licensed MIT. It adds 19 tokens to every session and 4,483 once invoked, about $0.0001 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-31.

Related

Query Optimization compared with skills from other repositories

Query Optimization next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
Query Optimizationcyperx84/claude-code-plugin-examplesSkill21y agoMITA19Claude Code
create-prprisma/ormSkill48ktodayApache-2.0A47Claude Code, Codex
schema-explorationlangchain-ai/deepagentsSkill32ktodayMITA57Claude Code, Codex
atlas-mssqlariga/atlasSkill8.9k5d agoApache-2.0A163Claude Code
ha-data-storesshiwenwen/hope-agentSkill1.9ktodayMITA115Claude Code, Codex
pentesting-mysqlxalgorix/xalgorixSkill1.5kyesterdayApache-2.0A65Claude Code, Codex
nornicdb-cypher-queriesorneryd/NornicDBSkill937todayMITA79Claude Code, Codex