SQL Query Rewriter
Installation
SKILL.md
SQL Query Rewriter
Reshape a slow query into a faster equivalent that returns identical rows. Shape beats tuning when the query does avoidable work - but a rewrite that changes results is worse than a slow query, so equivalence is proven, never assumed. This skill owns the structural rewrite only: index choice belongs to index-advisor, and plan diagnosis belongs to sql-query-optimizer.
Inputs to collect
- The query text and its
EXPLAIN (ANALYZE)output - ANALYZE if the query can be run safely, plain EXPLAIN otherwise (label conclusions from estimates as provisional). - Approximate row counts of each table involved, to spot Cartesian blowups.
- The existing indexes on the touched tables - a rewrite often assumes a supporting index; confirm it exists or hand off to index-advisor.
- What the caller actually consumes: which columns, whether order matters, whether duplicates are possible.
- A way to run both versions against the same data for the equivalence diff.