SQL Formatter & Static Index Advisor
Format dense one-line SQL queries with clean uppercase keywords and indentation while getting static index DDL suggestions for WHERE, JOIN, and ORDER BY predicates.
Input & Options
Local JS Execution
Parsed Output & Diagnostics
Ready
Status
...
Generated Output
Composite B-Tree Index Column Order Rule
| SQL Clause Type | Position in Composite Index | Reason |
|---|---|---|
| Equality (=, IN) | First columns | Narrows B-tree immediately to contiguous equality bucket |
| Range (>, >=, <, BETWEEN) | After equality columns | Subsequent B-tree columns lose sort efficiency after a range scan |
| ORDER BY / LIMIT | Match prefix + sort direction | Avoids explicit in-memory/disk Sort node |
| LIKE '%suffix' | Requires GIN pg_trgm index | Standard B-tree cannot use leading-wildcard patterns |
Parser Methodology & Privacy Guarantees
Formats SQL clauses using keyword line-breaks while preserving string literals, extracts table aliases, inspects WHERE/JOIN/ORDER BY columns for equality-then-range composite index ordering, and audits anti-patterns.
- Uppercases standard SQL clauses while preserving quoted string literals intact.
- Detects `SELECT *`, leading-wildcard `LIKE '%...'`, and non-sargable function-wrapped columns like `LOWER(col)`.
- Suggests `CREATE INDEX CONCURRENTLY` DDL statements prioritized by equality then range/sort selectivity.
Scope & limitations: Static analysis does not inspect live table cardinalities; confirm final index usage with PostgreSQL EXPLAIN ANALYZE.
Frequently Asked Questions
Why does column order matter in a composite B-tree index?
Place equality filters (=) before range comparisons (>=, <, BETWEEN). Putting a range column first prevents B-tree pruning on subsequent columns.
Why is LIKE '%term' flagged as non-sargable?
A standard B-tree sorts strings left-to-right, so leading % prevents index seek. Use PostgreSQL pg_trgm GIN indexes or reversed/full-text tsvector indexes instead.
Are SQL string literals modified when uppercasing keywords?
No. Single- and double-quoted literals remain byte-for-byte untouched during formatting.