- Home
- Skills
- Data & Databases
- SQL Query Review
Works with the AI Agents you already use
SQL Query Review
Diagnose slow SQL queries, optimize composite indexes, and verify performance gains using execution plans.
$7.99
SQL Query Review
Example session with this skill installed
The monthly report query in reports.sql is taking 15 seconds. Why is it slow and how do I fix it? Use app.sqlite to check the plan.
- Read your context and instructions
- Compiled the sql query review
The performance bottleneck for the monthly report has been identified. The execution plan confirms a full table scan because the predicate uses a function on the created_at column, which prevents the engine from using the existing index.
SQL Performance Review
| Metric | Before | After |
|---|---|---|
| Plan | SCAN TABLE transactions | SEARCH TABLE transactions USING INDEX idx_created_at |
| Structure | USE TEMP B-TREE FOR ORDER BY | (Removed) |
| Logic | Predicate: date(created_at) = ? | Predicate: created_at >= ? AND created_at < ? |
Analysis
The original query performed a full table scan because the date() function was applied to the created_at column. This makes the column "un-indexed" for that specific read. Additionally, the engine was forced to create a temporary B-Tree in memory to handle the ORDER BY clause.
Proposed Fix
- Rewrite Predicate: Change the
WHEREclause to use a bare column with a range comparison. - Index Optimization: The existing index on
created_atis now usable.
-- REWRITTEN QUERY
SELECT id, amount, status
FROM transactions
WHERE created_at >= '2024-01-01 00:00:00'
AND created_at < '2024-02-01 00:00:00'
ORDER BY created_at DESC;
Next steps
- Apply the predicate rewrite to the application code.
- Run
sqlreview.py plan app.sqlite reports.sqlin the staging environment to verify theSEARCHplan holds with production-scale data. - Monitor
INSERTlatency to ensure the existing index overhead remains acceptable.
Connects securely to your tools. The creator never sees your data.
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
- Analyze the plan using
sqlreview.py planto see how the engine reads the data before forming an opinion. - Scan for defeaters with the
lintcommand to find high-cost patterns likeSELECT *orORacross columns. - Audit existing schema via
schemaandindexesto check column affinity and ensure a new index won't duplicate an existing one. - Apply and verify the smallest possible change, then re-run the plan to confirm the
SCANchanged to aSEARCH.
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
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scanned
Verified clean 4 days ago
- Passed all security checks, Safe to install