Skip to content

Commit c6585e3

Browse files
authored
[fix](nullable) set SlotRef's nullable to right value for nestloop join (#59310)
this is follow up of #59092, we need change nestloop join's nullable info too. Related PR: #59092
1 parent 4a2c38c commit c6585e3

File tree

3 files changed

+322
-16
lines changed

3 files changed

+322
-16
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,24 +1862,14 @@ public PlanFragment visitPhysicalNestedLoopJoin(
18621862
// in the intermediate tuple, so fe have to do the same, if be fix the problem, we can change it back.
18631863
for (SlotDescriptor leftSlotDescriptor : leftSlotDescriptors) {
18641864
SlotReference sf = leftChildOutputMap.get(context.findExprId(leftSlotDescriptor.getId()));
1865-
SlotDescriptor sd;
1866-
if (sf == null && leftSlotDescriptor.getColumn().getName().equals(Column.ROWID_COL)) {
1867-
// TODO: temporary code for two phase read, should remove it after refactor
1868-
sd = context.getDescTable().copySlotDescriptor(intermediateDescriptor, leftSlotDescriptor);
1869-
} else {
1870-
sd = context.createSlotDesc(intermediateDescriptor, sf, leftSlotDescriptor.getParent().getTable());
1871-
}
1865+
SlotDescriptor sd = context.createSlotDesc(intermediateDescriptor, sf,
1866+
leftSlotDescriptor.getParent().getTable());
18721867
leftIntermediateSlotDescriptor.add(sd);
18731868
}
18741869
for (SlotDescriptor rightSlotDescriptor : rightSlotDescriptors) {
18751870
SlotReference sf = rightChildOutputMap.get(context.findExprId(rightSlotDescriptor.getId()));
1876-
SlotDescriptor sd;
1877-
if (sf == null && rightSlotDescriptor.getColumn().getName().equals(Column.ROWID_COL)) {
1878-
// TODO: temporary code for two phase read, should remove it after refactor
1879-
sd = context.getDescTable().copySlotDescriptor(intermediateDescriptor, rightSlotDescriptor);
1880-
} else {
1881-
sd = context.createSlotDesc(intermediateDescriptor, sf, rightSlotDescriptor.getParent().getTable());
1882-
}
1871+
SlotDescriptor sd = context.createSlotDesc(intermediateDescriptor, sf,
1872+
rightSlotDescriptor.getParent().getTable());
18831873
rightIntermediateSlotDescriptor.add(sd);
18841874
}
18851875

@@ -1890,10 +1880,20 @@ public PlanFragment visitPhysicalNestedLoopJoin(
18901880

18911881
// set slots as nullable for outer join
18921882
if (joinType == JoinType.LEFT_OUTER_JOIN || joinType == JoinType.FULL_OUTER_JOIN) {
1893-
rightIntermediateSlotDescriptor.forEach(sd -> sd.setIsNullable(true));
1883+
for (SlotDescriptor sd : rightIntermediateSlotDescriptor) {
1884+
sd.setIsNullable(true);
1885+
SlotRef slotRef = new SlotRef(sd);
1886+
ExprId exprId = context.findExprId(sd.getId());
1887+
context.addExprIdSlotRefPair(exprId, slotRef);
1888+
}
18941889
}
18951890
if (joinType == JoinType.RIGHT_OUTER_JOIN || joinType == JoinType.FULL_OUTER_JOIN) {
1896-
leftIntermediateSlotDescriptor.forEach(sd -> sd.setIsNullable(true));
1891+
for (SlotDescriptor sd : leftIntermediateSlotDescriptor) {
1892+
sd.setIsNullable(true);
1893+
SlotRef slotRef = new SlotRef(sd);
1894+
ExprId exprId = context.findExprId(sd.getId());
1895+
context.addExprIdSlotRefPair(exprId, slotRef);
1896+
}
18971897
}
18981898

18991899
nestedLoopJoinNode.setvIntermediateTupleDescList(Lists.newArrayList(intermediateDescriptor));
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !select --
3+
-11824.0 \N 1 \N \N
4+
-11824.0 \N 1 \N \N
5+
-11824.0 \N 1 \N \N
6+
-11824.0 \N 1 \N \N
7+
-11824.0 \N 1 \N \N
8+
-11824.0 \N 1 \N \N
9+
-11824.0 \N 1 \N \N
10+
-11824.0 \N 1 \N \N
11+
-11824.0 \N 1 \N \N
12+
-11824.0 \N 1 \N \N
13+
-11824.0 \N 1 \N \N
14+
-11824.0 \N 1 \N \N
15+
-11824.0 \N 2 \N \N
16+
-11824.0 \N 3 \N \N
17+
-11824.0 \N 4 \N \N
18+
-11824.0 \N 4 \N \N
19+
-11824.0 \N 4 \N \N
20+
-11824.0 \N 4 \N \N
21+
-11824.0 \N 4 \N \N
22+
-11824.0 \N 4 \N \N
23+
-11824.0 \N 4 \N \N
24+
-11824.0 \N 4 \N \N
25+
-11824.0 \N 4 \N \N
26+
-11824.0 \N 4 \N \N
27+
-11824.0 \N 4 \N \N
28+
-11824.0 \N 4 \N \N
29+
-11824.0 \N 6 \N \N
30+
-11824.0 \N 8 \N \N
31+
-11824.0 \N 8 \N \N
32+
-11824.0 \N 8 \N \N
33+
-11824.0 \N 8 \N \N
34+
-11824.0 \N 8 \N \N
35+
-11824.0 \N 8 \N \N
36+
-11824.0 \N 8 \N \N
37+
-11824.0 \N 8 \N \N
38+
-11824.0 \N 8 \N \N
39+
-11824.0 \N 8 \N \N
40+
-11824.0 \N 8 \N \N
41+
-11824.0 \N 8 \N \N
42+
-11824.0 \N 9 \N \N
43+
-11824.0 \N 10 \N \N
44+
-11824.0 \N 13 \N \N
45+
-11824.0 \N 13 \N \N
46+
-11824.0 \N 13 \N \N
47+
-11824.0 \N 13 \N \N
48+
-11824.0 \N 13 \N \N
49+
-11824.0 \N 13 \N \N
50+
-11824.0 \N 13 \N \N
51+
-11824.0 \N 13 \N \N
52+
-11824.0 \N 13 \N \N
53+
-11824.0 \N 13 \N \N
54+
-11824.0 \N 13 \N \N
55+
-11824.0 \N 13 \N \N
56+
-11824.0 \N 19 \N \N
57+
-11824.0 \N 20 \N \N
58+
-11824.0 \N 32 \N \N
59+
-11824.0 \N 33 \N \N
60+
-11824.0 -2355558 1 \N \N
61+
-11824.0 -1471873 3 -9832223 9832223
62+
-11824.0 -1471873 3 -5047939 5047939
63+
-11824.0 -1471873 3 -4396782 4396782
64+
-11824.0 -1471873 3 -1471984 1471984
65+
-11824.0 -1471873 3 -1471927 1471927
66+
-11824.0 -1471873 3 -1471885 1471885
67+
-11824.0 -1471873 3 -1471868 1471868
68+
-11824.0 -1471873 3 -1471830 1471830
69+
-11824.0 -1471873 3 -1456420 1456420
70+
-11824.0 -1471873 3 -1454151 1454151
71+
-11824.0 -1471873 3 -1453445 1453445
72+
-11824.0 -1471873 3 -1442796 1442796
73+
-11824.0 -1471873 7 \N \N
74+
-11824.0 -1471873 8 \N \N
75+
-11824.0 -6163 11 \N \N
76+
-11824.0 -126 7 -8360476 8360476
77+
-11824.0 -126 7 -3576192 3576192
78+
-11824.0 -126 7 -2925035 2925035
79+
-11824.0 -126 7 -237 237
80+
-11824.0 -126 7 -180 180
81+
-11824.0 -126 7 -138 138
82+
-11824.0 -126 7 -121 121
83+
-11824.0 -126 7 -83 83
84+
-11824.0 -126 7 15327 -15327
85+
-11824.0 -126 7 17596 -17596
86+
-11824.0 -126 7 18302 -18302
87+
-11824.0 -126 7 28951 -28951
88+
-11824.0 -126 17 \N \N
89+
-11824.0 -126 18 \N \N
90+
-11824.0 -48 11 -8360398 8360398
91+
-11824.0 -48 11 -3576114 3576114
92+
-11824.0 -48 11 -2924957 2924957
93+
-11824.0 -48 11 -159 159
94+
-11824.0 -48 11 -102 102
95+
-11824.0 -48 11 -60 60
96+
-11824.0 -48 11 -43 43
97+
-11824.0 -48 11 -5 5
98+
-11824.0 -48 11 15405 -15405
99+
-11824.0 -48 11 17674 -17674
100+
-11824.0 -48 11 18380 -18380
101+
-11824.0 -48 11 29029 -29029
102+
-11824.0 -48 26 \N \N
103+
-11824.0 -48 27 \N \N
104+
-11824.0 -39 28 \N \N
105+
-11824.0 43 23 \N \N
106+
-11824.0 44 10 -8360306 8360306
107+
-11824.0 44 10 -3576022 3576022
108+
-11824.0 44 10 -2924865 2924865
109+
-11824.0 44 10 -67 67
110+
-11824.0 44 10 -10 10
111+
-11824.0 44 10 32 -32
112+
-11824.0 44 10 49 -49
113+
-11824.0 44 10 87 -87
114+
-11824.0 44 10 15497 -15497
115+
-11824.0 44 10 17766 -17766
116+
-11824.0 44 10 18472 -18472
117+
-11824.0 44 10 29121 -29121
118+
-11824.0 44 24 \N \N
119+
-11824.0 44 25 \N \N
120+
-11824.0 79 5 -8360271 8360271
121+
-11824.0 79 5 -3575987 3575987
122+
-11824.0 79 5 -2924830 2924830
123+
-11824.0 79 5 -32 32
124+
-11824.0 79 5 25 -25
125+
-11824.0 79 5 67 -67
126+
-11824.0 79 5 84 -84
127+
-11824.0 79 5 122 -122
128+
-11824.0 79 5 15532 -15532
129+
-11824.0 79 5 17801 -17801
130+
-11824.0 79 5 18507 -18507
131+
-11824.0 79 5 29156 -29156
132+
-11824.0 79 12 \N \N
133+
-11824.0 79 13 \N \N
134+
-11824.0 92 6 -8360258 8360258
135+
-11824.0 92 6 -3575974 3575974
136+
-11824.0 92 6 -2924817 2924817
137+
-11824.0 92 6 -19 19
138+
-11824.0 92 6 38 -38
139+
-11824.0 92 6 80 -80
140+
-11824.0 92 6 97 -97
141+
-11824.0 92 6 135 -135
142+
-11824.0 92 6 15545 -15545
143+
-11824.0 92 6 17814 -17814
144+
-11824.0 92 6 18520 -18520
145+
-11824.0 92 6 29169 -29169
146+
-11824.0 92 15 \N \N
147+
-11824.0 92 16 \N \N
148+
-11824.0 121 29 \N \N
149+
-11824.0 7695 12 -8352655 8352655
150+
-11824.0 7695 12 -3568371 3568371
151+
-11824.0 7695 12 -2917214 2917214
152+
-11824.0 7695 12 7584 -7584
153+
-11824.0 7695 12 7641 -7641
154+
-11824.0 7695 12 7683 -7683
155+
-11824.0 7695 12 7700 -7700
156+
-11824.0 7695 12 7738 -7738
157+
-11824.0 7695 12 23148 -23148
158+
-11824.0 7695 12 25417 -25417
159+
-11824.0 7695 12 26123 -26123
160+
-11824.0 7695 12 36772 -36772
161+
-11824.0 7695 30 \N \N
162+
-11824.0 7695 31 \N \N
163+
-11824.0 9832 14 \N \N
164+
-11824.0 473442 2 -7886908 7886908
165+
-11824.0 473442 2 -3102624 3102624
166+
-11824.0 473442 2 -2451467 2451467
167+
-11824.0 473442 2 473331 -473331
168+
-11824.0 473442 2 473388 -473388
169+
-11824.0 473442 2 473430 -473430
170+
-11824.0 473442 2 473447 -473447
171+
-11824.0 473442 2 473485 -473485
172+
-11824.0 473442 2 488895 -488895
173+
-11824.0 473442 2 491164 -491164
174+
-11824.0 473442 2 491870 -491870
175+
-11824.0 473442 2 502519 -502519
176+
-11824.0 473442 4 \N \N
177+
-11824.0 473442 5 \N \N
178+
-11824.0 1527847 9 -6832503 6832503
179+
-11824.0 1527847 9 -2048219 2048219
180+
-11824.0 1527847 9 -1397062 1397062
181+
-11824.0 1527847 9 1527736 -1527736
182+
-11824.0 1527847 9 1527793 -1527793
183+
-11824.0 1527847 9 1527835 -1527835
184+
-11824.0 1527847 9 1527852 -1527852
185+
-11824.0 1527847 9 1527890 -1527890
186+
-11824.0 1527847 9 1543300 -1543300
187+
-11824.0 1527847 9 1545569 -1545569
188+
-11824.0 1527847 9 1546275 -1546275
189+
-11824.0 1527847 9 1556924 -1556924
190+
-11824.0 1527847 21 \N \N
191+
-11824.0 1527847 22 \N \N
192+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_nestloop_join_nullable") {
19+
multi_sql '''
20+
drop table if exists table_20_undef_partitions2_keys3_properties4_distributed_by510;
21+
drop table if exists table_20_undef_partitions2_keys3_properties4_distributed_by512;
22+
23+
create table table_20_undef_partitions2_keys3_properties4_distributed_by510 (
24+
col_int_undef_signed int/*agg_type_placeholder*/ ,
25+
col_int_undef_signed2 int/*agg_type_placeholder*/ ,
26+
col_float_undef_signed float/*agg_type_placeholder*/ ,
27+
col_int_undef_signed3 int/*agg_type_placeholder*/ ,
28+
col_int_undef_signed4 int/*agg_type_placeholder*/ ,
29+
col_int_undef_signed5 int/*agg_type_placeholder*/ ,
30+
pk int/*agg_type_placeholder*/
31+
) engine=olap
32+
distributed by hash(pk) buckets 10
33+
properties("replication_num" = "1");
34+
insert into table_20_undef_partitions2_keys3_properties4_distributed_by510(pk,col_int_undef_signed,col_int_undef_signed2,col_float_undef_signed,col_int_undef_signed3,col_int_undef_signed4,col_int_undef_signed5) values (19,-538797,111,-2357243,88,null,null),(18,11035,null,-7629271,null,2400941,-12250),(17,119,8360350,null,-101,-57,-2825979),(16,93,-5,101,81,-57,null),(15,24421,3576066,null,-8351025,3094515,null),(14,-32,-53,-117,null,408662,69),(13,-28788,null,-3424,58,-16,5885342),(12,4378160,54,-14810,17886,-30200,-10060),(11,77,-43,null,-35,null,23),(10,-2333750,-18428,58,1504,-6105795,31),(9,30258,-158232,8149676,null,null,-1923047),(8,-30473,-29077,null,-9975,-60,null),(7,1447364,-17722,-5366279,-4911,3433200,null),(6,8,21708,-61,null,null,null),(5,-7131891,-15453,13205,4832507,-4572942,-57),(4,-61,2924909,-3996268,-63,-8108590,11731),(3,-902463,12,null,-6,8136,23281),(2,null,null,null,4533188,-26763,85),(1,-27575,null,null,null,-9,-42),(0,17583,-121,null,null,-79,-22443);
35+
36+
create table table_20_undef_partitions2_keys3_properties4_distributed_by512 (
37+
pk int,
38+
col_int_undef_signed int ,
39+
col_int_undef_signed2 int ,
40+
col_float_undef_signed float ,
41+
col_int_undef_signed3 int ,
42+
col_int_undef_signed4 int ,
43+
col_int_undef_signed5 int
44+
) engine=olap
45+
DUPLICATE KEY(pk)
46+
distributed by hash(pk) buckets 10
47+
properties("replication_num" = "1");
48+
insert into table_20_undef_partitions2_keys3_properties4_distributed_by512(pk,col_int_undef_signed,col_int_undef_signed2,col_float_undef_signed,col_int_undef_signed3,col_int_undef_signed4,col_int_undef_signed5) values (19,null,-122,-4279753,-7311927,89,null),(18,-35,8334250,1537805,-112,-21552,1527847),(17,24212,null,null,62,-26157,43),(16,-3845324,null,-11824,5033341,null,121),(15,-4642469,null,-35,null,5146485,9832),(14,7780660,null,-3021705,-29468,105,-6163),(13,null,46,null,104,-20633,44),(12,7629243,null,-107,3637456,82,-39),(11,106,37,25249,null,2622107,null),(10,null,-13728,10270,-26,13731,92),(9,19752,58,null,-4083,1569134,473442),(8,null,-14922,-22053,null,1953,79),(7,-18243,null,null,-62,-87,-2355558),(6,-120,518201,null,null,-50,null),(5,5201336,5855553,-5913148,-8576,35,-1471873),(4,null,-30894,-24418,31495,null,-48),(3,-860330,7609530,73,6729250,-91,7695),(2,3009668,null,null,-26,2992,null),(1,-38,28,14143,null,-13643,-126),(0,-1141940,-50,null,7458207,66,null);
49+
'''
50+
51+
qt_select '''
52+
SELECT
53+
FIRST_VALUE(t2.col_float_undef_signed) OVER (
54+
ORDER BY
55+
t1.col_int_undef_signed4,
56+
(
57+
t2.col_int_undef_signed4 + t1.col_int_undef_signed4
58+
),
59+
t2.col_int_undef_signed4,
60+
t1.col_int_undef_signed3,
61+
t1.col_int_undef_signed5,
62+
abs(t1.col_int_undef_signed),
63+
t1.col_float_undef_signed,
64+
t2.col_int_undef_signed
65+
),
66+
LAST_VALUE(t2.col_int_undef_signed5) OVER (
67+
ORDER BY
68+
(
69+
t2.col_float_undef_signed * t2.col_int_undef_signed
70+
),
71+
t2.col_int_undef_signed5,
72+
1,
73+
t2.col_float_undef_signed,
74+
atan2(
75+
t2.col_int_undef_signed3,
76+
t1.col_int_undef_signed3
77+
),
78+
t2.col_int_undef_signed,
79+
t1.col_float_undef_signed,
80+
t2.col_float_undef_signed
81+
),
82+
RANK() OVER (
83+
PARTITION BY (t1.col_int_undef_signed2 * 80954088951981892)
84+
ORDER BY
85+
6,
86+
ln(t2.col_int_undef_signed3),
87+
t2.col_float_undef_signed,
88+
t2.col_int_undef_signed,
89+
(
90+
t1.col_int_undef_signed4 - t2.col_int_undef_signed4
91+
),
92+
t2.col_float_undef_signed,
93+
t1.col_int_undef_signed5,
94+
t2.col_int_undef_signed
95+
),
96+
(
97+
t2.col_int_undef_signed5 - t1.col_int_undef_signed2
98+
),
99+
(
100+
t1.col_int_undef_signed2 - t2.col_int_undef_signed5
101+
)
102+
from
103+
table_20_undef_partitions2_keys3_properties4_distributed_by510 t1
104+
RIGHT JOIN table_20_undef_partitions2_keys3_properties4_distributed_by512 t2 ON t1.col_int_undef_signed5 = t2.col_int_undef_signed3
105+
OR t1.col_int_undef_signed3 = t1.col_int_undef_signed3
106+
AND t2.col_int_undef_signed2 = t2.col_int_undef_signed2
107+
order by
108+
1,
109+
2,
110+
3,
111+
4,
112+
5;
113+
'''
114+
}

0 commit comments

Comments
 (0)