[
https://issues.apache.org/jira/browse/CALCITE-7438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18064196#comment-18064196
]
Julian Hyde commented on CALCITE-7438:
--------------------------------------
To be clear, you request is valid. Your request is to make NULLIF a real
function, not a "macro" expanded via syntactic sugar. You are welcome to
contribute it, as long as it is optional (i.e. NULLIF remains a macro by
default).
But I'm not sure that you need it. If you use {{RelBuilder}} to create the
{{Aggregate}} under the {{Project}} I'm pretty sure it will create one
{{COUNT}} aggregate function and use it twice. For other cases, when the
argument is a scalar expression, e.g. {{{}NULLIF(x + 1, 5){}}}, we use common
subexpression elimination so that the argument "x + 1" is only evaluated once.
> The nullif function stops optimizing to case when
> -------------------------------------------------
>
> Key: CALCITE-7438
> URL: https://issues.apache.org/jira/browse/CALCITE-7438
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.41.0
> Reporter: terran2010
> Priority: Major
>
> When execute sql:
> {code:java}
> select NULLIF(count(brand_name),1) from product{code}
> Calcite will make the following optimizations:
> {code:java}
> SELECT CASE WHEN COUNT(brand_name) = 1 THEN NULL ELSE COUNT(brand_name) END
> FROM foodmart.product{code}
> During the actual execution of the above SQL, COUNT (brandname) will be
> executed twice. Can we consider disabling this optimization
--
This message was sent by Atlassian Jira
(v8.20.10#820010)