[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-29 Thread Zoltan Haindrich (JIRA)

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

Zoltan Haindrich commented on CALCITE-2257:
---

[~zhong.j.yu] ; oh really, thanks for pointing out...I think it would be 
logical to only support degree 1 for now

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-26 Thread Zoltan Haindrich (JIRA)

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

Zoltan Haindrich commented on CALCITE-2257:
---

Thank you [~vitalii]!
I was using the wrong table...and apparently there is still some missing pieces 
to the puzzle to cover this with CALCITE-2247

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-26 Thread Vitalii Diravka (JIRA)

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

Vitalii Diravka commented on CALCITE-2257:
--

[~kgyrtkirk] At first glance, I have believed your test cases :)

But emp table doesn't have nullable columns. That's why it can be always true. 
Try to use EMPNULLABLES_20 view (from my test case), then the issue is 
reproduced:

{code}
@Test public void testOrAlwaysTrue2() {
 HepProgram program = new HepProgramBuilder()
 .addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE)
 .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
 .addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE)
 .build();

 final String sql = "select SAL from EMPNULLABLES_20 \n"
 + "where SAL IS NOT NULL OR SAL is null";

 checkPlanning(program, sql);
}
{code}
{code}











{code}

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-26 Thread Zoltan Haindrich (JIRA)

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

Zoltan Haindrich commented on CALCITE-2257:
---

[~vitalii]: I've tried to peek into this also...but it seems to me that {{x is 
null or x is not null}} should be true in 1.16;
I'm not sure, but it might be possible that somehow {{ReduceExpressionsRule}} 
is not kicking in
my branch where I've checked this: 
https://github.com/apache/calcite/compare/branch-1.16...kgyrtkirk:2257-b1.16-chk
note: it seems to be possible to extend CALCITE-2247 to cover OR cases also

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-16 Thread Vitalii Diravka (JIRA)

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

Vitalii Diravka commented on CALCITE-2257:
--

Got it! Thank you. I will do necessary changes

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-15 Thread Julian Hyde (JIRA)

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

Julian Hyde commented on CALCITE-2257:
--

For the expression {{x IS NOT NULL OR x IS NULL}} you will want to invoke 
simplify on the right-hand expression {{x IS NULL}} having created predicates 
for what you have learned from the left-hand expression. The RHS will only be 
invoked if {{x IS NULL}} is true.

This is extremely similar to what is needed to solve CALCITE-2247 (except OR 
rather than AND) so you should work with [~kgyrtkirk] and deliver a patch that 
solves both problems.

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-15 Thread Julian Hyde (JIRA)

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

Julian Hyde commented on CALCITE-2257:
--

I think this is great logic, but in the wrong place. RexCall#isAlwaysTrue is a 
simple structural test and should remain so.

RexSimplify is the right place for this. It takes into account predicates that 
are known for the input fields.

You should add tests to RexProgramTest.

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
>  Labels: filter
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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


[jira] [Commented] (CALCITE-2257) Combination of predicates can be proved to be always true

2018-04-15 Thread Vitalii Diravka (JIRA)

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

Vitalii Diravka commented on CALCITE-2257:
--

The PR is opened: [https://github.com/apache/calcite/pull/666]

[~julianhyde] 
I have chosen the way to add logic into RexCall#isAlwaysTrue method.
If it is so expensive there, I think it can be moved to _ReduceExpressionsRule_.

> Combination of predicates can be proved to be always true
> -
>
> Key: CALCITE-2257
> URL: https://issues.apache.org/jira/browse/CALCITE-2257
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Affects Versions: 1.16.0
>Reporter: Vitalii Diravka
>Assignee: Vitalii Diravka
>Priority: Major
> Fix For: 1.17.0
>
>
> I have found the case, when Filter operator is not necessary since filter 
> condition is always true, but that is not detected by current version of 
> Calcite.
> {code}
> select SAL from EMPNULLABLES_20 where SAL IS NOT NULL OR SAL is null
> {code}
> {code}
> LogicalProject(SAL=[$5])
>   LogicalFilter(condition=[OR(IS NOT NULL($5), IS NULL($5))])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], SLACKER=[$8])
>   LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
> LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
> {code}
> But filter condition _OR(IS NOT NULL($5), IS NULL($5))_ can be proved to be 
> always true.
> I have tried _ReduceExpressionsRule_, but it doesn't give effect.



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