Find COUNT subqueries used as existence checks

Proprietary

A scalar COUNT subquery compared to 0 or 1 tallies every matching row even though the outcome is decided by the first one. EXISTS or NOT EXISTS lets the engine stop as soon as a match is found. Comparisons against other values, such as > 5, express a genuine cardinality requirement and are not flagged.

org.openrewrite.sql.antipattern.FindCountAsExistenceCheck

Optional

markSourceBoolean

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.FindCountAsExistenceCheck

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.