# SQL Query Review

> Diagnose slow SQL queries, optimize composite indexes, and verify performance gains using execution plans.

SQL Query Review is a paid AI agent skill on Agensi by Bandonker Labs., in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $7.99 (one-time purchase)
- Creator: [Bandonker Labs.](https://www.agensi.io/creators/bandonkerlabs)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Version: 1.0
- Last updated: 2026-10-15
- Security: scan passed (2026-10-15); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/sql-query-review
- Tags: database, sql-optimization, sqlite, performance-tuning, code-review

## About this skill

Slow queries and unexplained table scans stall production performance and bloat cloud costs. This skill provides a systematic, plan-first methodology for identifying bottlenecks, verifying index efficiency, and proving performance fixes before code is shipped.

### What it does
- **Query plan analysis** interprets SQLite and SQL engine execution plans to identify scans, temp b-trees, and materialization.
- **SQL linting** flags dialect-agnostic anti-patterns like leading wildcards, function-wrapped predicates, and implicit type conversions.
- **Schema auditing** inventories existing indexes to prevent redundant or overlapping index creation.
- **Index optimization** recommends composite index column ordering based on equality, range, and sort requirements.
- **Verification reporting** generates before-and-after execution plans to prove that a proposed change actually resolves the bottleneck.

### How it works
1. **Analyze the plan** using `sqlreview.py plan` to see how the engine reads the data before forming an opinion.
2. **Scan for defeaters** with the `lint` command to find high-cost patterns like `SELECT *` or `OR` across columns.
3. **Audit existing schema** via `schema` and `indexes` to check column affinity and ensure a new index won't duplicate an existing one.
4. **Apply and verify** the smallest possible change, then re-run the plan to confirm the `SCAN` changed to a `SEARCH`.

### Frameworks & tools
This skill uses a Python 3 helper script (`sqlreview.py`) that relies on the standard library. It is designed for SQLite environments but the optimization logic transfers to other SQL engines.

### Why this beats prompting it yourself
Generic AI often guesses at missing indexes without looking at the execution plan. This skill forces a "plan-first" workflow, ensuring every recommendation is backed by evidence and verified with a re-run to avoid adding useless write overhead.

### Use cases
- Debugging a report query that suddenly slowed down from 1 second to 20 seconds.
- Reviewing a database migration PR to ensure new indexes are correctly ordered for specific predicates.
- Identifying why a query is ignoring an existing index due to collation or type mismatches.

### Known limitations
Execution plans and planner rules vary by engine; SQLite plans should not be quoted verbatim for PostgreSQL or MySQL. It cannot explain queries with active placeholders; literal values must be used.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the SQL Query Review skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this skill differ from simply asking a general AI model to optimize my SQL?

This skill follows a plan-first methodology that analyzes execution plans and column affinity before suggesting changes, preventing the common AI mistake of recommending redundant or ineffective indexes.

### Can I use this skill for databases other than SQLite, such as PostgreSQL or MySQL?

While the `sqlreview.py` script and verification logic are optimized for SQLite environments, the core indexing strategies and anti-pattern detection apply to any standard SQL engine.

### What exactly is included in the purchase of this skill?

You will receive the `sqlreview.py` Python helper script, the core logic for execution plan analysis, and a structured workflow for identifying and verifying performance bottlenecks.

### Are there any specific technical requirements or dependencies I need to install?

The skill requires a Python 3 environment (standard library only) and access to your database's execution plan output to provide evidence-based recommendations.

### Does the skill help me verify that a suggested index actually improves performance?

Yes, the skill includes a verification step that compares 'before' and 'after' execution plans to ensure the proposed index actually converts a full table scan into a targeted search.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
