- Home
- Skills
- Data & Databases
- SQL Query Performance Optimizer
Works with the AI tools you already use
SQL Query Performance Optimizer
Audit SQL queries, detect N+1 ORM patterns, and optimize database performance based on evidence, not assumptions.
$6.99
SQL Query Performance Optimizer
Example session with this skill installed
Audit this query for a PostgreSQL DB: SELECT * FROM orders JOIN users ON orders.user_id = users.id WHERE users.email LIKE '%@gmail.com' ORDER BY orders.created_at DESC LIMIT 50 OFFSET 10000;
- Read your context and instructions
- Compiled the sql query performance
- Generated the document
The audit identified two high-priority issues: a non-selective leading wildcard filter and expensive offset pagination on a large dataset.
Query Performance Audit
| Risk | Issue | Impact | Recommendation |
|---|---|---|---|
| Critical | Leading Wildcard (%@gmail.com) | Forces a Full Table Scan on users. Btree indexes cannot be used for suffix matching. | Use a Reverse String Index or pg_trgm GIN index if partial matching is required. |
| High | Large OFFSET (10,000) | DB must scan and discard 10,000 rows before returning 50. Latency increases linearly with offset. | Implement keyset pagination (e.g., WHERE created_at < ?) instead of OFFSET. |
| Medium | Over-fetching (SELECT *) | Retrieves all columns from both tables, increasing IO and memory usage. | Explicitly select only the columns required by the application. |
Optimized Query Suggestion
-- Keyset pagination approach with specific column selection
SELECT
o.id, o.amount, o.created_at, u.email
FROM orders o
INNER JOIN users u ON o.user_id = u.id
WHERE u.email LIKE '%@gmail.com'
AND o.created_at < '2023-10-01 12:00:00' -- Value from last record of previous page
ORDER BY o.created_at DESC
LIMIT 50;
Next steps
- Run
EXPLAIN ANALYZEon the original query to confirm the Full Table Scan on theuserstable. - Evaluate if the business logic can support an exact match (
=) or prefix match ('gmail.com%') to enable standard Btree index usage. - Replace the OFFSET-based pagination in the application code with a cursor-based approach.
sql-query-performance-optimizer.pdf
PDF · document
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
The problem
Slow database queries and hidden N+1 patterns often go unnoticed until production traffic causes a bottleneck. Manual SQL reviews are time-consuming and prone to missing subtle issues like row multiplication or ineffective composite indexes.
What it does
- Identifies N+1 query patterns in ORM and application code with concrete fix recommendations.
- Analyzes EXPLAIN and EXPLAIN ANALYZE output to detect sequential scans, row explosions, and estimate mismatches.
- Provides structured index recommendations including column ordering, write trade-offs, and verification steps.
- Rewrites inefficient SQL to fix correlated subqueries, unnecessary joins, and poor pagination logic.
- Generates prioritized performance reports that rank risks by severity and frequency.
Why this beats prompting it yourself
General-purpose LLMs often hallucinate performance metrics or suggest indexes without considering write overhead. This skill enforces strict evidence-based auditing, ensuring every optimization preserves query semantics and includes a verification plan rather than fabricated benchmarks.
Use cases
- Auditing legacy SQL queries for bottlenecks before a database migration.
- Detecting lazy-loading issues in Django, Hibernate, or Eloquent ORM code.
- Reviewing execution plans for high-latency production queries to find missing indexes.
- Refactoring offset-based pagination to keyset/cursor pagination for large datasets.
Known limitations
Does not provide actual execution times or performance metrics unless you supply the EXPLAIN output or runtime logs. Does not suggest caching as a primary fix for poor query structure.
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 8 days ago
- Passed all security checks, Safe to install