[ 
https://issues.apache.org/jira/browse/CALCITE-4385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18126193#comment-18126193
 ] 

Vladimir Sitnikov commented on CALCITE-4385:
--------------------------------------------

PR [#2253|https://github.com/apache/calcite/pull/2253] is closed. The review of 
the change against main (843f468405) is in [this 
comment|https://github.com/apache/calcite/pull/2253#issuecomment-6118568606]. 
Summary for whoever picks this up:

* Cases 3 and 4 (an OR of ANDs with common factors) are what 
{{RexUtil.pullFactors}} already does, and CALCITE-739 extended it to match {{$3 
= $6}} with {{$6 = $3}}. {{pullFactors}} has no production caller, so the 
planner does not apply it.
* CALCITE-7657 added the absorption law for a single absorbing term only ({{a 
AND (a OR b)}}). Cases 1 and 2 (an AND of ORs whose common part has several 
terms) are still not handled.
* The join example from the PR still keeps the condition {{OR(AND(=($0, $9), 
=($1, 'A')), AND(=($0, $9), =($1, 'B')))}} on main.

Problems the PR had, which a new attempt should avoid:
# Non-deterministic terms are merged: {{(RAND() < 0.5 AND a) OR (RAND() < 0.5 
AND b)}} becomes {{RAND() < 0.5 AND (a OR b)}}.
# Operand order comes from a {{HashSet}}, so the output order depends on hash 
codes.
# {{JoinReduceExpressionsRule}} discards the rewrite unless 
{{reduceExpressions}} changes something else in the condition.
# Changing {{RelOptUtil.decomposeConjunction}} and {{decomposeDisjunction}} 
from {{List}} to {{Collection}} breaks binary compatibility.

A possible shape: add the dual of {{pullFactors}} (pull common disjuncts out of 
an AND of ORs) with a {{LinkedHashMap}} and a {{RexUtil.isDeterministic}} 
check, call both from {{simplifyAnds}} and {{simplifyOrs}} with a term limit 
like {{MAX_TERMS_FOR_ABSORPTION}}, and test it through {{checkSimplify}} in 
{{RexProgramTest}}.


> Simplifies AND/OR condition that has common expressions, extract and 
> eliminate/merge them as much as possible
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4385
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4385
>             Project: Calcite
>          Issue Type: Sub-task
>          Components: core
>            Reporter: Jiatao Tao
>            Assignee: Jiatao Tao
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 21.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to