opyeb SQLPlan

Guides · Indexes and rewriting

Why format SQL, and what a linter can and cannot catch

Updated 28 Nov 2026 · 6 min read

SQL is read far more often than it is written. A query formatted with one clause per line, consistent keyword case and indentation can be reviewed in seconds; the same query as one long line hides a missing WHERE or a misplaced join condition. Formatting is not cosmetic when a mistake in a DELETE can remove a table.

The formatter on this page does not parse the full SQL grammar. It tokenises strings, comments, identifiers and punctuation, uppercases recognised keywords, and starts a new line before major clauses: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, joins, ON, AND and OR. It preserves string literals and comments, which is where a naive search-and-replace formatter usually breaks a query.

RuleSeverityWhy it matters
UPDATE or DELETE without WHEREHighTouches every row; often irreversible
SELECT *MediumMoves unneeded data, blocks covering indexes
Leading wildcard LIKEHighCannot use a B-tree, scans the table
NOT IN with a subqueryMediumA NULL in the list makes it match nothing
Function on a filtered columnLowOften prevents an index scan
LIMIT without ORDER BYLowReturns an unstable set of rows
OR across columnsInfoMay prevent a single index from being used

The rules that prevent incidents

An UPDATE or DELETE without a WHERE clause is the highest-value lint. It is almost always a mistake, it is hard to undo, and it is easy to spot in a review if the statement is formatted across lines. A linter that flags it, plus a transaction and a backup policy, prevents a class of incidents that no index tuning can fix.

A leading wildcard and a function on a filtered column are performance issues rather than correctness issues, but they are common and expensive. They do not make a query wrong, and on a small table they are harmless. The lint finding is a prompt to check the plan and the table size, not an instruction to rewrite blindly.

What static analysis cannot see

A linter does not know the data distribution, the indexes, the table size or the plan. It cannot tell whether an OR is cheap because both columns are indexed, whether a leading wildcard is fine on a 200-row lookup table, or whether a SELECT * is acceptable because the caller needs every column. It also cannot see dynamic SQL assembled in application code, which is where many risky statements actually live.

The useful workflow is: format for reading, run the linter for the high-severity patterns, then take the query to EXPLAIN ANALYZE with realistic parameters. The plan is the authority on performance; the linter is a checklist for the mistakes that are visible in the text.

Formatting conventions that help

None of these conventions is universal. What matters is that a team agrees on one and applies it, so a reviewer's eye knows where to look. A query that follows the local style is easier to compare with the previous version and easier to diff in a migration.

A practical routine

  1. Paste the query and format it before review.
  2. Read the high-severity lint findings first: missing WHERE, leading wildcard.
  3. Check SELECT * and the column list against what the caller actually needs.
  4. Run EXPLAIN ANALYZE with realistic parameters, not with production-scale guesses.
  5. Compare the plan before and after any change, and keep the measured numbers.

The formatter and linter on this page run locally in the browser. The SQL is not sent anywhere, which matters because queries often contain table names, literal values and sometimes personal data. The same caution applies to plans: a plan can reveal schema and data distribution, so treat it as sensitive when sharing.

Format for the reviewer, lint for the incident, and measure for the performance. They are three different jobs.

Sources

Questions

Does formatting change how the database executes a query?

No. Whitespace and keyword case do not affect the plan, except in rare cases where a comment or hint is sensitive. Formatting changes how people read and review the query, which affects the mistakes they catch. It is a human tool, not an optimizer.

Which lint rules actually prevent incidents?

The high-value ones are a DELETE or UPDATE without a WHERE clause, a SELECT * in a hot path, and a leading wildcard that will scan a large table. Style rules such as keyword case are useful for consistency but do not prevent data loss.

Can a linter tell me a query is slow?

No. It sees text, not data, indexes or a plan. It can flag patterns that often lead to a bad plan, but the only way to know is EXPLAIN ANALYZE on realistic data. Treat lint findings as hypotheses to check, not verdicts.

Format the default query and see the clause layout and lint findings side by side.

Open the analyzer

Written against the PostgreSQL and MySQL documentation and the standard cost model; every plan in the examples can be pasted into the analyzer linked above.

Back to the guides