- Home
- Skills
- Data & Databases
- SQL Query Clinic Planner
Works with the AI tools you already use
SQL Query Clinic Planner
Diagnose slow SQL, interpret execution plans, and rewrite queries for better performance and correctness.
$5
SQL Query Clinic Planner
Example session with this skill installed
Analyze this PostgreSQL query and EXPLAIN output. It is taking 5 seconds to run on a table with 10M rows.
SELECT * FROM orders WHERE DATE(created_at) = '2023-01-01';
Plan: Seq Scan on orders (cost=0.00..254.00 rows=50000 width=120) Filter: (date(created_at) = '2023-01-01'::date)
- Read your context and instructions
- Compiled the sql query clinic
I have analyzed the query and execution plan. The primary bottleneck is a non-sargable predicate preventing index usage.
Diagnosis
| Issue | Evidence | Severity | Confidence |
|---|---|---|---|
| Index Suppression | Function DATE() on column created_at | P1 | High |
| Full Table Scan | Seq Scan in EXPLAIN plan | P1 | High |
Correctness Issues
No correctness issues found. The query logic is sound but inefficient for large datasets.
Performance Bottlenecks
The use of the DATE() function on the created_at column makes the expression non-sargable (Search ARGumentable). Even if an index exists on created_at, the database must perform a full sequence scan to apply the function to every row before filtering.
Index Advice
- Table:
orders - Candidate Column:
created_at - Expected Benefit: Transform
Seq ScantoIndex Strategy Seek/Scan. - Risk: Minimal; standard B-tree index.
Recommended Rewrite
Original
SELECT * FROM orders WHERE DATE(created_at) = '2023-01-01';
Revised
SELECT * FROM orders
WHERE created_at >= '2023-01-01 00:00:00'
AND created_at < '2023-01-02 00:00:00';
Why
By using a range comparison on the raw column, the database can use a standard B-tree index on created_at. This avoids the O(N) cost of the function call per row.
Validation Checks
- Verify if an index exists on
created_at. If not, run:CREATE INDEX idx_orders_created_at ON orders(created_at); - Run
EXPLAIN ANALYZEwith the revised query to confirm anIndex ScanorIndex Only Scanis used. - Compare
Buffers(I/O) between the two versions.
Next steps
- Check if there are other queries using functions on
created_at. - Verify the distribution of data for Jan 1st to ensure index selectivity.
- Apply the range-based rewrite in the application code.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
The problem
Slow or broken SQL queries often result in guessing games involving trial-and-error indexing and rewrites that may change query semantics. Without an execution plan analysis, developers risk introducing production regressions or technical debt through redundant indexes.
What it does
- Analyzes EXPLAIN and EXPLAIN ANALYZE output to identify table scans, join algorithms, and cardinality misestimations.
- Performs correctness audits for NULL behavior, JOIN conditions, and three-valued logic to fix bug-prone queries.
- Audits existing indexes for redundancy, overlap, and sargability to minimize write overhead.
- Proposes semantically equivalent rewrites for correlated subqueries, non-selective predicates, and inefficient pagination.
- Classifies bottlenecks by severity (P0-P3) based on CPU, I/O, and locking contention evidence.
Frameworks & tools
Supports PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, BigQuery, and Redshift.
Why this beats prompting it yourself
Generic LLM prompts often hallucinate performance gains or suggest destructive changes without considering write costs. This skill follows a strict evidence-based workflow that distinguishes between confirmed bottlenecks and hypotheses, ensuring rewrites preserve original query semantics.
Use cases
- Diagnosing a sudden spike in CPU or I/O caused by a specific production query.
- Refactoring complex legacy CTEs and subqueries for better maintainability and plan stability.
- Auditing a table's index strategy to remove low-value indexes that slow down inserts.
- Debugging silent data loss or row multiplication in complex multi-way joins.
Known limitations
Requires user-supplied schema or execution plans for high-confidence advice. Cannot execute SQL or access live databases directly.
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
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
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 6 days ago
- Passed all security checks, Safe to install