rewrite_query
After preflight flags a slow or dangerous query, rewrites it into an equivalent cheaper one, proves the gain by comparing EXPLAIN planner costs, and returns changes, cost deltas, index suggestions.
Instructions
Rewrite a slow query into a cheaper, equivalent one and PROVE the improvement by EXPLAIN-ing both and comparing planner cost. Call after a preflight flags a query expensive/dangerous. Returns the rewritten query, what changed, before/after cost, and index suggestions — ONLY suggesting a btree index when the filter is selective enough to help (an HNSW index for a vector target). Includes equivalence caveats. Pass target= in a multi-DB setup.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| target | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |