SQL Optimizer
The optimizer takes a single query, runs it through the same Wave 1–7 rule engine that powers cluster recommendations, and returns a ranked list of issues with before/after rewrites. It works standalone — no cluster connection required.
How to use it
- 1Open the OptimizerUse Optimizer in the app sidebar, or the live playground on the landing page.
- 2Paste a queryDrop in any
SELECT. Start from one of the preset examples if you just want to see it work. - 3Set the workload knobsThree sliders — average GB read, runs per day, average duration — describe how the query behaves in production. They decide which rules fire.
- 4AnalyzeYou get a health score plus one card per issue: severity, rule name, confidence, expected impact and a copy-ready rewrite.
SELECT * over a tiny lookup table is harmless; the same query reading 10 GB a thousand times a day is not. The knobs let the rule engine judge real cost instead of guessing from the SQL text alone.What it checks
The optimizer covers the query-level rules from the recommendation catalog. The most common findings are:
| Issue | Rewrite it suggests |
|---|---|
| Missing PREWHERE | Moves a selective predicate into a PREWHERE clause. |
FROM ... FINAL | Replaces FINAL with argMax or LIMIT 1 BY over the version column. |
| Function on a partition / WHERE key | Rewrites the predicate so the partition index can be used. |
SELECT * | Narrows the projection to the columns actually consumed. |
| Memory-heavy JOIN | Adds join_algorithm = 'grace_hash' (or parallel_hash) settings. |
| Repeated subqueries | Collapses duplicated subqueries into a shared CTE. |
Reading the result
Each issue card shows a severity badge, the rule that fired, a confidence percentage and the expected impact. The before/after panel is diff-highlighted and has a copy button. A rewrite tagged paste-ready is an exact transformation; one tagged template still has placeholders you need to fill in — for example a version column the optimizer could not infer from the text alone.
Optimizer vs. recommendations
The optimizer is for one query you are actively working on — paste, rewrite, move on. Recommendations run the same rules continuously across your whole query_log, so they catch the expensive queries you did not think to check. Use the optimizer to fix a specific query; use recommendations to find which queries are worth fixing.