Find and fix SQL performance anti-patterns
ProprietaryAnalyzes SQL found in code and resource files for statically detectable performance anti-patterns such as SELECT *, COUNT(*) used as an existence check, scalar subqueries in the SELECT list, non-sargable predicates, and missing join conditions. Every occurrence is reported to the SqlAntiPatterns data table with a severity and suggested remediation, then fixed in place where a safe rewrite exists or marked in source otherwise.
org. openrewrite. sql. antipattern. SqlAntiPatternsOptional
Whether to mark each occurrence in source, and apply the fix where the rule remediates. Defaults to true; set to false to leave source untouched and report only to the data table, as an analysis-only pipeline requires.
mod run . --recipe= org. openrewrite. sql. antipattern. SqlAntiPatternsInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Find
SELECT *queries - Find
COUNTsubqueries used as existence checks - Find scalar subqueries in the
SELECTlist - Find non-sargable predicates
- Find
LIKEpatterns starting with a wildcard - Find
NOT INwith a subquery - Find optional filters written as
ORparameterIS NULL - Find
UPDATEandDELETEstatements without aWHEREclause - Find
INSERT ... VALUESstatements that omit the column list - Find
ORDER BYon a random function - Find
HAVINGconditions that use no aggregate - Find oversized
INlists - Find
UNIONwhereUNION ALLmay suffice - Find
DISTINCTmasking join fan-out - Find cartesian joins
- Find constant predicates that are always true or always false
- Find
OFFSET-based pagination - Find correlated aggregate subqueries in
WHERE - Replace
= NULLand<> NULLwithIS NULLandIS NOT NULL - Remove redundant
ORDER BYfrom subqueries - Find row limiters without an
ORDER BY