Skip to content

Commit 6097536

Browse files
committed
Improve
1 parent c64d260 commit 6097536

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@ public TrimResult trimFields(
836836
Join join,
837837
ImmutableBitSet fieldsUsed,
838838
Set<RelDataTypeField> extraFields) {
839+
// If the column "mark" is included, it needs to be excluded first.
840+
if (join.getJoinType() == JoinRelType.LEFT_MARK) {
841+
int markIndex = join.getRowType().getFieldCount() - 1;
842+
fieldsUsed = fieldsUsed.except(ImmutableBitSet.of(markIndex));
843+
}
839844
final int fieldCount = join.getSystemFieldList().size()
840845
+ join.getLeft().getRowType().getFieldCount()
841846
+ join.getRight().getRowType().getFieldCount();

core/src/test/resources/sql/new-decorr.iq

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,36 @@ INSERT INTO emps (empid, deptno, name, salary, commission) VALUES
6565

6666
!update
6767

68-
SELECT *, EXISTS(select * from (
68+
SELECT empid, EXISTS(select * from (
6969
SELECT e2.deptno FROM emps e2 where e1.commission = e2.commission) as table3
7070
where table3.deptno <> e1.deptno)
7171
from emps e1 order by empid;
72-
+-------+--------+-----------+----------+------------+--------+
73-
| EMPID | DEPTNO | NAME | SALARY | COMMISSION | EXPR$5 |
74-
+-------+--------+-----------+----------+------------+--------+
75-
| 100 | 10 | Bill | 10000.00 | 1000 | false |
76-
| 110 | 10 | Theodore | 11500.00 | 250 | true |
77-
| 140 | 10 | Sebastian | 7000.00 | | false |
78-
| 150 | 10 | Sebastian | 7000.00 | | false |
79-
| 170 | 30 | Theodore | 11500.00 | 250 | true |
80-
| 200 | 20 | Eric | 8000.00 | 500 | false |
81-
+-------+--------+-----------+----------+------------+--------+
72+
+-------+--------+
73+
| EMPID | EXPR$1 |
74+
+-------+--------+
75+
| 100 | false |
76+
| 110 | true |
77+
| 140 | false |
78+
| 150 | false |
79+
| 170 | true |
80+
| 200 | false |
81+
+-------+--------+
8282
(6 rows)
8383

8484
!ok
8585

8686
!if (use_new_decorr) {
8787
EnumerableSort(sort0=[$0], dir0=[ASC])
88-
EnumerableHashJoin(condition=[AND(IS NOT DISTINCT FROM($1, $6), IS NOT DISTINCT FROM($4, $7))], joinType=[left_mark])
89-
EnumerableTableScan(table=[[BLANK, EMPS]])
90-
EnumerableCalc(expr#0..3=[{inputs}], DEPTNO=[$t2], DEPTNO0=[$t0], COMMISSION0=[$t1])
91-
EnumerableHashJoin(condition=[AND(=($1, $3), <>($2, $0))], joinType=[inner])
92-
EnumerableAggregate(group=[{1, 4}])
93-
EnumerableTableScan(table=[[BLANK, EMPS]])
94-
EnumerableCalc(expr#0..4=[{inputs}], DEPTNO=[$t1], COMMISSION=[$t4])
95-
EnumerableTableScan(table=[[BLANK, EMPS]])
88+
EnumerableCalc(expr#0..3=[{inputs}], EMPID=[$t0], EXPR$1=[$t3])
89+
EnumerableHashJoin(condition=[AND(IS NOT DISTINCT FROM($1, $3), IS NOT DISTINCT FROM($2, $4))], joinType=[left_mark])
90+
EnumerableCalc(expr#0..4=[{inputs}], proj#0..1=[{exprs}], COMMISSION=[$t4])
91+
EnumerableTableScan(table=[[BLANK, EMPS]])
92+
EnumerableCalc(expr#0..3=[{inputs}], proj#0..1=[{exprs}])
93+
EnumerableHashJoin(condition=[AND(=($1, $3), <>($2, $0))], joinType=[inner])
94+
EnumerableAggregate(group=[{1, 4}])
95+
EnumerableTableScan(table=[[BLANK, EMPS]])
96+
EnumerableCalc(expr#0..4=[{inputs}], DEPTNO=[$t1], COMMISSION=[$t4])
97+
EnumerableTableScan(table=[[BLANK, EMPS]])
9698
!plan
9799
!}
98100

0 commit comments

Comments
 (0)