Introducing the SQL Script optimizer
SQL Script already helps you beautify SQL and add plain-English auto-comments in the browser. The new optimizer adds a third step: apply conservative structural rewrites, see exactly what changed, and get formatted output you can paste into a pull request, migration, or warehouse console.
What “optimize” means here
This is not a database execution planner. SQL Script does not connect to your server, run
EXPLAIN, or recommend indexes. Instead, the optimizer rewrites the query text using rules that
aim to preserve semantics while making the SQL easier for engines and humans to work with.
Today’s rewrites include:
- Inlining pass-through subqueries — flatten redundant
FROM (SELECT …) aliaslayers when projections match. - Pushing filters into subqueries — move outer
WHEREpredicates into an inner scope when they only reference the subquery alias. - Removing always-true conditions — drop patterns such as
WHERE TRUEor1 = 1from filter chains.
Before and after example
A common pattern is filtering on a derived table that only wraps a single source:
-- Before
SELECT u.id, u.email
FROM (
SELECT id, email
FROM users
) u
WHERE u.status = 'active';
-- After optimization (conceptually)
SELECT u.id, u.email
FROM users u
WHERE u.status = 'active'; The exact output depends on dialect and parser support, but the goal is the same: fewer nested layers and filters placed closer to the data they restrict.
How to use it
- Open the SQL tool on the homepage.
- Paste your query and choose the matching dialect.
- Click Optimize SQL.
- Review the Rewrites applied list under the editor.
- Copy or download the formatted result, or enable auto-comments for documentation.
Optimize, then format or comment
Optimization runs before beautifying. That keeps one workflow: clean up structure, apply your team’s style rules, and optionally generate explanation comments—without switching tools.
What to check before production
Structural rewrites are conservative, but SQL is subtle. Before running optimized text against production data:
- Compare row counts or spot-check results against the original query.
- Confirm dialect-specific functions and quoted identifiers survived the rewrite.
- Use your database’s execution plan for runtime performance—not just text cleanup.
Where the optimizer fits in SQL Script
SQL Script is built as three complementary capabilities on one page: a beautifier for readable style, an auto-commenter for shared understanding, and an optimizer for structural cleanup. Use whichever steps your task needs; they all run in your browser with no backend required.
Try the optimizer now on a messy query from a ticket, dashboard, or migration script.