This is experimental functionality, and as such subject to change. Use at your own risk!
COUNT(const)
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The COUNT(expression) aggregate function counts the number of non-NULL
expression
evaluations in the group. If the expression
is a constant, then there are only two options:
- The constant is
NULL
, in case of which theCOUNT(NULL)
value is always0
(but that's not an aggregate function, so we're currently not replacing it yet) - The constant is anything else, in case of which the
COUNT(const)
value is alwaysCOUNT(*)
For clarity reasons, and in some RDBMS also for (slight) performance reasons, COUNT(*)
should be preferred.
Using Settings.transformPatternsCountConstant
, the following transformations can be achieved:
-- With Settings.transformPatternsCountConstant active, this: SELECT COUNT(NULL), COUNT(1); -- ... is transformed into the equivalent expression: SELECT COUNT(NULL), -- Might be replaced by 0 in the future, if other aggregates are present COUNT(*);
Feedback
Do you have any feedback about this page? We'd love to hear it!