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

Zoltan Haindrich edited comment on CALCITE-2726 at 12/5/18 5:53 PM:
--------------------------------------------------------------------

Proposed change: invoke simplify directly; without the usage of ExprSimplifier; 
because RexSimplifier is able to do the recursion on its own.

* I think this modification also reduces unneccessary re-simplification runs...
* after this change nested things(which are by default not simplified) will not 
be simplified (they were earlier).
  example: {{$0 + CAST(1 as integer)}} earlier was simplified to {{$0 + 
1}}...after this change; things like this will be kept as is.

[~julianhyde] Could you please take a look?



was (Author: kgyrtkirk):
Proposed change: invoked simplify directly; without the usage of ExprSimplifier 
as RexSimplifier is able to recurse.

* I think this modification also reduces unneccessary re-simplification runs...
* after this change nested things(which are by default not simplified) will not 
be simplified (they were earlier).
  example: {{$0 + CAST(1 as integer)}} earlier was simplified to {{$0 + 
1}}...after this change; things like this will be kept as is.

> ReduceExpressionRule may oversimplify filter conditions containing nulls
> ------------------------------------------------------------------------
>
>                 Key: CALCITE-2726
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2726
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>             Fix For: 1.18.0
>
>
> ReduceExpressionsRule is invoking 
> [simplifications|https://github.com/apache/calcite/blob/efec74deb80da1708fd42bcc2b57289840869346/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java#L549]
>    - by using 
> [ExprSimplifier|https://github.com/apache/calcite/blob/efec74deb80da1708fd42bcc2b57289840869346/core/src/main/java/org/apache/calcite/rex/RexUtil.java#L2611]
>  which unfortunately doesn't switch unknownAs mode (because it's a visitor).
> Can be reproduced by adding the following test case to RelOptRulesTests
> {code}
>   @Test public void testIncorrectlyRemovedCondition() {
>     HepProgram program = new HepProgramBuilder()
>         .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
>         .build();
>     String sql =
>         //        "select * from emp where ( (empno=1 and mgr=1) or 
> (empno=null and mgr=1) ) is null";
>         "select * from emp where ( (empno=null and mgr=1) ) is null";
>     checkPlanning(program, sql);
>   }
> {code}
> Plan should retain the condition; right now it incorrectly simplified to 
> false.
> {code}
>     <TestCase name="testIncorrectlyRemovedCondition">
>         <Resource name="sql">
>             <![CDATA[select * from emp where ( (empno=null and mgr=1) ) is 
> null]]>
>         </Resource>
>         <Resource name="planBefore">
>             <![CDATA[
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
>   LogicalFilter(condition=[IS NULL(AND(=($0, null), =($3, 1)))])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> ]]>
>         </Resource>
>         <Resource name="planAfter">
>             <![CDATA[
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
>   LogicalValues(tuples=[[]])
> ]]>
>         </Resource>
>     </TestCase>
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to