analyze-query

A command guide for examining a SQL query and its execution plan, which shows how a database intends to run the query. It checks query structure and points out common causes of slow database work.

In plain words
What is it for?
Use it to review an inline SQL query or a query file, generate an EXPLAIN ANALYZE command, interpret scans, joins, sorts, and costs, and suggest indexes based on filtering or joining.
Why use it?
It helps find unnecessary data reads, inefficient joins, missing limits, and other sources of slow queries. It also explains how to inspect the database’s actual plan and consider indexes.

Command

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 commands/armanzeroeight/fastagent-plugins/analyze-query
Clone the repo
git clone --depth 1 https://github.com/armanzeroeight/fastagent-plugins
Per session 9 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 906 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.00009 $0.00906
Opus 5 $0.00005 $0.00453
Sonnet 5 $0.00002 $0.00181
Haiku 4.5 $0.00001 $0.00091

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

Security

Grade A, and why

analyze-query 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 2d 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.

plugins/database-toolkit/commands/analyze-query.md · 155 lines

How it starts

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

Analyze Query

Analyze SQL query execution plan and suggest optimizations.

Your Task

Analyze the provided SQL query and provide optimization recommendations.

Arguments

  • $1: SQL query (inline) or file path containing query

Steps

  1. Parse the query:

    • Identify SELECT, FROM, WHERE, JOIN, ORDER BY, GROUP BY clauses
    • Note any subqueries or CTEs
    • Check for functions on columns
  2. Analyze query structure:

    Check for common issues:

    • SELECT * (fetching unnecessary columns)
    • Missing WHERE clause (full table scan)
    • Functions on indexed columns
    • Correlated subqueries
    • Large OFFSET values
    • No LIMIT clause
  3. Provide EXPLAIN command:

    EXPLAIN ANALYZE
    [user's query];
    

    Instruct user to run this and share results.

  4. Analyze execution plan (if provided):

    Look for:

    • Seq Scan (sequential scan - bad for large tables)
    • Index Scan (good)
    • Nested Loop (can be slow for large datasets)
    • Hash Join (good for large datasets)
    • Sort operations (expensive)
    • High cost values
  5. Recommend indexes:

    Based on WHERE, JOIN, ORDER BY clauses:

    -- For WHERE user_id = ?
    CREATE INDEX idx_table_user_id ON table_name(user_id);
    
    -- For WHERE user_id = ? AND created_at > ?
    CREATE INDEX idx_table_user_created ON table_name(user_id, created_at);
    
    -- For JOIN
    CREATE INDEX idx_table_foreign_key ON table_name(foreign_key_column);
    
  6. Suggest query rewrites:

    *Replace SELECT :

    -- Instead of
    SELECT * FROM users;
    
    -- Use
    SELECT id, name, email FROM users;
    

    Add LIMIT:

    -- Instead of
    SELECT * FROM posts ORDER BY created_at DESC;
    
    -- Use
    SELECT * FROM posts ORDER BY created_at DESC LIMIT 20;
    

    Optimize subqueries:

    -- Instead of
    SELECT * FROM users WHERE id IN (SELECT user_id FROM posts);
    
    -- Use
    SELECT DISTINCT u.* FROM users u
    JOIN posts p ON u.id = p.user_id;
    

Read the full file on GitHub · 155 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. 2d ago First seen · 155 lines · 9 tokens per session scan A 74a101ae912b

Subscribe to this mod's changes

analyze-query is a command published in the GitHub repository armanzeroeight/fastagent-plugins (29 stars, last pushed 1mo ago), licensed MIT. It adds 9 tokens to every session and 906 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-30.