blob: ec91207f90f63b479214acc75e3b8428cb53c148 [file] [log] [blame]
<?xml version="1.0" ?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to you under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<Root>
<TestCase name="testAddRedundantSemiJoinRule">
<Resource name="sql">
<![CDATA[select 1 from emp inner join dept on emp.deptno = dept.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($7, $9)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateCaseToFilter">
<Resource name="sql">
<![CDATA[select
sum(sal) as sum_sal,
count(distinct case
when job = 'CLERK'
then deptno else null end) as count_distinct_clerk,
sum(case when deptno = 10 then sal end) as sum_sal_d10,
sum(case when deptno = 20 then sal else 0 end) as sum_sal_d20,
sum(case when deptno = 30 then 1 else 0 end) as count_d30,
count(case when deptno = 40 then 'x' end) as count_d40,
sum(case when deptno = 45 then 1 end) as count_d45,
sum(case when deptno = 50 then 1 else null end) as count_d50,
sum(case when deptno = 60 then null end) as sum_null_d60,
sum(case when deptno = 70 then null else 1 end) as sum_null_d70,
count(case when deptno = 20 then 1 end) as count_d20
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $1)], SUM_SAL_D10=[SUM($2)], SUM_SAL_D20=[SUM($3)], COUNT_D30=[SUM($4)], COUNT_D40=[COUNT($5)], COUNT_D45=[SUM($6)], COUNT_D50=[SUM($7)], SUM_NULL_D60=[SUM($8)], SUM_NULL_D70=[SUM($9)], COUNT_D20=[COUNT($10)])
LogicalProject(SAL=[$5], $f1=[CASE(=($2, 'CLERK'), $7, null:INTEGER)], $f2=[CASE(=($7, 10), $5, null:INTEGER)], $f3=[CASE(=($7, 20), $5, 0)], $f4=[CASE(=($7, 30), 1, 0)], $f5=[CASE(=($7, 40), 'x', null:CHAR(1))], $f6=[CASE(=($7, 45), 1, null:INTEGER)], $f7=[CASE(=($7, 50), 1, null:INTEGER)], $f8=[null:DECIMAL(19, 9)], $f9=[CASE(=($7, 70), null:INTEGER, 1)], $f10=[CASE(=($7, 20), 1, null:INTEGER)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SUM_SAL=[$0], COUNT_DISTINCT_CLERK=[$1], SUM_SAL_D10=[$2], SUM_SAL_D20=[$3], COUNT_D30=[CAST($4):INTEGER], COUNT_D40=[$5], COUNT_D45=[$6], COUNT_D50=[$7], SUM_NULL_D60=[$8], SUM_NULL_D70=[$9], COUNT_D20=[$10])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $2) FILTER $3], SUM_SAL_D10=[SUM($4) FILTER $5], SUM_SAL_D20=[SUM($6) FILTER $7], COUNT_D30=[COUNT() FILTER $8], COUNT_D40=[COUNT() FILTER $9], COUNT_D45=[SUM($10) FILTER $11], COUNT_D50=[SUM($12) FILTER $13], SUM_NULL_D60=[SUM($1)], SUM_NULL_D70=[SUM($14) FILTER $15], COUNT_D20=[COUNT() FILTER $16])
LogicalProject(SAL=[$5], $f8=[null:DECIMAL(19, 9)], DEPTNO=[$7], $f12=[=($2, 'CLERK')], SAL0=[$5], $f14=[=($7, 10)], SAL1=[$5], $f16=[=($7, 20)], $f17=[=($7, 30)], $f18=[=($7, 40)], $f19=[1], $f20=[=($7, 45)], $f21=[1], $f22=[=($7, 50)], $f23=[1], $f24=[<>($7, 70)], $f25=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateConstantKeyRule">
<Resource name="sql">
<![CDATA[select count(*) as c
from sales.emp
where deptno = 10
group by deptno, sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(C=[$2])
LogicalAggregate(group=[{0, 1}], C=[COUNT()])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(C=[$2])
LogicalProject(DEPTNO=[10], SAL=[$0], C=[$1])
LogicalAggregate(group=[{0}], C=[COUNT()])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateConstantKeyRule2">
<Resource name="sql">
<![CDATA[select count(*) as c
from sales.emp
where deptno = 10
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(C=[$1])
LogicalAggregate(group=[{0}], C=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(C=[$1])
LogicalAggregate(group=[{0}], C=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateConstantKeyRule3">
<Resource name="sql">
<![CDATA[select job
from sales.emp
where sal is null and job = 'Clerk'
group by sal, job
having count(*) > 3]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(JOB=[$1])
LogicalFilter(condition=[>($2, 3)])
LogicalAggregate(group=[{0, 1}], agg#0=[COUNT()])
LogicalProject(SAL=[$5], JOB=[$2])
LogicalFilter(condition=[AND(IS NULL($5), =($2, 'Clerk'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$1])
LogicalFilter(condition=[>($2, 3)])
LogicalProject(SAL=[$0], JOB=['Clerk':VARCHAR(10)], $f2=[$1])
LogicalAggregate(group=[{0}], agg#0=[COUNT()])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[AND(IS NULL($5), =($2, 'Clerk'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateDynamicFunction">
<Resource name="sql">
<![CDATA[select hiredate
from sales.emp
where sal is null and hiredate = current_timestamp
group by sal, hiredate
having count(*) > 3]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(HIREDATE=[$1])
LogicalFilter(condition=[>($2, 3)])
LogicalAggregate(group=[{0, 1}], agg#0=[COUNT()])
LogicalProject(SAL=[$5], HIREDATE=[$4])
LogicalFilter(condition=[AND(IS NULL($5), =($4, CURRENT_TIMESTAMP))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(HIREDATE=[$1])
LogicalFilter(condition=[>($2, 3)])
LogicalProject(SAL=[$0], HIREDATE=[CURRENT_TIMESTAMP], $f2=[$1])
LogicalAggregate(group=[{0}], agg#0=[COUNT()])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[AND(IS NULL($5), =($4, CURRENT_TIMESTAMP))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateExtractProjectRule">
<Resource name="sql">
<![CDATA[select sum(sal)
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject(SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateExtractProjectRuleWithFilter">
<Resource name="sql">
<![CDATA[select sum(sal) filter (where empno = 40)
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0) FILTER $1])
LogicalProject(SAL=[$5], $f1=[=($0, 40)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateExtractProjectRuleWithGroupingSets">
<Resource name="sql">
<![CDATA[select empno, deptno, sum(sal)
from emp
group by grouping sets ((empno, deptno),(deptno),(empno))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 7}], groups=[[{0, 7}, {0}, {7}]], EXPR$2=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 2}], groups=[[{0, 2}, {0}, {2}]], EXPR$2=[SUM($1)])
LogicalProject(EMPNO=[$0], SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateExtractProjectRuleWithGroupingSets2">
<Resource name="sql">
<![CDATA[select empno, deptno, sum(empno)
from emp
group by grouping sets ((empno, deptno),(deptno),(empno))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 7}], groups=[[{0, 7}, {0}, {7}]], EXPR$2=[SUM($0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}]], EXPR$2=[SUM($0)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateGroupingSetsProjectMerge">
<Resource name="sql">
<![CDATA[select x, sum(z), y from (
select deptno as x, empno as y, sal as z, sal * 2 as zz
from emp)
group by rollup(x, y)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[$0], EXPR$1=[$2], Y=[$1])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$1=[SUM($2)])
LogicalProject(X=[$7], Y=[$0], Z=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(X=[$0], EXPR$1=[$2], Y=[$1])
LogicalProject(DEPTNO=[$1], EMPNO=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{0, 7}], groups=[[{0, 7}, {7}, {}]], EXPR$1=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove1">
<Resource name="sql">
<![CDATA[select distinct e.deptno from sales.emp e
left outer join sales.dept d on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove10">
<Resource name="sql">
<![CDATA[SELECT e.deptno, COUNT(DISTINCT d1.name, d2.name)
FROM sales.emp e
LEFT JOIN sales.dept d1 ON e.deptno = d1.deptno
LEFT JOIN sales.dept d2 ON e.deptno = d2.deptno
GROUP BY e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1, $2)])
LogicalProject(DEPTNO=[$7], NAME=[$10], NAME0=[$12])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(DISTINCT $10, $12)])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove11">
<Resource name="sql">
<![CDATA[select e.deptno, count(distinct e.slacker)
from sales.emp e
left outer join sales.dept d on e.deptno = d.deptno
group by e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(DISTINCT $8)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove2">
<Resource name="sql">
<![CDATA[select e.deptno, count(distinct e.job)
from sales.emp e
left outer join sales.dept d on e.deptno = d.deptno
group by e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(DISTINCT $2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove3">
<Resource name="sql">
<![CDATA[select e.deptno, count(distinct d.name)
from sales.emp e
left outer join sales.dept d on e.deptno = d.deptno
group by e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(DISTINCT $10)])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove4">
<Resource name="sql">
<![CDATA[select distinct d.deptno
from sales.emp e
right outer join sales.dept d on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$9])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove5">
<Resource name="sql">
<![CDATA[select d.deptno, count(distinct d.name)
from sales.emp e
right outer join sales.dept d on e.deptno = d.deptno
group by d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove6">
<Resource name="sql">
<![CDATA[select d.deptno, count(distinct e.job)
from sales.emp e
right outer join sales.dept d on e.deptno = d.deptno
group by d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$9], JOB=[$2])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{9}], EXPR$1=[COUNT(DISTINCT $2)])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove7">
<Resource name="sql">
<![CDATA[SELECT distinct e.deptno
FROM sales.emp e
LEFT JOIN sales.dept d1 ON e.deptno = d1.deptno
LEFT JOIN sales.dept d2 ON e.deptno = d2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove8">
<Resource name="sql">
<![CDATA[SELECT e.deptno, COUNT(DISTINCT d2.name)
FROM sales.emp e
LEFT JOIN sales.dept d1 ON e.deptno = d1.deptno
LEFT JOIN sales.dept d2 ON e.deptno = d2.deptno
GROUP BY e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], NAME0=[$12])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(DISTINCT $10)])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemove9">
<Resource name="sql">
<![CDATA[SELECT distinct e.deptno, d2.name
FROM sales.emp e
LEFT JOIN sales.dept d1 ON e.deptno = d1.deptno
LEFT JOIN sales.dept d2 ON e.deptno = d2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], NAME=[$12])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7, 10}])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemoveRule1">
<Resource name="sql">
<![CDATA[select count(distinct sal) from sales.emp e
left outer join sales.dept d1 on e.job = d1.name
left outer join sales.dept d2 on e.job = d2.name
group by e.job
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(JOB=[$2], NAME0=[$12])
LogicalJoin(condition=[=($2, $12)], joinType=[left])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{2}], EXPR$1=[COUNT(DISTINCT $10)])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateJoinRemoveRule2">
<Resource name="sql">
<![CDATA[select count(distinct sal) from sales.emp e
left outer join sales.dept d1 on e.job = d1.name
left outer join sales.dept d2 on e.job = d2.name
group by e.job
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalProject(JOB=[$2], NAME=[$12])
LogicalJoin(condition=[=($2, $12)], joinType=[left])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{2, 10}])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge1">
<Resource name="sql">
<![CDATA[select deptno c, min(y), max(z) z,
sum(r), sum(m) n, sum(x) sal from (
select deptno, ename, sum(sal) x, max(sal) z,
min(sal) y, count(hiredate) m, count(mgr) r
from sales.emp group by deptno, ename) t
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[MIN($4)], Z=[MAX($3)], EXPR$3=[SUM($6)], N=[SUM($5)], SAL=[SUM($2)])
LogicalAggregate(group=[{1, 7}], X=[SUM($5)], Z=[MAX($5)], Y=[MIN($5)], M=[COUNT()], R=[COUNT($3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{7}], EXPR$1=[MIN($5)], Z=[MAX($5)], EXPR$3=[COUNT($3)], N=[COUNT()], SAL=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge2">
<Resource name="sql">
<![CDATA[select deptno, empno, sum(x), sum(y)
from (
select ename, empno, deptno, sum(sal) x, count(mgr) y
from sales.emp
group by deptno, ename, empno) t
group by grouping sets(deptno, empno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$1], EMPNO=[$0], EXPR$2=[$2], EXPR$3=[$3])
LogicalAggregate(group=[{0, 2}], groups=[[{0}, {2}]], EXPR$2=[SUM($3)], EXPR$3=[SUM($4)])
LogicalAggregate(group=[{0, 1, 7}], X=[SUM($5)], Y=[COUNT($3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$1], EMPNO=[$0], EXPR$2=[$2], EXPR$3=[$3])
LogicalAggregate(group=[{0, 7}], groups=[[{0}, {7}]], EXPR$2=[SUM($5)], EXPR$3=[COUNT($3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge3">
<Resource name="sql">
<![CDATA[select deptno, sum(x) from (
select ename, deptno, sum(sal) x from
sales.emp group by cube(deptno, ename)) t
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[SUM($2)])
LogicalAggregate(group=[{1, 7}], groups=[[{1, 7}, {1}, {7}, {}]], X=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[SUM($2)])
LogicalAggregate(group=[{1, 7}], groups=[[{1, 7}, {1}, {7}, {}]], X=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge4">
<Resource name="sql">
<![CDATA[select deptno, sum(x) from (
select ename, deptno, count(distinct sal) x
from sales.emp group by deptno, ename) t
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[SUM($2)])
LogicalAggregate(group=[{1, 7}], X=[COUNT(DISTINCT $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[SUM($2)])
LogicalAggregate(group=[{1, 7}], X=[COUNT(DISTINCT $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge5">
<Resource name="sql">
<![CDATA[select deptno, avg(x) from (
select mgr, deptno, avg(sal) x from
sales.emp group by deptno, mgr) t
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[AVG($2)])
LogicalAggregate(group=[{3, 7}], X=[AVG($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[AVG($2)])
LogicalAggregate(group=[{3, 7}], X=[AVG($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge6">
<Resource name="sql">
<![CDATA[select sum(x) from (
select mgr, deptno, count(sal) x from
sales.emp group by deptno, mgr) t]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($2)])
LogicalAggregate(group=[{3, 7}], X=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($2)])
LogicalAggregate(group=[{3, 7}], X=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge7">
<Resource name="sql">
<![CDATA[select mgr, deptno, sum(x) from (
select mgr, deptno, count(sal) x from
sales.emp group by deptno, mgr) t
group by cube(mgr, deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}, {}]], EXPR$2=[SUM($2)])
LogicalAggregate(group=[{3, 7}], X=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}, {}]], EXPR$2=[SUM($2)])
LogicalAggregate(group=[{3, 7}], X=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMerge8">
<Resource name="sql">
<![CDATA[select sum(x) x, min(y) z from (
select sum(sal) x, min(sal) y from sales.emp)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], X=[SUM($0)], Z=[MIN($1)])
LogicalAggregate(group=[{}], X=[SUM($5)], Y=[MIN($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], X=[SUM($5)], Z=[MIN($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateMergeSum0">
<Resource name="sql">
<![CDATA[select coalesce(sum(count_comm), 0)
from (
select deptno, count(comm) as count_comm
from sales.emp
group by deptno, mgr) t]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], agg#0=[$SUM0($2)])
LogicalAggregate(group=[{3, 7}], COUNT_COMM=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateProjectMerge">
<Resource name="sql">
<![CDATA[select x, sum(z), y from (
select deptno as x, empno as y, sal as z, sal * 2 as zz
from emp)
group by x, y]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[$0], EXPR$1=[$2], Y=[$1])
LogicalAggregate(group=[{0, 1}], EXPR$1=[SUM($2)])
LogicalProject(X=[$7], Y=[$0], Z=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(X=[$0], EXPR$1=[$2], Y=[$1])
LogicalProject(DEPTNO=[$1], EMPNO=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{0, 7}], EXPR$1=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateProjectPullUpConstants">
<Resource name="sql">
<![CDATA[select job, empno, sal, sum(sal) as s
from emp where empno = 10
group by job, empno, sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1, 2}], S=[SUM($2)])
LogicalProject(JOB=[$2], EMPNO=[$0], SAL=[$5])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$0], EMPNO=[10], SAL=[$1], S=[$2])
LogicalAggregate(group=[{0, 1}], S=[SUM($1)])
LogicalProject(JOB=[$2], SAL=[$5])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateProjectPullUpConstants2">
<Resource name="sql">
<![CDATA[select ename, sal
from (select '1', ename, sal from emp where ename = 'John') subq
group by ename, sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1, 5}])
LogicalFilter(condition=[=($1, 'John')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=['John':VARCHAR(20)], SAL=[$0])
LogicalAggregate(group=[{5}])
LogicalFilter(condition=[=($1, 'John')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove1">
<Resource name="sql">
<![CDATA[select empno, sum(sal), min(sal), max(sal), bit_and(distinct sal), bit_or(sal), count(distinct sal) from sales.emp group by empno, deptno
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$2], EXPR$2=[$3], EXPR$3=[$4], EXPR$4=[$5], EXPR$5=[$6], EXPR$6=[$7])
LogicalAggregate(group=[{0, 1}], EXPR$1=[SUM($2)], EXPR$2=[MIN($2)], EXPR$3=[MAX($2)], EXPR$4=[BIT_AND($2)], EXPR$5=[BIT_OR($2)], EXPR$6=[COUNT(DISTINCT $2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$5], EXPR$2=[$5], EXPR$3=[$5], EXPR$4=[$5], EXPR$5=[$5], EXPR$6=[1:BIGINT])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove2">
<Resource name="sql">
<![CDATA[select distinct empno, deptno from sales.emp
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove3">
<Resource name="sql">
<![CDATA[select empno, count(mgr) from sales.emp group by empno, deptno
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$1=[COUNT($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[CASE(IS NOT NULL($3), 1:BIGINT, 0:BIGINT)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove4">
<Resource name="sql">
<![CDATA[select empno, max(sal), avg(sal) from sales.emp group by empno, deptno
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$2], EXPR$2=[$3])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)], EXPR$2=[AVG($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$2], EXPR$2=[$3])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)], EXPR$2=[AVG($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove5">
<Resource name="sql">
<![CDATA[select empno, deptno, sum(sal) from sales.emp group by cube(empno, deptno)
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}, {}]], EXPR$2=[SUM($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {1}, {}]], EXPR$2=[SUM($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove6">
<Resource name="sql">
<![CDATA[select deptno, max(sal) from sales.emp group by deptno
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateRemove7">
<Resource name="sql">
<![CDATA[select mgr, sum(sum_sal)
from
(select mgr, deptno, sum(sal) sum_sal
from sales.emp
group by mgr, deptno)
where deptno=100
group by mgr]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(MGR=[$0], SUM_SAL=[$2])
LogicalFilter(condition=[=($1, 100)])
LogicalAggregate(group=[{0, 1}], SUM_SAL=[SUM($2)])
LogicalProject(MGR=[$3], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(MGR=[$0], SUM_SAL=[$2])
LogicalFilter(condition=[=($1, 100)])
LogicalAggregate(group=[{0, 1}], SUM_SAL=[SUM($2)])
LogicalProject(MGR=[$3], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateUnionTransposeWithAllInputsUnique">
<Resource name="sql">
<![CDATA[select deptno, SUM(t) from (
select deptno, 1 as t from sales.emp e1
union all
select distinct deptno, 2 as t from sales.emp e2)
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], T=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], T=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], T=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], T=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAggregateUnionTransposeWithOneInputUnique">
<Resource name="sql">
<![CDATA[select deptno, SUM(t) from (
select deptno, 1 as t from sales.emp e1
union all
select distinct deptno, 2 as t from sales.emp e2)
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7], T=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], T=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(DEPTNO=[$7], T=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], T=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAll">
<Resource name="sql">
<![CDATA[select * from emp e1
where e1.empno > ALL (select deptno from dept)]]>
</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=[NOT(<= SOME($0, {
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
}))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[NOT(CAST(OR(AND(IS TRUE(<=($0, $9)), <>($10, 0)), AND(>($10, $11), null, <>($10, 0), IS NOT TRUE(<=($0, $9))), AND(<=($0, $9), <>($10, 0), IS NOT TRUE(<=($0, $9)), <=($10, $11)))):BOOLEAN NOT NULL)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$0], c=[$1], d=[$1])
LogicalAggregate(group=[{}], m=[MAX($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[NOT(CAST(OR(AND(IS TRUE(<=($0, $9)), <>($10, 0)), AND(>($10, $11), null, <>($10, 0), IS NOT TRUE(<=($0, $9))), AND(<=($0, $9), <>($10, 0), IS NOT TRUE(<=($0, $9)), <=($10, $11)))):BOOLEAN NOT NULL)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$0], c=[$1], d=[$1])
LogicalAggregate(group=[{}], m=[MAX($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAlreadyFalseEliminatesFilter">
<Resource name="sql">
<![CDATA[select * from (values (1,2)) where false]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalFilter(condition=[false])
LogicalValues(tuples=[[{ 1, 2 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testAntiJoinProjectTranspose">
<Resource name="sql">
<![CDATA[select a.name from dept a
where a.deptno not in (select b.deptno * 2 from dept);
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $3)], joinType=[anti])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject($f0=[*(2, $0)])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[anti])
LogicalProject(DEPTNO=[$0], DNAME=[$1])
LogicalTableScan(table=[[scott, DEPT]])
LogicalProject($f0=[$0])
LogicalAggregate(group=[{0}])
LogicalProject($f0=[*(2, $0)])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testAnyInProjectNonNullable">
<Resource name="sql">
<![CDATA[select name, deptno > ANY (
select deptno from emp)
from dept]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1], EXPR$1=[> SOME($0, {
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(NAME=[$1], EXPR$1=[CAST(OR(AND(IS TRUE(>($0, $2)), <>($3, 0)), AND(>($3, $4), null, <>($3, 0), IS NOT TRUE(>($0, $2))), AND(>($0, $2), <>($3, 0), IS NOT TRUE(>($0, $2)), <=($3, $4)))):BOOLEAN NOT NULL])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(m=[$0], c=[$1], d=[$1])
LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$1], EXPR$1=[CAST(OR(AND(IS TRUE(>($0, $2)), <>($3, 0)), AND(>($3, $4), null, <>($3, 0), IS NOT TRUE(>($0, $2))), AND(>($0, $2), <>($3, 0), IS NOT TRUE(>($0, $2)), <=($3, $4)))):BOOLEAN NOT NULL])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(m=[$0], c=[$1], d=[$1])
LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testAnyInProjectNullable">
<Resource name="sql">
<![CDATA[select deptno, name = ANY (
select mgr from emp)
from dept]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[IN($1, {
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[OR(AND(IS NOT NULL($5), <>($2, 0)), AND(<($3, $2), null, <>($2, 0), IS NULL($5)))])
LogicalJoin(condition=[=($1, $4)], joinType=[left])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(MGR=[$3], i=[true])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[OR(AND(IS NOT NULL($5), <>($2, 0)), AND(<($3, $2), null, <>($2, 0), IS NULL($5)))])
LogicalJoin(condition=[=($1, $4)], joinType=[left])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(MGR=[$3], i=[true])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testBitAndReuseDistinctAttrWithMixedOptionality">
<Resource name="sql">
<![CDATA[select sum(distinct deptno), count(distinct deptno), bit_and(deptno) from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM(DISTINCT $0)], EXPR$1=[COUNT(DISTINCT $0)], EXPR$2=[BIT_AND($0)])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[BIT_AND($0)])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testBitOrReuseDistinctAttrWithMixedOptionality">
<Resource name="sql">
<![CDATA[select sum(distinct deptno), count(distinct deptno), bit_or(deptno) from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM(DISTINCT $0)], EXPR$1=[COUNT(DISTINCT $0)], EXPR$2=[BIT_OR($0)])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[BIT_OR($0)])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testCallOverCorrelationVariableIsNotFlattened">
<Resource name="sql">
<![CDATA[select * from emp e1 where exists (select * from emp e2 where (e1.deptno+30) = e2.deptno)]]>
</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 NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=(+($cor0.DEPTNO, 30), $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testCanNotPushAntiJoinConditionsToLeft">
<Resource name="sql">
<![CDATA[select * from emp
where emp.deptno not in
(select dept.deptno from dept where emp.deptno > 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[AND(IS NOT DISTINCT FROM($7, $8), >($0, 20))], joinType=[anti])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testCanNotPushAntiJoinConditionsToRight">
<Resource name="sql">
<![CDATA[select * from emp
where emp.deptno
not in (select dept.deptno from dept where dept.dname = 'ddd')]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[AND(IS NOT DISTINCT FROM($7, $8), =($9, 'ddd'))], joinType=[anti])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testCasePushIsAlwaysWorking">
<Resource name="sql">
<![CDATA[select empno from emp where case when sal > 1000 then empno else sal end = 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[=(CASE(>($5, 1000), $0, $5), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(AND(>($5, 1000), =($0, 1)), =($5, 1))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testCastInAggregateExpandDistinctAggregatesRule">
<Resource name="sql">
<![CDATA[select name, sum(distinct cn), sum(distinct sm)
from (
select name, count(dept.deptno) as cn,sum(dept.deptno) as sm
from sales.dept group by name)
group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM(DISTINCT $1)], EXPR$2=[SUM(DISTINCT $2)])
LogicalAggregate(group=[{0}], CN=[COUNT()], SM=[SUM($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[CAST($1):BIGINT NOT NULL], EXPR$2=[CAST($2):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) FILTER $3], EXPR$2=[SUM($2) FILTER $4])
LogicalProject(NAME=[$0], CN=[$1], SM=[$2], $g_1=[=($3, 1)], $g_2=[=($3, 2)])
LogicalAggregate(group=[{0, 1, 2}], groups=[[{0, 1}, {0, 2}]], $g=[GROUPING($0, $1, $2)])
LogicalAggregate(group=[{0}], CN=[COUNT()], SM=[SUM($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testCastInAggregateReduceFunctions">
<Resource name="sql">
<![CDATA[select name, stddev_pop(deptno), avg(deptno),
stddev_samp(deptno),var_pop(deptno), var_samp(deptno)
from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], EXPR$2=[AVG($1)], EXPR$3=[STDDEV_SAMP($1)], EXPR$4=[VAR_POP($1)], EXPR$5=[VAR_SAMP($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[CAST(POWER(/(-($1, /(*($2, $2), $3)), $3), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(POWER(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1))), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$4=[CAST(/(-($1, /(*($2, $2), $3)), $3)):INTEGER NOT NULL], EXPR$5=[CAST(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1)))):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($2)], agg#1=[$SUM0($1)], agg#2=[COUNT()])
LogicalProject(NAME=[$0], DEPTNO=[$1], $f2=[*($1, $1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testCastRemove">
<Resource name="sql">
<![CDATA[select
case when cast(ename as double) < 5 then 0.0
else coalesce(cast(ename as double), 1.0)
end as t
from (
select
case when ename > 'abc' then ename
else null
end as ename from emp
)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(T=[CASE(<(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE, 5), 0.0:DOUBLE, CASE(IS NOT NULL(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE), CAST(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE):DOUBLE NOT NULL, 1.0:DOUBLE))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(T=[CASE(<(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE, 5), 0.0:DOUBLE, CASE(IS NOT NULL(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE), CAST(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE):DOUBLE NOT NULL, 1.0:DOUBLE))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testConvertMultiJoinRule">
<Resource name="sql">
<![CDATA[select e1.ename from emp e1, dept d, emp e2
where e1.deptno = d.deptno and d.deptno = e2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($9, $18))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
MultiJoin(joinFilter=[AND(=($9, $18), =($7, $9))], isFullOuterJoin=[false], joinTypes=[[INNER, INNER, INNER]], outerJoinConditions=[[NULL, NULL, NULL]], projFields=[[ALL, ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testConvertMultiJoinRuleOuterJoins">
<Resource name="sql">
<![CDATA[select * from (select * from (select * from (select * from A right outer join B on a = b) left outer join (select * from C full outer join D on c = d) on a = c and b = d) right outer join (select * from (select * from E full outer join F on e = f) right outer join (select * from G left outer join H on g = h) on e = g and f = h) on a = e and b = f and c = g and d = h) inner join (select * from I inner join J on i = j) on a = i and h = j]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(A=[$0], B=[$1], C=[$2], D=[$3], E=[$4], F=[$5], G=[$6], H=[$7], I=[$8], J=[$9])
LogicalJoin(condition=[AND(=($0, $8), =($7, $9))], joinType=[inner])
LogicalProject(A=[$0], B=[$1], C=[$2], D=[$3], E=[$4], F=[$5], G=[$6], H=[$7])
LogicalJoin(condition=[AND(=($0, $4), =($1, $5), =($2, $6), =($3, $7))], joinType=[right])
LogicalProject(A=[$0], B=[$1], C=[$2], D=[$3])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[left])
LogicalProject(A=[$0], B=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalProject(C=[$0], D=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, C]])
LogicalTableScan(table=[[CATALOG, SALES, D]])
LogicalProject(E=[$0], F=[$1], G=[$2], H=[$3])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[right])
LogicalProject(E=[$0], F=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, E]])
LogicalTableScan(table=[[CATALOG, SALES, F]])
LogicalProject(G=[$0], H=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, G]])
LogicalTableScan(table=[[CATALOG, SALES, H]])
LogicalProject(I=[$0], J=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, I]])
LogicalTableScan(table=[[CATALOG, SALES, J]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
MultiJoin(joinFilter=[AND(=($0, $8), =($7, $9), =($8, $9))], isFullOuterJoin=[false], joinTypes=[[INNER, INNER, INNER]], outerJoinConditions=[[NULL, NULL, NULL]], projFields=[[ALL, ALL, ALL]])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[RIGHT, INNER]], outerJoinConditions=[[AND(=($0, $4), =($1, $5), =($2, $6), =($3, $7)), NULL]], projFields=[[ALL, ALL]])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER, LEFT]], outerJoinConditions=[[NULL, AND(=($0, $2), =($1, $3))]], projFields=[[ALL, ALL]])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[RIGHT, INNER]], outerJoinConditions=[[=($0, $1), NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
MultiJoin(joinFilter=[=($0, $1)], isFullOuterJoin=[true], joinTypes=[[INNER, INNER]], outerJoinConditions=[[NULL, NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
LogicalTableScan(table=[[CATALOG, SALES, D]])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[RIGHT, INNER]], outerJoinConditions=[[AND(=($0, $2), =($1, $3)), NULL]], projFields=[[ALL, ALL]])
MultiJoin(joinFilter=[=($0, $1)], isFullOuterJoin=[true], joinTypes=[[INNER, INNER]], outerJoinConditions=[[NULL, NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, E]])
LogicalTableScan(table=[[CATALOG, SALES, F]])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER, LEFT]], outerJoinConditions=[[NULL, =($0, $1)]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, G]])
LogicalTableScan(table=[[CATALOG, SALES, H]])
LogicalTableScan(table=[[CATALOG, SALES, I]])
LogicalTableScan(table=[[CATALOG, SALES, J]])
]]>
</Resource>
</TestCase>
<TestCase name="testConvertMultiJoinRuleOuterJoins2">
<Resource name="sql">
<![CDATA[select * from A right join B on a = b join C on b = c]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(A=[$0], B=[$1], C=[$2])
LogicalJoin(condition=[=($1, $2)], joinType=[inner])
LogicalJoin(condition=[=($0, $1)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
MultiJoin(joinFilter=[=($1, $2)], isFullOuterJoin=[false], joinTypes=[[INNER, INNER]], outerJoinConditions=[[NULL, NULL]], projFields=[[ALL, ALL]])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[RIGHT, INNER]], outerJoinConditions=[[=($0, $1), NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
]]>
</Resource>
</TestCase>
<TestCase name="testConvertMultiJoinRuleOuterJoins3">
<Resource name="sql">
<![CDATA[select * from A join B on a = b left join C on b = c]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(A=[$0], B=[$1], C=[$2])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
MultiJoin(joinFilter=[=($0, $1)], isFullOuterJoin=[false], joinTypes=[[INNER, INNER, LEFT]], outerJoinConditions=[[NULL, NULL, =($1, $2)]], projFields=[[ALL, ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
]]>
</Resource>
</TestCase>
<TestCase name="testConvertMultiJoinRuleOuterJoins4">
<Resource name="sql">
<![CDATA[select * from A join B on a = b right join C on b = c]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(A=[$0], B=[$1], C=[$2])
LogicalJoin(condition=[=($1, $2)], joinType=[right])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[RIGHT, INNER]], outerJoinConditions=[[=($1, $2), NULL]], projFields=[[ALL, ALL]])
MultiJoin(joinFilter=[=($0, $1)], isFullOuterJoin=[false], joinTypes=[[INNER, INNER]], outerJoinConditions=[[NULL, NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[CATALOG, SALES, A]])
LogicalTableScan(table=[[CATALOG, SALES, B]])
LogicalTableScan(table=[[CATALOG, SALES, C]])
]]>
</Resource>
</TestCase>
<TestCase name="testCorrelationScalarAggAndFilter">
<Resource name="sql">
<![CDATA[SELECT e1.empno
FROM emp e1, dept d1 where e1.deptno = d1.deptno
and e1.deptno < 10 and d1.deptno < 15
and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[AND(=($0, $4), >($1, $5))], joinType=[inner])
LogicalJoin(condition=[=($2, $3)], joinType=[inner])
LogicalFilter(condition=[<($2, 10)])
LogicalProject(EMPNO=[$0], SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[<($0, 15)])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}], EXPR$0=[AVG($1)])
LogicalProject(EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testCustomColumnResolvingInCorrelatedSubQuery">
<Resource name="sql">
<![CDATA[select *
from struct.t t1
where c0 = (
select max(f1.c0) from struct.t t2 where t1.k0 = t2.k0)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalFilter(condition=[=($4, $SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject("F1"."C0"=[$5])
LogicalFilter(condition=[=($cor0."K0", $0)])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
}))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalFilter(condition=[=($4, $9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject("F1"."C0"=[$5])
LogicalFilter(condition=[=($cor0."K0", $0)])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
]]>
</Resource>
</TestCase>
<TestCase name="testCustomColumnResolvingInCorrelatedSubQuery2">
<Resource name="sql">
<![CDATA[select *
from struct.t t1
where c0 in (
select f1.c0 from struct.t t2 where t1.c2 = t2.c2)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalFilter(condition=[IN($4, {
LogicalProject(C0=[$5])
LogicalFilter(condition=[=($cor0."F1"."C2", $7)])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
})], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalFilter(condition=[=($4, $9)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
LogicalAggregate(group=[{0}])
LogicalProject(C0=[$5])
LogicalFilter(condition=[=($cor0."F1"."C2", $7)])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
]]>
</Resource>
</TestCase>
<TestCase name="testCustomColumnResolvingInNonCorrelatedSubQuery">
<Resource name="sql">
<![CDATA[select *
from struct.t t1
where c0 in (
select f1.c0 from struct.t t2)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalFilter(condition=[IN($4, {
LogicalProject(C0=[$5])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
})])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalProject("K0"=[$0], "C1"=[$1], "F1"."A0"=[$2], "F2"."A0"=[$3], "F0"."C0"=[$4], "F1"."C0"=[$5], "F0"."C1"=[$6], "F1"."C2"=[$7], "F2"."C3"=[$8])
LogicalJoin(condition=[=($4, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
LogicalAggregate(group=[{0}])
LogicalProject(C0=[$5])
LogicalTableScan(table=[[CATALOG, STRUCT, T]])
]]>
</Resource>
</TestCase>
<TestCase name="testCustomDecorrelate">
<Resource name="Comparing Plans from LogicalCorrelate and CustomCorrelate">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], EMPNO0=[CAST($11):INTEGER], EXPR$0=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($0, $11), >($5, $12))], joinType=[inner])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalFilter(condition=[<($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[<($0, 15)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}], EXPR$0=[AVG($1)])
LogicalProject(EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateAggWithConstantGroupKey">
<Resource name="sql">
<![CDATA[SELECT * FROM emp A where sal in
(SELECT max(sal) FROM emp B where A.mgr = B.empno group by deptno, 'abc')]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{3, 5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($cor0.SAL, $0)])
LogicalAggregate(group=[{0}])
LogicalProject(EXPR$0=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$0=[MAX($2)])
LogicalProject(DEPTNO=[$7], $f1=['abc'], SAL=[$5])
LogicalFilter(condition=[=($cor0.MGR, $0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{3, 5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($cor0.SAL, $0)])
LogicalAggregate(group=[{0}])
LogicalProject(EXPR$0=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$0=[MAX($2)])
LogicalProject(DEPTNO=[$7], $f1=['abc'], SAL=[$5])
LogicalFilter(condition=[=($cor0.MGR, $0)])
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])
LogicalJoin(condition=[AND(=($3, $10), =($5, $9))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(EXPR$0=[$2], EMPNO=[$1])
LogicalAggregate(group=[{0, 1}], EXPR$0=[MAX($2)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateAggWithMultiParamsAggCall">
<Resource name="sql">
<![CDATA[SELECT * FROM (SELECT MYAGG(sal, 1) AS c FROM emp) as m,
LATERAL TABLE(ramp(m.c)) AS T(s)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(C=[$0], S=[$1])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])
LogicalAggregate(group=[{}], C=[MYAGG($0, $1)])
LogicalProject(SAL=[$5], $f1=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableFunctionScan(invocation=[RAMP($cor0.C)], rowType=[RecordType(INTEGER I)])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(C=[$0], S=[$1])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])
LogicalAggregate(group=[{}], C=[MYAGG($0, $1)])
LogicalProject(SAL=[$5], $f1=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableFunctionScan(invocation=[RAMP($cor0.C)], rowType=[RecordType(INTEGER I)])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateAggWithMultiParamsAggCall2">
<Resource name="sql">
<![CDATA[SELECT * FROM (SELECT MYAGG(sal, 1) AS c FROM emp group by empno, 'abc') as m,
LATERAL TABLE(ramp(m.c)) AS T(s)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(C=[$0], S=[$1])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])
LogicalProject(C=[$2])
LogicalAggregate(group=[{0, 1}], C=[MYAGG($2, $3)])
LogicalProject(EMPNO=[$0], $f1=['abc'], SAL=[$5], $f3=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableFunctionScan(invocation=[RAMP($cor0.C)], rowType=[RecordType(INTEGER I)])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(C=[$0], S=[$1])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])
LogicalProject(C=[$2])
LogicalAggregate(group=[{0, 1}], C=[MYAGG($2, $3)])
LogicalProject(EMPNO=[$0], $f1=['abc'], SAL=[$5], $f3=[1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableFunctionScan(invocation=[RAMP($cor0.C)], rowType=[RecordType(INTEGER I)])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateExists">
<Resource name="sql">
<![CDATA[select * from sales.emp
where EXISTS (
select * from emp e where emp.deptno = e.deptno)]]>
</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=[EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], variablesSet=[[$cor0]])
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])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], $f1=[true])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateTwoExists">
<Resource name="sql">
<![CDATA[select * from sales.emp
where EXISTS (
select * from emp e where emp.deptno = e.deptno)
AND NOT EXISTS (
select * from emp ee where ee.job = emp.job AND ee.sal=34)]]>
</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=[AND(EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), NOT(EXISTS({
LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[IS NULL($10)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{2}])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
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])
LogicalFilter(condition=[IS NULL($12)])
LogicalJoin(condition=[=($2, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], $f1=[true])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(JOB=[$0], $f1=[true])
LogicalAggregate(group=[{0}])
LogicalProject(JOB=[$2])
LogicalFilter(condition=[=($5, 34)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateTwoIn">
<Resource name="sql">
<![CDATA[select sal
from sales.emp
where empno IN (
select deptno from dept where emp.job = dept.name)
AND empno IN (
select empno from emp e where emp.ename = e.ename)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[AND(IN($0, {
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
}), IN($0, {
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[=($cor0.ENAME, $1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, $10)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{1}])
LogicalFilter(condition=[=($0, $9)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[=($cor0.ENAME, $1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[AND(=($1, $12), =($0, $11))], joinType=[inner])
LogicalJoin(condition=[AND(=($2, $10), =($0, $9))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateTwoScalar">
<Resource name="sql">
<![CDATA[select deptno,
(select min(1) from emp where empno > d.deptno) as i0,
(select min(0) from emp
where deptno = d.deptno and ename = 'SMITH') as i1
from dept as d]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], I0=[$SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
LogicalProject($f0=[1])
LogicalFilter(condition=[>($0, $cor0.DEPTNO)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], I1=[$SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
LogicalProject($f0=[0])
LogicalFilter(condition=[AND(=($7, $cor1.DEPTNO), =($1, 'SMITH'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(DEPTNO=[$0], I0=[$2], I1=[$3])
LogicalJoin(condition=[true], joinType=[left])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
LogicalProject($f0=[1])
LogicalFilter(condition=[>($0, $cor0.DEPTNO)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
LogicalProject($f0=[0])
LogicalFilter(condition=[AND(=($7, $cor1.DEPTNO), =($1, 'SMITH'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelateUncorrelatedInAndCorrelatedExists">
<Resource name="sql">
<![CDATA[select * from sales.emp
WHERE job in (
select job from emp ee where ee.sal=34)AND EXISTS (
select * from emp e where emp.deptno = e.deptno)
]]>
</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=[AND(IN($2, {
LogicalProject(JOB=[$2])
LogicalFilter(condition=[=($5, 34)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{7}])
LogicalJoin(condition=[=($2, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(JOB=[$2])
LogicalFilter(condition=[=($5, 34)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
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])
LogicalJoin(condition=[=($7, $10)], joinType=[inner])
LogicalJoin(condition=[=($2, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(JOB=[$2])
LogicalFilter(condition=[=($5, 34)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], $f1=[true])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelationWithSort">
<Resource name="sql">
<![CDATA[SELECT e1.empno
FROM emp e1, dept d1 where e1.deptno = d1.deptno
and e1.deptno < 10 and d1.deptno < 15
and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)
order by e1.empno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], EMPNO0=[CAST($11):INTEGER], EXPR$0=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($0, $11), >($5, $12))], joinType=[inner])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalFilter(condition=[<($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[<($0, 15)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}], EXPR$0=[AVG($1)])
LogicalProject(EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], EMPNO0=[CAST($11):INTEGER], EXPR$0=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($0, $11), >($5, $12))], joinType=[inner])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalFilter(condition=[<($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[<($0, 15)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}], EXPR$0=[AVG($1)])
LogicalProject(EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDigestOfApproximateDistinctAggregateCall">
<Resource name="sql">
<![CDATA[select *
from (
select deptno, count(distinct empno) from emp group by deptno
union all
select deptno, approx_count_distinct(empno) from emp group by deptno)]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
LogicalUnion(all=[true])
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(DISTINCT $0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{7}], EXPR$1=[COUNT(APPROXIMATE DISTINCT $0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(APPROXIMATE DISTINCT $1)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCount1">
<Resource name="sql">
<![CDATA[select deptno, count(distinct ename)
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[COUNT($0)])
LogicalAggregate(group=[{1, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCount2">
<Resource name="sql">
<![CDATA[select deptno, count(distinct ename), sum(sal)
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], ENAME=[$1], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], EXPR$2=[CAST($2):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT($1) FILTER $3], EXPR$2=[MIN($2) FILTER $4])
LogicalProject(DEPTNO=[$0], ENAME=[$1], EXPR$2=[$2], $g_0=[=($3, 0)], $g_1=[=($3, 1)])
LogicalProject(DEPTNO=[$1], ENAME=[$0], EXPR$2=[$2], $g=[$3])
LogicalAggregate(group=[{1, 7}], groups=[[{1, 7}, {7}]], EXPR$2=[SUM($5)], $g=[GROUPING($7, $1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCount3">
<Resource name="sql">
<![CDATA[select count(distinct deptno), sum(sal) from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$2])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT(DISTINCT $0)], EXPR$1=[SUM($1)])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$2])
LogicalProject(DEPTNO=[$0], EXPR$0=[$1], EXPR$1=[CAST($2):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT($0) FILTER $2], EXPR$1=[MIN($1) FILTER $2])
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], $g_0=[=($2, 0)])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], $g=[GROUPING($0)])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountGroupingSets1">
<Resource name="sql">
<![CDATA[select deptno, job, count(distinct ename)
from sales.emp group by rollup(deptno,job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[COUNT(DISTINCT $2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[COUNT($2) FILTER $3])
LogicalProject(DEPTNO=[$0], JOB=[$1], ENAME=[$2], $g_0=[=($3, 0)])
LogicalAggregate(group=[{0, 1, 2}], $g=[GROUPING($0, $1, $2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountGroupingSets2">
<Resource name="sql">
<![CDATA[select deptno, job, count(distinct ename), sum(sal)
from sales.emp group by rollup(deptno,job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[COUNT(DISTINCT $2)], EXPR$3=[SUM($3)])
LogicalProject(DEPTNO=[$7], JOB=[$2], ENAME=[$1], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], JOB=[$1], EXPR$2=[$2], EXPR$3=[CAST($3):INTEGER NOT NULL])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[COUNT($2) FILTER $4], EXPR$3=[MIN($3) FILTER $5])
LogicalProject(DEPTNO=[$0], JOB=[$1], ENAME=[$2], EXPR$3=[$3], $g_0=[=($4, 0)], $g_1=[=($4, 1)])
LogicalAggregate(group=[{0, 1, 2}], groups=[[{0, 1, 2}, {0, 1}]], EXPR$3=[SUM($3)], $g=[GROUPING($0, $1, $2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], ENAME=[$1], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountMixed">
<Resource name="sql">
<![CDATA[select deptno, count(distinct deptno, job) as cddj,
sum(sal) as s
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], CDDJ=[COUNT(DISTINCT $0, $1)], S=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], CDDJ=[$1], S=[CAST($2):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], CDDJ=[COUNT($0, $1) FILTER $3], S=[MIN($2) FILTER $4])
LogicalProject(DEPTNO=[$0], JOB=[$1], S=[$2], $g_0=[=($3, 0)], $g_1=[=($3, 1)])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}]], S=[SUM($2)], $g=[GROUPING($0, $1)])
LogicalProject(DEPTNO=[$7], JOB=[$2], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountMixed2">
<Resource name="sql">
<![CDATA[select deptno, count(distinct ename) as cde,
count(distinct job, ename) as cdje,
count(distinct deptno, job) as cddj,
sum(sal) as s
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], CDE=[COUNT(DISTINCT $1)], CDJE=[COUNT(DISTINCT $2, $1)], CDDJ=[COUNT(DISTINCT $0, $2)], S=[SUM($3)])
LogicalProject(DEPTNO=[$7], ENAME=[$1], JOB=[$2], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], CDE=[$1], CDJE=[$2], CDDJ=[$3], S=[CAST($4):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], CDE=[COUNT($1) FILTER $5], CDJE=[COUNT($2, $1) FILTER $4], CDDJ=[COUNT($0, $2) FILTER $6], S=[MIN($3) FILTER $7])
LogicalProject(DEPTNO=[$2], ENAME=[$0], JOB=[$1], S=[$3], $g_0=[=($4, 0)], $g_1=[=($4, 1)], $g_2=[=($4, 2)], $g_3=[=($4, 3)])
LogicalAggregate(group=[{1, 2, 7}], groups=[[{1, 2, 7}, {1, 7}, {2, 7}, {7}]], S=[SUM($5)], $g=[GROUPING($7, $1, $2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountMixedJoin">
<Resource name="sql">
<![CDATA[select deptno, count(distinct ename), count(distinct job, ename),
count(distinct deptno, job), sum(sal)
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)], EXPR$2=[COUNT(DISTINCT $2, $1)], EXPR$3=[COUNT(DISTINCT $0, $2)], EXPR$4=[SUM($3)])
LogicalProject(DEPTNO=[$7], ENAME=[$1], JOB=[$2], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$3], EXPR$2=[$5], EXPR$3=[$7], EXPR$4=[$1])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $6)], joinType=[inner])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $4)], joinType=[inner])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $2)], joinType=[inner])
LogicalAggregate(group=[{7}], EXPR$4=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], EXPR$1=[COUNT($0)])
LogicalAggregate(group=[{1, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{2}], EXPR$2=[COUNT($1, $0)])
LogicalAggregate(group=[{1, 2, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], EXPR$3=[COUNT($1, $0)])
LogicalAggregate(group=[{2, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountMultiple">
<Resource name="sql">
<![CDATA[select deptno, count(distinct ename),
count(distinct job)
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)], EXPR$2=[COUNT(DISTINCT $2)])
LogicalProject(DEPTNO=[$7], ENAME=[$1], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT($1) FILTER $3], EXPR$2=[COUNT($2) FILTER $4])
LogicalProject(DEPTNO=[$0], ENAME=[$1], JOB=[$2], $g_1=[=($3, 1)], $g_2=[=($3, 2)])
LogicalProject(DEPTNO=[$2], ENAME=[$0], JOB=[$1], $g=[$3])
LogicalAggregate(group=[{1, 2, 7}], groups=[[{1, 7}, {2, 7}]], $g=[GROUPING($7, $1, $2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountMultipleNoGroup">
<Resource name="sql">
<![CDATA[select count(distinct ename), count(distinct job)
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT(DISTINCT $0)], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(ENAME=[$1], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT($0) FILTER $2], EXPR$1=[COUNT($1) FILTER $3])
LogicalProject(ENAME=[$0], JOB=[$1], $g_1=[=($2, 1)], $g_2=[=($2, 2)])
LogicalAggregate(group=[{1, 2}], groups=[[{1}, {2}]], $g=[GROUPING($1, $2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountMultipleViaJoin">
<Resource name="sql">
<![CDATA[select deptno, count(distinct ename),
count(distinct job, ename),
count(distinct deptno, job), sum(sal)
from sales.emp group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)], EXPR$2=[COUNT(DISTINCT $2, $1)], EXPR$3=[COUNT(DISTINCT $0, $2)], EXPR$4=[SUM($3)])
LogicalProject(DEPTNO=[$7], ENAME=[$1], JOB=[$2], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$3], EXPR$2=[$5], EXPR$3=[$7], EXPR$4=[$1])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $6)], joinType=[inner])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $4)], joinType=[inner])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $2)], joinType=[inner])
LogicalAggregate(group=[{7}], EXPR$4=[SUM($5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], EXPR$1=[COUNT($0)])
LogicalAggregate(group=[{1, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{2}], EXPR$2=[COUNT($1, $0)])
LogicalAggregate(group=[{1, 2, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], EXPR$3=[COUNT($1, $0)])
LogicalAggregate(group=[{2, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountWithExpandSumType">
<Resource name="sql">
<![CDATA[SELECT count(comm), COUNT(DISTINCT comm) FROM emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()], EXPR$1=[COUNT(DISTINCT $0)])
LogicalProject(COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], EXPR$1=[$1])
LogicalAggregate(group=[{}], EXPR$0=[$SUM0($1)], EXPR$1=[COUNT($0)])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctCountWithoutGroupBy">
<Resource name="sql">
<![CDATA[select max(deptno), count(distinct ename)
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)], EXPR$1=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[MIN($1) FILTER $3], EXPR$1=[COUNT($0) FILTER $2])
LogicalProject(ENAME=[$0], EXPR$0=[$1], $g_0=[=($2, 0)], $g_1=[=($2, 1)])
LogicalAggregate(group=[{1}], groups=[[{1}, {}]], EXPR$0=[MAX($7)], $g=[GROUPING($1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctNonDistinctAggregates">
<Resource name="sql">
<![CDATA[select emp.empno, count(*), avg(distinct dept.deptno)
from sales.emp emp inner join sales.dept dept
on emp.deptno = dept.deptno
group by emp.empno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()], EXPR$2=[AVG(DISTINCT $1)])
LogicalProject(EMPNO=[$0], DEPTNO0=[$9])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[$SUM0($2)], EXPR$2=[AVG($1)])
LogicalAggregate(group=[{0, 1}], EXPR$1=[COUNT()])
LogicalProject(EMPNO=[$0], DEPTNO0=[$9])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctNonDistinctAggregatesWithGrouping1">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(deptno), SUM(DISTINCT sal), MAX(deptno), MAX(comm)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($0)], EXPR$2=[SUM(DISTINCT $1)], EXPR$3=[MAX($0)], EXPR$4=[MAX($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($2)], EXPR$2=[SUM($1)], EXPR$3=[MAX($3)], EXPR$4=[MAX($4)])
LogicalAggregate(group=[{0, 1}], EXPR$1=[SUM($0)], EXPR$3=[MAX($0)], EXPR$4=[MAX($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctNonDistinctAggregatesWithGrouping2">
<Resource name="sql">
<![CDATA[SELECT deptno, COUNT(deptno), SUM(DISTINCT sal)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()], EXPR$2=[SUM(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[$SUM0($2)], EXPR$2=[SUM($1)])
LogicalAggregate(group=[{0, 1}], EXPR$1=[COUNT()])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctNonDistinctTwoAggregatesWithGrouping">
<Resource name="sql">
<![CDATA[SELECT deptno, SUM(comm), MIN(comm), SUM(DISTINCT sal)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)], EXPR$3=[SUM(DISTINCT $2)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($2)], EXPR$2=[MIN($3)], EXPR$3=[SUM($1)])
LogicalAggregate(group=[{0, 2}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctWithDiffFiltersAndSameGroupSet">
<Resource name="sql">
<![CDATA[SELECT COUNT(DISTINCT c) FILTER (WHERE d),
COUNT(DISTINCT d) FILTER (WHERE c)
FROM (select sal > 1000 is true as c, sal < 500 is true as d, comm from emp)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT(DISTINCT $0) FILTER $1], EXPR$1=[COUNT(DISTINCT $1) FILTER $0])
LogicalProject(C=[>($5, 1000)], D=[<($5, 500)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT($0) FILTER $3], EXPR$1=[COUNT($1) FILTER $2])
LogicalProject(C=[$0], D=[$1], $g_0_f_0=[AND(=($2, 0), $0)], $g_0_f_1=[AND(=($2, 0), $1)])
LogicalAggregate(group=[{0, 1}], $g=[GROUPING($0, $1)])
LogicalProject(C=[>($5, 1000)], D=[<($5, 500)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctWithFilterAndGroupBy">
<Resource name="sql">
<![CDATA[SELECT deptno, SUM(comm), COUNT(DISTINCT sal) FILTER (WHERE sal > 1000)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT(DISTINCT $2) FILTER $3])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5], $f3=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[CAST($1):INTEGER NOT NULL], EXPR$2=[$2])
LogicalAggregate(group=[{0}], EXPR$1=[MIN($2) FILTER $4], EXPR$2=[COUNT($1) FILTER $3])
LogicalProject(DEPTNO=[$0], SAL=[$1], EXPR$1=[$3], $g_0_f_2=[AND(=($4, 0), IS TRUE($2))], $g_3=[=($4, 3)])
LogicalAggregate(group=[{0, 2, 3}], groups=[[{0, 2, 3}, {0}]], EXPR$1=[SUM($1)], $g=[GROUPING($0, $2, $3)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5], $f3=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctWithFilterWithoutGroupBy">
<Resource name="sql">
<![CDATA[SELECT SUM(comm), COUNT(DISTINCT sal) FILTER (WHERE sal > 1000)
FROM emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT(DISTINCT $1) FILTER $2])
LogicalProject(COMM=[$6], SAL=[$5], $f2=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[MIN($1) FILTER $3], EXPR$1=[COUNT($0) FILTER $2])
LogicalProject(SAL=[$0], EXPR$0=[$2], $g_0_f_1=[AND(=($3, 0), IS TRUE($1))], $g_3=[=($3, 3)])
LogicalAggregate(group=[{1, 2}], groups=[[{1, 2}, {}]], EXPR$0=[SUM($0)], $g=[GROUPING($1, $2)])
LogicalProject(COMM=[$6], SAL=[$5], $f2=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctWithGrouping">
<Resource name="sql">
<![CDATA[SELECT sal, SUM(comm), MIN(comm), SUM(DISTINCT sal)
FROM emp
GROUP BY sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)], EXPR$3=[SUM(DISTINCT $0)])
LogicalProject(SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[MIN($2)], EXPR$3=[SUM($0)])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)])
LogicalProject(SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctWithMultipleInputs">
<Resource name="sql">
<![CDATA[SELECT deptno, SUM(comm), MIN(comm), COUNT(DISTINCT sal, comm)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)], EXPR$3=[COUNT(DISTINCT $2, $1)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($3)], EXPR$2=[MIN($4)], EXPR$3=[COUNT($2, $1)])
LogicalAggregate(group=[{0, 1, 2}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDistinctWithMultipleInputsAndGroupby">
<Resource name="sql">
<![CDATA[SELECT deptno, SUM(comm), MIN(comm), COUNT(DISTINCT sal, deptno, comm)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)], EXPR$3=[COUNT(DISTINCT $2, $0, $1)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($3)], EXPR$2=[MIN($4)], EXPR$3=[COUNT($2, $0, $1)])
LogicalAggregate(group=[{0, 1, 2}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)])
LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDynamicStarWithUnion">
<Resource name="sql">
<![CDATA[(select n_nationkey from SALES.CUSTOMER) union all (select n_name from CUSTOMER_MODIFIABLEVIEW)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(N_NATIONKEY=[$0])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
LogicalProject(N_NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
EnumerableUnion(all=[true])
EnumerableProject(N_NATIONKEY=[$0])
EnumerableTableScan(table=[[CATALOG, SALES, CUSTOMER]])
EnumerableProject(N_NAME=[$1])
EnumerableTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyAggregate">
<Resource name="sql">
<![CDATA[select sum(empno) from emp where false group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1])
LogicalAggregate(group=[{0}], EXPR$0=[SUM($1)])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyAggregateEmptyKey">
<Resource name="sql">
<![CDATA[select sum(empno) from emp where false]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyAggregateEmptyKeyWithAggregateValuesRule">
<Resource name="sql">
<![CDATA[select count(*), sum(empno) from emp where false]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()], EXPR$1=[SUM($0)])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[{ 0, null }]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyFilterProjectUnion">
<Resource name="sql">
<![CDATA[select * from (
select * from (values (10, 1), (30, 3)) as t (x, y)
union all
select * from (values (20, 2))
)
where x + y > 30]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[$0], Y=[$1])
LogicalFilter(condition=[>(+($0, $1), 30)])
LogicalUnion(all=[true])
LogicalProject(X=[$0], Y=[$1])
LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 20, 2 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(X=[$0], Y=[$1])
LogicalValues(tuples=[[{ 30, 3 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyIntersect">
<Resource name="sql">
<![CDATA[select * from (values (30, 3))intersect
select *
from (values (10, 1), (30, 3)) as t (x, y) where x > 50
intersect
select * from (values (30, 3))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalIntersect(all=[false])
LogicalIntersect(all=[false])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 30, 3 }]])
LogicalProject(X=[$0], Y=[$1])
LogicalFilter(condition=[>($0, 50)])
LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 30, 3 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyLimitZero">
<Resource name="sql">
<![CDATA[select * from emp order by deptno limit 0]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
SortRel(sort0=[$7], dir0=[Ascending], fetch=[0])
ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
EmptyRel
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyMinus">
<Resource name="sql">
<![CDATA[select * from (values (30, 3)) as t (x, y)
where x > 30
except
select * from (values (20, 2))
except
select * from (values (40, 4))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalMinus(all=[false])
LogicalMinus(all=[false])
LogicalProject(X=[$0], Y=[$1])
LogicalFilter(condition=[>($0, 30)])
LogicalValues(tuples=[[{ 30, 3 }]])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 20, 2 }]])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 40, 4 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyMinus2">
<Resource name="sql">
<![CDATA[select * from (values (30, 3)) as t (x, y)
except
select * from (values (20, 2)) as t (x, y) where x > 30
except
select * from (values (40, 4))
except
select * from (values (50, 5)) as t (x, y) where x > 50]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalMinus(all=[false])
LogicalMinus(all=[false])
LogicalMinus(all=[false])
LogicalProject(X=[$0], Y=[$1])
LogicalValues(tuples=[[{ 30, 3 }]])
LogicalProject(X=[$0], Y=[$1])
LogicalFilter(condition=[>($0, 30)])
LogicalValues(tuples=[[{ 20, 2 }]])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 40, 4 }]])
LogicalProject(X=[$0], Y=[$1])
LogicalFilter(condition=[>($0, 50)])
LogicalValues(tuples=[[{ 50, 5 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalMinus(all=[false])
LogicalProject(X=[$0], Y=[$1])
LogicalValues(tuples=[[{ 30, 3 }]])
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[{ 40, 4 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyProject">
<Resource name="sql">
<![CDATA[select z + x from (
select x + y as z, x from (
select * from (values (10, 1), (30, 3)) as t (x, y)
where x + y > 50))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+(+($0, $1), $0)])
LogicalFilter(condition=[>(+($0, $1), 50)])
LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptyProject2">
<Resource name="sql">
<![CDATA[select z + x from (
select x + y as z, x from (
select * from (values (10, 1), (30, 3)) as t (x, y)
where x + y > 50))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+(+($0, $1), $0)])
LogicalFilter(condition=[>(+($0, $1), 50)])
LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptySort">
<Resource name="sql">
<![CDATA[select * from emp where false order by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$7], dir0=[ASC])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptySort2">
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$1], sort1=[$0], dir0=[ASC], dir1=[ASC])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEmptySortLimitZero">
<Resource name="sql">
<![CDATA[select * from emp order by deptno limit 0]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$7], dir0=[ASC], fetch=[0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testEnumerableCalcRule">
<Resource name="sql">
<![CDATA[select ename from emp where sal > 10.0]]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(FNAME=[$1], LNAME=[$2])
LogicalFilter(condition=[>($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
EnumerableProject(FNAME=[$1], LNAME=[$2])
EnumerableCalc(expr#0..2=[{inputs}], expr#3=[10], expr#4=[>($t0, $t3)], proj#0..2=[{exprs}], $condition=[$t4])
EnumerableTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
</TestCase>
<TestCase name="testExchangeRemoveConstantKeysRule">
<Resource name="planBefore">
<![CDATA[
LogicalSortExchange(distribution=[hash[0, 1]], collation=[[0, 1]])
LogicalProject(EMPNO=[$0], ENAME=[$1])
LogicalExchange(distribution=[hash[0]])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSortExchange(distribution=[hash[1]], collation=[[1]])
LogicalProject(EMPNO=[$0], ENAME=[$1])
LogicalExchange(distribution=[single])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterExists">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where exists (select deptno from sales.emp where empno < 20)
or emp.sal < 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(EXISTS({
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), <($5, 100))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(IS NOT NULL($9), <($5, 100))])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterExists3Value">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where empno
< case exists (select deptno from sales.emp where empno < 20)
when true then 10 when false then 20 else 30 end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[<($0, CASE(=(IN($7, {
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), true), 10, =(IN($7, {
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), false), 20, 30))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[<($0, CASE(=(CASE(=($9, 0), false, IS NOT NULL($12), true, <($10, $9), null, false), true), 10, =(CASE(=($9, 0), false, IS NOT NULL($12), true, <($10, $9), null, false), false), 20, 30))])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(EXPR$0=[$0], i=[true])
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterExistsSimple">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where exists (select deptno from sales.emp where empno < 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[EXISTS({
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterExistsSimpleAnd">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where exists (select deptno from sales.emp where empno < 20)
and emp.sal < 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[AND(EXISTS({
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), <($5, 100))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[<($5, 100)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterIn">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where deptno in (select deptno from sales.emp where empno < 20)
or emp.sal < 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(IN($7, {
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), <($5, 100))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(IS NOT NULL($10), <($5, 100))])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterIn3Value">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where empno
< case deptno in (select case when true then deptno else null end
from sales.emp where empno < 20)
when true then 10
when false then 20
else 30
end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[<($0, CASE(=(IN($7, {
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null:INTEGER)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), true), 10, =(IN($7, {
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null:INTEGER)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), false), 20, 30))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[<($0, CASE(=(CASE(=($9, 0), false, IS NOT NULL($12), true, <($10, $9), null:BOOLEAN, false), true), 10, =(CASE(=($9, 0), false, IS NOT NULL($12), true, <($10, $9), null:BOOLEAN, false), false), 20, 30))])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null:INTEGER)])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(EXPR$0=[CASE(true, CAST($7):INTEGER, null:INTEGER)], i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterInComposite">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where (empno, deptno) in (
select empno, deptno from sales.emp where empno < 20)
or emp.sal < 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(IN($0, $7, {
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), <($5, 100))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(IS NOT NULL($11), <($5, 100))])
LogicalJoin(condition=[AND(=($0, $9), =($7, $10))], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandFilterScalar">
<Resource name="sql">
<![CDATA[select empno
from sales.emp
where (select deptno from sales.emp where empno < 20)
< (select deptno from sales.emp where empno > 100)
or emp.sal < 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(<($SCALAR_QUERY({
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), $SCALAR_QUERY({
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($0, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})), <($5, 100))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(<($9, $10), <($5, 100))])
LogicalJoin(condition=[true], joinType=[left])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($0, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandJoinExists">
<Resource name="sql">
<![CDATA[select empno
from sales.emp left join sales.dept
on exists (select deptno from sales.emp where empno < 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[EXISTS({
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandJoinIn">
<Resource name="sql">
<![CDATA[select empno
from sales.emp left join sales.dept
on emp.deptno in (select deptno from sales.emp where empno < 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[IN($7, {
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalJoin(condition=[=($7, $11)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandJoinInComposite">
<Resource name="sql">
<![CDATA[select empno
from sales.emp left join sales.dept
on (emp.empno, dept.deptno) in (
select empno, deptno from sales.emp where empno < 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[IN($0, $9, {
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalJoin(condition=[AND(=($0, $11), =($9, $12))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandJoinScalar">
<Resource name="sql">
<![CDATA[select empno
from sales.emp left join sales.dept
on (select deptno from sales.emp where empno < 20)
< (select deptno from sales.emp where empno > 100)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[<($SCALAR_QUERY({
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), $SCALAR_QUERY({
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($0, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], $f0=[$11])
LogicalJoin(condition=[<($11, $12)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalJoin(condition=[true], joinType=[left])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($0, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandProjectExists">
<Resource name="sql">
<![CDATA[select empno,
exists (select deptno from sales.emp where empno < 20) as d
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[EXISTS({
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[IS NOT NULL($9)])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandProjectIn">
<Resource name="sql">
<![CDATA[select empno,
deptno in (select deptno from sales.emp where empno < 20) as d
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[IN($7, {
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[CASE(IS NOT NULL($10), true, false)])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandProjectInComposite">
<Resource name="sql">
<![CDATA[select empno, (empno, deptno) in (
select empno, deptno from sales.emp where empno < 20) as d
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[IN($0, $7, {
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[CASE(IS NOT NULL($11), true, false)])
LogicalJoin(condition=[AND(=($0, $9), =($7, $10))], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandProjectInNullable">
<Resource name="sql">
<![CDATA[with e2 as (
select empno, case when true then deptno else null end as deptno
from sales.emp)
select empno,
deptno in (select deptno from e2 where empno < 20) as d
from e2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[IN(CASE(true, CAST($7):INTEGER, null:INTEGER), {
LogicalProject(DEPTNO=[$1])
LogicalFilter(condition=[<($0, 20)])
LogicalProject(EMPNO=[$0], DEPTNO=[CASE(true, CAST($7):INTEGER, null:INTEGER)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[CASE(=($9, 0), false, IS NULL(CASE(true, CAST($7):INTEGER, null:INTEGER)), null:BOOLEAN, IS NOT NULL($12), true, <($10, $9), null:BOOLEAN, false)])
LogicalJoin(condition=[=(CASE(true, CAST($7):INTEGER, null:INTEGER), $11)], joinType=[left])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
LogicalProject(DEPTNO=[$1])
LogicalFilter(condition=[<($0, 20)])
LogicalProject(EMPNO=[$0], DEPTNO=[CASE(true, CAST($7):INTEGER, null:INTEGER)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$1], i=[true])
LogicalFilter(condition=[<($0, 20)])
LogicalProject(EMPNO=[$0], DEPTNO=[CASE(true, CAST($7):INTEGER, null:INTEGER)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandProjectScalar">
<Resource name="sql">
<![CDATA[select empno,
(select deptno from sales.emp where empno < 20) as d
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[$SCALAR_QUERY({
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], D=[$9])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($0, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpandWhereComparisonCorrelated">
<Resource name="sql">
<![CDATA[select empno
from sales.emp as e
where sal = (
select max(sal) from sales.emp e2 where e2.empno = e.empno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[=($5, $SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[=($0, $cor0.EMPNO)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($5, $9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[=($0, $cor0.EMPNO)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExpressionInWindowFunction">
<Resource name="sql">
<![CDATA[select
sum(deptno) over(partition by deptno order by sal) as sum1,
sum(deptno + sal) over(partition by deptno order by sal) as sum2
from emp]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject($0=[$3], $1=[$4])
LogicalWindow(window#0=[window(partition {1} order by [0] aggs [SUM($1), SUM($2)])])
LogicalProject(SAL=[$5], DEPTNO=[$7], $2=[+($7, $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SUM1=[SUM($7) OVER (PARTITION BY $7 ORDER BY $5)], SUM2=[SUM(+($7, $5)) OVER (PARTITION BY $7 ORDER BY $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testExtractJoinFilterRule">
<Resource name="sql">
<![CDATA[select 1 from emp inner join dept on emp.deptno=dept.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[=($7, $9)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testExtractYearMonthToRange">
<Resource name="sql">
<![CDATA[select *
from sales.emp_b as e
where extract(year from birthdate) = 2014and extract(month from birthdate) = 4]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], BIRTHDATE=[$9])
LogicalFilter(condition=[AND(=(EXTRACT(FLAG(YEAR), $9), 2014), =(EXTRACT(FLAG(MONTH), $9), 4))])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], BIRTHDATE=[$9])
LogicalFilter(condition=[SEARCH($9, Sarg[[2014-04-01..2014-05-01)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
</TestCase>
<TestCase name="testExtractYearToRange">
<Resource name="sql">
<![CDATA[select *
from sales.emp_b as e
where extract(year from birthdate) = 2014]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], BIRTHDATE=[$9])
LogicalFilter(condition=[=(EXTRACT(FLAG(YEAR), $9), 2014)])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], BIRTHDATE=[$9])
LogicalFilter(condition=[SEARCH($9, Sarg[[2014-01-01..2015-01-01)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
</TestCase>
<TestCase name="testFilterAndProjectWithMultiJoin">
<Resource name="sql">
<![CDATA[select * from emp e1 left outer join dept d on e1.deptno = d.deptno where d.deptno > 3]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
MyProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
MyFilter(condition=[>($9, 3)])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER, LEFT]], outerJoinConditions=[[NULL, =($7, $9)]], projFields=[[{0, 1, 2, 3, 4, 5, 6, 7, 8}, {0, 1}]], postJoinFilter=[>($9, 3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testFilterProjectTranspose">
<Resource name="sql">
<![CDATA[SELECT e.empno
FROM emp as e
WHERE exists (
SELECT *
FROM (
SELECT deptno * 2 AS twiceDeptno
FROM dept) AS d
WHERE e.deptno = d.twiceDeptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalProject(TWICEDEPTNO=[*($0, 2)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalProject(TWICEDEPTNO=[*($0, 2)])
LogicalFilter(condition=[=($cor0.DEPTNO, *($0, 2))])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testFilterProjectTransposePreventedByCorrelation">
<Resource name="sql">
<![CDATA[SELECT e.empno
FROM emp as e
WHERE exists (
SELECT *
FROM (
SELECT deptno * 2 AS twiceDeptno
FROM dept) AS d
WHERE e.deptno = d.twiceDeptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalProject(TWICEDEPTNO=[*($0, 2)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testFilterRemoveIsNotDistinctFromRule">
<Resource name="planBefore">
<![CDATA[
LogicalFilter(condition=[IS NOT DISTINCT FROM($7, 20)])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testFlattenUncorrelatedCallBelowEquals">
<Resource name="sql">
<![CDATA[select * from emp e1 where exists (select * from emp e2 where e1.deptno = (e2.deptno+30))]]>
</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 NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, +($7, 30))])
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])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($cor0.DEPTNO, $9)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testFlattenUncorrelatedTwoLevelCallBelowEqualsSucceeds">
<Resource name="sql">
<![CDATA[select * from emp e1 where exists (select * from emp e2 where e1.deptno = (2 * e2.deptno+30))]]>
</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 NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, +(*(2, $7), 30))])
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])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($cor0.DEPTNO, $9)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+(*(2, $7), 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testFullOuterJoinSimplificationToInner">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d full outer join sales.emp e
on d.deptno = e.deptno
where d.name = 'Charlie' and e.sal > 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[AND(=($1, 'Charlie'), >($7, 100))])
LogicalJoin(condition=[=($0, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalProject(DEPTNO=[CAST($0):INTEGER], NAME=[CAST($1):VARCHAR(10)], EMPNO=[CAST($2):INTEGER], ENAME=[CAST($3):VARCHAR(20)], JOB=[CAST($4):VARCHAR(10)], MGR=[$5], HIREDATE=[CAST($6):TIMESTAMP(0)], SAL=[CAST($7):INTEGER], COMM=[CAST($8):INTEGER], DEPTNO0=[CAST($9):INTEGER], SLACKER=[CAST($10):BOOLEAN])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalFilter(condition=[=($1, 'Charlie')])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testFullOuterJoinSimplificationToLeftOuter">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d full outer join sales.emp e
on d.deptno = e.deptno
where d.name = 'Charlie']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[=($1, 'Charlie')])
LogicalJoin(condition=[=($0, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalProject(DEPTNO=[CAST($0):INTEGER], NAME=[CAST($1):VARCHAR(10)], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalFilter(condition=[=($1, 'Charlie')])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testFullOuterJoinSimplificationToRightOuter">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d full outer join sales.emp e
on d.deptno = e.deptno
where e.sal > 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[>($7, 100)])
LogicalJoin(condition=[=($0, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[CAST($2):INTEGER], ENAME=[CAST($3):VARCHAR(20)], JOB=[CAST($4):VARCHAR(10)], MGR=[$5], HIREDATE=[CAST($6):TIMESTAMP(0)], SAL=[CAST($7):INTEGER], COMM=[CAST($8):INTEGER], DEPTNO0=[CAST($9):INTEGER], SLACKER=[CAST($10):BOOLEAN])
LogicalJoin(condition=[=($0, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testHeterogeneousConversion">
<Resource name="sql">
<![CDATA[select upper(ename) from emp union all
select lower(ename) from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(EXPR$0=[UPPER($1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[LOWER($1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[true])
LogicalCalc(expr#0..8=[{inputs}], expr#9=[UPPER($t1)], EXPR$0=[$t9])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[LOWER($1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testInferringPredicatesWithNotOperatorInJoinCondition">
<Resource name="sql">
<![CDATA[select * from sales.emp d
join sales.emp e on e.deptno = d.deptno and d.deptno not in (4, 6)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalJoin(condition=[AND(=($16, $7), NOT(OR(=($7, 4), =($7, 6))))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
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], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalJoin(condition=[=($16, $7)], joinType=[inner])
LogicalFilter(condition=[SEARCH($7, Sarg[(-∞..4), (4..6), (6..+∞)])])
LogicalFilter(condition=[NOT(OR(=($7, 4), =($7, 6)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[SEARCH($7, Sarg[(-∞..4), (4..6), (6..+∞)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testIntersectToDistinct">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
intersect
select * from emp where deptno = 20
intersect
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalIntersect(all=[false])
LogicalIntersect(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
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])
LogicalFilter(condition=[=($9, 3)])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testIntersectToDistinctAll">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
intersect
select * from emp where deptno = 20
intersect all
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalIntersect(all=[true])
LogicalIntersect(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalIntersect(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($9, 2)])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], agg#0=[COUNT()])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testIsNullPushDown">
<Resource name="sql">
<![CDATA[select empno, deptno, w_count from (
select empno, deptno, count(empno) over (w) w_count
from emp
window w as (partition by deptno order by empno)
) sub_query where w_count is null]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], DEPTNO=[$1], W_COUNT=[$2])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], DEPTNO=[$1], W_COUNT=[$2])
LogicalFilter(condition=[IS NULL($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], $2=[$9])
LogicalWindow(window#0=[window(partition {7} order by [0] aggs [COUNT($0)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testIsNullPushDown2">
<Resource name="sql">
<![CDATA[select empno, deptno, w_count from (
select empno, deptno, count(empno) over (ROWS BETWEEN 10 PRECEDING AND 1 PRECEDING) w_count
from emp
) sub_query where w_count is null]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], DEPTNO=[$1], W_COUNT=[$2])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], DEPTNO=[$1], W_COUNT=[$2])
LogicalFilter(condition=[IS NULL($2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], $2=[$9])
LogicalWindow(window#0=[window(aggs [COUNT($0)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinAssociateRuleWithBottomAlwaysTrueConditionAllowed">
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[=($2, $12)], joinType=[inner])
LogicalJoin(condition=[=($7, $8)], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[AND(=($2, $12), =($7, $8))], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinAssociateRuleWithBottomAlwaysTrueConditionDisallowed">
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[=($2, $12)], joinType=[inner])
LogicalJoin(condition=[=($7, $8)], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinAssociateRuleWithTopAlwaysTrueConditionAllowed">
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[=($7, $12)], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, BONUS]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($7, $12)], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, BONUS]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinAssociateRuleWithTopAlwaysTrueConditionDisallowed">
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[=($7, $12)], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, BONUS]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinCommuteRuleWithAlwaysTrueConditionAllowed">
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$3], ENAME=[$4], JOB=[$5], MGR=[$6], HIREDATE=[$7], SAL=[$8], COMM=[$9], DEPTNO=[$10], DEPTNO0=[$0], DNAME=[$1], LOC=[$2])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinCommuteRuleWithAlwaysTrueConditionDisallowed">
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose1">
<Resource name="sql">
<![CDATA[select a.name
from dept a
left join dept b on b.deptno > 10
right join dept c on b.deptno > 10
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0])
LogicalJoin(condition=[$1], joinType=[right])
LogicalProject(NAME=[$1], $f4=[$5])
LogicalJoin(condition=[$4], joinType=[left])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[>($0, 10)], $f4=[>($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalJoin(condition=[>($2, 10)], joinType=[right])
LogicalJoin(condition=[>($2, 10)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose2">
<Resource name="sql">
<![CDATA[select *
from dept a
left join (select name, 1 from dept) as b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose3">
<Resource name="sql">
<![CDATA[select *
from (select name, 1 from dept) as a
right join dept b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], DEPTNO=[$2], NAME0=[$3])
LogicalJoin(condition=[=($0, $3)], joinType=[right])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], DEPTNO=[$2], NAME0=[$3])
LogicalJoin(condition=[=($0, $3)], joinType=[right])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose4">
<Resource name="sql">
<![CDATA[select *
from dept a
left join (select x name, y is not null from
(values (2, cast(null as integer)), (2, 1)) as t(x, y)) b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$3], EXPR$1=[$4])
LogicalJoin(condition=[=($2, $3)], joinType=[left])
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[CAST($1):INTEGER NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], EXPR$1=[IS NOT NULL($1)])
LogicalValues(tuples=[[{ 2, null }, { 2, 1 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], EXPR$1=[IS NOT NULL($1)])
LogicalUnion(all=[true])
LogicalProject(EXPR$0=[2], EXPR$1=[null:INTEGER])
LogicalValues(tuples=[[{ 0 }]])
LogicalProject(EXPR$0=[2], EXPR$1=[1])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose5">
<Resource name="sql">
<![CDATA[select *
from dept a
left join (select name, 1 + 1 from dept) as b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[+(1, 1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[+(1, 1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose6">
<Resource name="sql">
<![CDATA[select *
from (select name, 1 from dept) a
full join (select name, 1 from dept) as b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], NAME0=[$2], EXPR$10=[$3])
LogicalJoin(condition=[=($0, $2)], joinType=[full])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], NAME0=[$2], EXPR$10=[$3])
LogicalJoin(condition=[=($0, $2)], joinType=[full])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose7">
<Resource name="sql">
<![CDATA[select *
from dept a
left join (select name from dept) as b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2])
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$3])
LogicalJoin(condition=[=($1, $3)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTranspose8">
<Resource name="sql">
<![CDATA[select *
from dept a
left join (
select name, deptno > 10 and cast(null as boolean)
from dept) as b
on a.name = b.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], EXPR$1=[AND(>($0, 10), null)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$3], EXPR$1=[AND(>($2, 10), null)])
LogicalJoin(condition=[=($1, $3)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinProjectTransposeWindow">
<Resource name="sql">
<![CDATA[select *
from dept a
join (select rank() over (order by name) as r, 1 + 1 from dept) as b
on a.name = b.r]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], R=[$3], EXPR$1=[$4])
LogicalJoin(condition=[=($2, $3)], joinType=[inner])
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[CAST($1):BIGINT NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(R=[RANK() OVER (ORDER BY $1)], EXPR$1=[+(1, 1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], R=[$3], EXPR$1=[$4])
LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[CAST($1):BIGINT NOT NULL], R=[$2], EXPR$1=[$3])
LogicalJoin(condition=[=(CAST($1):BIGINT NOT NULL, $2)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(R=[RANK() OVER (ORDER BY $1)], EXPR$1=[+(1, 1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinPushTransitivePredicatesRule">
<Resource name="sql">
<![CDATA[select d.deptno from sales.emp d where d.deptno
IN (select e.deptno from sales.emp e where e.deptno = d.deptno or e.deptno = 4)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[OR(=($7, $cor0.DEPTNO), =($7, 4))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinPushTransitivePredicatesRule2">
<Resource name="sql">
<![CDATA[select n1.SAL
from EMPNULLABLES_20 n1
where n1.SAL IN (
select n2.SAL
from EMPNULLABLES_20 n2
where n1.SAL = n2.SAL or n1.SAL = 4)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[AND(=($5, $11), =($9, $12))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8], SAL0=[$5], $f9=[=($5, 4)])
LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
LogicalFilter(condition=[=($1, $0)])
LogicalAggregate(group=[{0, 1, 2}])
LogicalProject(SAL=[$5], SAL0=[$8], $f9=[$9])
LogicalJoin(condition=[OR(=($8, $5), $9)], joinType=[inner])
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]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(SAL=[$5], $f9=[=($5, 4)])
LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[AND(=($5, $11), =($9, $12))], joinType=[inner])
LogicalFilter(condition=[>($5, 1000)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8], SAL0=[$5], $f9=[=($5, 4)])
LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
LogicalFilter(condition=[=($1, $0)])
LogicalAggregate(group=[{0, 1, 2}])
LogicalProject(SAL=[$5], SAL0=[$8], $f9=[$9])
LogicalJoin(condition=[OR(=($8, $5), $9)], joinType=[inner])
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]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(SAL=[$5], $f9=[=($5, 4)])
LogicalFilter(condition=[AND(=($7, 20), >($5, 1000))])
LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinToMultiJoinDoesNotMatchAntiJoin">
<Resource name="sql">
<![CDATA[select * from
(select * from emp join dept ON emp.deptno = emp.deptno) t
where not exists (select job from bonus where emp.job = bonus.job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[=($2, $12)], joinType=[anti])
LogicalJoin(condition=[=($7, $8)], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($2, $12)], joinType=[anti])
MultiJoin(joinFilter=[=($7, $8)], isFullOuterJoin=[false], joinTypes=[[INNER, INNER]], outerJoinConditions=[[NULL, NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinToMultiJoinDoesNotMatchSemiJoin">
<Resource name="sql">
<![CDATA[select * from
(select * from emp join dept ON emp.deptno = emp.deptno) t
where emp.job in (select job from bonus))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalJoin(condition=[=($2, $12)], joinType=[semi])
LogicalJoin(condition=[=($7, $8)], joinType=[inner])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($2, $12)], joinType=[semi])
MultiJoin(joinFilter=[=($7, $8)], isFullOuterJoin=[false], joinTypes=[[INNER, INNER]], outerJoinConditions=[[NULL, NULL]], projFields=[[ALL, ALL]])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinToSemiJoinRuleOnAntiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $3)], joinType=[anti])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftEmptyAntiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[=($7, $8)], joinType=[anti])
LogicalValues(tuples=[[]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftEmptyFullJoin">
<Resource name="sql">
<![CDATA[select * from (
select * from emp where false) e
full join dept d on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[full])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[full])
LogicalValues(tuples=[[]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftEmptyInnerJoin">
<Resource name="sql">
<![CDATA[select * from (
select * from emp where false) as e
join dept as d on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftEmptyLeftJoin">
<Resource name="sql">
<![CDATA[select * from (
select * from emp where false) e
left join dept d on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftEmptyRightJoin">
<Resource name="sql">
<![CDATA[select * from (
select * from emp where false) e
right join dept d on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalValues(tuples=[[]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftEmptySemiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[=($7, $8)], joinType=[semi])
LogicalValues(tuples=[[]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testLeftOuterJoinSimplificationToInner">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d left outer join sales.emp e
on d.deptno = e.deptno
where e.sal > 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[>($7, 100)])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[CAST($2):INTEGER], ENAME=[CAST($3):VARCHAR(20)], JOB=[CAST($4):VARCHAR(10)], MGR=[$5], HIREDATE=[CAST($6):TIMESTAMP(0)], SAL=[CAST($7):INTEGER], COMM=[CAST($8):INTEGER], DEPTNO0=[CAST($9):INTEGER], SLACKER=[CAST($10):BOOLEAN])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testLimitSort">
<Resource name="sql">
<![CDATA[select mgr from sales.emp
union select mgr from sales.emp
order by mgr limit 10 offset 5]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], offset=[5], fetch=[10])
LogicalProject(MGR=[$0])
LogicalUnion(all=[false])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
EnumerableLimitSort(sort0=[$0], dir0=[ASC], offset=[5], fetch=[10])
EnumerableProject(MGR=[$0])
EnumerableUnion(all=[false])
EnumerableProject(MGR=[$3])
EnumerableTableScan(table=[[CATALOG, SALES, EMP]])
EnumerableProject(MGR=[$3])
EnumerableTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testManyFiltersOnTopOfMultiJoinShouldCollapse">
<Resource name="sql">
<![CDATA[select * from (select * from emp e1 left outer join dept d
on e1.deptno = d.deptno
where d.deptno > 3) where ename LIKE 'bar']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalFilter(condition=[LIKE($1, 'bar')])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalFilter(condition=[>($9, 3)])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER, LEFT]], outerJoinConditions=[[NULL, =($7, $9)]], projFields=[[{0, 1, 2, 3, 4, 5, 6, 7, 8}, {0, 1}]], postJoinFilter=[AND(LIKE($1, 'bar'), >($9, 3))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testMaxReuseDistinctAttrWithMixedOptionality">
<Resource name="sql">
<![CDATA[select sum(distinct deptno), count(distinct deptno), max(deptno) from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM(DISTINCT $0)], EXPR$1=[COUNT(DISTINCT $0)], EXPR$2=[MAX($0)])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[MAX($0)])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeFilter">
<Resource name="sql">
<![CDATA[select name from (
select *
from dept
where deptno = 10)
where deptno = 10
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalFilter(condition=[=($0, 10)])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeFilterWithJoinCondition">
<Resource name="sql">
<![CDATA[select d.name as dname,e.ename as ename
from emp e inner join dept d
on e.deptno=d.deptno
where d.name='Propane']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$10], ENAME=[$1])
LogicalFilter(condition=[=($10, 'Propane')])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalCalc(expr#0..10=[{inputs}], expr#11=[=($t7, $t9)], expr#12=['Propane':VARCHAR(10)], expr#13=[=($t10, $t12)], expr#14=[AND($t11, $t13)], DNAME=[$t10], ENAME=[$t1], $condition=[$t14])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeIntersect">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
intersect
select * from emp where deptno = 20
intersect
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalIntersect(all=[false])
LogicalIntersect(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalIntersect(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeJoinCollation">
<Resource name="sql">
<![CDATA[select r.ename, s.sal from
sales.emp r join sales.bonus s
on r.ename=s.ename where r.sal+1=s.sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1], SAL=[$11])
LogicalFilter(condition=[=(+($5, 1), $11)])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
EnumerableProject(ENAME=[$5], SAL=[$2])
EnumerableHashJoin(condition=[AND(=($0, $5), =(+($9, 1), $2))], joinType=[inner])
EnumerableTableScan(table=[[CATALOG, SALES, BONUS]])
EnumerableTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeJoinFilter">
<Resource name="sql">
<![CDATA[select * from (
select d.deptno, e.ename
from emp as e
join dept as d
on e.deptno = d.deptno
and d.deptno = 10)
where deptno = 10
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], ENAME=[$1])
LogicalFilter(condition=[=($0, 10)])
LogicalProject(DEPTNO=[$9], ENAME=[$1])
LogicalJoin(condition=[AND(=($7, $9), =($9, 10))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], ENAME=[$1])
LogicalProject(DEPTNO=[$9], ENAME=[$1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeMinus">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
except
select * from emp where deptno = 20
except
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalMinus(all=[false])
LogicalMinus(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalMinus(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeMinusRightDeep">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
except
select * from (
select * from emp where deptno = 20
except
select * from emp where deptno = 30)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalMinus(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalMinus(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeSetOpMixed">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
union
select * from emp where deptno = 20
intersect
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalIntersect(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeUnion">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
union all
select * from emp where deptno = 20
union all
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeUnionAll">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
union all
select * from emp where deptno = 20
union all
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeUnionDistinct">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
union distinct
select * from emp where deptno = 20
union
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[false])
LogicalUnion(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeUnionMixed">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
union
select * from emp where deptno = 20
union all
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalUnion(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMergeUnionMixed2">
<Resource name="sql">
<![CDATA[select * from emp where deptno = 10
union all
select * from emp where deptno = 20
union
select * from emp where deptno = 30
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[false])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMinReuseDistinctAttrWithMixedOptionality">
<Resource name="sql">
<![CDATA[select sum(distinct deptno), count(distinct deptno), min(deptno) from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM(DISTINCT $0)], EXPR$1=[COUNT(DISTINCT $0)], EXPR$2=[MIN($0)])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[MIN($0)])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testMinusMergeRule">
<Resource name="sql">
<![CDATA[select * from (
select * from (
select name, deptno from
(
select name, deptno, count(1) from dept group by name, deptno
except all
select name, deptno, 1 from dept
) subq
except all
select name, deptno from
(
select name, deptno, 1 from dept
except all
select name, deptno, count(1) from dept group by name, deptno
) subq2
) a
except all
select name, deptno from dept
) aa
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalMinus(all=[true])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalMinus(all=[true])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalMinus(all=[true])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalMinus(all=[true])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalMinus(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalMinus(all=[true])
LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testMultipleDistinctWithGrouping">
<Resource name="sql">
<![CDATA[SELECT sal, SUM(comm), AVG(DISTINCT comm), SUM(DISTINCT sal)
FROM emp
GROUP BY sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[AVG(DISTINCT $1)], EXPR$3=[SUM(DISTINCT $0)])
LogicalProject(SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$0], EXPR$1=[$1], EXPR$2=[$3], EXPR$3=[$5])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $4)], joinType=[inner])
LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $2)], joinType=[inner])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$2=[AVG($1)])
LogicalAggregate(group=[{0, 1}])
LogicalProject(SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$3=[SUM($0)])
LogicalAggregate(group=[{0}])
LogicalProject(SAL=[$0])
LogicalProject(SAL=[$5], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testNestedAggregates">
<Resource name="sql">
<![CDATA[SELECT
avg(sum(sal) + 2 * min(empno) + 3 * avg(empno))
over (partition by deptno)
from emp
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[CAST(/(SUM(+(+($1, *(2, $2)), *(3, $3))) OVER (PARTITION BY $0), COUNT(+(+($1, *(2, $2)), *(3, $3))) OVER (PARTITION BY $0))):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[SUM($1)], agg#1=[MIN($2)], agg#2=[AVG($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[CAST(/($2, $3)):INTEGER NOT NULL])
LogicalWindow(window#0=[window(partition {0} aggs [SUM($1), COUNT($1)])])
LogicalProject(DEPTNO=[$0], $1=[+(+($1, *(2, $2)), *(3, $3))])
LogicalAggregate(group=[{0}], agg#0=[SUM($1)], agg#1=[MIN($2)], agg#2=[AVG($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testNoOversimplificationBelowIsNull">
<Resource name="sql">
<![CDATA[select *
from emp
where ( (empno=1 and mgr=1) or (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(OR(AND(=($0, 1), =($3, 1)), 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])
LogicalFilter(condition=[IS NULL(OR(AND(=($0, 1), =($3, 1)), AND(null, =($3, 1))))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testNoReduceAverage">
<Resource name="sql">
<![CDATA[select name, max(name), avg(deptno), min(name) from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($0)], EXPR$2=[AVG($1)], EXPR$3=[MIN($0)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($0)], EXPR$2=[AVG($1)], EXPR$3=[MIN($0)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testNoReduceSum">
<Resource name="sql">
<![CDATA[select name, sum(deptno) from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testNotPushExpression">
<Resource name="sql">
<![CDATA[select 1 from emp inner join dept
on emp.deptno=dept.deptno and emp.ename is not null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[AND(=($7, $9), IS NOT NULL($1))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[AND(=($7, $9), IS NOT NULL($1))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testOrAlwaysTrue">
<Resource name="sql">
<![CDATA[select * from EMPNULLABLES_20
where sal is null or sal is not null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$7])
LogicalFilter(condition=[OR(IS NULL($5), IS NOT 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]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$7])
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]])
]]>
</Resource>
</TestCase>
<TestCase name="testOrAlwaysTrue2">
<Resource name="sql">
<![CDATA[select * from EMPNULLABLES_20
where sal is not null or sal is null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$7])
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]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$7])
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]])
]]>
</Resource>
</TestCase>
<TestCase name="testOversimplifiedCaseStatement">
<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=[AND(>($3, 0), >(CASE(>($3, 0), /($7, $3), null:INTEGER), 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])
LogicalFilter(condition=[AND(>($3, 0), CASE(>($3, 0), >(/($7, $3), 1), false))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="sql">
<![CDATA[select * from emp where MGR > 0 and case when MGR > 0 then deptno / MGR else null end > 1]]>
</Resource>
</TestCase>
<TestCase name="testProjectAggregateMerge">
<Resource name="sql">
<![CDATA[select deptno + ss
from (
select job, deptno, min(sal) as ms, sum(sal) as ss
from sales.emp
group by job, deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($1, $3)])
LogicalAggregate(group=[{0, 1}], MS=[MIN($2)], SS=[SUM($2)])
LogicalProject(JOB=[$2], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject($f0=[+($1, $2)])
LogicalAggregate(group=[{0, 1}], SS=[SUM($2)])
LogicalProject(JOB=[$2], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectAggregateMergeNoOp">
<Resource name="sql">
<![CDATA[select deptno + ss + ms
from (
select job, deptno, min(sal) as ms, sum(sal) as ss
from sales.emp
group by job, deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+(+($1, $3), $2)])
LogicalAggregate(group=[{0, 1}], MS=[MIN($2)], SS=[SUM($2)])
LogicalProject(JOB=[$2], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectAggregateMergeSum0">
<Resource name="sql">
<![CDATA[select coalesce(sum_sal, 0) as ss0
from (
select sum(sal) as sum_sal
from sales.emp)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SS0=[CASE(IS NOT NULL($0), CAST($0):INTEGER NOT NULL, 0)])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)])
LogicalProject(SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], agg#0=[$SUM0($0)])
LogicalProject(SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectAggregateMergeSum0AndSum">
<Resource name="sql">
<![CDATA[select sum_sal * 2, coalesce(sum_sal, 0) as ss0
from (
select sum(sal) as sum_sal
from sales.emp)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[*($0, 2)], SS0=[CASE(IS NOT NULL($0), CAST($0):INTEGER NOT NULL, 0)])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)])
LogicalProject(SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject($f0=[*($0, 2)], $f1=[$1])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], agg#1=[$SUM0($0)])
LogicalProject(SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTranspose">
<Resource name="sql">
<![CDATA[select t1.name, t2.ename
from DEPT_NESTED as t1,
unnest(t1.employees) as t2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1], ENAME=[$5])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{3}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
Uncollect
LogicalProject(EMPLOYEES=[$cor0.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], ENAME=[$2])
LogicalCorrelate(correlation=[$cor1], joinType=[inner], requiredColumns=[{1}])
LogicalProject(NAME=[$1], EMPLOYEES=[$3])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
LogicalProject(ENAME=[$1])
Uncollect
LogicalProject(EMPLOYEES=[$cor1.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTransposeDynamic">
<Resource name="sql">
<![CDATA[select t1.c_nationkey, t2.a as fake_col2 from SALES.CUSTOMER as t1, unnest(t1.fake_col) as t2(a)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(C_NATIONKEY=[$1], FAKE_COL2=[$2])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
LogicalProject(A=[$0])
Uncollect
LogicalProject(FAKE_COL=[$cor0.FAKE_COL])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(C_NATIONKEY=[$1], FAKE_COL2=[$2])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
LogicalProject(A=[$0])
Uncollect
LogicalProject(FAKE_COL=[$cor0.FAKE_COL])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTransposeRuleAntiCorrelate">
<Resource name="planBefore">
<![CDATA[
LogicalProject(f=[$0])
LogicalCorrelate(correlation=[$cor0], joinType=[anti], requiredColumns=[{0}])
LogicalValues(tuples=[[{ '1', '2' }]])
LogicalProject(f3=[$0], $f1=[$cor0.f])
LogicalValues(tuples=[[{ '1', '2' }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalCorrelate(correlation=[$cor0], joinType=[anti], requiredColumns=[{0}])
LogicalProject(f=[$0])
LogicalValues(tuples=[[{ '1', '2' }]])
LogicalProject
LogicalProject(f3=[$0], $f1=[$cor0.f])
LogicalValues(tuples=[[{ '1', '2' }]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTransposeRuleLeftCorrelate">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($1)])
LogicalProject(EMPNO=[$0], $f0=[$2])
LogicalCorrelate(correlation=[$cor2], joinType=[left], requiredColumns=[{1}])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject($f0=[$0])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor2.DEPTNO, $0)])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="sql">
<![CDATA[SELECT e1.empno
FROM emp e1 where exists (select empno, deptno from dept d2 where e1.deptno = d2.deptno)]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTransposeRuleSemiCorrelate">
<Resource name="planBefore">
<![CDATA[
LogicalProject(f=[$0])
LogicalCorrelate(correlation=[$cor0], joinType=[semi], requiredColumns=[{0}])
LogicalValues(tuples=[[{ '1', '2' }]])
LogicalProject(f3=[$0], $f1=[$cor0.f])
LogicalValues(tuples=[[{ '1', '2' }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalCorrelate(correlation=[$cor0], joinType=[semi], requiredColumns=[{0}])
LogicalProject(f=[$0])
LogicalValues(tuples=[[{ '1', '2' }]])
LogicalProject
LogicalProject(f3=[$0], $f1=[$cor0.f])
LogicalValues(tuples=[[{ '1', '2' }]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTransposeWithExprCond">
<Resource name="sql">
<![CDATA[select t1.name, t2.ename
from DEPT_NESTED as t1,
unnest(t1.employees) as t2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1], ENAME=[$5])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{3}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
Uncollect
LogicalProject(EMPLOYEES=[$cor0.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], ENAME=[$2])
LogicalCorrelate(correlation=[$cor1], joinType=[inner], requiredColumns=[{1}])
LogicalProject(NAME=[$1], EMPLOYEES=[$3])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
LogicalProject(ENAME=[$1])
Uncollect
LogicalProject(EMPLOYEES=[$cor1.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectCorrelateTransposeWithOver">
<Resource name="sql">
<![CDATA[select sum(t1.deptno + 1) over (partition by t1.name),
count(t2.empno) over ()
from DEPT_NESTED as t1,
unnest(t1.employees) as t2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[SUM(+($0, 1)) OVER (PARTITION BY $1)], EXPR$1=[COUNT($4) OVER ()])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{3}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
Uncollect
LogicalProject(EMPLOYEES=[$cor0.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[SUM($2) OVER (PARTITION BY $0)], EXPR$1=[COUNT($3) OVER ()])
LogicalCorrelate(correlation=[$cor1], joinType=[inner], requiredColumns=[{1}])
LogicalProject(NAME=[$1], EMPLOYEES=[$3], EXPR$0=[+($0, 1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
LogicalProject(EMPNO=[$0])
Uncollect
LogicalProject(EMPLOYEES=[$cor1.EMPLOYEES])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectFilterTransposeRuleOnEmptyRowType">
<Resource name="planBefore">
<![CDATA[
LogicalProject
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject
LogicalFilter(condition=[=($0, 20)])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove1">
<Resource name="sql">
<![CDATA[SELECT e.deptno, d2.deptno
FROM sales.emp e
LEFT JOIN sales.dept d1 ON e.deptno = d1.deptno
LEFT JOIN sales.dept d2 ON e.deptno = d2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7], DEPTNO0=[$11])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7], DEPTNO0=[$9])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove10">
<Resource name="sql">
<![CDATA[SELECT e.deptno, e.slacker
FROM sales.emp e
LEFT JOIN sales.dept d ON e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove2">
<Resource name="sql">
<![CDATA[SELECT e.deptno, d1.deptno
FROM sales.emp e
LEFT JOIN sales.dept d1 ON e.deptno = d1.deptno
LEFT JOIN sales.dept d2 ON e.deptno = d2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7], DEPTNO0=[$9])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7], DEPTNO0=[$9])
LogicalJoin(condition=[=($7, $11)], joinType=[left])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove3">
<Resource name="sql">
<![CDATA[SELECT e1.deptno, d.deptno
FROM sales.emp e1
LEFT JOIN sales.emp e2 ON e1.deptno = e2.deptno
LEFT JOIN sales.dept d ON e1.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7], DEPTNO0=[$18])
LogicalJoin(condition=[=($7, $18)], joinType=[left])
LogicalJoin(condition=[=($7, $16)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7], DEPTNO0=[$18])
LogicalJoin(condition=[=($7, $18)], joinType=[left])
LogicalJoin(condition=[=($7, $16)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove4">
<Resource name="sql">
<![CDATA[SELECT e.deptno
FROM sales.emp e
LEFT JOIN sales.dept d ON e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove5">
<Resource name="sql">
<![CDATA[SELECT e1.deptno
FROM sales.emp e1
LEFT JOIN sales.emp e2 ON e1.deptno = e2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalJoin(condition=[=($7, $16)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalJoin(condition=[=($7, $16)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove6">
<Resource name="sql">
<![CDATA[SELECT e.deptno, d.name
FROM sales.emp e
LEFT JOIN sales.dept d ON e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove7">
<Resource name="sql">
<![CDATA[SELECT e.deptno
FROM sales.dept d
RIGHT JOIN sales.emp e ON e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$9])
LogicalJoin(condition=[=($9, $0)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove8">
<Resource name="sql">
<![CDATA[SELECT e2.deptno
FROM sales.emp e1
RIGHT JOIN sales.emp e2 ON e1.deptno = e2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$16])
LogicalJoin(condition=[=($7, $16)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$16])
LogicalJoin(condition=[=($7, $16)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinRemove9">
<Resource name="sql">
<![CDATA[SELECT e.deptno, d.name
FROM sales.dept d
RIGHT JOIN sales.emp e ON e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$9], NAME=[$1])
LogicalJoin(condition=[=($9, $0)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$9], NAME=[$1])
LogicalJoin(condition=[=($9, $0)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinTransposeItem">
<Resource name="sql">
<![CDATA[select t1.c_nationkey[0], t2.c_nationkey[0]
from sales.customer as t1
left outer join sales.customer as t2
on t1.c_nationkey[0] = t2.c_nationkey[0]]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[ITEM($0, 0)], EXPR$1=[ITEM($2, 0)])
LogicalJoin(condition=[=($1, $3)], joinType=[left])
LogicalProject(C_NATIONKEY=[$0], $f1=[ITEM($0, 0)])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
LogicalProject(C_NATIONKEY=[$0], $f1=[ITEM($0, 0)])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$3])
LogicalJoin(condition=[=($0, $2)], joinType=[left])
LogicalProject($f1=[$1], EXPR$0=[ITEM($0, 0)])
LogicalProject(C_NATIONKEY=[$0], $f1=[ITEM($0, 0)])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
LogicalProject($f1=[$1], EXPR$0=[ITEM($0, 0)])
LogicalProject(C_NATIONKEY=[$0], $f1=[ITEM($0, 0)])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectJoinTransposeRuleOnAggWithNoFieldsWithTrimmer">
<Resource name="planBeforeTrimming">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{}], DUMMY_COUNT=[COUNT()])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
<Resource name="planAfterTrimming">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[true], joinType=[inner])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{}], DUMMY=[COUNT()])
LogicalProject(EMPNO=[$0])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
<Resource name="finalPlan">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[true], joinType=[inner])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{}], DUMMY=[COUNT()])
LogicalProject(EMPNO=[$0])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectMergeShouldIgnoreOver">
<Resource name="sql">
<![CDATA[select row_number() over (order by deptno), col1
from (
select deptno,
sum(100) over (partition by deptno order by sal) as col1
from emp)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[ROW_NUMBER() OVER (ORDER BY $0)], COL1=[$1])
LogicalProject(DEPTNO=[$7], COL1=[SUM(100) OVER (PARTITION BY $7 ORDER BY $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectSetOpTranspose">
<Resource name="sql">
<![CDATA[select job, sum(sal + 100) over (partition by deptno) from
(select * from emp e1 union all select * from emp e2)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(JOB=[$2], EXPR$1=[SUM(+($5, 100)) OVER (PARTITION BY $7)])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$0], EXPR$1=[SUM($2) OVER (PARTITION BY $1)])
LogicalUnion(all=[true])
LogicalProject(JOB=[$2], DEPTNO=[$7], EXPR$0=[+($5, 100)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(JOB=[$2], DEPTNO=[$7], EXPR$0=[+($5, 100)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectToSemiJoinRuleOnAntiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $3)], joinType=[anti])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectToWindowRuleForMultipleWindows">
<Resource name="sql">
<![CDATA[select
count(*) over(partition by empno order by sal) as count1,
count(*) over(partition by deptno order by sal) as count2,
sum(deptno) over(partition by empno order by sal) as sum1,
sum(deptno) over(partition by deptno order by sal) as sum2
from emp]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject($0=[$9], $1=[$11], $2=[$10], $3=[$12])
LogicalWindow(window#0=[window(partition {0} order by [5] aggs [COUNT(), SUM($7)])], window#1=[window(partition {7} order by [5] aggs [COUNT(), SUM($7)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(COUNT1=[COUNT() OVER (PARTITION BY $0 ORDER BY $5)], COUNT2=[COUNT() OVER (PARTITION BY $7 ORDER BY $5)], SUM1=[SUM($7) OVER (PARTITION BY $0 ORDER BY $5)], SUM2=[SUM($7) OVER (PARTITION BY $7 ORDER BY $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectWindowTransposeRule">
<Resource name="sql">
<![CDATA[select count(empno) over(), deptno from emp]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$2], DEPTNO=[$1])
LogicalWindow(window#0=[window(aggs [COUNT($0)])])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[COUNT($0) OVER ()], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testProjectWindowTransposeRuleWithConstants">
<Resource name="sql">
<![CDATA[select col1, col2
from (
select empno,
sum(100) over (partition by deptno order by sal) as col1,
sum(1000) over(partition by deptno order by sal) as col2
from emp)]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject($0=[$2], $1=[$3])
LogicalWindow(window#0=[window(partition {1} order by [0] aggs [SUM($2), SUM($3)])])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(COL1=[SUM(100) OVER (PARTITION BY $7 ORDER BY $5)], COL2=[SUM(1000) OVER (PARTITION BY $7 ORDER BY $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullAggregateThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job from (select deptno, job from emp as e1 group by deptno,job union all select deptno, job from emp as e2 group by deptno,job) group by deptno,job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullAggregateThroughUnion2">
<Resource name="sql">
<![CDATA[select deptno, job from (select deptno, job from emp as e1 group by deptno,job union all select deptno, job from emp as e2 group by deptno,job) group by deptno,job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullAggregateThroughUnionAndAddProjects">
<Resource name="sql">
<![CDATA[select job, deptno from (select job, deptno from emp as e1 group by job, deptno union all select job, deptno from emp as e2 group by job, deptno) group by job, deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}])
LogicalProject(JOB=[$2], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(JOB=[$2], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalProject(JOB=[$2], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(JOB=[$2], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullAggregateThroughUnionWithAlias">
<Resource name="sql">
<![CDATA[select job, c from (select job, deptno c from emp as e1 group by job, deptno union all select job, deptno from emp as e2 group by job, deptno) group by job, c]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}])
LogicalProject(JOB=[$2], C=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(JOB=[$2], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalProject(JOB=[$0], C=[$1])
LogicalUnion(all=[true])
LogicalAggregate(group=[{2, 7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(JOB=[$2], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantIntoFilter">
<Resource name="sql">
<![CDATA[select * from (select * from sales.emp where deptno = 10)
where deptno + 5 > empno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[>(+($7, 5), $0)])
LogicalFilter(condition=[=($7, 10)])
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])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[>(15, $0)])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantIntoJoin">
<Resource name="sql">
<![CDATA[select * from (select * from sales.emp where empno = 10) as e
left join sales.dept as d on e.empno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[true], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantIntoJoin2">
<Resource name="sql">
<![CDATA[select * from (select * from sales.emp where empno = 10) as e
join sales.dept as d on e.empno = d.deptno and e.deptno + e.empno = d.deptno + 5]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$10], NAME=[$11])
LogicalJoin(condition=[AND(=($0, $10), =($9, $12))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[10], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[10], NAME=[$11])
LogicalJoin(condition=[=($9, 15)], joinType=[inner])
LogicalProject(EMPNO=[10], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, 10)])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[10], NAME=[$1], $f2=[15])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantIntoProject">
<Resource name="sql">
<![CDATA[select deptno, deptno + 1, empno + deptno
from sales.emp where deptno = 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7], EXPR$1=[+($7, 1)], EXPR$2=[+($0, $7)])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[10], EXPR$1=[11], EXPR$2=[+($0, 10)])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregateAllConst">
<Resource name="sql">
<![CDATA[select 4, 2+3, max(five) from (
select *, 4 as four, 2+3 as two_plus_three, 5 as five, deptno+42 as deptno42 from emp
) group by 4, 2+3]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], EXPR$2=[MAX($2)])
LogicalProject(EXPR$0=[4], EXPR$1=[+(2, 3)], FIVE=[5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[+(2, 3)], EXPR$2=[$1])
LogicalAggregate(group=[{0}], EXPR$2=[MAX($1)])
LogicalProject(EXPR$0=[4], FIVE=[5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregateAllLiterals">
<Resource name="sql">
<![CDATA[select 4, 2+3, max(5) from (
select *, 4 as four, 2+3 as two_plus_three, 5 as five, deptno+42 as deptno42 from emp
) group by 4, 2+3]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], EXPR$2=[MAX($2)])
LogicalProject(EXPR$0=[4], EXPR$1=[+(2, 3)], $f2=[5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[+(2, 3)], EXPR$2=[$1])
LogicalAggregate(group=[{0}], EXPR$2=[MAX($1)])
LogicalProject(EXPR$0=[4], $f2=[5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregateConstGroupBy">
<Resource name="sql">
<![CDATA[select 4, 2+3, max(mgr) from (
select *, 4 as four, 2+3 as two_plus_three, deptno+42 as deptno42 from emp
) group by 4, 2+3]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], EXPR$2=[MAX($2)])
LogicalProject(EXPR$0=[4], EXPR$1=[+(2, 3)], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[+(2, 3)], EXPR$2=[$1])
LogicalAggregate(group=[{0}], EXPR$2=[MAX($1)])
LogicalProject(EXPR$0=[4], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregatePermuted">
<Resource name="sql">
<![CDATA[select deptno, max(mgr) from (
select *, 4 as four, 2+3 as two_plus_three, deptno+42 as deptno42 from emp
) group by deptno, four, two_plus_three, deptno42]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$4])
LogicalAggregate(group=[{0, 1, 2, 3}], EXPR$1=[MAX($4)])
LogicalProject(DEPTNO=[$7], FOUR=[4], TWO_PLUS_THREE=[+(2, 3)], DEPTNO42=[+($7, 42)], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)])
LogicalProject(DEPTNO=[$7], DEPTNO42=[+($7, 42)], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregatePermutedConstFirst">
<Resource name="sql">
<![CDATA[select deptno, max(mgr) from (
select *, 4 as four, 2+3 as two_plus_three, deptno+42 as deptno42 from emp
) group by four, deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$1], EXPR$1=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)])
LogicalProject(FOUR=[4], DEPTNO=[$7], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(DEPTNO=[$7], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregatePermutedConstGroupBy">
<Resource name="sql">
<![CDATA[select deptno, max(mgr) from (
select *, 4 as four, 2+3 as two_plus_three, deptno+42 as deptno42 from emp
) group by 42+24, deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$1], EXPR$1=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)])
LogicalProject($f0=[+(42, 24)], DEPTNO=[$7], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(DEPTNO=[$7], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughAggregateSimpleNonNullable">
<Resource name="sql">
<![CDATA[select deptno, max(ename) from (
select *, 4 as four, 2+3 as two_plus_three, deptno+42 as deptno42 from emp
) group by deptno, four]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)])
LogicalProject(DEPTNO=[$7], FOUR=[4], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(DEPTNO=[$7], ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughConstLast">
<Resource name="sql">
<![CDATA[select deptno, max(mgr) from (
select *, 4 as four, 2+3 as two_plus_three, deptno+42 as deptno42 from emp
) group by deptno, four]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{0, 1}], EXPR$1=[MAX($2)])
LogicalProject(DEPTNO=[$7], FOUR=[4], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(DEPTNO=[$7], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughUnion">
<Resource name="sql">
<![CDATA[select 2, deptno, job from emp as e1
union all
select 2, deptno, job from emp as e2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(EXPR$0=[2], DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[2], DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[2], DEPTNO=[$0], JOB=[$1])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughUnion2">
<Resource name="sql">
<![CDATA[select 2, deptno, job from emp as e1
union all
select 1, deptno, job from emp as e2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(EXPR$0=[2], DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[1], DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullConstantThroughUnion3">
<Resource name="sql">
<![CDATA[select 2, 3 from emp as e1
union all
select 2, 3 from emp as e2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(EXPR$0=[2], EXPR$1=[3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[2], EXPR$1=[3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[2], EXPR$1=[3])
LogicalUnion(all=[true])
LogicalProject(EXPR$0=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullFilterThroughAggregate">
<Resource name="sql">
<![CDATA[select ename, sal, deptno from ( select ename, sal, deptno from emp where sal > 5000)group by ename, sal, deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1, 2}])
LogicalFilter(condition=[>($1, 5000)])
LogicalProject(ENAME=[$1], SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalFilter(condition=[>($1, 5000)])
LogicalAggregate(group=[{0, 1, 2}])
LogicalProject(ENAME=[$1], SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullFilterThroughAggregateGroupingSets">
<Resource name="sql">
<![CDATA[select ename, sal, deptno from ( select ename, sal, deptno from emp where sal > 5000)group by rollup(ename, sal, deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1, 2}], groups=[[{0, 1, 2}, {0, 1}, {0}, {}]])
LogicalFilter(condition=[>($1, 5000)])
LogicalProject(ENAME=[$1], SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1, 2}], groups=[[{0, 1, 2}, {0, 1}, {0}, {}]])
LogicalFilter(condition=[>($1, 5000)])
LogicalAggregate(group=[{0, 1, 2}])
LogicalProject(ENAME=[$1], SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPullNull">
<Resource name="sql">
<![CDATA[select *
from emp
where deptno=7
and empno = 10 and mgr is null and empno = 10]]>
</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=[AND(=($7, 7), =($0, 10), IS NULL($3), =($0, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[10], ENAME=[$1], JOB=[$2], MGR=[null:INTEGER], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[7], SLACKER=[$8])
LogicalFilter(condition=[AND(=($7, 7), =($0, 10), IS NULL($3))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAboveFiltersIntoInnerJoinCondition">
<Resource name="sql">
<![CDATA[select * from sales.dept d inner join sales.emp e
on d.deptno = e.deptno and d.deptno > e.mgr
where d.deptno > e.mgr]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalFilter(condition=[>($0, $5)])
LogicalJoin(condition=[AND(=($0, $9), >($0, $5))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalJoin(condition=[AND(=($0, $9), >($0, $5))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggThroughUnion">
<Resource name="sql">
<![CDATA[select ename,sum(empno),count(*) from (select * from emp as e1 union all select * from emp as e2) group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
AggregateRel(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT()])
ProjectRel(ENAME=[$1], EMPNO=[$0])
UnionRel(all=[true])
ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
ProjectRel(ENAME=[$0], EXPR$1=[$1], EXPR$2=[CAST($2):BIGINT NOT NULL])
AggregateRel(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[SUM($2)])
UnionRel(all=[true])
AggregateRel(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT()])
ProjectRel(ENAME=[$1], EMPNO=[$0])
ProjectRel(EMPNO=[$0], ENAME=[$1])
ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
AggregateRel(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT()])
ProjectRel(ENAME=[$1], EMPNO=[$0])
ProjectRel(EMPNO=[$0], ENAME=[$1])
ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateFunctionsThroughJoin">
<Resource name="sql">
<![CDATA[select e.job,
min(sal) as min_sal, min(e.deptno) as min_deptno,
sum(sal) + 1 as sum_sal_plus, max(sal) as max_sal,
sum(sal) as sum_sal_2, count(sal) as count_sal,
count(mgr) as count_mgr
from sales.emp as e
join sales.dept as d on e.job = d.name
group by e.job,d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(JOB=[$0], MIN_SAL=[$2], MIN_DEPTNO=[$3], SUM_SAL_PLUS=[+($4, 1)], MAX_SAL=[$5], SUM_SAL_2=[$4], COUNT_SAL=[$6], COUNT_MGR=[$7])
LogicalAggregate(group=[{2, 10}], MIN_SAL=[MIN($5)], MIN_DEPTNO=[MIN($7)], SUM_SAL_2=[SUM($5)], MAX_SAL=[MAX($5)], COUNT_SAL=[COUNT()], COUNT_MGR=[COUNT($3)])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$0], MIN_SAL=[$2], MIN_DEPTNO=[$3], SUM_SAL_PLUS=[+($4, 1)], MAX_SAL=[$5], SUM_SAL_2=[$4], COUNT_SAL=[$6], COUNT_MGR=[$7])
LogicalProject(JOB=[$0], NAME=[$7], MIN_SAL=[$1], MIN_DEPTNO=[$2], $f9=[CAST(*($3, $8)):INTEGER NOT NULL], MAX_SAL=[$4], $f10=[*($5, $8)], $f11=[*($6, $8)])
LogicalJoin(condition=[=($0, $7)], joinType=[inner])
LogicalAggregate(group=[{2}], MIN_SAL=[MIN($5)], MIN_DEPTNO=[MIN($7)], SUM_SAL_2=[SUM($5)], MAX_SAL=[MAX($5)], COUNT_SAL=[COUNT()], COUNT_MGR=[COUNT($3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateSumNoGroup">
<Resource name="sql">
<![CDATA[select count(*) from sales.emp join sales.dept on job = name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[$SUM0($0)])
LogicalProject($f4=[*($1, $3)])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalAggregate(group=[{2}], EXPR$0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], EXPR$0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateSumThroughJoin">
<Resource name="sql">
<![CDATA[select e.job,sum(sal)
from (select * from sales.emp where ename = 'A') as e
join sales.dept as d on e.job = d.name
group by e.job,d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(JOB=[$0], EXPR$1=[$2])
LogicalAggregate(group=[{2, 10}], EXPR$1=[SUM($5)])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$0], EXPR$1=[$2])
LogicalProject(JOB=[$0], NAME=[$2], $f4=[CAST(*($1, $3)):INTEGER NOT NULL])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalAggregate(group=[{2}], EXPR$1=[SUM($5)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateSumThroughJoinAfterAggregateReduce">
<Resource name="sql">
<![CDATA[select sum(sal)
from (select * from sales.emp where ename = 'A') as e
join sales.dept as d on e.job = d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($5)])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[CASE(=($1, 0), null:INTEGER, $0)])
LogicalAggregate(group=[{}], EXPR$0=[$SUM0($0)], agg#1=[$SUM0($1)])
LogicalProject($f5=[CAST(*($1, $4)):INTEGER NOT NULL], $f6=[*($2, $4)])
LogicalJoin(condition=[=($0, $3)], joinType=[inner])
LogicalAggregate(group=[{2}], EXPR$0=[$SUM0($5)], agg#1=[COUNT()])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateSumWithoutGroupKeyThroughJoin">
<Resource name="sql">
<![CDATA[select sum(sal)
from (select * from sales.emp where ename = 'A') as e
join sales.dept as d on e.job = d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($5)])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject($f4=[CAST(*($1, $3)):INTEGER])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalAggregate(group=[{2}], EXPR$0=[SUM($5)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin1">
<Resource name="sql">
<![CDATA[select e.job,d.name
from (select * from sales.emp where ename = 'A') as e
join sales.dept as d on e.job = d.name
group by e.job,d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2, 10}])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin2">
<Resource name="sql">
<![CDATA[select e.job,d.name
from (select * from sales.emp where ename = 'A') as e
join sales.dept as d on e.job = d.name
and e.deptno + e.empno = d.deptno + 5
group by e.job,d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2, 11}])
LogicalJoin(condition=[AND(=($2, $11), =($9, $12))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 2}])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[inner])
LogicalAggregate(group=[{2, 9}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1, 2}])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin3">
<Resource name="sql">
<![CDATA[select e.empno,d.deptno
from (select * from sales.emp where empno = 10) as e
join sales.dept as d on e.empno < d.deptno
group by e.empno,d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 9}])
LogicalJoin(condition=[<($0, $9)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 9}])
LogicalJoin(condition=[<($0, $9)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin4">
<Resource name="sql">
<![CDATA[select e.deptno
from sales.emp as e join sales.dept as d on e.deptno = d.deptno
group by e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{7}])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalAggregate(group=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin5">
<Resource name="sql">
<![CDATA[select e.deptno, d.deptno
from sales.emp as e join sales.dept as d on e.deptno = d.deptno
group by e.deptno, d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], DEPTNO0=[$1])
LogicalAggregate(group=[{7, 9}])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], DEPTNO0=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalAggregate(group=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin6">
<Resource name="sql">
<![CDATA[select sum(B.sal)
from sales.emp as A
join (select distinct sal from sales.emp) as B
on A.sal=B.sal
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($9)])
LogicalJoin(condition=[=($5, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject($f3=[CAST(*($1, $2)):INTEGER])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalAggregate(group=[{5}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin7">
<Resource name="sql">
<![CDATA[select any_value(distinct B.sal)
from sales.emp as A
join (select distinct sal from sales.emp) as B
on A.sal=B.sal
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[ANY_VALUE($9)])
LogicalJoin(condition=[=($5, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[ANY_VALUE($1)])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoin8">
<Resource name="sql">
<![CDATA[select single_value(distinct B.sal)
from sales.emp as A
join (select distinct sal from sales.emp) as B
on A.sal=B.sal
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SINGLE_VALUE($9)])
LogicalJoin(condition=[=($5, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SINGLE_VALUE($1)])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{5}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoinDistinct">
<Resource name="sql">
<![CDATA[select d.name,
sum(sal) as sum_sal, count(*) as c
from sales.emp as e
join (select distinct name from sales.dept) as d
on e.job = d.name
group by d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{9}], SUM_SAL=[SUM($5)], C=[COUNT()])
LogicalJoin(condition=[=($2, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$3], SUM_SAL=[$1], C=[$2])
LogicalJoin(condition=[=($0, $3)], joinType=[inner])
LogicalAggregate(group=[{2}], SUM_SAL=[SUM($5)], C=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoinOnEmptyLogicalValues">
<Resource name="sql">
<![CDATA[select count(*) volume, sum(C1.sal) C1_sum_sal from (select sal, ename from sales.emp where 1=2) C1 inner join (select ename from sales.emp) C2 on C1.ename = C2.ename ]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], VOLUME=[COUNT()], C1_SUM_SAL=[SUM($0)])
LogicalJoin(condition=[=($1, $2)], joinType=[inner])
LogicalProject(SAL=[$5], ENAME=[$1])
LogicalValues(tuples=[[]])
LogicalProject(ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], VOLUME=[$SUM0($0)], C1_SUM_SAL=[SUM($1)])
LogicalProject(VOLUME=[$3], $f4=[CAST(*($1, $3)):INTEGER])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalProject(ENAME=[$1], SAL=[$0])
LogicalProject(SAL=[$5], ENAME=[$1])
LogicalValues(tuples=[[]])
LogicalAggregate(group=[{0}], VOLUME=[COUNT()])
LogicalProject(ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughJoinWithUniqueInput">
<Resource name="sql">
<![CDATA[select A.job, B.mgr, A.deptno,
max(B.hiredate1) as hiredate1, sum(B.comm1) as comm1
from sales.emp as A
join (select mgr, sal, max(hiredate) as hiredate1,
sum(comm) as comm1 from sales.emp group by mgr, sal) as B
on A.sal=B.sal
group by A.job, B.mgr, A.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(JOB=[$0], MGR0=[$2], DEPTNO=[$1], HIREDATE1=[$3], COMM1=[$4])
LogicalAggregate(group=[{2, 7, 9}], HIREDATE1=[MAX($11)], COMM1=[SUM($12)])
LogicalJoin(condition=[=($5, $10)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{3, 5}], HIREDATE1=[MAX($4)], COMM1=[SUM($6)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$0], MGR0=[$2], DEPTNO=[$1], HIREDATE1=[$3], COMM1=[$4])
LogicalAggregate(group=[{0, 1, 2}], HIREDATE1=[MAX($3)], COMM1=[SUM($4)])
LogicalProject(JOB=[$0], DEPTNO=[$2], MGR=[$4], HIREDATE1=[$6], $f8=[CAST(*($3, $7)):INTEGER NOT NULL])
LogicalJoin(condition=[=($1, $5)], joinType=[inner])
LogicalAggregate(group=[{2, 5, 7}], agg#0=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{3, 5}], HIREDATE1=[MAX($4)], COMM1=[SUM($6)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin1">
<Resource name="sql">
<![CDATA[select e.ename
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
group by e.ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1}])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalAggregate(group=[{1, 2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin10">
<Resource name="sql">
<![CDATA[select count(e.ename)
from (select * from sales.emp where empno = 10) as e
left outer join sales.emp as d on e.job = d.job
group by e.ename,d.mgr]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$2])
LogicalAggregate(group=[{1, 12}], EXPR$0=[COUNT()])
LogicalJoin(condition=[=($2, $11)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin11">
<Resource name="sql">
<![CDATA[select e.empno,d.deptno
from (select * from sales.emp where empno = 10) as e
left outer join sales.dept as d on e.empno < d.deptno
group by e.empno,d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 9}])
LogicalJoin(condition=[<($0, $9)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin12">
<Resource name="sql">
<![CDATA[select e.job
from (select * from sales.emp where ename = 'A') as e
right outer join sales.dept as d on e.job = d.name
group by e.job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2}])
LogicalJoin(condition=[=($2, $10)], joinType=[right])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalJoin(condition=[=($0, $1)], joinType=[right])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin13">
<Resource name="sql">
<![CDATA[select e.job
from (select * from sales.emp where ename = 'A') as e
full outer join sales.dept as d on e.job = d.name
group by e.job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2}])
LogicalJoin(condition=[=($2, $10)], joinType=[full])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalJoin(condition=[=($0, $1)], joinType=[full])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin14">
<Resource name="sql">
<![CDATA[select e.mgr, d.mgr
from sales.emp as e
full outer join sales.emp as d on e.mgr = d.mgr
group by d.mgr, e.mgr]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(MGR=[$1], MGR0=[$0])
LogicalProject(MGR0=[$1], MGR=[$0])
LogicalAggregate(group=[{3, 12}])
LogicalJoin(condition=[=($3, $12)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(MGR=[$1], MGR0=[$0])
LogicalProject(MGR0=[$1], MGR=[$0])
LogicalAggregate(group=[{0, 1}])
LogicalJoin(condition=[=($0, $1)], joinType=[full])
LogicalAggregate(group=[{3}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{3}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin15">
<Resource name="sql">
<![CDATA[select e.ename, d.mgr
from (select * from sales.emp where ename = 'A') as e
full outer join sales.emp as d on e.job = d.job
group by e.ename,d.mgr]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1, 12}])
LogicalJoin(condition=[=($2, $11)], joinType=[full])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 3}])
LogicalJoin(condition=[=($1, $2)], joinType=[full])
LogicalAggregate(group=[{1, 2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{2, 3}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin16">
<Resource name="sql">
<![CDATA[select e.job
from (select * from sales.emp where ename = 'A') as e
full outer join sales.dept as d on e.job = d.name
and e.deptno + e.empno = d.deptno + 5
group by e.job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2}])
LogicalJoin(condition=[AND(=($2, $11), =($9, $12))], joinType=[full])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[full])
LogicalAggregate(group=[{2, 9}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1, 2}])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin2">
<Resource name="sql">
<![CDATA[select d.ename
from (select * from sales.emp where ename = 'A') as e
left outer join sales.emp as d on e.job = d.job
group by d.ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{10}])
LogicalJoin(condition=[=($2, $11)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}])
LogicalJoin(condition=[=($0, $2)], joinType=[left])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1, 2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin3">
<Resource name="sql">
<![CDATA[select e.ename, d.mgr
from (select * from sales.emp where ename = 'A') as e
left outer join sales.emp as d on e.job = d.job
group by e.ename,d.mgr]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1, 12}])
LogicalJoin(condition=[=($2, $11)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 3}])
LogicalJoin(condition=[=($1, $2)], joinType=[left])
LogicalAggregate(group=[{1, 2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{2, 3}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin4">
<Resource name="sql">
<![CDATA[select e.job
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
group by e.job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2}])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(JOB=[$0])
LogicalJoin(condition=[=($0, $1)], joinType=[left])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin5">
<Resource name="sql">
<![CDATA[select d.name
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
group by d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{10}])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}])
LogicalJoin(condition=[=($0, $1)], joinType=[left])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin6">
<Resource name="sql">
<![CDATA[select e.job,d.name
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
group by e.job,d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2, 10}])
LogicalJoin(condition=[=($2, $10)], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($0, $1)], joinType=[left])
LogicalAggregate(group=[{2}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin7">
<Resource name="sql">
<![CDATA[select e.job
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
and e.deptno + e.empno = d.deptno + 5
group by e.job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2}])
LogicalJoin(condition=[AND(=($2, $11), =($9, $12))], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[left])
LogicalAggregate(group=[{2, 9}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1, 2}])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin8">
<Resource name="sql">
<![CDATA[select d.name
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
and e.deptno + e.empno = d.deptno + 5
group by d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{11}])
LogicalJoin(condition=[AND(=($2, $11), =($9, $12))], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{2}])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[left])
LogicalAggregate(group=[{2, 9}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1, 2}])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAggregateThroughOuterJoin9">
<Resource name="sql">
<![CDATA[select e.job, d.name
from (select * from sales.emp where ename = 'A') as e
left outer join sales.dept as d on e.job = d.name
and e.deptno + e.empno = d.deptno + 5
group by e.job, d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{2, 11}])
LogicalJoin(condition=[AND(=($2, $11), =($9, $12))], joinType=[left])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 2}])
LogicalJoin(condition=[AND(=($0, $2), =($1, $3))], joinType=[left])
LogicalAggregate(group=[{2, 9}])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, $0)])
LogicalFilter(condition=[=($1, 'A')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{1, 2}])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 5)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAvgGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, avg(empno) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno, job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[AVG($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[AVG($2)])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushAvgThroughUnion">
<Resource name="sql">
<![CDATA[select ename,avg(empno) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[AVG($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[AVG($1)])
LogicalUnion(all=[true])
LogicalProject(ENAME=[$1], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$1], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushBoolAndBoolOrThroughUnion">
<Resource name="sql">
<![CDATA[select ename, bool_and(empbol), bool_or(empbol) from
(select ename, case when mod(empno, 2) = 1 then true else false end as empbol from emp as e1 union all
select ename, case when mod(empno, 2) = 1 then true else false end as empbol from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[BOOL_AND($1)], EXPR$2=[BOOL_OR($1)])
LogicalUnion(all=[true])
LogicalProject(ENAME=[$1], EMPBOL=[=(MOD($0, 2), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$1], EMPBOL=[=(MOD($0, 2), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[BOOL_AND($1)], EXPR$2=[BOOL_OR($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[BOOL_AND($1)], EXPR$2=[BOOL_OR($1)])
LogicalProject(ENAME=[$1], EMPBOL=[=(MOD($0, 2), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[BOOL_AND($1)], EXPR$2=[BOOL_OR($1)])
LogicalProject(ENAME=[$1], EMPBOL=[=(MOD($0, 2), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushCountFilterThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, count(*) filter (where job = 'CLERK')
from (
select * from emp where deptno = 10
union all
select * from emp where deptno > 20)
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT() FILTER $1])
LogicalProject(DEPTNO=[$7], $f1=[=($2, 'CLERK')])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[>($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[$SUM0($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT() FILTER $1])
LogicalProject(DEPTNO=[$7], $f1=[=($2, 'CLERK')])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT() FILTER $1])
LogicalProject(DEPTNO=[$7], $f1=[=($2, 'CLERK')])
LogicalFilter(condition=[>($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushCountNullableGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, count(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno, job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[COUNT($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[$SUM0($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushCountNullableThroughUnion">
<Resource name="sql">
<![CDATA[select ename,count(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[$SUM0($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushCountStarGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, count(*) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno, job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[COUNT()])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[$SUM0($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(DEPTNO=[$7], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushCountStarThroughUnion">
<Resource name="sql">
<![CDATA[select ename,count(*) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(ENAME=[$1])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[$SUM0($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(ENAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushDistinctAggregateIntoJoin">
<Resource name="sql">
<![CDATA[select count(distinct sal) from sales.emp
join sales.dept on job = name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT(DISTINCT $0)])
LogicalProject(SAL=[$5])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT(DISTINCT $5)])
LogicalJoin(condition=[=($2, $10)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastAgg">
<Resource name="sql">
<![CDATA[select dname, c from
(select name dname, count(*) as c from dept group by name) t
where dname = 'Charlie']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$0], C=[$1])
LogicalFilter(condition=[=($0, 'Charlie')])
LogicalAggregate(group=[{0}], C=[COUNT()])
LogicalProject(DNAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DNAME=[$0], C=[$1])
LogicalAggregate(group=[{0}], C=[COUNT()])
LogicalFilter(condition=[=($0, 'Charlie')])
LogicalProject(DNAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastAggFour">
<Resource name="sql">
<![CDATA[select emp.deptno, count(*) from emp where emp.sal > '12'
group by emp.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[$SUM0($2)])
LogicalFilter(condition=[>($0, CAST('12'):INTEGER NOT NULL)])
LogicalAggregate(group=[{5, 7}], EXPR$1=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{1}], EXPR$1=[$SUM0($2)])
LogicalAggregate(group=[{5, 7}], EXPR$1=[COUNT()])
LogicalFilter(condition=[>($5, 12)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastAggThree">
<Resource name="sql">
<![CDATA[select deptno from emp
group by deptno having count(*) > 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[>($1, 1)])
LogicalAggregate(group=[{0}], agg#0=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[>($1, 1)])
LogicalAggregate(group=[{0}], agg#0=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastAggTwo">
<Resource name="sql">
<![CDATA[select dept1.c1 from (
select dept.name as c1, count(*) as c2
from dept where dept.name > 'b' group by dept.name) dept1
where dept1.c1 > 'c' and (dept1.c2 > 30 or dept1.c1 < 'z')]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(C1=[$0])
LogicalFilter(condition=[AND(>($0, 'c'), OR(>($1, 30), <($0, 'z')))])
LogicalAggregate(group=[{0}], C2=[COUNT()])
LogicalProject(C1=[$1])
LogicalFilter(condition=[>($1, 'b')])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(C1=[$0])
LogicalFilter(condition=[OR(>($1, 30), <($0, 'z'))])
LogicalAggregate(group=[{0}], C2=[COUNT()])
LogicalFilter(condition=[>($0, 'c')])
LogicalProject(C1=[$1])
LogicalFilter(condition=[>($1, 'b')])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastAggWithGroupingSets1">
<Resource name="sql">
<![CDATA[select ddeptno, dname, c from
(select deptno ddeptno, name dname, count(*) as c
from dept group by rollup(deptno,name)) t
where dname = 'Charlie']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DDEPTNO=[$0], DNAME=[$1], C=[$2])
LogicalProject(DDEPTNO=[$0], DNAME=[$1], C=[$2])
LogicalFilter(condition=[=($1, 'Charlie')])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], C=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DDEPTNO=[$0], DNAME=[$1], C=[$2])
LogicalProject(DDEPTNO=[CASE($2, null, $0)], DNAME=[CASE($3, null, $1)], C=[$4])
LogicalFilter(condition=[=(CASE($3, null, $1), 'Charlie')])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], indicator=[true], C=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastAggWithGroupingSets2">
<Resource name="sql">
<![CDATA[select dname, ddeptno, c from
(select name dname, deptno ddeptno, count(*) as c
from dept group by grouping sets ((name,deptno),(name))) t
where dname = 'Charlie']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$0], DDEPTNO=[$1], C=[$2])
LogicalFilter(condition=[=($0, 'Charlie')])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}]], C=[COUNT()])
LogicalProject(DNAME=[$1], DDEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DNAME=[$0], DDEPTNO=[$1], C=[$2])
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}]], C=[COUNT()])
LogicalFilter(condition=[=($0, 'Charlie')])
LogicalProject(DNAME=[$1], DDEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterPastProject">
<Resource name="sql">
<![CDATA[select a.name
from dept a
left join dept b on b.deptno > 10
right join dept c on b.deptno > 10
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalJoin(condition=[$4], joinType=[right])
LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[$2], NAME0=[$3], $f4=[>($2, 10)])
LogicalJoin(condition=[$4], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[>($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalJoin(condition=[true], joinType=[right])
LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[$2], NAME0=[$3], $f4=[>($2, 10)])
LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[CAST($2):INTEGER], NAME0=[CAST($3):VARCHAR(10)], $f2=[CAST($4):BOOLEAN])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[>($0, 10)])
LogicalFilter(condition=[>($0, 10)])
LogicalFilter(condition=[>($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterSemijoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[AND(=($0, $10), =($8, 100))], joinType=[semi])
LogicalTableScan(table=[[scott, DEPT]])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $10)], joinType=[semi])
LogicalTableScan(table=[[scott, DEPT]])
LogicalFilter(condition=[=($5, 100)])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterThroughOuterJoin">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d left outer join sales.emp e on d.deptno = e.deptno where d.name = 'Charlie']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
ProjectRel(EXPR$0=[1])
FilterRel(condition=[=($1, 'Charlie')])
JoinRel(condition=[=($0, $9)], joinType=[left])
TableAccessRel(table=[[CATALOG, SALES, DEPT]])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
ProjectRel(EXPR$0=[1])
JoinRel(condition=[=($0, $9)], joinType=[left])
FilterRel(condition=[=($1, 'Charlie')])
TableAccessRel(table=[[CATALOG, SALES, DEPT]])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterThroughSemiJoin">
<Resource name="sql">
<![CDATA[select * from (
select * from dept where dept.deptno in (
select emp.deptno from emp))R
where R.deptno <=10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[<=($0, 10)])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalFilter(condition=[<=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterWithIsNotDistinctFromPastJoin">
<Resource name="sql">
<![CDATA[SELECT * FROM emp t1 INNER JOIN emp t2 ON t1.deptno = t2.deptno WHERE t1.ename is not distinct from t2.ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalFilter(condition=[OR(AND(IS NULL($1), IS NULL($10)), IS TRUE(=($1, $10)))])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
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], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalJoin(condition=[AND(=($7, $16), IS NOT DISTINCT FROM($1, $10))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterWithRank">
<Resource name="sql">
<![CDATA[select e1.ename, r
from (
select ename, rank() over(partition by deptno order by sal) as r from emp) e1
where r < 2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$0], R=[$1])
LogicalFilter(condition=[<($1, 2)])
LogicalProject(ENAME=[$1], R=[RANK() OVER (PARTITION BY $7 ORDER BY $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$0], R=[$1])
LogicalFilter(condition=[<($1, 2)])
LogicalProject(ENAME=[$1], R=[RANK() OVER (PARTITION BY $7 ORDER BY $5 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushFilterWithRankExpr">
<Resource name="sql">
<![CDATA[select e1.ename, r
from (
select ename,
rank() over(partition by deptno order by sal) + 1 as r from emp) e1
where r < 2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$0], R=[$1])
LogicalFilter(condition=[<($1, 2)])
LogicalProject(ENAME=[$1], R=[+(RANK() OVER (PARTITION BY $7 ORDER BY $5), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$0], R=[$1])
LogicalFilter(condition=[<($1, 2)])
LogicalProject(ENAME=[$1], R=[+(RANK() OVER (PARTITION BY $7 ORDER BY $5 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushJoinCondDownToProject">
<Resource name="sql">
<![CDATA[select d.deptno, e.deptno from sales.dept d, sales.emp e
where d.deptno + 10 = e.deptno * 2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], DEPTNO0=[$9])
LogicalFilter(condition=[=(+($0, 10), *($9, 2))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], DEPTNO0=[$9])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$3], ENAME=[$4], JOB=[$5], MGR=[$6], HIREDATE=[$7], SAL=[$8], COMM=[$9], DEPTNO0=[$10], SLACKER=[$11])
LogicalJoin(condition=[=($2, $12)], joinType=[inner])
LogicalProject(DEPTNO=[$0], NAME=[$1], $f2=[+($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[*($7, 2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushJoinThroughUnionOnLeft">
<Resource name="sql">
<![CDATA[select r1.sal from
(select * from emp e1 union all select * from emp e2) r1,
emp r2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[true], joinType=[inner])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalUnion(all=[true])
LogicalJoin(condition=[true], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalJoin(condition=[true], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushJoinThroughUnionOnRight">
<Resource name="sql">
<![CDATA[select r1.sal from
emp r1,
(select * from emp e1 union all select * from emp e2) r2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalUnion(all=[true])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushJoinThroughUnionOnRightDoesNotMatchAntiJoin">
<Resource name="sql">
<![CDATA[select r1.sal from emp r1 where r1.deptno not in (select deptno from dept d1 where deptno < 10 union all select deptno from dept d2 where deptno > 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[=($7, $8)], joinType=[anti])
LogicalTableScan(table=[[scott, EMP]])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[<($0, 10)])
LogicalTableScan(table=[[scott, DEPT]])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[>($0, 20)])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushJoinThroughUnionOnRightDoesNotMatchSemiJoin">
<Resource name="sql">
<![CDATA[select r1.sal from emp r1 where r1.deptno in (select deptno from dept d1 where deptno > 100 union all select deptno from dept d2 where deptno > 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[=($7, $8)], joinType=[semi])
LogicalTableScan(table=[[scott, EMP]])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[<($0, 10)])
LogicalTableScan(table=[[scott, DEPT]])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[>($0, 20)])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushMaxNullableGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, max(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno, job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[MAX($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[MAX($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[MAX($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[MAX($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushMaxNullableThroughUnion">
<Resource name="sql">
<![CDATA[select ename,max(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[MAX($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushMinGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, min(empno) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno, job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[MIN($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[MIN($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[MIN($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[MIN($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushMinThroughUnion">
<Resource name="sql">
<![CDATA[select ename,min(empno) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MIN($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MIN($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[MIN($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[MIN($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFilter">
<Resource name="sql">
<![CDATA[select empno + deptno from emp where sal = 10 * comm
and upper(ename) = 'FOO']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($0, $7)])
LogicalFilter(condition=[AND(=($5, *(10, $6)), =(UPPER($1), 'FOO'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($0, $4)])
LogicalFilter(condition=[AND(=($2, *(10, $3)), =(UPPER($1), 'FOO'))])
LogicalProject(EMPNO=[$0], ENAME=[$1], SAL=[$5], COMM=[$6], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFilter2">
<Resource name="sql">
<![CDATA[select count(*)
from emp
where case when mgr < 10 then true else false end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[0])
LogicalFilter(condition=[CASE(<($3, 10), true, false)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[0])
LogicalFilter(condition=[<($0, 10)])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFilter3">
<Resource name="sql">
<![CDATA[select empno + deptno as x, ename, job, mgr,
hiredate, sal, comm, slacker
from emp
where sal = 10 * comm
and upper(ename) = 'FOO']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[+($0, $7)], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8])
LogicalFilter(condition=[AND(=($5, *(10, $6)), =(UPPER($1), 'FOO'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($0, $7)], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8])
LogicalFilter(condition=[AND(=($5, *(10, $6)), =(UPPER($1), 'FOO'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFilter3b">
<Resource name="sql">
<![CDATA[select empno + deptno as x, ename, job, mgr,
hiredate, sal, comm, slacker
from emp
where sal = 10 * comm
and upper(ename) = 'FOO']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[+($0, $7)], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8])
LogicalFilter(condition=[AND(=($5, *(10, $6)), =(UPPER($1), 'FOO'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(X=[$8], ENAME=[$0], JOB=[$1], MGR=[$2], HIREDATE=[$3], SAL=[$4], COMM=[$5], SLACKER=[$6])
LogicalFilter(condition=[$7])
LogicalProject(ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8], $f7=[AND(=($5, *(10, $6)), =(UPPER($1), 'FOO'))], $f8=[+($0, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFilter3c">
<Resource name="sql">
<![CDATA[select empno + deptno as x, ename, job, mgr,
hiredate, sal, comm, slacker
from emp
where sal = 10 * comm
and upper(ename) = 'FOO']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[+($0, $7)], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8])
LogicalFilter(condition=[AND(=($5, *(10, $6)), =(UPPER($1), 'FOO'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(X=[$7], ENAME=[$0], JOB=[$1], MGR=[$2], HIREDATE=[$3], SAL=[$4], COMM=[$5], SLACKER=[$6])
LogicalFilter(condition=[AND(=($4, *(10, $5)), =(UPPER($0), 'FOO'))])
LogicalProject(ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], SLACKER=[$8], $f7=[+($0, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFullJoin">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then 11 else -1 * e.sal end
from emp e full outer join bonus b on e.ename = b.ename
group by case when e.sal < 11 then 11 else -1 * e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalJoin(condition=[=($1, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE($1, 11, $2)])
LogicalJoin(condition=[=($0, $3)], joinType=[full])
LogicalProject(ENAME=[$1], EXPR$0=[<($5, 11)], EXPR$1=[*(-1, $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastFullJoinStrong">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then -1 * e.sal else e.sal end
from emp e full outer join bonus b on e.ename = b.ename
group by case when e.sal < 11 then -1 * e.sal else e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalJoin(condition=[=($1, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[full])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastInnerJoin">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then 11 else -1 * e.sal end
from emp e inner join bonus b on e.ename = b.ename
group by case when e.sal < 11 then 11 else -1 * e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastInnerJoinStrong">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then -1 * e.sal else e.sal end
from emp e inner join bonus b on e.ename = b.ename
group by case when e.sal < 11 then -1 * e.sal else e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastJoin">
<Resource name="sql">
<![CDATA[select e.sal + b.comm from emp e inner join bonus b
on e.ename = b.ename and e.deptno = 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($5, $12)])
LogicalJoin(condition=[AND(=($1, $9), =($7, 10))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($1, $4)])
LogicalJoin(condition=[AND(=($0, $3), $2)], joinType=[inner])
LogicalProject(ENAME=[$1], SAL=[$5], EXPR$0=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0], COMM=[$3])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastLeftJoin">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then 11 else -1 * e.sal end
from emp e left outer join bonus b on e.ename = b.ename
group by case when e.sal < 11 then 11 else -1 * e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalJoin(condition=[=($1, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[left])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastLeftJoinStrong">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then -1 * e.sal else e.sal end
from bonus b left outer join emp e on e.ename = b.ename group by
case when e.sal < 11 then -1 * e.sal else e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($9, 11), *(-1, $9), $9)])
LogicalJoin(condition=[=($5, $0)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$2])
LogicalJoin(condition=[=($1, $0)], joinType=[left])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalProject(ENAME=[$1], CASE=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastLeftJoinSwap">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then 11 else -1 * e.sal end
from bonus b left outer join emp e on e.ename = b.ename
group by case when e.sal < 11 then 11 else -1 * e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($9, 11), 11, *(-1, $9))])
LogicalJoin(condition=[=($5, $0)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE($2, 11, $3)])
LogicalJoin(condition=[=($1, $0)], joinType=[left])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalProject(ENAME=[$1], EXPR$0=[<($5, 11)], EXPR$1=[*(-1, $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastLeftJoinSwapStrong">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then -1 * e.sal else e.sal end
from bonus b left outer join emp e on e.ename = b.ename
group by case when e.sal < 11 then -1 * e.sal else e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($9, 11), *(-1, $9), $9)])
LogicalJoin(condition=[=($5, $0)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$2])
LogicalJoin(condition=[=($1, $0)], joinType=[left])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastRightJoin">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then 11 else -1 * e.sal end
from emp e right outer join bonus b on e.ename = b.ename
group by case when e.sal < 11 then 11 else -1 * e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalJoin(condition=[=($1, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE($1, 11, $2)])
LogicalJoin(condition=[=($0, $3)], joinType=[right])
LogicalProject(ENAME=[$1], EXPR$0=[<($5, 11)], EXPR$1=[*(-1, $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastRightJoinStrong">
<Resource name="sql">
<![CDATA[select count(*),
case when e.sal < 11 then -1 * e.sal else e.sal end
from emp e right outer join bonus b on e.ename = b.ename
group by case when e.sal < 11 then -1 * e.sal else e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalJoin(condition=[=($1, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[right])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastRightJoinSwap">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then 11 else -1 * e.sal end
from bonus b right outer join emp e on e.ename = b.ename
group by case when e.sal < 11 then 11 else -1 * e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($9, 11), 11, *(-1, $9))])
LogicalJoin(condition=[=($5, $0)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$2])
LogicalJoin(condition=[=($1, $0)], joinType=[right])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), 11, *(-1, $5))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastRightJoinSwapStrong">
<Resource name="sql">
<![CDATA[select count(*), case when e.sal < 11 then -1 * e.sal else e.sal end
from bonus b right outer join emp e on e.ename = b.ename
group by case when e.sal < 11 then -1 * e.sal else e.sal end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[CASE(<($9, 11), *(-1, $9), $9)])
LogicalJoin(condition=[=($5, $0)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$0])
LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
LogicalProject(EXPR$1=[$2])
LogicalJoin(condition=[=($1, $0)], joinType=[right])
LogicalProject(ENAME=[$0])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
LogicalProject(ENAME=[$1], EXPR$1=[CASE(<($5, 11), *(-1, $5), $5)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectPastSetOp">
<Resource name="sql">
<![CDATA[select sal from
(select * from emp e1 union all select * from emp e2)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectWithIsNotDistinctFromPastJoin">
<Resource name="sql">
<![CDATA[select e.sal + b.comm from emp e inner join bonus b
on (e.ename || e.job) IS NOT DISTINCT FROM (b.ename || b.job) and e.deptno = 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($5, $13)])
LogicalJoin(condition=[AND(IS NOT DISTINCT FROM($9, $14), =($7, 10))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[||($1, $2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0], JOB=[$1], SAL=[$2], COMM=[$3], $f4=[||($0, $1)])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($0, $3)])
LogicalJoin(condition=[AND(IS NOT DISTINCT FROM($1, $4), $2)], joinType=[inner])
LogicalProject(SAL=[$5], $f9=[$9], EXPR$0=[=($7, 10)])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[||($1, $2)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(COMM=[$3], $f4=[$4])
LogicalProject(ENAME=[$0], JOB=[$1], SAL=[$2], COMM=[$3], $f4=[||($0, $1)])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectWithOverPastJoin1">
<Resource name="sql">
<![CDATA[select e.sal + b.comm,
count(e.empno) over (partition by e.deptno)
from emp e join bonus b
on e.ename = b.ename and e.deptno = 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($5, $12)], EXPR$1=[COUNT($0) OVER (PARTITION BY $7)])
LogicalJoin(condition=[AND(=($1, $9), =($7, 10))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($2, $6)], EXPR$1=[COUNT($0) OVER (PARTITION BY $3)])
LogicalJoin(condition=[AND(=($1, $5), $4)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], SAL=[$5], DEPTNO=[$7], EXPR$0=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0], COMM=[$3])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectWithOverPastJoin2">
<Resource name="sql">
<![CDATA[select e.sal + b.comm,
count(b.sal) over (partition by b.job)
from emp e join bonus b
on e.ename = b.ename and e.deptno = 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($5, $12)], EXPR$1=[COUNT($11) OVER (PARTITION BY $10)])
LogicalJoin(condition=[AND(=($1, $9), =($7, 10))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($1, $6)], EXPR$1=[COUNT($5) OVER (PARTITION BY $4)])
LogicalJoin(condition=[AND(=($0, $3), $2)], joinType=[inner])
LogicalProject(ENAME=[$1], SAL=[$5], EXPR$0=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0], JOB=[$1], SAL=[$2], COMM=[$3])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushProjectWithOverPastJoin3">
<Resource name="sql">
<![CDATA[select e.sal + b.comm,
sum(b.sal + b.sal + 100) over (partition by b.job)
from emp e join bonus b
on e.ename = b.ename and e.deptno = 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($5, $12)], EXPR$1=[SUM(+(+($11, $11), 100)) OVER (PARTITION BY $10)])
LogicalJoin(condition=[AND(=($1, $9), =($7, 10))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[+($1, $5)], EXPR$1=[SUM($6) OVER (PARTITION BY $4)])
LogicalJoin(condition=[AND(=($0, $3), $2)], joinType=[inner])
LogicalProject(ENAME=[$1], SAL=[$5], EXPR$0=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ENAME=[$0], JOB=[$1], COMM=[$3], EXPR$0=[+(+($2, $2), 100)])
LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSemiJoinConditions">
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[AND(OR(=($0, $2), AND(IS NULL($0), IS NULL($2))), OR(=($1, $3), AND(IS NULL($1), IS NULL($3))))], joinType=[semi])
LogicalProject(DEPTNO=[$7], ENAME=[$1])
LogicalTableScan(table=[[scott, EMP]])
LogicalProject(DEPTNO=[$0], DNAME=[$1])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalProject(DEPTNO=[$7], ENAME=[$1])
LogicalJoin(condition=[AND(IS NOT DISTINCT FROM($7, $8), IS NOT DISTINCT FROM($1, $9))], joinType=[semi])
LogicalTableScan(table=[[scott, EMP]])
LogicalProject(DEPTNO=[$0], DNAME=[$1])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSemiJoinConditionsToLeft">
<Resource name="sql">
<![CDATA[select * from emp
where emp.deptno
in (select dept.deptno from dept where emp.empno > 20)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[AND(IS NOT DISTINCT FROM($7, $8), >($0, 20))], joinType=[semi])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSemiJoinPastFilter">
<Resource name="sql">
<![CDATA[select e.ename from emp e, dept d
where e.deptno = d.deptno and e.ename = 'foo']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($1, 'foo'))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalFilter(condition=[=($1, 'foo')])
LogicalJoin(condition=[=($7, $9)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSemiJoinPastJoinRuleLeft">
<Resource name="sql">
<![CDATA[select e1.ename from emp e1, dept d, emp e2
where e1.deptno = d.deptno and e1.empno = e2.empno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($0, $11))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($0, $11)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($0, $9)], joinType=[semi])
LogicalJoin(condition=[=($7, $9)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSemiJoinPastJoinRuleRight">
<Resource name="sql">
<![CDATA[select e1.ename from emp e1, dept d, emp e2
where e1.deptno = d.deptno and d.deptno = e2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($9, $18))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($9, $18)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($7, $9)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalJoin(condition=[=($0, $9)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSemiJoinPastProject">
<Resource name="sql">
<![CDATA[select e.* from
(select ename, trim(job), sal * 2, deptno from emp) e, dept d
where e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$0], EXPR$1=[$1], EXPR$2=[$2], DEPTNO=[$3])
LogicalFilter(condition=[=($3, $4)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalProject(ENAME=[$1], EXPR$1=[TRIM(FLAG(BOTH), ' ', $2)], EXPR$2=[*($5, 2)], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$0], EXPR$1=[$1], EXPR$2=[$2], DEPTNO=[$3])
LogicalJoin(condition=[=($3, $4)], joinType=[inner], semiJoinDone=[true])
LogicalProject(ENAME=[$1], EXPR$1=[TRIM(FLAG(BOTH), ' ', $2)], EXPR$2=[*($5, 2)], DEPTNO=[$7])
LogicalJoin(condition=[=($7, $9)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumConstantGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, sum(u) from
(select *, 2 u from emp as e1 union all
select *, 3 u from emp as e2)
group by rollup(deptno,job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], U=[$9])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], U=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], U=[3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumConstantThroughUnion">
<Resource name="sql">
<![CDATA[select ename, sum(u) from
(select *, 2 u from emp as e1 union all
select *, 3 u from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], U=[$9])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], U=[2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], U=[3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumCountStarGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno,job,sum(empno),count(*),min(deptno),max(empno) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno,job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)], EXPR$3=[COUNT()], EXPR$4=[MIN($0)], EXPR$5=[MAX($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)], EXPR$3=[$SUM0($3)], EXPR$4=[MIN($4)], EXPR$5=[MAX($5)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)], EXPR$3=[COUNT()], EXPR$4=[MIN($0)], EXPR$5=[MAX($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)], EXPR$3=[COUNT()], EXPR$4=[MIN($0)], EXPR$5=[MAX($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumCountStarThroughUnion">
<Resource name="sql">
<![CDATA[select ename,sum(empno),count(*),min(deptno),max(empno) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT()], EXPR$3=[MIN($2)], EXPR$4=[MAX($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0], DEPTNO=[$7])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[$SUM0($2)], EXPR$3=[MIN($3)], EXPR$4=[MAX($4)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT()], EXPR$3=[MIN($2)], EXPR$4=[MAX($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT()], EXPR$3=[MIN($2)], EXPR$4=[MAX($1)])
LogicalProject(ENAME=[$1], EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumNullConstantGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, sum(u) from
(select *, cast(null as integer) u from emp as e1 union all
select *, cast(null as integer) u from emp as e2)
group by rollup(deptno,job)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], U=[$9])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumNullConstantThroughUnion">
<Resource name="sql">
<![CDATA[select ename, sum(u) from
(select *, cast(null as integer) u from emp as e1 union all
select *, cast(null as integer) u from emp as e2)
group by ename]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], U=[$9])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], U=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumNullableGroupingSetsThroughUnion">
<Resource name="sql">
<![CDATA[select deptno, job, sum(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
group by rollup(deptno, job)
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[SUM($2)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)])
LogicalProject(DEPTNO=[$7], JOB=[$2], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumNullableNOGBYThroughUnion">
<Resource name="sql">
<![CDATA[select sum(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject(MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject(MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testPushSumNullableThroughUnion">
<Resource name="sql">
<![CDATA[select ename, sum(mgr) from
(select * from emp as e1 union all
select * from emp as e2)
group by ename
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
LogicalProject(ENAME=[$1], MGR=[$3])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceAllAggregateFunctions">
<Resource name="sql">
<![CDATA[select name, stddev_pop(deptno), avg(deptno), stddev_samp(deptno), var_pop(deptno), var_samp(deptno)
from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], EXPR$2=[AVG($1)], EXPR$3=[STDDEV_SAMP($1)], EXPR$4=[VAR_POP($1)], EXPR$5=[VAR_SAMP($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[CAST(POWER(/(-($1, /(*($2, $2), $3)), $3), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(POWER(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1))), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$4=[CAST(/(-($1, /(*($2, $2), $3)), $3)):INTEGER NOT NULL], EXPR$5=[CAST(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1)))):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($2)], agg#1=[$SUM0($1)], agg#2=[COUNT()])
LogicalProject(NAME=[$0], DEPTNO=[$1], $f2=[*($1, $1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceAverage">
<Resource name="sql">
<![CDATA[select name, max(name), avg(deptno), min(name)
from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($0)], EXPR$2=[AVG($1)], EXPR$3=[MIN($0)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[$4])
LogicalAggregate(group=[{0}], EXPR$1=[MAX($0)], agg#1=[$SUM0($1)], agg#2=[COUNT()], EXPR$3=[MIN($0)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceAverageAndSumWithNoReduceStddevAndVar">
<Resource name="sql">
<![CDATA[select name, stddev_pop(deptno), avg(deptno), var_pop(deptno)
from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], EXPR$2=[AVG($1)], EXPR$3=[VAR_POP($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[$4])
LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], agg#1=[$SUM0($1)], agg#2=[COUNT()], EXPR$3=[VAR_POP($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceAverageAndVarWithNoReduceStddev">
<Resource name="sql">
<![CDATA[select name, stddev_pop(deptno), avg(deptno), var_pop(deptno)
from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], EXPR$2=[AVG($1)], EXPR$3=[VAR_POP($1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(/(-($4, /(*($2, $2), $3)), $3)):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], agg#1=[SUM($1)], agg#2=[COUNT()], agg#3=[SUM($2)])
LogicalProject(NAME=[$0], DEPTNO=[$1], $f2=[*($1, $1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceAverageWithNoReduceSum">
<Resource name="sql">
<![CDATA[select name, max(name), avg(deptno), min(name)
from sales.dept group by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[MAX($0)], EXPR$2=[AVG($1)], EXPR$3=[MIN($0)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[$1], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[$4])
LogicalAggregate(group=[{0}], EXPR$1=[MAX($0)], agg#1=[SUM($1)], agg#2=[COUNT()], EXPR$3=[MIN($0)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCase">
<Resource name="sql">
<![CDATA[select
case when false then cast(2.1 as float)
else cast(1 as integer) end as newcol
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NEWCOL=[CASE(false, 2.1:FLOAT, 1:FLOAT)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NEWCOL=[1E0:FLOAT])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCaseNullabilityChange">
<Resource name="sql">
<![CDATA[select case when empno = 1 then 1
when 1 IS NOT NULL then 2
else null end as qx from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(QX=[CASE(=($0, 1), 1, IS NOT NULL(1), 2, null:INTEGER)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(QX=[CAST(CASE(=($0, 1), 1, 2)):INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCaseWhenWithCast">
<Resource name="planBefore">
<![CDATA[
LogicalProject($f0=[CAST(CASE(=(MOD($0, 2:BIGINT), 1), <($0, 2:BIGINT), =(MOD($0, 3:BIGINT), 2), <($0, 1:BIGINT), <($0, 3:BIGINT))):BOOLEAN])
LogicalValues(tuples=[[{ 1, 2 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCastAndConsts">
<Resource name="sql">
<![CDATA[select * from emp
where cast((empno + (10/2)) as int) = 13]]>
</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=[=(CAST(+($0, /(10, 2))):INTEGER NOT NULL, 13)])
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])
LogicalFilter(condition=[=(+($0, 5), 13)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCastTimeUnchanged">
<Resource name="sql">
<![CDATA[select cast(time '12:34:56' as timestamp) from emp as e]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[CAST(12:34:56):TIMESTAMP(0) NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCasts">
<Resource name="sql">
<![CDATA[select cast(d.name as varchar(128)), cast(e.empno as integer)
from dept as d inner join emp as e
on cast(d.deptno as integer) = cast(e.deptno as integer)
where cast(e.job as varchar(1)) = 'Manager']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[CAST($1):VARCHAR(128) NOT NULL], EXPR$1=[CAST($2):INTEGER NOT NULL])
LogicalFilter(condition=[=(CAST(CAST($4):VARCHAR(1) NOT NULL):VARCHAR(7) NOT NULL, 'Manager')])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$3], ENAME=[$4], JOB=[$5], MGR=[$6], HIREDATE=[$7], SAL=[$8], COMM=[$9], DEPTNO1=[$10], SLACKER=[$11])
LogicalJoin(condition=[=($2, $12)], joinType=[inner])
LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[CAST($0):INTEGER NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[CAST($7):INTEGER NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[CAST($1):VARCHAR(128) NOT NULL], EXPR$1=[$2])
LogicalFilter(condition=[=(CAST(CAST($4):VARCHAR(1) NOT NULL):VARCHAR(7) NOT NULL, 'Manager')])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$3], ENAME=[$4], JOB=[$5], MGR=[$6], HIREDATE=[$7], SAL=[$8], COMM=[$9], DEPTNO1=[$10], SLACKER=[$11])
LogicalJoin(condition=[=($2, $12)], joinType=[inner])
LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCastsNullable">
<Resource name="sql">
<![CDATA[insert into sales.dept(deptno, name)
select empno, cast(job as varchar(128)) from sales.empnullables]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalTableModify(table=[[CATALOG, SALES, DEPT]], operation=[INSERT], flattened=[false])
LogicalProject(DEPTNO=[$0], NAME=[CAST($2):VARCHAR(128)])
LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalTableModify(table=[[CATALOG, SALES, DEPT]], operation=[INSERT], flattened=[false])
LogicalCalc(expr#0..8=[{inputs}], expr#9=[CAST($t2):VARCHAR(10) NOT NULL], DEPTNO=[$t0], NAME=[$t9])
LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceCompositeInSubQuery">
<Resource name="sql">
<![CDATA[select *
from emp
where (empno, deptno) in (
select empno, deptno from (
select empno, deptno
from emp
group by empno, deptno))
or deptno < 40 + 60]]>
</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=[OR(IN($0, $7, {
LogicalProject(EMPNO=[$0], DEPTNO=[$1])
LogicalAggregate(group=[{0, 1}])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), <($7, +(40, 60)))])
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])
LogicalFilter(condition=[OR(IN($0, $7, {
LogicalProject(EMPNO=[$0], DEPTNO=[$1])
LogicalAggregate(group=[{0, 1}])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), <($7, 100))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstants">
<Resource name="sql">
<![CDATA[select 1+2, d.deptno+(3+4), (5+6)+d.deptno, cast(null as integer), coalesce(2,null), row(7+8) from dept d inner join emp e on d.deptno = e.deptno + (5-5) where d.deptno=(7+8) and d.deptno=(8+7) and d.deptno=coalesce(2,null)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+(1, 2)], EXPR$1=[+($0, +(3, 4))], EXPR$2=[+(+(5, 6), $0)], EXPR$3=[null:INTEGER], EXPR$4=[CASE(IS NOT NULL(2), 2, null:INTEGER)], EXPR$5=[ROW(+(7, 8))])
LogicalFilter(condition=[AND(=($0, +(7, 8)), =($0, +(8, 7)), =($0, CASE(IS NOT NULL(2), 2, null:INTEGER)))])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalJoin(condition=[=($0, $11)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+($7, -(5, 5))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[3], EXPR$1=[22], EXPR$2=[26], EXPR$3=[null:INTEGER], EXPR$4=[CAST(2):INTEGER], EXPR$5=[ROW(15)])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstants2">
<Resource name="sql">
<![CDATA[select p1 is not distinct from p0
from (values (2, cast(null as integer))) as t(p0, p1)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[false])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[false])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstants3">
<Resource name="sql">
<![CDATA[select e.mgr is not distinct from f.mgr from emp e join emp f on (e.mgr=f.mgr) where e.mgr is null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[OR(AND(IS NULL($3), IS NULL($12)), IS TRUE(=($3, $12)))])
LogicalFilter(condition=[IS NULL($3)])
LogicalJoin(condition=[=($3, $12)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[IS NULL($12)])
LogicalFilter(condition=[IS NULL($3)])
LogicalJoin(condition=[=($3, $12)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsCalc">
<Resource name="sql">
<![CDATA[select * from (
select upper(substring(x FROM 1 FOR 2) || substring(x FROM 3)) as u,
substring(x FROM 1 FOR 1) as s
from (
select 'table' as x from (values (true))
union
select 'view' from (values (true))
union
select 'foreign table' from (values (true))
)
) where u = 'TABLE']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(U=[$0], S=[$1])
LogicalFilter(condition=[=($0, 'TABLE')])
LogicalProject(U=[UPPER(||(SUBSTRING($0, 1, 2), SUBSTRING($0, 3)))], S=[SUBSTRING($0, 1, 1)])
LogicalUnion(all=[false])
LogicalUnion(all=[false])
LogicalProject(X=['table'])
LogicalValues(tuples=[[{ true }]])
LogicalProject(EXPR$0=['view'])
LogicalValues(tuples=[[{ true }]])
LogicalProject(EXPR$0=['foreign table'])
LogicalValues(tuples=[[{ true }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalCalc(expr#0=[{inputs}], expr#1=['TABLE ':VARCHAR(26)], expr#2=['t':VARCHAR(13)], U=[$t1], S=[$t2])
LogicalValues(tuples=[[{ true }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsCaseEquals">
<Resource name="sql">
<![CDATA[select count(1) from emp
where case deptno
when 20 then 2
when 10 then 1
else 3 end = 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[=(CASE(=($7, 20), 2, =($7, 10), 1, 3), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsCaseEquals2">
<Resource name="sql">
<![CDATA[select count(1) from emp
where case deptno
when 20 then 2
when 10 then 1
else cast(null as integer) end = 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[=(CASE(=($7, 20), 2, =($7, 10), 1, null:INTEGER), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsCaseEquals3">
<Resource name="sql">
<![CDATA[select count(1) from emp
where case deptno
when 30 then 1
when 20 then 2
when 10 then 1
when 30 then 111
else 0 end = 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[=(CASE(=($7, 30), 1, =($7, 20), 2, =($7, 10), 1, =($7, 30), 111, 0), 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[SEARCH($7, Sarg[10, 30])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDup">
<Resource name="sql">
<![CDATA[select d.deptno from dept d where d.deptno=7 and d.deptno=8]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[AND(=($0, 7), =($0, 8))])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDup2">
<Resource name="sql">
<![CDATA[select *
from emp
where deptno=7 and deptno=8
and empno = 10 and mgr is null and empno = 10]]>
</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=[AND(=($7, 7), =($7, 8), =($0, 10), IS NULL($3), =($0, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[10], ENAME=[$1], JOB=[$2], MGR=[null:INTEGER], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDup3">
<Resource name="sql">
<![CDATA[select d.deptno from dept d where d.deptno<>7 or d.deptno<>8]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[OR(<>($0, 7), <>($0, 8))])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDup3Null">
<Resource name="sql">
<![CDATA[select e.empno from emp e where e.mgr<>7 or e.mgr<>8]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(<>($3, 7), <>($3, 8))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDupNot">
<Resource name="sql">
<![CDATA[select d.deptno from dept d where not(d.deptno=7 and d.deptno=8)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[NOT(AND(=($0, 7), =($0, 8)))])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDupNot2">
<Resource name="sql">
<![CDATA[select d.deptno from dept d where not(d.deptno=7 and d.name='foo' and d.deptno=8)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[NOT(AND(=($0, 7), =($1, 'foo'), =($0, 8)))])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDupNot2Null">
<Resource name="sql">
<![CDATA[select e.empno from emp e where not(e.mgr=7 and e.deptno=8 and e.mgr=8)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[NOT(AND(=($3, 7), =($7, 8), =($3, 8)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[OR(IS NOT NULL($3), <>($7, 8))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDupNotNull">
<Resource name="sql">
<![CDATA[select e.empno from emp e where not(e.mgr=7 and e.mgr=8)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[NOT(AND(=($3, 7), =($3, 8)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IS NOT NULL($3)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsDynamicFunction">
<Resource name="sql">
<![CDATA[select sal, t
from (select sal, current_timestamp t from emp)
where t > TIMESTAMP '2018-01-01 00:00:00']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$0], T=[$1])
LogicalFilter(condition=[>($1, 2018-01-01 00:00:00)])
LogicalProject(SAL=[$5], T=[CURRENT_TIMESTAMP])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$0], T=[$1])
LogicalFilter(condition=[>($1, 2018-01-01 00:00:00)])
LogicalProject(SAL=[$5], T=[CURRENT_TIMESTAMP])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsEliminatesFilter">
<Resource name="sql">
<![CDATA[select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalFilter(condition=[>(+(1, 2), +(3, null))])
LogicalValues(tuples=[[{ 1, 2 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsIsNotNull">
<Resource name="sql">
<![CDATA[select empno from emp
where empno=10 and empno is not null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[AND(=($0, 10), IS NOT NULL($0))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[=($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsIsNull">
<Resource name="sql">
<![CDATA[select empno from emp where empno=10 and empno is null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[AND(=($0, 10), IS NULL($0))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsNegated">
<Resource name="sql">
<![CDATA[select empno from emp
where empno=10 and not(empno=10)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[AND(=($0, 10), NOT(=($0, 10)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsNegatedInverted">
<Resource name="sql">
<![CDATA[select empno from emp where empno>10 and empno<=10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[AND(>($0, 10), <=($0, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsNonDeterministicFunction">
<Resource name="sql">
<![CDATA[select sal, r
from (select sal, rand() as r from emp)
where r > 0.5]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalFilter(condition=[>($1, 10)])
LogicalProject(SAL=[$5], N=[NDC()])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsNull">
<Resource name="sql">
<![CDATA[select * from (
select *
from (
select cast(null as integer) as n
from emp)
where n is null and n is null)
where n is null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(N=[$0])
LogicalFilter(condition=[IS NULL($0)])
LogicalProject(N=[$0])
LogicalFilter(condition=[AND(IS NULL($0), IS NULL($0))])
LogicalProject(N=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(N=[$0])
LogicalProject(N=[$0])
LogicalProject(N=[null:INTEGER])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsNullEqualsOne">
<Resource name="sql">
<![CDATA[select count(1) from emp where cast(null as integer) = 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalFilter(condition=[=(null, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
LogicalProject($f0=[1])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsProjectNullable">
<Resource name="sql">
<![CDATA[select mgr from emp where mgr=10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(MGR=[$3])
LogicalFilter(condition=[=($3, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(MGR=[CAST(10):INTEGER])
LogicalFilter(condition=[=($3, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsRequiresExecutor">
<Resource name="sql">
<![CDATA[select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalFilter(condition=[>(+(1, 2), +(3, null))])
LogicalValues(tuples=[[{ 1, 2 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceConstantsWindow">
<Resource name="sql">
<![CDATA[select col1, col2, col3
from (
select empno,
sum(100) over (partition by deptno, sal order by sal) as col1,
sum(100) over (partition by sal order by deptno) as col2,
sum(sal) over (partition by deptno order by sal) as col3
from emp where sal = 5000)]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject($0=[$2], $1=[$3], $2=[$4])
LogicalWindow(window#0=[window(partition {1} range between UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM($2)])], window#1=[window(order by [1] aggs [SUM($2)])], window#2=[window(partition {1} range between UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM(5000)])])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalFilter(condition=[=($5, 5000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(COL1=[SUM(100) OVER (PARTITION BY $7, $5 ORDER BY $5)], COL2=[SUM(100) OVER (PARTITION BY $5 ORDER BY $7)], COL3=[SUM($5) OVER (PARTITION BY $7 ORDER BY $5)])
LogicalFilter(condition=[=($5, 5000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceDecimal">
<Resource name="sql">
<![CDATA[select ename from emp where sal > cast (100.0 as decimal(4, 1))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[>($5, 100.0:DECIMAL(4, 1))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalCalc(expr#0..8=[{inputs}], expr#9=[10:BIGINT], expr#10=[*($t5, $t9)], expr#11=[100.0:DECIMAL(4, 1)], expr#12=[Reinterpret($t11)], expr#13=[>($t10, $t12)], proj#0..8=[{exprs}], $condition=[$t13])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceExpressionsNot">
<Resource name="sql">
<![CDATA[select * from (values (false),(true)) as q (col1) where not(col1)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(COL1=[$0])
LogicalFilter(condition=[NOT($0)])
LogicalValues(tuples=[[{ false }, { true }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(COL1=[$0])
LogicalFilter(condition=[NOT($0)])
LogicalValues(tuples=[[{ false }, { true }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceNestedCaseWhen">
<Resource name="sql">
<![CDATA[select sal
from emp
where case when (sal = 1000) then
(case when sal = 1000 then null else 1 end is null) else
(case when sal = 2000 then null else 1 end is null) end is true]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[SEARCH($5, Sarg[1000, 2000])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[IS TRUE(CASE(=($5, 1000), IS NULL(CASE(=($5, 1000), null:INTEGER, 1)), IS NULL(CASE(=($5, 2000), null:INTEGER, 1))))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceNot">
<Resource name="sql">
<![CDATA[select *
from (select (case when sal > 1000 then null else false end) as caseCol from emp)
where NOT(caseCol)]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(CASECOL=[$0])
LogicalFilter(condition=[NOT($0)])
LogicalProject(CASECOL=[CASE(>($5, 1000), null, false)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(CASECOL=[$0])
LogicalFilter(condition=[NOT($0)])
LogicalProject(CASECOL=[AND(>($5, 1000), null)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceNullableCase">
<Resource name="sql">
<![CDATA[SELECT CASE WHEN 1=2 THEN cast((values(1)) as integer) ELSE 2 end from (values(1))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[CAST(2):INTEGER])
LogicalJoin(condition=[true], joinType=[left])
LogicalValues(tuples=[[{ 1 }]])
LogicalValues(tuples=[[{ 1 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[CAST(2):INTEGER])
LogicalJoin(condition=[true], joinType=[left])
LogicalValues(tuples=[[{ 1 }]])
LogicalValues(tuples=[[{ 1 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceNullableCase2">
<Resource name="sql">
<![CDATA[SELECT deptno, ename, CASE WHEN 1=2 THEN substring(ename, 1, cast(2 as int)) ELSE NULL end from emp group by deptno, ename, case when 1=2 then substring(ename,1, cast(2 as int)) else null end]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0, 1, 2}])
LogicalProject(DEPTNO=[$7], ENAME=[$1], EXPR$2=[null:VARCHAR(20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1, 2}])
LogicalProject(DEPTNO=[$7], ENAME=[$1], EXPR$2=[null])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceNullableToNotNull">
<Resource name="sql">
<![CDATA[select
empno + case when 'a' = 'a' then 1 else null end as newcol
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NEWCOL=[+($0, CASE(=('a', 'a'), 1, null:INTEGER))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NEWCOL=[+($0, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceNullableToNotNull2">
<Resource name="sql">
<![CDATA[select
empno + case when 'a' = 'a' then 1 else null end as newcol
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NEWCOL=[+($0, CASE(=('a', 'a'), 1, null:INTEGER))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NEWCOL=[+($0, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceOrCaseWhen">
<Resource name="sql">
<![CDATA[select sal
from emp
where case when sal = 1000 then null else 1 end is null
OR case when sal = 2000 then null else 1 end is null]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[SEARCH($5, Sarg[1000, 2000])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[OR(IS NULL(CASE(=($5, 1000), null:INTEGER, 1)), IS NULL(CASE(=($5, 2000), null:INTEGER, 1)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceValuesNull">
<Resource name="sql">
<![CDATA[insert into EMPNULLABLES(EMPNO, ENAME, JOB) (select 0, 'null', NULL)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalTableModify(table=[[CATALOG, SALES, EMPNULLABLES]], operation=[INSERT], flattened=[false])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[null:INTEGER], COMM=[null:INTEGER], DEPTNO=[null:INTEGER], SLACKER=[null:BOOLEAN])
LogicalValues(tuples=[[{ 0, 'null', null }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalTableModify(table=[[CATALOG, SALES, EMPNULLABLES]], operation=[INSERT], flattened=[false])
LogicalValues(tuples=[[{ 0, 'null', null, null, null, null, null, null, null }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceValuesToEmpty">
<Resource name="sql">
<![CDATA[select a + b as x, b, a from (values (10, 1), (30, 7)) as t(a, b)
where a - b < 0]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[+($0, $1)], B=[$1], A=[$0])
LogicalFilter(condition=[<(-($0, $1), 0)])
LogicalValues(tuples=[[{ 10, 1 }, { 30, 7 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceValuesUnderFilter">
<Resource name="sql">
<![CDATA[select a, b from (values (10, 'x'), (20, 'y')) as t(a, b) where a < 15]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(A=[$0], B=[$1])
LogicalFilter(condition=[<($0, 15)])
LogicalValues(tuples=[[{ 10, 'x' }, { 20, 'y' }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(A=[$0], B=[$1])
LogicalValues(tuples=[[{ 10, 'x' }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceValuesUnderProject">
<Resource name="sql">
<![CDATA[select a + b from (values (10, 1), (20, 3)) as t(a, b)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[+($0, $1)])
LogicalValues(tuples=[[{ 10, 1 }, { 20, 3 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[{ 11 }, { 23 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testReduceValuesUnderProjectFilter">
<Resource name="sql">
<![CDATA[select a + b as x, b, a
from (values (10, 1), (30, 7), (20, 3)) as t(a, b)
where a - b < 21]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(X=[+($0, $1)], B=[$1], A=[$0])
LogicalFilter(condition=[<(-($0, $1), 21)])
LogicalValues(tuples=[[{ 10, 1 }, { 30, 7 }, { 20, 3 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalValues(tuples=[[{ 11, 1, 10 }, { 23, 3, 20 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testRemoveDistinctOnAgg">
<Resource name="sql">
<![CDATA[SELECT empno, SUM(distinct sal), MIN(sal), MIN(distinct sal), MAX(distinct sal), bit_and(distinct sal), bit_or(sal), count(distinct sal) from sales.emp group by empno, deptno
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$2], EXPR$2=[$3], EXPR$3=[$3], EXPR$4=[$4], EXPR$5=[$5], EXPR$6=[$6], EXPR$7=[$7])
LogicalAggregate(group=[{0, 1}], EXPR$1=[SUM(DISTINCT $2)], EXPR$2=[MIN($2)], EXPR$4=[MAX($2)], EXPR$5=[BIT_AND($2)], EXPR$6=[BIT_OR($2)], EXPR$7=[COUNT(DISTINCT $2)])
LogicalProject(EMPNO=[$0], DEPTNO=[$7], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], EXPR$1=[$5], EXPR$2=[$5], EXPR$3=[$5], EXPR$4=[$5], EXPR$5=[$5], EXPR$6=[$5], EXPR$7=[1:BIGINT])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testRemoveSemiJoin">
<Resource name="sql">
<![CDATA[select e.ename from emp e, dept d
where e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[=($7, $9)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testRemoveSemiJoinRight">
<Resource name="sql">
<![CDATA[select e1.ename from emp e1, dept d, emp e2
where e1.deptno = d.deptno and d.deptno = e2.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($9, $18))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($9, $18)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testRemoveSemiJoinRightWithFilter">
<Resource name="sql">
<![CDATA[select e1.ename from emp e1, dept d, emp e2
where e1.deptno = d.deptno and d.deptno = e2.deptno
and d.name = 'foo']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($9, $18), =($10, 'foo'))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($9, $18)], joinType=[inner], semiJoinDone=[true])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($1, 'foo')])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testRemoveSemiJoinWithFilter">
<Resource name="sql">
<![CDATA[select e.ename from emp e, dept d
where e.deptno = d.deptno and e.ename = 'foo']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalFilter(condition=[AND(=($7, $9), =($1, 'foo'))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$1])
LogicalJoin(condition=[=($7, $9)], joinType=[inner], semiJoinDone=[true])
LogicalFilter(condition=[=($1, 'foo')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptyAntiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[=($7, $8)], joinType=[anti])
LogicalTableScan(table=[[scott, EMP]])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptyAntiJoinNonEqui">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[AND(=($7, $8), =($5, 2000))], joinType=[anti])
LogicalTableScan(table=[[scott, EMP]])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalTableScan(table=[[scott, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptyFullJoin">
<Resource name="sql">
<![CDATA[select * from emp e
full join (select * from dept where false) as d
on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptyInnerJoin">
<Resource name="sql">
<![CDATA[select * from emp e
join (select * from dept where false) as d
on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptyLeftJoin">
<Resource name="sql">
<![CDATA[select * from emp e
left join (select * from dept where false) as d
on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptyRightJoin">
<Resource name="sql">
<![CDATA[select * from emp e
right join (select * from dept where false) as d
on e.deptno = d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalFilter(condition=[false])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightEmptySemiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[=($7, $8)], joinType=[semi])
LogicalTableScan(table=[[scott, EMP]])
LogicalValues(tuples=[[]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testRightOuterJoinSimplificationToInner">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d right outer join sales.emp e
on d.deptno = e.deptno
where d.name = 'Charlie']]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[=($1, 'Charlie')])
LogicalJoin(condition=[=($0, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalProject(DEPTNO=[CAST($0):INTEGER], NAME=[CAST($1):VARCHAR(10)], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalFilter(condition=[=($1, 'Charlie')])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSelectAnyCorrelated">
<Resource name="sql">
<![CDATA[select empno > ANY (
select deptno from dept where emp.job = dept.name)
from emp
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[> SOME($0, {
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EXPR$0=[CAST(OR(AND(IS TRUE(>($0, $9)), IS NOT TRUE(OR(IS NULL($12), =($10, 0)))), AND(IS TRUE(>($10, $11)), null, IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9))), AND(>($0, $9), IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9)), IS NOT TRUE(>($10, $11))))):BOOLEAN NOT NULL])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$0], c=[$1], d=[$1], trueLiteral=[true])
LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[CAST(OR(AND(IS TRUE(>($0, $9)), IS NOT TRUE(OR(IS NULL($12), =($10, 0)))), AND(IS TRUE(>($10, $11)), null, IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9))), AND(>($0, $9), IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9)), IS NOT TRUE(>($10, $11))))):BOOLEAN NOT NULL])
LogicalJoin(condition=[=($2, $13)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$1], c=[$2], d=[$2], trueLiteral=[true], NAME=[$0])
LogicalAggregate(group=[{0}], m=[MIN($1)], c=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSelectNotInCorrelated">
<Resource name="sql">
<![CDATA[select sal,
empno NOT IN (
select deptno from dept
where emp.job=dept.name)
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5], EXPR$1=[NOT(IN($0, {
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
}))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(SAL=[$5], EXPR$1=[IS NULL($10)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0, 2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($cor0.EMPNO, $0)])
LogicalProject(DEPTNO=[$0], i=[true])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5], EXPR$1=[IS NULL($10)])
LogicalJoin(condition=[AND(=($0, $9), =($2, $11))], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], i=[true], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinProjectTranspose">
<Resource name="sql">
<![CDATA[select a.name from dept a
where a.deptno in (select b.deptno * 2 from dept);
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $3)], joinType=[semi])
LogicalTableScan(table=[[scott, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject($f0=[*(2, $0)])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DNAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalProject(DEPTNO=[$0], DNAME=[$1])
LogicalTableScan(table=[[scott, DEPT]])
LogicalProject($f0=[$0])
LogicalAggregate(group=[{0}])
LogicalProject($f0=[*(2, $0)])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinReduceConstants">
<Resource name="sql">
<![CDATA[select e1.sal
from (select * from emp where deptno = 200) as e1
where e1.deptno in (
select e2.deptno from emp e2 where e2.sal = 100)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$0])
LogicalJoin(condition=[=($1, $2)], joinType=[semi])
LogicalFilter(condition=[=($1, 200)])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$1])
LogicalFilter(condition=[=($0, 100)])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$0])
LogicalJoin(condition=[=(200, $2)], joinType=[semi])
LogicalFilter(condition=[=($1, 200)])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$1])
LogicalFilter(condition=[=($0, 100)])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinRule">
<Resource name="sql">
<![CDATA[select dept.* from dept join (
select distinct deptno from emp
where sal > 100) using (deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinRuleExists">
<Resource name="sql">
<![CDATA[select * from dept where exists (
select * from emp
where emp.deptno = dept.deptno
and emp.sal > 100)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinRuleFull">
<Resource name="sql">
<![CDATA[select dept.* from dept full join (
select distinct deptno from emp
where sal > 100) using (deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinRuleLeft">
<Resource name="sql">
<![CDATA[select name from dept left join (
select distinct deptno from emp
where sal > 100) using (deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinRuleRight">
<Resource name="sql">
<![CDATA[select dept.* from dept right join (
select distinct deptno from emp
where sal > 100) using (deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalJoin(condition=[=($0, $2)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSemiJoinTrim">
<Resource name="sql">
<![CDATA[select s.deptno from (select * from dept where exists (
select * from emp
where emp.deptno = dept.deptno
and emp.sal > 100)) s join customer.account on s.deptno = account.acctno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[=($0, $2)], joinType=[inner])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7], $f0=[true])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, CUSTOMER, ACCOUNT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalJoin(condition=[=($0, $1)], joinType=[semi])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$1])
LogicalFilter(condition=[>($0, 100)])
LogicalProject(SAL=[$5], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(ACCTNO=[$0])
LogicalTableScan(table=[[CATALOG, CUSTOMER, ACCOUNT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSimplifyFilter">
<Resource name="sql">
<![CDATA[select * from (select * from sales.emp where deptno > 10)
where empno > 3 and deptno > 5]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[AND(>($0, 3), >($7, 5))])
LogicalFilter(condition=[>($7, 10)])
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])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[>($0, 3)])
LogicalFilter(condition=[>($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSimplifyItemIsNotNull">
<Resource name="sql">
<![CDATA[select *
from sales.customer as t1
where t1.c_nationkey[0] is not null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(**=[$1])
LogicalFilter(condition=[IS NOT NULL(ITEM($0, 0))])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
</TestCase>
<TestCase name="testSimplifyItemIsNull">
<Resource name="sql">
<![CDATA[select * from sales.customer as t1 where t1.c_nationkey[0] is null]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(**=[$1])
LogicalFilter(condition=[IS NULL(ITEM($0, 0))])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
</TestCase>
<TestCase name="testSkipReduceConstantsCaseEquals">
<Resource name="sql">
<![CDATA[select * from emp e1, emp e2
where coalesce(e1.mgr, -1) = coalesce(e2.mgr, -1)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalFilter(condition=[=(CASE(IS NOT NULL($3), CAST($3):INTEGER NOT NULL, -1), CASE(IS NOT NULL($12), CAST($12):INTEGER NOT NULL, -1))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
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], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalJoin(condition=[=(CASE(IS NOT NULL($3), CAST($3):INTEGER NOT NULL, -1), CASE(IS NOT NULL($12), CAST($12):INTEGER NOT NULL, -1))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSome">
<Resource name="sql">
<![CDATA[select * from emp e1
where e1.empno > SOME (select deptno from dept)]]>
</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=[> SOME($0, {
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(AND(IS TRUE(>($0, $9)), <>($10, 0)), AND(>($10, $11), null, <>($10, 0), IS NOT TRUE(>($0, $9))), AND(>($0, $9), <>($10, 0), IS NOT TRUE(>($0, $9)), <=($10, $11)))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$0], c=[$1], d=[$1])
LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(AND(IS TRUE(>($0, $9)), <>($10, 0)), AND(>($10, $11), null, <>($10, 0), IS NOT TRUE(>($0, $9))), AND(>($0, $9), <>($10, 0), IS NOT TRUE(>($0, $9)), <=($10, $11)))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$0], c=[$1], d=[$1])
LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSomeWithEquality">
<Resource name="sql">
<![CDATA[select * from emp e1
where e1.deptno = SOME (select deptno from dept)]]>
</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=[IN($7, {
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSomeWithEquality2">
<Resource name="sql">
<![CDATA[select * from emp e1
where e1.ename= SOME (select name from dept)]]>
</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=[IN($1, {
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSomeWithNotEquality">
<Resource name="sql">
<![CDATA[select * from emp e1
where e1.deptno <> SOME (select deptno from dept)]]>
</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=[<> SOME($7, {
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(AND(<>($10, $9), <=($10, 1), OR(<>($7, $11), null), <>($9, 0)), AND(=($10, 1), <>($7, $11), <>($9, 0), OR(=($10, $9), >($10, 1))), AND(<>($9, 0), OR(=($10, $9), >($10, 1)), <>($10, 1)))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(c=[$0], d=[$0], m=[$1])
LogicalAggregate(group=[{}], c=[COUNT()], m=[MAX($0)])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(AND(<>($10, $9), <=($10, 1), OR(<>($7, $11), null), <>($9, 0)), AND(=($10, 1), <>($7, $11), <>($9, 0), OR(=($10, $9), >($10, 1))), AND(<>($9, 0), OR(=($10, $9), >($10, 1)), <>($10, 1)))])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(c=[$0], d=[$0], m=[$1])
LogicalAggregate(group=[{}], c=[COUNT()], m=[MAX($0)])
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinCopyInnerJoinOrderBy">
<Resource name="sql">
<![CDATA[select * from sales.emp join sales.dept on
sales.emp.deptno = sales.dept.deptno order by sal]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], dir0=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], dir0=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalSort(sort0=[$5], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinCopyInnerJoinOrderByLimit">
<Resource name="sql">
<![CDATA[select * from sales.emp e join (
select * from sales.dept d) d on e.deptno = d.deptno
order by sal limit 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], dir0=[ASC], fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], dir0=[ASC], fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalSort(sort0=[$5], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinCopyInnerJoinOrderByTwoFields">
<Resource name="sql">
<![CDATA[select * from sales.emp e join sales.dept d on
e.deptno = d.deptno order by e.sal,d.name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], sort1=[$10], dir0=[ASC], dir1=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], sort1=[$10], dir0=[ASC], dir1=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalSort(sort0=[$5], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalSort(sort0=[$1], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinCopySemiJoinOrderBy">
<Resource name="sql">
<![CDATA[select * from sales.dept d where d.deptno in
(select e.deptno from sales.emp e) order by d.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinCopySemiJoinOrderByLimitOffset">
<Resource name="sql">
<![CDATA[select * from sales.dept d where d.deptno in
(select e.deptno from sales.emp e) order by d.deptno limit 10 offset 2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], offset=[2], fetch=[10])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], offset=[2], fetch=[10])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinCopySemiJoinOrderByOffset">
<Resource name="sql">
<![CDATA[select * from sales.dept d where d.deptno in (select e.deptno from sales.emp e) order by d.deptno offset 2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], offset=[2])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], offset=[2])
LogicalJoin(condition=[=($0, $2)], joinType=[semi])
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose1">
<Resource name="sql">
<![CDATA[select * from sales.emp e left join (
select * from sales.dept d) d on e.deptno = d.deptno
order by sal limit 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], dir0=[ASC], fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], dir0=[ASC], fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalSort(sort0=[$5], dir0=[ASC], fetch=[10])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose2">
<Resource name="sql">
<![CDATA[select * from sales.emp e right join (
select * from sales.dept d) d on e.deptno = d.deptno
order by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$10], dir0=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$10], dir0=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalSort(sort0=[$1], dir0=[ASC])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose3">
<Resource name="sql">
<![CDATA[select * from sales.emp e left join (
select * from sales.dept) d on e.deptno = d.deptno
order by sal, name limit 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], sort1=[$10], dir0=[ASC], dir1=[ASC], fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$5], sort1=[$10], dir0=[ASC], dir1=[ASC], fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose4">
<Resource name="sql">
<![CDATA[select * from sales.emp e right join (
select * from sales.dept d) d on e.deptno = d.deptno
order by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$10], dir0=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(sort0=[$10], dir0=[ASC])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalSort(sort0=[$1], dir0=[ASC])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose5">
<Resource name="sql">
<![CDATA[select * from sales.emp e right join (
select * from sales.dept d) d on e.deptno = d.deptno
limit 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalSort(fetch=[10])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalSort(fetch=[10])
LogicalJoin(condition=[=($7, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalSort(fetch=[10])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose6">
<Resource name="sql">
<![CDATA[select d.deptno, empno from sales.dept d
right join sales.emp e using (deptno) limit 10 offset 2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EMPNO=[$2])
LogicalSort(offset=[2], fetch=[10])
LogicalJoin(condition=[=($0, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EMPNO=[$2])
LogicalSort(offset=[2], fetch=[10])
LogicalJoin(condition=[=($0, $9)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalSort(offset=[2], fetch=[10])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortJoinTranspose7">
<Resource name="sql">
<![CDATA[select d.deptno, empno from sales.dept d
left join sales.emp e using (deptno) order by d.deptno offset 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], EMPNO=[$2])
LogicalSort(sort0=[$0], dir0=[ASC], offset=[1])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EMPNO=[$2])
LogicalSort(sort0=[$0], dir0=[ASC], offset=[1])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortProjectTranspose1">
<Resource name="sql">
<![CDATA[select d.deptno from sales.dept d
order by cast(d.deptno as integer) offset 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$1], dir0=[ASC], offset=[1])
LogicalProject(DEPTNO=[$0], EXPR$1=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$0])
LogicalSort(sort0=[$0], dir0=[ASC], offset=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortProjectTranspose2">
<Resource name="sql">
<![CDATA[select d.deptno from sales.dept d
order by cast(d.deptno as double) offset 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$1], dir0=[ASC], offset=[1])
LogicalProject(DEPTNO=[$0], EXPR$1=[CAST($0):DOUBLE NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[CAST($0):DOUBLE NOT NULL])
LogicalSort(sort0=[$0], dir0=[ASC], offset=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortProjectTranspose3">
<Resource name="sql">
<![CDATA[select d.deptno from sales.dept d
order by cast(d.deptno as varchar(10)) offset 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$1], dir0=[ASC], offset=[1])
LogicalProject(DEPTNO=[$0], EXPR$1=[CAST($0):VARCHAR(10) NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$1], dir0=[ASC], offset=[1])
LogicalProject(DEPTNO=[$0], EXPR$1=[CAST($0):VARCHAR(10) NOT NULL])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortRemovalAllKeysConstant">
<Resource name="sql">
<![CDATA[select count(*) as c
from sales.emp
where deptno = 10
group by deptno, sal
order by deptno desc nulls last]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$1], dir0=[DESC-nulls-last])
LogicalProject(C=[$2], DEPTNO=[$0])
LogicalAggregate(group=[{0, 1}], C=[COUNT()])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(C=[$2], DEPTNO=[$0])
LogicalAggregate(group=[{0, 1}], C=[COUNT()])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortRemovalOneKeyConstant">
<Resource name="sql">
<![CDATA[select count(*) as c
from sales.emp
where deptno = 10
group by deptno, sal
order by deptno, sal desc nulls first]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$1], sort1=[$2], dir0=[ASC], dir1=[DESC])
LogicalProject(C=[$2], DEPTNO=[$0], SAL=[$1])
LogicalAggregate(group=[{0, 1}], C=[COUNT()])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$2], dir0=[DESC])
LogicalProject(C=[$2], DEPTNO=[$0], SAL=[$1])
LogicalAggregate(group=[{0, 1}], C=[COUNT()])
LogicalProject(DEPTNO=[$7], SAL=[$5])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortUnionTranspose">
<Resource name="sql">
<![CDATA[select a.name from dept a
union all
select b.name from dept b
order by name limit 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[10])
LogicalProject(NAME=[$0])
LogicalUnion(all=[true])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[10])
LogicalUnion(all=[true])
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[10])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[10])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortUnionTranspose2">
<Resource name="sql">
<![CDATA[select a.name from dept a
union all
select b.name from dept b
order by name]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalProject(NAME=[$0])
LogicalUnion(all=[true])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalUnion(all=[true])
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalSort(sort0=[$0], dir0=[ASC])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortUnionTranspose3">
<Resource name="sql">
<![CDATA[select a.name from dept a
union all
select b.name from dept b
order by name limit 0]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[0])
LogicalProject(NAME=[$0])
LogicalUnion(all=[true])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[0])
LogicalUnion(all=[true])
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[0])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalSort(sort0=[$0], dir0=[ASC], fetch=[0])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialContainsPoint">
<Resource name="sql">
<![CDATA[select *
from GEO.Restaurants as r
where ST_Contains(
ST_Buffer(ST_Point(10.0, 20.0), 6),
ST_Point(r.longitude, r.latitude))]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[ST_CONTAINS(ST_BUFFER(ST_POINT(10.0:DECIMAL(3, 1), 20.0:DECIMAL(3, 1)), 6), ST_POINT($2, $1))])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[AND(SEARCH($4, Sarg[[33033..33035], [33050..33053], [33055..33080], [33092..33100], [33112..33156], [33164..33176], [33236..33244], [33252..33254], [36456..36464], [36496..36520]]), ST_CONTAINS(MULTIPOLYGON (((16 20, 15.987153539431617 20.39241877538086, 15.948669168242859 20.78315715332031, 15.884711682419379 21.17054193209677, 15.795554957734407 21.552914270615126, 15.68158077697063 21.92863679181897, 15.543277195067716 22.296100594190538, 15.381236449196127 22.65373214131401, 15.196152422706628 23, 14.98881767381527 23.333421398117615, 14.76012004174741 23.652568574052324, 14.511038844873863 23.956074890600412, 14.242640687119284 24.242640687119284, 13.956074890600412 24.511038844873866, 13.652568574052323 24.760120041747413, 13.333421398117613 24.988817673815273, 13 25.196152422706632, 12.653732141314007 25.38123644919613, 12.296100594190538 25.54327719506772, 11.928636791818969 25.681580776970634, 11.552914270615124 25.79555495773441, 11.17054193209677 25.884711682419383, 10.78315715332031 25.948669168242862, 10.392418775380857 25.98715353943162, 10 26, 9.60758122461914 25.987153539431617, 9.21684284667969 25.94866916824286, 8.82945806790323 25.88471168241938, 8.447085729384876 25.795554957734407, 8.07136320818103 25.68158077697063, 7.703899405809461 25.543277195067716, 7.346267858685993 25.381236449196127, 7 25.19615242270663, 6.666578601882387 24.98881767381527, 6.347431425947676 24.76012004174741, 6.043925109399586 24.511038844873863, 5.757359312880714 24.242640687119284, 5.488961155126135 23.956074890600412, 5.239879958252589 23.652568574052324, 5.011182326184728 23.33342139811761, 4.803847577293368 23, 4.6187635508038705 22.653732141314006, 4.45672280493228 22.296100594190538, 4.318419223029367 21.92863679181897, 4.204445042265591 21.552914270615123, 4.115288317580618 21.170541932096768, 4.051330831757139 20.78315715332031, 4.01284646056838 20.392418775380857, 4 20, 4.012846460568384 19.60758122461914, 4.051330831757142 19.21684284667969, 4.115288317580622 18.82945806790323, 4.204445042265594 18.447085729384874, 4.31841922302937 18.07136320818103, 4.456722804932283 17.703899405809462, 4.618763550803873 17.34626785868599, 4.803847577293371 17, 5.011182326184731 16.666578601882385, 5.239879958252591 16.347431425947676, 5.4889611551261375 16.043925109399588, 5.757359312880716 15.757359312880714, 6.043925109399588 15.488961155126134, 6.347431425947677 15.239879958252589, 6.666578601882387 15.011182326184727, 7.000000000000001 14.803847577293368, 7.346267858685993 14.61876355080387, 7.703899405809462 14.45672280493228, 8.071363208181031 14.318419223029366, 8.447085729384876 14.20444504226559, 8.82945806790323 14.115288317580617, 9.21684284667969 14.051330831757138, 9.607581224619143 14.01284646056838, 10 14, 10.39241877538086 14.012846460568383, 10.78315715332031 14.051330831757141, 11.17054193209677 14.115288317580621, 11.552914270615124 14.204445042265593, 11.92863679181897 14.31841922302937, 12.296100594190538 14.456722804932284, 12.653732141314007 14.618763550803873, 13 14.803847577293372, 13.333421398117613 15.01118232618473, 13.652568574052324 15.23987995825259, 13.956074890600414 15.488961155126137, 14.242640687119286 15.757359312880716, 14.511038844873866 16.043925109399588, 14.760120041747411 16.347431425947676, 14.988817673815273 16.66657860188239, 15.196152422706632 17, 15.38123644919613 17.346267858685994, 15.54327719506772 17.703899405809462, 15.681580776970634 18.07136320818103, 15.79555495773441 18.447085729384877, 15.884711682419383 18.829458067903232, 15.948669168242862 19.21684284667969, 15.98715353943162 19.607581224619143, 16 20))):GEOMETRY, ST_POINT($2, $1)))])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialDWithinLine">
<Resource name="sql">
<![CDATA[select *
from GEO.Restaurants as r
where ST_DWithin(
ST_MakeLine(ST_Point(8.0, 20.0), ST_Point(12.0, 20.0)),
ST_Point(r.longitude, r.latitude), 4)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[ST_DWITHIN(ST_MAKELINE(ST_POINT(8.0:DECIMAL(2, 1), 20.0:DECIMAL(3, 1)), ST_POINT(12.0:DECIMAL(3, 1), 20.0:DECIMAL(3, 1))), ST_POINT($2, $1), 4)])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[AND(SEARCH($4, Sarg[[33064..33076], [33092..33100], [33112..33156], [33164..33176], [33236..33240], [36457..36459], [36501..36503], [36505..36507], [36517..36519]]), ST_DWITHIN(MULTILINESTRING ((8 20, 12 20)):GEOMETRY, ST_POINT($2, $1), 4))])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialDWithinReversed">
<Resource name="sql">
<![CDATA[select *
from GEO.Restaurants as r
where ST_DWithin(ST_Point(r.longitude, r.latitude),
ST_Point(10.0, 20.0), 6)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[ST_DWITHIN(ST_POINT($2, $1), ST_POINT(10.0:DECIMAL(3, 1), 20.0:DECIMAL(3, 1)), 6)])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[AND(SEARCH($4, Sarg[[33033..33035], [33050..33053], [33055..33080], [33092..33100], [33112..33156], [33164..33176], [33236..33244], [33252..33254], [36456..36464], [36496..36520]]), ST_DWITHIN(ST_POINT($2, $1), POINT (10 20):GEOMETRY, 6))])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialDWithinToHilbert">
<Resource name="sql">
<![CDATA[select *
from GEO.Restaurants as r
where ST_DWithin(ST_Point(10.0, 20.0),
ST_Point(r.longitude, r.latitude), 10)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[ST_DWITHIN(ST_POINT(10.0:DECIMAL(3, 1), 20.0:DECIMAL(3, 1)), ST_POINT($2, $1), 10)])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[AND(SEARCH($4, Sarg[[28988..28989], [28991..28994], [29006..29009], [29011..29014], [32426..32429], [32431..32434], [32446..32449], [32451..32454], [32506..32509], [32511..32514], [32526..32527], [32929..32930], [32942..32949], [32951..32953], [32955..32970], [32973..32975], [33009..33011], [33014..33185], [33187..33190], [33205..33207], [33209..33211], [33226..33229], [33231..33265], [33267..33270], [36392..36401], [36403..36404], [36421..36423], [36425..36427], [36442..36445], [36447..36548], [36556..36568]]), ST_DWITHIN(POINT (10 20):GEOMETRY, ST_POINT($2, $1), 10))])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialDWithinToHilbertNegative">
<Resource name="sql">
<![CDATA[select *
from GEO.Restaurants as r
where ST_DWithin(ST_Point(10.0, 20.0),
ST_Point(r.longitude, r.latitude), -2)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[ST_DWITHIN(ST_POINT(10.0:DECIMAL(3, 1), 20.0:DECIMAL(3, 1)), ST_POINT($2, $1), -2)])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialDWithinToHilbertZero">
<Resource name="sql">
<![CDATA[select *
from GEO.Restaurants as r
where ST_DWithin(ST_Point(10.0, 20.0),
ST_Point(r.longitude, r.latitude), 0)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[ST_DWITHIN(ST_POINT(10.0:DECIMAL(3, 1), 20.0:DECIMAL(3, 1)), ST_POINT($2, $1), 0)])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], LATITUDE=[$1], LONGITUDE=[$2], CUISINE=[$3], HILBERT=[$4])
LogicalFilter(condition=[AND(=($4, 33139), =(POINT (10 20), ST_POINT($2, $1)))])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
</TestCase>
<TestCase name="testSpatialReduce">
<Resource name="sql">
<![CDATA[select
ST_Buffer(ST_Point(0.0, 1.0), 2) as b
from GEO.Restaurants as r]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(B=[ST_BUFFER(ST_POINT(0.0:DECIMAL(2, 1), 1.0:DECIMAL(2, 1)), 2)])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(B=[CAST(MULTIPOLYGON (((2 1, 1.9957178464772056 1.1308062584602858, 1.9828897227476194 1.2610523844401027, 1.9615705608064595 1.3901806440322562, 1.9318516525781353 1.517638090205041, 1.8938602589902103 1.6428789306063227, 1.8477590650225726 1.7653668647301788, 1.7937454830653756 1.8845773804380017, 1.7320508075688765 1.9999999999999991, 1.6629392246050898 2.1111404660392035, 1.5867066805824699 2.217522858017441, 1.5036796149579543 2.318691630200137, 1.4142135623730947 2.4142135623730945, 1.3186916302001375 2.5036796149579543, 1.217522858017441 2.58670668058247, 1.1111404660392044 2.66293922460509, 0.9999999999999999 2.7320508075688767, 0.8845773804380025 2.7937454830653765, 0.7653668647301795 2.847759065022573, 0.6428789306063231 2.893860258990211, 0.5176380902050415 2.9318516525781364, 0.3901806440322565 2.961570560806461, 0.26105238444010315 2.982889722747621, 0.13080625846028612 2.995717846477207, 0 3, -0.13080625846028585 2.9957178464772056, -0.2610523844401028 2.982889722747619, -0.3901806440322561 2.9615705608064595, -0.517638090205041 2.9318516525781355, -0.6428789306063226 2.8938602589902103, -0.7653668647301789 2.8477590650225726, -0.8845773804380018 2.7937454830653756, -0.9999999999999992 2.7320508075688767, -1.1111404660392037 2.66293922460509, -1.2175228580174406 2.58670668058247, -1.318691630200137 2.5036796149579543, -1.4142135623730945 2.414213562373095, -1.5036796149579543 2.3186916302001377, -1.5867066805824699 2.217522858017441, -1.66293922460509 2.1111404660392044, -1.732050807568877 2, -1.7937454830653763 1.8845773804380026, -1.8477590650225733 1.7653668647301795, -1.8938602589902112 1.6428789306063232, -1.9318516525781366 1.5176380902050415, -1.9615705608064609 1.3901806440322564, -1.9828897227476208 1.2610523844401031, -1.995717846477207 1.130806258460286, -2 1, -1.9957178464772056 0.8691937415397142, -1.9828897227476194 0.7389476155598972, -1.9615705608064595 0.6098193559677438, -1.9318516525781353 0.48236190979495897, -1.8938602589902103 0.3571210693936774, -1.8477590650225726 0.2346331352698211, -1.7937454830653756 0.11542261956199817, -1.7320508075688765 7.7715611723760960e-16, -1.6629392246050898 -0.11114046603920369, -1.5867066805824699 -0.21752285801744065, -1.5036796149579543 -0.318691630200137, -1.4142135623730947 -0.4142135623730945, -1.3186916302001375 -0.5036796149579543, -1.217522858017441 -0.5867066805824699, -1.1111404660392044 -0.66293922460509, -0.9999999999999999 -0.732050807568877, -0.8845773804380025 -0.7937454830653763, -0.7653668647301795 -0.8477590650225733, -0.6428789306063231 -0.8938602589902112, -0.5176380902050415 -0.9318516525781366, -0.3901806440322565 -0.9615705608064609, -0.26105238444010315 -0.9828897227476208, -0.13080625846028612 -0.995717846477207, 0 -1, 0.13080625846028585 -0.9957178464772056, 0.2610523844401028 -0.9828897227476194, 0.3901806440322561 -0.9615705608064595, 0.517638090205041 -0.9318516525781353, 0.6428789306063226 -0.8938602589902103, 0.7653668647301789 -0.8477590650225726, 0.8845773804380018 -0.7937454830653756, 0.9999999999999992 -0.7320508075688765, 1.1111404660392037 -0.6629392246050898, 1.2175228580174406 -0.5867066805824699, 1.318691630200137 -0.5036796149579543, 1.4142135623730945 -0.4142135623730947, 1.5036796149579543 -0.31869163020013747, 1.5867066805824699 -0.2175228580174411, 1.66293922460509 -0.11114046603920436, 1.732050807568877 1.1102230246251565e-16, 1.7937454830653763 0.11542261956199751, 1.8477590650225733 0.23463313526982055, 1.8938602589902112 0.35712106939367694, 1.9318516525781366 0.4823619097949585, 1.9615705608064609 0.6098193559677435, 1.9828897227476208 0.7389476155598969, 1.995717846477207 0.8691937415397138, 2 1))):GEOMETRY):GEOMETRY])
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
]]>
</Resource>
</TestCase>
<TestCase name="testStrengthenJoinType">
<Resource name="sql">
<![CDATA[select *
from dept left join emp on dept.deptno = emp.deptno
where emp.deptno is not null and emp.sal > 100]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalFilter(condition=[AND(IS NOT NULL($9), >($7, 100))])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[CAST($2):INTEGER], ENAME=[CAST($3):VARCHAR(20)], JOB=[CAST($4):VARCHAR(10)], MGR=[$5], HIREDATE=[CAST($6):TIMESTAMP(0)], SAL=[CAST($7):INTEGER], COMM=[CAST($8):INTEGER], DEPTNO0=[CAST($9):INTEGER], SLACKER=[CAST($10):BOOLEAN])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalFilter(condition=[>($5, 100)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testSubQueryWithDynamicStarHang">
<Resource name="sql">
<![CDATA[select n.n_regionkey from (select * from
(select * from sales.customer) t) n where n.n_nationkey >1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(N_REGIONKEY=[ITEM($0, 'N_REGIONKEY')])
LogicalFilter(condition=[>(ITEM($0, 'N_NATIONKEY'), 1)])
LogicalProject(**=[$0])
LogicalTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
EnumerableProject(N_REGIONKEY=[ITEM($0, 'N_REGIONKEY')])
EnumerableFilter(condition=[>(ITEM($0, 'N_NATIONKEY'), 1)])
EnumerableTableScan(table=[[CATALOG, SALES, CUSTOMER]])
]]>
</Resource>
</TestCase>
<TestCase name="testSwapAntiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[=($7, $8)], joinType=[anti])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSwapOuterJoin">
<Resource name="sql">
<![CDATA[select 1 from sales.dept d left outer join sales.emp e
on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalProject(DEPTNO=[$9], NAME=[$10], EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO0=[$7], SLACKER=[$8])
LogicalJoin(condition=[=($9, $7)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSwapOuterJoinFieldAccess">
<Resource name="sql">
<![CDATA[select t1.name, e.ename
from DEPT_NESTED as t1 left outer join sales.emp e
on t1.skill.type = e.job]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$1], ENAME=[$5])
LogicalJoin(condition=[=($2.TYPE, $6)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$10], ENAME=[$1])
LogicalJoin(condition=[=($11.TYPE, $2)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
]]>
</Resource>
</TestCase>
<TestCase name="testSwapSemiJoin">
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalJoin(condition=[=($7, $8)], joinType=[semi])
LogicalTableScan(table=[[scott, EMP]])
LogicalTableScan(table=[[scott, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceAggregate">
<Resource name="sql">
<![CDATA[select 1 from (select deptno, count(*) from sales.emp where deptno > 7
group by deptno) d inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceComplexPredicate">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
inner join sales.emp e on d.deptno = e.deptno
where d.deptno > 7 and e.sal = e.deptno and d.comm = d.deptno
and d.comm + d.deptno > d.comm/2]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[AND(>($7, 7), =($6, $7), >(+($6, $7), /($6, 2)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($5, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[AND(>($7, 7), =($6, $7), >(+($6, $7), /($6, 2)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalFilter(condition=[=($5, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceConjunctInPullUp">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
inner join sales.emp e on d.deptno = e.deptno
where d.deptno in (7, 9) or d.deptno > 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[SEARCH($7, Sarg[7, 9, (10..+∞)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[SEARCH($7, Sarg[7, 9, (10..+∞)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[SEARCH($7, Sarg[7, 9, (10..+∞)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceConstantEquiPredicate">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
inner join sales.emp e on d.deptno = e.deptno where 1 = 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceConstantPredicate">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d inner join sales.emp e on d.deptno = e.deptno where 2 > 1]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
ProjectRel(EXPR$0=[1])
JoinRel(condition=[=($7, $16)], joinType=[inner])
FilterRel(condition=[>(2, 1)])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
ProjectRel(EXPR$0=[1])
JoinRel(condition=[=($7, $16)], joinType=[inner])
FilterRel(condition=[>(2, 1)])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceFullOuterJoin">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d full outer join sales.emp e
on d.deptno = e.deptno where d.deptno > 7 and e.deptno > 9]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[AND(>($7, 7), >($16, 9))])
LogicalJoin(condition=[=($7, $16)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[AND(>($7, 7), >($16, 9))])
LogicalJoin(condition=[=($7, $16)], joinType=[full])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceJoin">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
inner join sales.emp e on d.deptno = e.deptno where e.deptno > 7]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceJoin3way">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
inner join sales.emp e on d.deptno = e.deptno
inner join sales.emp f on e.deptno = f.deptno
where d.deptno > 7]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($16, $25)], joinType=[inner])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($16, $25)], joinType=[inner])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceJoin3wayAgg">
<Resource name="sql">
<![CDATA[select 1 from
(select deptno, count(*) from sales.emp where deptno > 7 group by deptno) d
inner join sales.emp e on d.deptno = e.deptno
inner join sales.emp f on e.deptno = f.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($9, $18)], joinType=[inner])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($9, $18)], joinType=[inner])
LogicalJoin(condition=[=($0, $9)], joinType=[inner])
LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceLeftOuterJoin">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
left outer join sales.emp e on d.deptno = e.deptno
where d.deptno > 7 and e.deptno > 9]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[>($16, 9)])
LogicalJoin(condition=[=($7, $16)], joinType=[left])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[>($16, 9)])
LogicalJoin(condition=[=($7, $16)], joinType=[left])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceNoPullUpExprs">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
inner join sales.emp e on d.deptno = e.deptno
where d.deptno in (7, 9) or d.comm > 10]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[OR(SEARCH($7, Sarg[7, 9]), >($6, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalFilter(condition=[OR(SEARCH($7, Sarg[7, 9]), >($6, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferencePreventProjectPullUp">
<Resource name="sql">
<![CDATA[select 1 from (select comm as deptno from sales.emp where deptno > 7) d
inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalProject(DEPTNO=[$6])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalProject(DEPTNO=[$6])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceProject">
<Resource name="sql">
<![CDATA[select 1 from (select * from sales.emp where deptno > 7) d
inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($7, $16)], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferencePullUpThruAlias">
<Resource name="sql">
<![CDATA[select 1 from (select comm as deptno from sales.emp where comm > 7) d
inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalProject(DEPTNO=[$6])
LogicalFilter(condition=[>($6, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalProject(DEPTNO=[$6])
LogicalFilter(condition=[>($6, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceRightOuterJoin">
<Resource name="sql">
<![CDATA[select 1 from sales.emp d
right outer join sales.emp e on d.deptno = e.deptno
where d.deptno > 7 and e.deptno > 9]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[>($7, 7)])
LogicalJoin(condition=[=($7, $16)], joinType=[right])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 9)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalFilter(condition=[>($7, 7)])
LogicalJoin(condition=[=($7, $16)], joinType=[right])
LogicalFilter(condition=[>($7, 9)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 9)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceUnion">
<Resource name="sql">
<![CDATA[select 1 from
(select deptno from sales.emp where deptno > 7
union all select deptno from sales.emp where deptno > 10) d
inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceUnion3way">
<Resource name="sql">
<![CDATA[select 1 from
(select deptno from sales.emp where deptno > 7
union all
select deptno from sales.emp where deptno > 10
union all
select deptno from sales.emp where deptno > 1) d
inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalUnion(all=[true])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($0, $8)], joinType=[inner])
LogicalUnion(all=[true])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[>($7, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceUnion3wayOr">
<Resource name="sql">
<![CDATA[select 1 from
(select empno, deptno from sales.emp where deptno > 7 or empno < 10
union all
select empno, deptno from sales.emp where deptno > 10 or empno < deptno
union all
select empno, deptno from sales.emp where deptno > 1) d
inner join sales.emp e on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalUnion(all=[true])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[OR(>($7, 7), <($0, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[OR(>($7, 10), <($0, $7))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[>($7, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[1])
LogicalJoin(condition=[=($1, $9)], joinType=[inner])
LogicalUnion(all=[true])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[OR(>($7, 7), <($0, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[OR(>($7, 10), <($0, $7))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], DEPTNO=[$7])
LogicalFilter(condition=[>($7, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testTransitiveInferenceUnionAlwaysTrue">
<Resource name="sql">
<![CDATA[select d.deptno, e.deptno from
(select deptno from sales.emp where deptno < 4) d
inner join
(select deptno from sales.emp where deptno > 7
union all select deptno from sales.emp) e
on d.deptno = e.deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$0], DEPTNO0=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($7, 4)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], DEPTNO0=[$1])
LogicalJoin(condition=[=($0, $1)], joinType=[inner])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[<($7, 4)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[<($0, 4)])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[>($7, 7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testUncorrelatedCallBelowNonComparisonOpIsNotFlattened">
<Resource name="sql">
<![CDATA[select * from emp e1 where exists (select * from emp e2 where (e1.deptno + (e2.deptno+30)) > 0)]]>
</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 NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[>(+($cor0.DEPTNO, +($7, 30)), 0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testUncorrelatedCallInConjunctionIsFlattenedOnlyIfSiblingOfCorrelation">
<Resource name="sql">
<![CDATA[select * from emp e1 where exists (select * from emp e2 where (e2.empno+50) < 20 and e1.deptno >= (30+e2.deptno))]]>
</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 NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalFilter(condition=[AND(<(+($0, 50), 20), >=($cor0.DEPTNO, +(30, $7)))])
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])
LogicalFilter(condition=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{}], agg#0=[MIN($0)])
LogicalProject($f0=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[AND(<(+($0, 50), 20), >=($cor0.DEPTNO, $9))])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f9=[+(30, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testUnionMergeRule">
<Resource name="sql">
<![CDATA[select * from (
select * from (
select name, deptno from dept
union all
select name, deptno from
(
select name, deptno, count(1) from dept group by name, deptno
union all
select name, deptno, count(1) from dept group by name, deptno
) subq
) a
union all
select name, deptno from dept
) aa
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalUnion(all=[true])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalUnion(all=[true])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalUnion(all=[true])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$0], DEPTNO=[$1])
LogicalUnion(all=[true])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testUnionToDistinctRule">
<Resource name="sql">
<![CDATA[select * from dept union select * from dept]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
LogicalUnion(all=[true])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalUnion(all=[false])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereAnyCorrelatedInSelect">
<Resource name="sql">
<![CDATA[select * from emp where empno > ANY (
select deptno from dept where emp.job = dept.name)
]]>
</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=[> SOME($0, {
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(AND(IS TRUE(>($0, $9)), IS NOT TRUE(OR(IS NULL($12), =($10, 0)))), AND(IS TRUE(>($10, $11)), null, IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9))), AND(>($0, $9), IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9)), IS NOT TRUE(>($10, $11))))])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$0], c=[$1], d=[$1], trueLiteral=[true])
LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(AND(>($0, $9), IS NOT TRUE(OR(IS NULL($12), =($10, 0)))), AND(>($0, $9), IS NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9)), IS NOT TRUE(>($10, $11))))])
LogicalJoin(condition=[=($2, $13)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(m=[$1], c=[$2], d=[$2], trueLiteral=[true], NAME=[$0])
LogicalAggregate(group=[{0}], m=[MIN($1)], c=[COUNT()])
LogicalProject(NAME=[$1], DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereExpressionInCorrelated">
<Resource name="sql">
<![CDATA[select ename from (
select ename, deptno, sal + 1 as salPlus from emp) as e
where deptno in (
select deptno from emp where sal + 1 = e.salPlus)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(ENAME=[$0])
LogicalFilter(condition=[IN($1, {
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[=(+($5, 1), $cor0.SALPLUS)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], variablesSet=[[$cor0]])
LogicalProject(ENAME=[$1], DEPTNO=[$7], SALPLUS=[+($5, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(ENAME=[$0])
LogicalProject(ENAME=[$0], DEPTNO=[$1], SALPLUS=[$2])
LogicalFilter(condition=[=($1, $3)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{2}])
LogicalProject(ENAME=[$1], DEPTNO=[$7], SALPLUS=[+($5, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[=(+($5, 1), $cor0.SALPLUS)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(ENAME=[$0])
LogicalJoin(condition=[AND(=($2, $4), =($1, $3))], joinType=[inner])
LogicalProject(ENAME=[$1], DEPTNO=[$7], SALPLUS=[+($5, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], $f9=[+($5, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereExpressionInCorrelated2">
<Resource name="sql">
<![CDATA[select name from (
select name, deptno, deptno - 10 as deptnoMinus from dept) as d
where deptno in (
select deptno from emp where sal + 1 = d.deptnoMinus)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(NAME=[$0])
LogicalFilter(condition=[IN($1, {
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[=(+($5, 1), $cor0.DEPTNOMINUS)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], variablesSet=[[$cor0]])
LogicalProject(NAME=[$1], DEPTNO=[$0], DEPTNOMINUS=[-($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(NAME=[$0])
LogicalProject(NAME=[$0], DEPTNO=[$1], DEPTNOMINUS=[$2])
LogicalFilter(condition=[=($1, $3)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{2}])
LogicalProject(NAME=[$1], DEPTNO=[$0], DEPTNOMINUS=[-($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[=(+($5, 1), $cor0.DEPTNOMINUS)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0])
LogicalJoin(condition=[AND(=($2, $4), =($1, $3))], joinType=[inner])
LogicalProject(NAME=[$1], DEPTNO=[$0], DEPTNOMINUS=[-($0, 10)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0, 1}])
LogicalProject(DEPTNO=[$7], $f9=[+($5, 1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereInCorrelated">
<Resource name="sql">
<![CDATA[select sal from emp where empno IN (
select deptno from dept where emp.job = dept.name)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[IN($0, {
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($0, $9)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalJoin(condition=[AND(=($2, $10), =($0, $9))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereInJoinCorrelated">
<Resource name="sql">
<![CDATA[select empno from emp as e
join dept as d using (deptno)
where e.sal in (
select e2.sal from emp as e2 where e2.deptno > e.deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[IN($5, {
LogicalProject(SAL=[$5])
LogicalFilter(condition=[>($7, $cor0.DEPTNO)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})], variablesSet=[[$cor0]])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalFilter(condition=[=($5, $11)])
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{7}])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalAggregate(group=[{0}])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[>($7, $cor0.DEPTNO)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereNotInCorrelated">
<Resource name="sql">
<![CDATA[select sal from emp
where empno NOT IN (
select deptno from dept
where emp.job = dept.name)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[NOT(IN($0, {
LogicalProject(DEPTNO=[$0])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
}))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalFilter(condition=[OR(=($9, 0), IS NOT TRUE(OR(IS NOT NULL($13), <($10, $9))))])
LogicalJoin(condition=[AND(=($0, $12), =($2, $14))], joinType=[left])
LogicalJoin(condition=[=($2, $11)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(c=[$1], ck=[$1], NAME=[$0])
LogicalAggregate(group=[{0}], c=[COUNT()])
LogicalProject(NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(DEPTNO=[$0], i=[true], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(=($9, 0), IS NOT TRUE(OR(IS NOT NULL($12), <($10, $9))))])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0, 2}])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{2}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(c=[$0], ck=[$0])
LogicalAggregate(group=[{}], c=[COUNT()])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalFilter(condition=[=($cor0.EMPNO, $0)])
LogicalProject(DEPTNO=[$0], i=[true])
LogicalFilter(condition=[=($cor0.JOB, $1)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereNotInCorrelated2">
<Resource name="sql">
<![CDATA[select * from emp e1
where e1.empno NOT IN
(select empno from (select ename, empno, sal as r from emp) e2
where r > 2 and e1.ename= e2.ename)]]>
</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=[NOT(IN($0, {
LogicalProject(EMPNO=[$1])
LogicalFilter(condition=[AND(>($2, 2), =($cor0.ENAME, $0))])
LogicalProject(ENAME=[$1], EMPNO=[$0], R=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(=($9, 0), IS NOT TRUE(OR(IS NOT NULL($12), <($10, $9))))])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0, 1}])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{1}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(c=[$0], ck=[$0])
LogicalAggregate(group=[{}], c=[COUNT()])
LogicalFilter(condition=[AND(>($2, 2), =($cor0.ENAME, $0))])
LogicalProject(ENAME=[$1], EMPNO=[$0], R=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[=($cor0.EMPNO, $0)])
LogicalProject(EMPNO=[$1], i=[true])
LogicalFilter(condition=[AND(>($2, 2), =($cor0.ENAME, $0))])
LogicalProject(ENAME=[$1], EMPNO=[$0], R=[$5])
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])
LogicalFilter(condition=[OR(=($9, 0), IS NOT TRUE(OR(IS NOT NULL($13), <($10, $9))))])
LogicalJoin(condition=[AND(=($0, $12), =($1, $14))], joinType=[left])
LogicalJoin(condition=[=($1, $11)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(c=[$1], ck=[$1], ENAME=[$0])
LogicalAggregate(group=[{0}], c=[COUNT()])
LogicalProject(ENAME=[$0])
LogicalFilter(condition=[>($2, 2)])
LogicalProject(ENAME=[$1], EMPNO=[$0], R=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$1], i=[true], ENAME=[$0])
LogicalFilter(condition=[>($2, 2)])
LogicalProject(ENAME=[$1], EMPNO=[$0], R=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWhereOrSubQuery">
<Resource name="sql">
<![CDATA[select * from emp
where sal = 4
or empno NOT IN (select deptno from dept)]]>
</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=[OR(=($5, 4), NOT(IN($0, {
LogicalProject(DEPTNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(=($5, 4), IS NULL($10))])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], i=[true])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[OR(=($5, 4), IS NULL($10))])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], i=[true])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testWindowFunctionOnAggregations">
<Resource name="sql">
<![CDATA[SELECT
min(empno),
sum(sal),
sum(sum(sal))
over (partition by min(empno) order by sum(sal))
from emp
group by deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$2], EXPR$2=[SUM($2) OVER (PARTITION BY $1 ORDER BY $2)])
LogicalAggregate(group=[{0}], EXPR$0=[MIN($1)], EXPR$1=[SUM($2)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$1], EXPR$1=[$2], $2=[$3])
LogicalWindow(window#0=[window(partition {1} order by [2] aggs [SUM($2)])])
LogicalAggregate(group=[{0}], EXPR$0=[MIN($1)], EXPR$1=[SUM($2)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0], SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWindowInParenthesis">
<Resource name="sql">
<![CDATA[select count(*) over (w), count(*) over w
from emp
window w as (partition by empno order by empno)]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[$9], EXPR$1=[$9])
LogicalWindow(window#0=[window(partition {0} order by [0] aggs [COUNT()])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[COUNT() OVER (PARTITION BY $0 ORDER BY $0)], EXPR$1=[COUNT() OVER (PARTITION BY $0 ORDER BY $0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinct">
<Resource name="sql">
<![CDATA[SELECT deptno, SUM(sal), SUM(sal) WITHIN DISTINCT (job)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[SUM($1) WITHIN DISTINCT ($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], $f1=[CAST($1):INTEGER NOT NULL], $f2=[$2])
LogicalAggregate(group=[{0}], agg#0=[MIN($1) FILTER $3], agg#1=[$SUM0($2) FILTER $4])
LogicalProject(DEPTNO=[$0], $f2=[$2], $f3=[$3], $f6=[=($5, 1)], $f7=[AND(=($5, 0), $THROW_UNLESS(OR(<>($5, 0), =($3, $4)), 'more than one distinct value in agg UNIQUE_VALUE'))])
LogicalAggregate(group=[{0, 2}], groups=[[{0, 2}, {0}]], agg#0=[$SUM0($1)], agg#1=[MIN($1)], agg#2=[MAX($1)], agg#3=[GROUPING($0, $2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctCountDistinct">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (comm) AS ss_c,
COUNT(DISTINCT job) cdj,
COUNT(job) WITHIN DISTINCT (job) AS cj_j,
COUNT(DISTINCT job) WITHIN DISTINCT (job) AS cdj_j,
COUNT(DISTINCT job) FILTER (WHERE sal > 1000) AS cdj_filtered
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], SS_C=[SUM($1) WITHIN DISTINCT ($2)], CDJ=[COUNT(DISTINCT $3)], CJ_J=[COUNT() WITHIN DISTINCT ($3)], CDJ_J=[COUNT(DISTINCT $3) WITHIN DISTINCT ($3)], CDJ_FILTERED=[COUNT(DISTINCT $3) FILTER $4])
LogicalProject(DEPTNO=[$7], SAL=[$5], COMM=[$6], JOB=[$2], $f4=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], $f1=[$1], $f2=[$2], $f20=[$2], $f21=[$2], $f3=[$3])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($1) FILTER $3], agg#1=[COUNT() FILTER $4], agg#2=[COUNT($2) FILTER $5])
LogicalProject(DEPTNO=[$0], $f3=[$3], $f4=[$4], $f7=[=($6, 1)], $f8=[=($6, 2)], $f9=[AND(=($6, 2), >($5, 0))])
LogicalAggregate(group=[{0, 2, 3}], groups=[[{0, 2}, {0, 3}]], agg#0=[MIN($1)], agg#1=[MIN($3) FILTER $4], agg#2=[COUNT() FILTER $4], agg#3=[GROUPING($0, $2, $3)])
LogicalProject(DEPTNO=[$7], SAL=[$5], COMM=[$6], JOB=[$2], $f4=[>($5, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctFilteredAggs">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (job) FILTER (WHERE comm > 10),
AVG(comm) WITHIN DISTINCT (sal) FILTER (WHERE ename LIKE '%ok%')
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) WITHIN DISTINCT ($3) FILTER $2], EXPR$2=[AVG($4) WITHIN DISTINCT ($1) FILTER $5])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($6, 10)], JOB=[$2], COMM=[$6], $f5=[LIKE($1, '%ok%')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[CASE(=($2, 0), null:INTEGER, $1)], EXPR$2=[CAST(/($3, $4)):INTEGER])
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], $f2=[$2], $f3=[CASE(=($4, 0), null:INTEGER, $3)], $f4=[$4])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($1) FILTER $3], agg#1=[COUNT() FILTER $4], agg#2=[$SUM0($2) FILTER $5], agg#3=[COUNT() FILTER $6])
LogicalProject(DEPTNO=[$0], $f3=[$3], $f6=[$6], $f10=[AND(=($9, 2), >($5, 0), $THROW_UNLESS(OR(<>($9, 2), AND(IS NULL($3), IS NULL($4)), IS TRUE(=($3, $4))), 'more than one distinct value in agg UNIQUE_VALUE'))], $f11=[AND(=($9, 2), >($5, 0))], $f12=[AND(=($9, 1), >($8, 0), $THROW_UNLESS(OR(<>($9, 1), AND(IS NULL($6), IS NULL($7)), IS TRUE(=($6, $7))), 'more than one distinct value in agg UNIQUE_VALUE'))], $f13=[AND(=($9, 1), >($8, 0))])
LogicalAggregate(group=[{0, 1, 3}], groups=[[{0, 1}, {0, 3}]], agg#0=[MIN($1) FILTER $2], agg#1=[MAX($1) FILTER $2], agg#2=[COUNT() FILTER $2], agg#3=[MIN($4) FILTER $5], agg#4=[MAX($4) FILTER $5], agg#5=[COUNT() FILTER $5], agg#6=[GROUPING($0, $1, $3)])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($6, 10)], JOB=[$2], COMM=[$6], $f5=[LIKE($1, '%ok%')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctFilteredAggsSameFilter">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (job) FILTER (WHERE ename LIKE '%ok%'),
AVG(comm) WITHIN DISTINCT (sal) FILTER (WHERE ename LIKE '%ok%')
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) WITHIN DISTINCT ($3) FILTER $2], EXPR$2=[AVG($4) WITHIN DISTINCT ($1) FILTER $2])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[LIKE($1, '%ok%')], JOB=[$2], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[CASE(=($2, 0), null:INTEGER, $1)], EXPR$2=[CAST(/($3, $4)):INTEGER])
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], $f2=[$2], $f3=[CASE(=($4, 0), null:INTEGER, $3)], $f4=[$4])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($1) FILTER $3], agg#1=[COUNT() FILTER $4], agg#2=[$SUM0($2) FILTER $5], agg#3=[COUNT() FILTER $6])
LogicalProject(DEPTNO=[$0], $f3=[$3], $f6=[$6], $f9=[AND(=($8, 2), >($5, 0), $THROW_UNLESS(OR(<>($8, 2), AND(IS NULL($3), IS NULL($4)), IS TRUE(=($3, $4))), 'more than one distinct value in agg UNIQUE_VALUE'))], $f10=[AND(=($8, 2), >($5, 0))], $f11=[AND(=($8, 1), >($5, 0), $THROW_UNLESS(OR(<>($8, 1), AND(IS NULL($6), IS NULL($7)), IS TRUE(=($6, $7))), 'more than one distinct value in agg UNIQUE_VALUE'))], $f12=[AND(=($8, 1), >($5, 0))])
LogicalAggregate(group=[{0, 1, 3}], groups=[[{0, 1}, {0, 3}]], agg#0=[MIN($1) FILTER $2], agg#1=[MAX($1) FILTER $2], agg#2=[COUNT() FILTER $2], agg#3=[MIN($4) FILTER $2], agg#4=[MAX($4) FILTER $2], agg#5=[GROUPING($0, $1, $3)])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[LIKE($1, '%ok%')], JOB=[$2], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctFilteredAggsUniformDistinctKeys">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (job) FILTER (WHERE comm > 10),
AVG(comm) WITHIN DISTINCT (job) FILTER (WHERE ename LIKE '%ok%')
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) WITHIN DISTINCT ($3) FILTER $2], EXPR$2=[AVG($4) WITHIN DISTINCT ($3) FILTER $5])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($6, 10)], JOB=[$2], COMM=[$6], $f5=[LIKE($1, '%ok%')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[CASE(=($2, 0), null:INTEGER, $1)], EXPR$2=[CAST(/($3, $4)):INTEGER])
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], $f2=[$2], $f3=[CASE(=($4, 0), null:INTEGER, $3)], $f4=[$4])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($1) FILTER $3], agg#1=[COUNT() FILTER $4], agg#2=[$SUM0($2) FILTER $5], agg#3=[COUNT() FILTER $6])
LogicalProject(DEPTNO=[$0], $f2=[$2], $f5=[$5], $f8=[AND(>($4, 0), $THROW_UNLESS(OR(AND(IS NULL($2), IS NULL($3)), IS TRUE(=($2, $3))), 'more than one distinct value in agg UNIQUE_VALUE'))], $f9=[>($4, 0)], $f10=[AND(>($7, 0), $THROW_UNLESS(OR(AND(IS NULL($5), IS NULL($6)), IS TRUE(=($5, $6))), 'more than one distinct value in agg UNIQUE_VALUE'))], $f11=[>($7, 0)])
LogicalAggregate(group=[{0, 3}], agg#0=[MIN($1) FILTER $2], agg#1=[MAX($1) FILTER $2], agg#2=[COUNT() FILTER $2], agg#3=[MIN($4) FILTER $5], agg#4=[MAX($4) FILTER $5], agg#5=[COUNT() FILTER $5])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($6, 10)], JOB=[$2], COMM=[$6], $f5=[LIKE($1, '%ok%')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctFilteredAggsUniformDistinctKeysNoThrow">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (job) FILTER (WHERE comm > 10),
AVG(comm) WITHIN DISTINCT (job) FILTER (WHERE ename LIKE '%ok%')
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) WITHIN DISTINCT ($3) FILTER $2], EXPR$2=[AVG($4) WITHIN DISTINCT ($3) FILTER $5])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($6, 10)], JOB=[$2], COMM=[$6], $f5=[LIKE($1, '%ok%')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[CASE(=($2, 0), null:INTEGER, $1)], EXPR$2=[CAST(/($3, $4)):INTEGER])
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], $f2=[$2], $f3=[CASE(=($4, 0), null:INTEGER, $3)], $f4=[$4])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($1) FILTER $3], agg#1=[COUNT() FILTER $3], agg#2=[$SUM0($2) FILTER $4], agg#3=[COUNT() FILTER $4])
LogicalProject(DEPTNO=[$0], $f2=[$2], $f4=[$4], $f6=[>($3, 0)], $f7=[>($5, 0)])
LogicalAggregate(group=[{0, 3}], agg#0=[MIN($1) FILTER $2], agg#1=[COUNT() FILTER $2], agg#2=[MIN($4) FILTER $5], agg#3=[COUNT() FILTER $5])
LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($6, 10)], JOB=[$2], COMM=[$6], $f5=[LIKE($1, '%ok%')])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctNoThrow">
<Resource name="sql">
<![CDATA[SELECT deptno, SUM(sal), SUM(sal) WITHIN DISTINCT (job)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[SUM($1) WITHIN DISTINCT ($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], $f1=[CAST($1):INTEGER NOT NULL], $f2=[$2])
LogicalAggregate(group=[{0}], agg#0=[MIN($1) FILTER $3], agg#1=[$SUM0($2) FILTER $4])
LogicalProject(DEPTNO=[$0], $f2=[$2], $f3=[$3], $f5=[=($4, 1)], $f6=[=($4, 0)])
LogicalAggregate(group=[{0, 2}], groups=[[{0, 2}, {0}]], agg#0=[$SUM0($1)], agg#1=[MIN($1)], agg#2=[GROUPING($0, $2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctUniformDistinctKeys">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (job),
AVG(comm) WITHIN DISTINCT (job)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) WITHIN DISTINCT ($2)], EXPR$2=[AVG($3) WITHIN DISTINCT ($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($1) FILTER $3], agg#1=[$SUM0($2) FILTER $4], agg#2=[COUNT()])
LogicalProject(DEPTNO=[$0], $f2=[$2], $f4=[$4], $f6=[$THROW_UNLESS(=($2, $3), 'more than one distinct value in agg UNIQUE_VALUE')], $f7=[$THROW_UNLESS(=($4, $5), 'more than one distinct value in agg UNIQUE_VALUE')])
LogicalAggregate(group=[{0, 2}], agg#0=[MIN($1)], agg#1=[MAX($1)], agg#2=[MIN($3)], agg#3=[MAX($3)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testWithinDistinctUniformDistinctKeysNoThrow">
<Resource name="sql">
<![CDATA[SELECT deptno,
SUM(sal) WITHIN DISTINCT (job),
AVG(comm) WITHIN DISTINCT (job)
FROM emp
GROUP BY deptno]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) WITHIN DISTINCT ($2)], EXPR$2=[AVG($3) WITHIN DISTINCT ($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$0], EXPR$1=[$1], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($2)], agg#1=[$SUM0($3)], agg#2=[COUNT()])
LogicalAggregate(group=[{0, 2}], agg#0=[MIN($1)], agg#1=[MIN($3)])
LogicalProject(DEPTNO=[$7], SAL=[$5], JOB=[$2], COMM=[$6])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
</Root>