From sql-quality
Automatically fix SQL performance issues with step-by-step measurement. Rewrites problematic SQL patterns (functions on columns, implicit conversions), creates indexes, measures their impact, and rolls back ineffective indexes. Reports improvements at each step with cost reduction percentages.
How this skill is triggered — by the user, by Claude, or both
Slash command
/sql-quality:sql-quality-fixThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Automatically fix SQL performance issues with step-by-step measurement.
Automatically fix SQL performance issues with step-by-step measurement.
$ARGUMENTS: SQL directory and params file
--no-index: Skip index creation, only suggest DDLphp bin/sql-quality analyze \
--sql-dir="$(echo $ARGUMENTS | cut -d' ' -f1)" \
--params="$(echo $ARGUMENTS | cut -d' ' -f2)" \
--format=json
Record as baseline.
Apply SQL fixes:
| Issue | Fix |
|---|---|
| FullTableScan | Add WHERE with indexed columns |
| FunctionInvalidatesIndex | Rewrite: YEAR(col)=2024 → col >= '2024-01-01' |
| IneffectiveLikePattern | Use prefix match if possible |
| IneffectiveJoin | Reorder JOINs, use explicit syntax |
Re-analyze and record SQL fix impact.
For each suggested index:
Create index
CREATE INDEX idx_name ON table(columns);
Re-analyze
Evaluate impact
DROP INDEX idx_name ON table;
Record as "ineffective, rolled back"Save to build/sql-quality/fix-result.json:
{
"executed_at": "2024-01-15T10:30:00",
"steps": [
{
"step": "initial",
"total_cost": 650.00
},
{
"step": "sql_fix",
"total_cost": 450.00,
"improvement": "-30.8%",
"changes": [
{"file": "1_full_table_scan.sql", "change": "Added WHERE user_id = :user_id"}
]
},
{
"step": "index",
"total_cost": 57.30,
"improvement": "-87.3%",
"indexes_created": [
{"ddl": "CREATE INDEX idx_posts_user_id ON posts(user_id)", "impact": "-60%"}
],
"indexes_rolled_back": [
{"ddl": "CREATE INDEX idx_posts_title ON posts(title)", "reason": "no improvement"}
]
}
],
"final": {
"total_cost": 57.30,
"total_improvement": "-91.2%"
},
"manual_review_needed": []
}
Generate markdown:
php bin/sql-quality report --input=build/sql-quality/fix-result.json
SQL Quality Fix: Complete
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Step-by-Step Improvement
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
| Step | Cost | Change |
|-----------|--------|--------|
| Initial | 650.00 | - |
| SQL Fix | 450.00 | -30.8% |
| Index | 57.30 | -87.3% |
| **Final** | **57.30** | **-91.2%** |
SQL Changes:
✓ 1_full_table_scan.sql: Added WHERE clause
Indexes Created:
✓ idx_posts_user_id (-60% cost)
Indexes Rolled Back (ineffective):
✗ idx_posts_title (no improvement)
Manual Review:
(none)
Report: build/sql-quality/fix-report.md
npx claudepluginhub koriym/koriym.sqlquality --plugin sql-qualityOptimize slow database queries — analyze execution plans, add indexes, rewrite queries. Use when asked about "slow query", "optimize SQL", "query performance", or "explain this query".
Optimizes slow database queries by analyzing execution plans, suggesting indexes, and rewriting SQL. Useful for slow query, optimize SQL, query performance, or explain query issues.
<!-- AUTO-GENERATED by export-plugins.py — DO NOT EDIT -->