About mysql query formatter
Format messy MySQL queries into readable, indented SQL with consistent keyword case.
Readable query habits
- One clause per line.
- Alias tables with short, meaningful names.
- Select only the columns you need instead of *.
A worked example
select u.id,u.name,count(o.id) from users u left join orders o on o.user_id=u.id group by u.id order by 3 desc is laid out with each clause and join on a new line, making the relationship between the two tables obvious.
MySQL habits
- Select only the columns you need, not *.
- Index columns used in joins and WHERE clauses.
- Use EXPLAIN to see how MySQL plans to run a slow query.
Reviewing joins
With each join on its own line, it is easier to see missing ON conditions, which cause accidental cross joins that return far too many rows.
Backticks
MySQL uses backticks around names that clash with keywords, such as `order`. The formatter keeps them as they are.
