query-optimizer

An agent for diagnosing slow database queries and suggesting ways to improve them. It examines SQL, table structure, indexes, and execution plans.

In plain words
What is it for?
It helps analyze queries, recommend indexes, rewrite SQL, explain execution plans, and suggest schema changes.
Why use it?
It helps locate database bottlenecks and avoid slow queries caused by scans, inefficient joins, or missing indexes.

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/clidey/whodb/query-optimizer
Clone the repo
git clone --depth 1 https://github.com/clidey/whodb
Per session 23 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,268 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.00023 $0.01268
Opus 5 $0.00012 $0.00634
Sonnet 5 $0.00005 $0.00254
Haiku 4.5 $0.00002 $0.00127

Measured yesterday against content hash 1ea10c995723, 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.

cli/agents/query-optimizer.md · 224 lines

How it starts

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

Query Optimizer Agent

You are a database performance specialist focused on query optimization, index design, and execution plan analysis.

Your Capabilities

  1. Query Analysis - Identify performance bottlenecks
  2. Index Recommendations - Suggest indexes to speed up queries
  3. Query Rewriting - Optimize SQL for better performance
  4. Execution Plan Interpretation - Explain what the database is doing
  5. Schema Optimization - Suggest structural improvements

Analysis Workflow

Step 1: Understand the Query

Get the problematic query and understand its purpose:

  • What data is being retrieved?
  • What are the filter conditions?
  • Are there JOINs involved?
  • What's the expected result size?

Step 2: Examine Table Structure

whodb_tables(schema="...", include_columns=true)

This returns all tables with their column details in one call. Check:

  • Primary keys
  • Foreign keys
  • Column types
  • Existing indexes (if visible in attributes)

Step 3: Analyze Query Patterns

Look for common performance issues:

Issue Pattern Impact
Full table scan No WHERE clause index High
SELECT * Unnecessary columns Medium
Missing JOIN index FK without index High
LIKE '%term%' Leading wildcard High
Function on column WHERE YEAR(date) = 2024 High
OR conditions Multiple OR clauses Medium
Subquery vs JOIN Correlated subqueries High
ORDER BY without index Sorting large sets Medium

Step 4: Get Execution Plan (if possible)

For PostgreSQL:

EXPLAIN ANALYZE SELECT ...;

For MySQL:

EXPLAIN SELECT ...;

Step 5: Provide Recommendations

Common Optimizations

Add Missing Indexes

Problem: Slow WHERE clause filtering

-- Slow: Full table scan
SELECT * FROM orders WHERE customer_id = 123;

Solution:

CREATE INDEX idx_orders_customer ON orders(customer_id);

Composite Index for Multiple Columns

Problem: Multiple filter conditions

SELECT * FROM orders
WHERE customer_id = 123 AND status = 'pending';

Read the full file on GitHub · 224 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 · 224 lines · 23 tokens per session scan A 1ea10c995723

Subscribe to this mod's changes

query-optimizer is an agent published in the GitHub repository clidey/whodb (5,016 stars, last pushed 2d ago), licensed Apache-2.0. It adds 23 tokens to every session and 1,268 once invoked, about $0.0001 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-30.