Lint and Cleanup
SQL Cleanup Checklist
Clean messy SQL before review by separating formatting, joins, filters, aliases, parameters and performance-sensitive changes. This reference is written for developers who need practical validation behavior, reviewable rules and safe examples rather than copied snippets with no explanation.
Recommended workflow
| Step | Why it matters |
|---|---|
| Format without changing logic | The first pass should make the query readable while preserving behavior. |
| Name every alias | Meaningful aliases make joins and selected fields easier to review. |
| Inspect filters | WHERE clauses decide data scope, security and performance. |
| Review plans after edits | A readable query can still become slower if predicates or joins change. |
Starter snippet
1. Format
2. Name aliases
3. Check joins
4. Check WHERE
5. Run EXPLAIN when behavior changesReview checks
- Keep formatting commits separate from behavior changes when possible.
- Avoid SELECT star in shared reports and API queries.
- Use parameters rather than string-built values.
- Compare row counts before and after cleanup.
Common mistakes
- Mixing a cosmetic cleanup with a logic rewrite.
- Changing join type to make the result look right.
- Removing parentheses from complex boolean filters without tests.
Validation should help users correct input while protecting systems from bad data. Keep syntax checks, product policy, security review and deliverability checks separate.
Related Formalint references
Continue with Sql Cleanup, Sql Join Debugging Guide, Postgresql Explain Analyze Guide.