Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,13 @@ public RelNode convertToSingleValueSubq(
case ALL:
return RexUtil.composeConjunction(rexBuilder, comparisons, true);
case NOT_IN:
if (comparisons.stream().allMatch(c -> c.getKind() == SqlKind.EQUALS)) {
final List<RexNode> notEqualsComparisons =
Util.transform(comparisons,
c -> rexBuilder.makeCall(SqlStdOperatorTable.NOT_EQUALS,
((RexCall) c).getOperands()));
return RexUtil.composeConjunction(rexBuilder, notEqualsComparisons, false);
}
return rexBuilder.makeCall(SqlStdOperatorTable.NOT,
RexUtil.composeDisjunction(rexBuilder, comparisons));
case IN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,16 @@ public static void checkActualAndReferenceFiles() {
sql(sql).ok();
}

@Test void testNotInSingleValue() {
final String sql = "select * from emp where deptno not in (10)";
sql(sql).ok();
}

@Test void testNotInMultiValue() {
final String sql = "select * from emp where deptno not in (10, 20)";
sql(sql).ok();
}

@Test void testAggFilterWithInSubQuery() {
final String sql = "select\n"
+ " count(*) filter (where empno in (select deptno from empnullables))\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6582,7 +6582,7 @@ join sales.emp e on e.deptno = d.deptno and d.deptno not in (4, 6)]]>
<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])
LogicalJoin(condition=[AND(=($16, $7), <>($7, 4), <>($7, 6))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
Expand All @@ -6591,7 +6591,7 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
<![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=[NOT(OR(=($7, 4), =($7, 6)))])
LogicalFilter(condition=[AND(<>($7, 4), <>($7, 6))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[SEARCH($7, Sarg[(-∞..4), (4..6), (6..+∞)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6015,7 +6015,7 @@ LogicalProject(EXPR$0=[COMPARE_STRINGS_OR_NUMERIC_VALUES(1, 1)])
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[CASE(true, NOT(OR(=($7, 10), =($7, 20))), false, NOT(false), NOT(OR(=($7, 30), =($7, 40))))])
LogicalFilter(condition=[CASE(true, AND(<>($7, 10), <>($7, 20)), false, NOT(false), AND(<>($7, 30), <>($7, 40)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand All @@ -6027,7 +6027,7 @@ LogicalProject(EMPNO=[$0])
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[CASE(true, NOT(OR(=($7, 10), =($7, 20))), NOT(true))])
LogicalFilter(condition=[CASE(true, AND(<>($7, 10), <>($7, 20)), NOT(true))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand All @@ -6039,7 +6039,7 @@ LogicalProject(EMPNO=[$0])
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[CASE(true, CAST(NOT(OR(=($7, 10), =($7, 20)))):BOOLEAN, null:BOOLEAN)])
LogicalFilter(condition=[CASE(true, CAST(AND(<>($7, 10), <>($7, 20))):BOOLEAN, null:BOOLEAN)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand All @@ -6059,6 +6059,30 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testNotInMultiValue">
<Resource name="sql">
<![CDATA[select * from emp where deptno not in (10, 20)]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[AND(<>($7, 10), <>($7, 20))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testNotInSingleValue">
<Resource name="sql">
<![CDATA[select * from emp where deptno not in (10)]]>
</Resource>
<Resource name="plan">
<![CDATA[
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]])
]]>
</Resource>
</TestCase>
Expand Down
Loading