[
https://issues.apache.org/jira/browse/CALCITE-1790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16008320#comment-16008320
]
Julian Hyde commented on CALCITE-1790:
--------------------------------------
Clearly the "switched case" variant, which starts off as "case x when c1 then
... when c2 then ... end" and is rewritten "case when x = c1 then ... when x =
c2 ... end" has the "disjoint property" and we can optimize away all of the
"not"s.
But I wouldn't set it as a goal to eliminate all of the "not"s. My hunch is
that if we we can eliminate a significant number of them most of the time if we
focus on simplifying expressions of the form "p3 AND NOT p1 AND NOT p2".
Or, to be pedantic, I should say "p3 IS TRUE AND p1 IS NOT TRUE AND p2 IS NOT
TRUE". Case 1 will have failed if p1 is unknown.
In summary, I think we should do our best to simplify " ... and not ... and
not" expressions, and we should place a limit so that the rewrite is not
performed if it expands beyond a certain size limit.
> Simplify CASE P1 THEN <boolean> P@ THEN <booleans> ... ELSE TRUE/FALSE
> -----------------------------------------------------------------------
>
> Key: CALCITE-1790
> URL: https://issues.apache.org/jira/browse/CALCITE-1790
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Remus Rusanu
> Assignee: Remus Rusanu
> Priority: Minor
>
> In HIVE-14431 [~jcamachorodriguez] proposed a simplification for CASE when
> all branches are not nullable boolean expression into an alternative
> AND/OR/NOT based expression. This allows for more aggressive reductions and
> split/push-down on the whole. Meantime the simplifier code migrated to
> Calcite so I'm reviving this here.
> The proposed simplification is:
> {code}
> CASE
> WHEN p1 THEN ex1
> WHEN p2 THEN ex2
> ...
> WHEN pn THEN exn
> ELSE TRUE/FALSE
> END
> {code}
> to be transformed into:
> {code}
> (p1 AND ex1)
> OR (not(p1) AND p2 AND x2)
> ...
> OR (not(p1) AND not(p2) ... AND not(pn-1) AND Pn AND exn)
> [OR (not(p1) AND not(p2) ... AND not(pn))]
> {code}
> The last OR is depending on the ELSE branch being TRUE/FALSE.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)