Sql optimizer
Diagnose and speed up slow SQL queries (indexes, query shape, execution plans). Use when the user shares a slow query, asks to optimize SQL, or asks why a query is slow.From its SKILL.md
npx -y skills add minagayid/Agents --skill sql-optimizerAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
1.6 KB, as published. Nobody here has run it
SQL Optimizer
Make slow queries fast without changing their results.
Process
- Measure first. Get the execution plan:
EXPLAIN ANALYZE(Postgres/MySQL 8+),EXPLAIN QUERY PLAN(SQLite). Identify the costliest node and row estimates vs. actuals. - Find the bottleneck. Common culprits:
- Sequential/full scans on large tables where an index would help.
- Missing index on
JOIN/WHERE/ORDER BYcolumns. SELECT *pulling unneeded columns; functions on indexed columns preventing index use.- N+1 query patterns from the app layer.
- Bad cardinality estimates → stale statistics (
ANALYZE).
- Fix the highest-impact issue, then re-measure. Change one thing at a time.
Techniques
- Add a targeted (often composite) index matching the filter+sort; put equality columns before range.
- Rewrite to be sargable:
WHERE created_at >= $1instead ofWHERE date(created_at) = $1. - Select only needed columns; consider a covering index.
- Replace correlated subqueries with joins or
EXISTSwhere clearer/faster. - Paginate with keyset (
WHERE id > $last) instead of largeOFFSET. - For aggregates over big tables, consider materialized views / summary tables.
Guidelines
- Verify the optimized query returns identical results.
- Note the trade-off: indexes speed reads but cost writes and storage.
- Report before/after timings and the plan change, not just the new query.