Code review is where a query stops being yours and has to become readable to someone else, under time pressure, in a diff view. Most SQL that stalls in review does not stall because its logic is exotic. It stalls because of how it is laid out: the reviewer opens the change, meets a statement written as a single line or formatted three different ways at once, and has to do unpaid formatting work before the actual review can start. Some reviewers do that work and resent it. Others send the change back. Either way, the review slows down for reasons that have nothing to do with the query itself.

Every mistake in this guide is a layout mistake with a mechanical fix. The SQL Formatter on Ovatly will lay out a query with keywords in upper case and clauses on their own lines in one pass. The slowdowns happen around the tool: in what gets submitted, in which order the commits land, and in what people assume a tidy query proves.

Contents

  • Quick answer
  • The mistakes, one by one
  • How to format a query for review, step by step
  • Worked example: one commit that hides its own change
  • Limitations and alternatives
  • FAQs
  • Conclusion

Quick answer

Before you request a review, run the query through the SQL Formatter with the dialect your database uses selected, and commit that format pass on its own. Never bundle a reformat with a logic change, never submit a one-line query for someone else to untangle, and never treat a formatted query as a verified one: formatting changes layout and keyword case only, and the tool cannot run your query. Do those four things and the review starts at the logic, which is where it should start.

The mistakes, one by one

Submitting a one-line query. A statement pasted out of application code arrives as one long line, and the reviewer's first job becomes reformatting it before reading it. That is your work, not theirs. A one-line query also breaks the diff view itself: change one condition and the whole line shows as changed, so even the tooling cannot point at what moved.

Mixing keyword cases and indentation inside one query. select on one line, FROM on the next, columns indented by three spaces here and a tab there. Inconsistent layout forces the reader to re-parse every line instead of settling into a rhythm, and it signals, fairly or not, that the query was assembled from fragments nobody read as a whole. One mechanical pass, with keywords upper-cased and clauses on their own lines, removes the noise entirely.

Reformatting and changing logic in the same commit. This is the most expensive mistake on the list. A format pass rewrites nearly every line of a query. If the same commit also changes a join condition or a filter, that change is one altered line among dozens of rearranged ones, and reviewers miss it. The fix costs nothing: format first, commit, then change the logic and commit again. The first diff is obviously layout-only and can be skimmed; the second diff is small and gets real attention.

Formatting with the wrong dialect selected. The formatter supports eight dialects, including PostgreSQL, MySQL and SQL Server, and the choice is not cosmetic. Some syntax only parses correctly in its own dialect: MySQL backticks and T-SQL brackets are the standard examples. Format a SQL Server query as PostgreSQL and it may fail to format, or come back laid out in a way that does not match how the database reads it, and the reviewer is now debugging your settings instead of your query.

Assuming formatted means correct. A tidy query looks authoritative, and that look is unearned. Formatting changes layout and keyword case only; the statement your database receives is equivalent to the one you pasted. The formatter does not connect to any database and cannot tell you whether the query will run or return rows. Reviewers still have to check the logic, and authors still have to run the query. Submitting a formatted query as if its tidiness were evidence is how wrong queries get approved quickly.

Hand-aligning SQL the next formatter pass will rewrite. Developers sometimes align column lists or conditions into careful columns by hand. It looks precise, and it is fragile: the moment anyone runs a formatter, every hand-aligned line is rewritten, and the diff fills with churn that has to be reviewed again. Hand alignment is a recurring tax on every future change. One standard mechanical layout, even if it is not the one you would have drawn, ends the tax permanently.

How to format a query for review, step by step

  1. Finish the query's logic first. Formatting is the last step before submission, not a step in development.
  2. Paste the statement into the input box of the SQL Formatter.
  3. Choose the dialect your database uses. If the query carries MySQL backticks or T-SQL brackets, the dialect is already decided for you.
  4. Press Format SQL.
  5. Copy or download the formatted query, replace the original with it, and commit that replacement on its own, with a message that says it is a format-only change.
  6. Make any further logic changes in their own commits, on top of the formatted version.

Worked example: one commit that hides its own change

An author needs to change which orders a report includes. The original query, as stored in the application, is one line:

select o.id, c.name, o.total from orders o join customers c on c.id = o.customer_id where o.status = 'paid' order by o.created_at desc

The change is small: unpaid orders should be included too, so the filter becomes a check on two statuses. Submitted as one commit, the new version is also one line, and the diff shows the entire line replaced. The reviewer sees two walls of text and has to compare them character by character to find that 'paid' became a two-value list.

Split into two commits, the same work reviews in seconds. The first commit only formats, producing the tool's standard layout:

SELECT
  o.id,
  c.name,
  o.total
FROM
  orders o
JOIN
  customers c
  ON c.id = o.customer_id
WHERE
  o.status = 'paid'
ORDER BY
  o.created_at DESC

Nothing in that commit needs scrutiny beyond confirming it is layout-only, which the shape of the output makes obvious. The second commit then changes exactly one line of the WHERE clause, and the diff points straight at it. Same author, same change, same tool: the only difference is that the formatting stopped competing with the logic for the reviewer's attention.

Limitations and alternatives

The formatter's scope is layout, and this guide's advice stops where layout stops. It cannot tell you whether a query will run, whether a join is right, or whether the results are correct, because it never connects to a database. It also cannot settle a team's style argument by itself: it produces one consistent layout, and a team that wants a different house style, enforced automatically on every commit, needs a formatter wired into its own pipeline or editor setup, run against the same dialect every time. What the browser tool does settle is the submitted artifact in front of you now. For related reading across the category, the developer tools guides cover the neighbouring tools and habits.

One more boundary: if a query fails to format, the usual cause is an unfinished statement or syntax from a different dialect than the one selected. Fix the dialect selection first, and only then suspect the query itself.

FAQs

Why do reviewers ask for formatting before they will read a query? Because layout is the reading interface. A one-line query or one with mixed keyword cases has to be reformatted mentally or mechanically before its logic can be checked, and reviewers rightly refuse to do that work inside a review.

Should I reformat and change a query's logic in the same commit? No. A reformat rewrites nearly every line, so a logic change inside the same commit disappears into the noise. Commit the format pass on its own, then the logic change, so each diff is reviewable.

Does a cleanly formatted query still need its logic checked? Yes. Formatting changes layout and keyword case only. The formatter does not connect to any database and cannot tell you whether the query will run or return rows, so a tidy query can still be a wrong one.

What goes wrong if I select the wrong dialect? Syntax that belongs to another database may fail to format or format misleadingly. MySQL backticks and T-SQL brackets only parse correctly in their own dialect, so match the selector to the database the query runs on.

Is hand-aligned SQL ever worth keeping? Rarely. Alignment that the next formatter pass will rewrite wholesale creates churn in every later diff. One mechanical format, applied consistently, ends the argument.

Conclusion

Slow SQL reviews are rarely about SQL. They are about one-line submissions, mixed styles, reformats tangled up with logic changes, wrong dialect settings, and tidiness mistaken for correctness. Format before you submit, keep the format in its own commit, and let the review be about the query. The companion guide, How to Format SQL with Long JOIN Chains, shows the same habit from the reader's side: how a formatted chain lets you check every join condition one at a time.