Available in versions: Dev (3.20) | Latest (3.19) | 3.18

Unnecessary EXISTS subquery clauses

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The EXISTS predicate can safely ignore a few of its subquery clauses without changing semantics, including:

All of the above applies only if there are no aggregate functions in the EXISTS subquery.

Using Settings.transformPatternsUnnecessaryExistsSubqueryClauses, the following transformations can be achieved:

-- With Settings.transformPatternsUnnecessaryExistsSubqueryClauses active, this:
SELECT EXISTS (SELECT DISTINCT a, b FROM t);

-- ... is transformed into the equivalent expression:
SELECT EXISTS (SELECT 1 FROM t);

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo