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

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

COUNT(*) scalar subquery comparison

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

When comparing a scalar subquery that calculates COUNT(*) with a single value, then chances are that weaker optimisers might be better off with an equivalent EXISTS predicate as can be seen in this blog post about COUNT(*) vs EXISTS.

This transformation is only applied under certain circumstances, including:

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

-- With Settings.transformPatternsScalarSubqueryCountAsteriskGtZero active, this:
  (SELECT COUNT(*) FROM tab) > 0;

-- ... is transformed into the equivalent expression:

References to this page


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

The jOOQ Logo