A SQL Formatter & Query Performance Linter tokenizes SQL queries while preserving quoted string literals and comments, formats clauses (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY, CTEs) with consistent indentation and keyword casing, and performs static anti-pattern analysis to warn about index-defeating constructs such as leading-wildcard LIKE '%term%', SELECT *, deep OFFSET scans, and unguarded UPDATE/DELETE statements.
How to Use SQL Formatter & Linter
- 1Paste Your Raw or ORM-Generated SQL Query
Drop minified query logs from Prisma, Drizzle, TypeORM, pg_stat_statements, or Snowflake query history into the editor, or load one of the built-in Postgres presets.
- 2Choose Dialect, Keyword Casing, and Format or Minify Mode
Select your SQL dialect label, toggle UPPERCASE vs lowercase keywords, and switch between multi-line Beautify or single-line Minify formatting.
- 3Review Static Performance Linter Alerts and Export
Inspect highlighted errors (such as UPDATE/DELETE without WHERE) and index warnings (leading % LIKE, deep OFFSET, SELECT *), fix your query, and copy or download the clean .sql file.
Core Capabilities & Specifications
- Clause-aware SQL formatter preserving single-quoted strings and comments
- UPPERCASE or lowercase keyword casing toggle + single-line SQL minifier
- Static performance & safety linter flagging 6 high-impact production issues
- Works across PostgreSQL, MySQL, SQLite, Snowflake, DuckDB & BigQuery syntax
- One-click copy and .sql file export with 100% browser-local execution
Why SARGable Predicates Decide Whether Your B-Tree Index Actually Fires
Creating a B-Tree index on a column does not guarantee that the query planner will use it. For PostgreSQL or MySQL to perform a fast O(log N) B-Tree index seek, the predicate must be SARGable (Search ARGument-able): the indexed column must stand unmodified on one side of a comparison operator against a constant or range.
Wrapping an indexed column in a function—such as WHERE LOWER(email) = 'user@example.com' or WHERE DATE(created_at) = '2026-11-01'—or running a leading-wildcard pattern like LIKE '%search%' forces a sequential full-table scan unless you explicitly maintain a functional expression index or a pg_trgm GIN trigram index.
- Rewrite DATE(created_at) = '2026-11-01' as created_at >= '2026-11-01' AND created_at < '2026-11-02'.
- Replace LIKE '%keyword%' on large text columns with PostgreSQL pg_trgm GIN indexes or tsvector full-text search.
- Avoid NOT IN (SELECT nullable_col ...) because a single NULL in the subquery returns zero rows—prefer NOT EXISTS.
-- Slow: scans and discards 100,000 rows on every request
-- SELECT id, title, created_at FROM articles ORDER BY created_at DESC LIMIT 25 OFFSET 100000;
-- Fast O(log N): uses composite index (created_at DESC, id DESC)
CREATE INDEX CONCURRENTLY idx_articles_cursor
ON articles (created_at DESC, id DESC);
SELECT id, title, created_at
FROM articles
WHERE (created_at, id) < ($1::timestamptz, $2::bigint)
ORDER BY created_at DESC, id DESC
LIMIT 25;The Hidden Cost of SELECT * and Deep OFFSET Pagination
Using SELECT * in application code breaks index-only scans (covering indexes), inflates network egress by transferring large JSONB or TEXT columns that the caller ignores, and silently breaks schema contracts whenever a migration adds or reorders columns. Explicitly listing required columns lets PostgreSQL satisfy hot queries purely from the index heap visibility map.
Deep OFFSET pagination degrades linearly with page depth. Executing OFFSET 50000 LIMIT 20 forces the storage engine to fetch, sort, and throw away 50,000 rows before returning 20. Switching to cursor-based keyset pagination using a deterministic tuple (created_at, id) keeps p99 latency flat under 2 milliseconds whether you are on page 1 or page 10,000.
- Index-only scans require every column in SELECT and WHERE to exist in the index key or INCLUDE clause.
- Keyset pagination eliminates both deep-offset latency spikes and skipped/duplicated rows during live inserts.
- Always verify query plans in staging with EXPLAIN (ANALYZE, BUFFERS) before shipping schema migrations.
Guardrails Against Destructive DML in Production Terminals
Every seasoned backend engineer knows the dread of accidentally running an UPDATE or DELETE without a WHERE clause. Beyond static SQL linting, production teams enforce transactional safety rails: wrap ad-hoc fixes inside BEGIN; ... ROLLBACK; until the affected row count matches expectations, enforce statement_timeout on read replicas, and prefer soft-delete or batched chunk deletes to avoid holding multi-second table locks and triggering autovacuum bloat.
BEGIN;
SET LOCAL lock_timeout = '3s';
SET LOCAL statement_timeout = '15s';
WITH target_rows AS (
SELECT id
FROM expired_sessions
WHERE expires_at < NOW() - INTERVAL '30 days'
LIMIT 5000
FOR UPDATE SKIP LOCKED
)
DELETE FROM expired_sessions
WHERE id IN (SELECT id FROM target_rows)
RETURNING id;
-- Inspect row count before committing; run ROLLBACK if unexpected
COMMIT;Engineering Comparison Matrix
| SQL Anti-Pattern | Planner Impact | Recommended Fix | Typical Latency Gain |
|---|---|---|---|
| SELECT * FROM wide_table | Disables covering index-only scans; fetches TOAST blobs | Project explicit columns + INCLUDE covering indexes | 2x – 10x lower I/O |
| WHERE col LIKE '%term%' | Defeats B-Tree prefix ordering (Seq Scan) | Use pg_trgm GIN index or full-text tsvector | 10x – 500x faster |
| LIMIT 20 OFFSET 100000 | Scans & discards 100K rows per request | Cursor / keyset pagination on (created_at, id) | 50x – 1,000x faster |
| NOT IN (SELECT col ...) | Breaks on NULLs; poor anti-join plan | Rewrite with NOT EXISTS correlated check | Correctness + faster anti-join |
| UPDATE / DELETE without WHERE | Full table rewrite & catastrophic data loss | Require WHERE + run inside BEGIN/COMMIT block | Prevents P0 outages |
Common Production Pitfalls to Avoid
- •Formatting SQL queries containing production table schemas or customer emails on third-party websites that log input payloads.
- •Benchmarking queries only on empty local Docker databases instead of realistic row counts with ANALYZE statistics.
- •Using OR predicates across two different columns without checking whether PostgreSQL can execute a BitmapOr index scan.
- •Forgetting CONCURRENTLY when adding indexes to live PostgreSQL tables, blocking writes for the duration of the build.
Frequently Asked Questions
Which SQL dialects does this formatter support?
The formatter handles standard ANSI SQL plus dialect constructs used in PostgreSQL, MySQL, MariaDB, SQLite, Snowflake, BigQuery, and DuckDB—including Common Table Expressions (WITH ... AS), window functions, LEFT/INNER/CROSS JOINs, RETURNING clauses, and CASE expressions.
Does the SQL formatter preserve strings and comments safely?
Yes. The tokenizer isolates single-quoted string literals, double-quoted identifiers, single-line comments (--), and block comments (/* ... */) before normalizing keywords or line breaks, so text inside strings is never altered.
Why does the linter warn against NOT IN with a subquery?
In three-valued SQL logic, if a subquery inside NOT IN returns even a single NULL value, the entire predicate evaluates to UNKNOWN and returns zero rows. Rewriting it as NOT EXISTS avoids this silent bug and allows the planner to run an efficient hash or merge anti-join.
Should SQL keywords be UPPERCASE or lowercase?
Both are functionally identical in SQL engines. UPPERCASE keywords (SELECT, FROM, WHERE) visually separate reserved syntax from snake_case table and column identifiers in logs and PR diffs, which is why most style guides prefer UPPERCASE—though you can toggle lowercase in one click.
Does this tool connect to my database or send queries to a server?
No. Everything executes statically in your browser without network requests or database credentials. To check exact row estimates and buffer hits against your real indexes, run EXPLAIN (ANALYZE, BUFFERS) inside your database client.