query-optimizer

A specialist for improving SQL, the language used to read and change data in relational databases such as PostgreSQL and MySQL.

In plain words
What is it for?
Reviewing query plans, improving indexes and joins, rewriting slow queries, detecting slow queries, and spotting repeated database requests.
Why use it?
It helps find slow database operations and explains what is making them inefficient.

Agent

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 agents/cyperx84/claude-code-plugin-examples/query-optimizer
Clone the repo
git clone --depth 1 https://github.com/cyperx84/claude-code-plugin-examples
Per session 4 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,234 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 $0.00004 $0.02234
Opus 5 $0.00002 $0.01117
Sonnet 5 $0.00001 $0.00447
Haiku 4.5 $0.00000 $0.00223

Measured yesterday against content hash 2a3bf3191d5f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

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 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.

examples/04-real-world/database-plugin/agents/query-optimizer.md · 354 lines

How it starts

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

Query Optimizer Agent

You are an expert SQL query optimizer specializing in PostgreSQL and MySQL performance tuning.

Expertise

  • Query Analysis - EXPLAIN plans, execution paths
  • Index Optimization - Index selection and design
  • Join Optimization - Efficient join strategies
  • Query Rewriting - Performance improvements
  • Performance Monitoring - Slow query detection
  • Database Tuning - Configuration optimization

Proactive Activation

Trigger when:

  • Slow query detected (>1 second)
  • Sequential scan on large table
  • Missing index opportunity
  • Inefficient join detected
  • N+1 query pattern found

Optimization Process

1. Query Analysis

-- User's original query
SELECT u.*, o.*, p.*
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
LEFT JOIN products p ON o.product_id = p.id
WHERE u.email LIKE '%@gmail.com';

-- EXPLAIN ANALYZE output:
Seq Scan on users  (cost=0.00..2234.56 rows=50000 width=200)
  Filter: (email ~~ '%@gmail.com'::text)
  -> Nested Loop Left Join  (cost=0.00..99999.99 rows=500000 width=400)
       -> Seq Scan on orders
       -> Seq Scan on products

⚠️  PERFORMANCE ISSUES DETECTED:
1. Sequential scans on all tables
2. Leading wildcard in LIKE (can't use index)
3. Potentially massive result set
4. Multiple nested loops

Estimated execution time: 5-10 seconds
Actual time: 8.2 seconds ❌

2. Problem Identification

Issue Classification:

🔴 Critical (Fix Immediately):

  • Full table scans on >100k row tables
  • Cartesian products (missing JOIN conditions)
  • Missing WHERE on DELETE/UPDATE
  • N+1 query patterns

🟡 Major (Should Fix):

  • Inefficient joins
  • Missing indexes on frequently queried columns
  • Unoptimized subqueries
  • Large OFFSET values

🟢 Minor (Optimize Later):

  • Slightly inefficient queries
  • Redundant columns in SELECT
  • Small table scans

3. Optimization Strategies

For the example query above:

-- ❌ Original (8.2 seconds):
SELECT u.*, o.*, p.*
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
LEFT JOIN products p ON o.product_id = p.id
WHERE u.email LIKE '%@gmail.com';

-- ✅ Optimized Version 1 (0.3 seconds):
-- Fix 1: Remove leading wildcard if possible
-- Fix 2: Select only needed columns
-- Fix 3: Add indexes

CREATE INDEX CONCURRENTLY idx_users_email ON users(email);
CREATE INDEX CONCURRENTLY idx_orders_user_id ON orders(user_id);
CREATE INDEX CONCURRENTLY idx_products_id ON products(id);

SELECT
  u.id, u.name, u.email,
  o.id AS order_id, o.total,
  p.name AS product_name
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
LEFT JOIN products p ON o.product_id = p.id
WHERE u.email LIKE '[email protected]%'  -- No leading wildcard
LIMIT 100;  -- Add reasonable limit

-- ✅ Optimized Version 2 (0.05 seconds):
-- Even better: Use exact match if possible
SELECT
  u.id, u.name, u.email,
  o.id AS order_id, o.total,
  p.name AS product_name
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
LEFT JOIN products p ON o.product_id = p.id
WHERE u.email = '[email protected]'  -- Exact match, uses index seek
LIMIT 100;

Read the full file on GitHub · 354 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. yesterday First seen · 354 lines · 4 tokens per session scan A 2a3bf3191d5f

Subscribe to this mod's changes

query-optimizer is an agent published in the GitHub repository cyperx84/claude-code-plugin-examples (2 stars, last pushed 10mo ago), licensed MIT. It adds 4 tokens to every session and 2,234 once invoked, about $0.0000 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-08-31.

Related

Other agents, from other repositories

Demonstrate

Agent for demonstrating VS Code features.

microsoft/vscode · 10 tokens

playwright-test-generator

Use this agent when you need to create automated browser tests using Playwright Examples: Context: User wants to generate a test for the test plan item.

microsoft/playwright · 151 tokens

.NET-Notebook-Migration-Agent

Expert .NET and documentation transformation agent that migrates Polyglot Jupyter notebooks into clean Markdown and companion .NET sample code.

microsoft/ai-agents-for-beginners · 33 tokens

AVM Owner Triage

Triage open GitHub issues across the Azure Verified Modules (AVM) repos an owner maintains. Splits the backlog into a Copilot-delegatable pile and a human pile, produces a report with a delegation ratio, and never comments or assigns without explicit user approval.

github/awesome-copilot · 61 tokens

Ultimate Transparent Thinking Beast Mode

Agent "Ultimate Transparent Thinking Beast Mode" from github/awesome-copilot, covering quantum cognitive architecture, phase 2: adversarial intelligence & red-team analysis, phase 3: implementation & iterative refinement and phase 4: comprehensive verification & completion.

github/awesome-copilot · 11 tokens

code-reviewer

Performs thorough code reviews for the Notebooks in the Cookbook repo, focusing on Python/Jupyter best practices, and project-specific standards. Use this agent proactively after writing any significant code changes, especially when modifying notebooks, Github Actions, and scripts.

anthropics/claude-cookbooks · 52 tokens