[
https://issues.apache.org/jira/browse/CALCITE-7438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18068827#comment-18068827
]
Julian Hyde commented on CALCITE-7438:
--------------------------------------
Constant reduction will simplify the expression in your query {code}SELECT CASE
WHEN 1 + 1 = 1 THEN NULL ELSE 1 + 1 END
FROM `foodmart`.`product`{code} to a literal. If you replace '1 + 1' with ,
say, 'product_id + 1', it will either introduce a Project or use a RexProgram
inside a Calc so that, once again, 'product_id + 1' is only evaluated once.
In summary, Calcite has so many tactics for eliminating common subexpressions
that expansion of NULLIF is not a problem in practice.
That said, if you want to add an option to not expand NULLIF, and leave it as a
function, I am fine with that. As long as expanding NULLIF remains the default.
> Do not rewrite NULLIF to a CASE expression
> ------------------------------------------
>
> 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
> Labels: pull-request-available
>
> 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)