Rewrite a query to fix an anti-pattern (SIXTA)
sixta_rewrite_queryTurn a flagged anti-pattern into the safe, equivalent rewrite — no connection needed. Paste a SQL query and get ready-to-run rewrites anchored to deterministic rules: = NULL → IS NULL, NOT IN (subquery) → NOT EXISTS (NULL-safe), deep OFFSET → keyset pagination, ORDER BY RAND() → a keyed random sample — each with its semantics caveat spelled out. Every literal rewrite is then re-analyzed in-process and reported as 'clean' or 'still flags X', so the safe rewrite is self-checked — no need to feed it back through sixta_analyze_query. Use when the user asks 'how do I fix / rewrite this query' or after sixta_analyze_query flags a smell. Input is analyzed in memory and never stored.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL query to rewrite (paste it verbatim) | |
| engine | No | Database engine: postgresql or mysql. Optional but improves the rewrite (e.g. random-sample syntax). | |
| version | No | Engine version, e.g. '16' (PostgreSQL major) or '8.0.35' (MySQL). Omit for a modern default; some verdicts are version-dependent and the assumption is stated in the result. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| engine | No | Engine the analysis targeted, when known. | |
| report | Yes | The full human-readable SIXTA report (markdown). | |
| findings | No | Named findings as structured data, when the tool produces them. | |
| finding_count | No | Number of findings/issues identified. | |
| overall_severity | No | Highest severity across findings (Critical/High/Medium/Low/Info). |