@@ -1056,13 +1056,11 @@ where t1.t1_id > 40 or t1.t1_id in (select t2.t2_id from t2 where t1.t1_int > 0)
1056
1056
----
1057
1057
logical_plan
1058
1058
01)Projection: t1.t1_id, t1.t1_name, t1.t1_int
1059
- 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_1.__exists IS NOT NULL
1060
- 03)----Projection: t1.t1_id, t1.t1_name, t1.t1_int, __correlated_sq_1.__exists
1061
- 04)------Left Join: t1.t1_id = __correlated_sq_1.t2_id Filter: t1.t1_int > Int32(0)
1062
- 05)--------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1063
- 06)--------SubqueryAlias: __correlated_sq_1
1064
- 07)----------Projection: t2.t2_id, Boolean(true) AS __exists
1065
- 08)------------TableScan: t2 projection=[t2_id]
1059
+ 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_1.mark
1060
+ 03)----LeftMark Join: t1.t1_id = __correlated_sq_1.t2_id Filter: t1.t1_int > Int32(0)
1061
+ 04)------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1062
+ 05)------SubqueryAlias: __correlated_sq_1
1063
+ 06)--------TableScan: t2 projection=[t2_id]
1066
1064
1067
1065
query ITI rowsort
1068
1066
select t1.t1_id,
@@ -1085,13 +1083,12 @@ where t1.t1_id = 11 or t1.t1_id + 12 not in (select t2.t2_id + 1 from t2 where t
1085
1083
----
1086
1084
logical_plan
1087
1085
01)Projection: t1.t1_id, t1.t1_name, t1.t1_int
1088
- 02)--Filter: t1.t1_id = Int32(11) OR __correlated_sq_1.__exists IS NULL
1089
- 03)----Projection: t1.t1_id, t1.t1_name, t1.t1_int, __correlated_sq_1.__exists
1090
- 04)------Left Join: CAST(t1.t1_id AS Int64) + Int64(12) = __correlated_sq_1.t2.t2_id + Int64(1) Filter: t1.t1_int > Int32(0)
1091
- 05)--------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1092
- 06)--------SubqueryAlias: __correlated_sq_1
1093
- 07)----------Projection: CAST(t2.t2_id AS Int64) + Int64(1), Boolean(true) AS __exists
1094
- 08)------------TableScan: t2 projection=[t2_id]
1086
+ 02)--Filter: t1.t1_id = Int32(11) OR NOT __correlated_sq_1.mark
1087
+ 03)----LeftMark Join: CAST(t1.t1_id AS Int64) + Int64(12) = __correlated_sq_1.t2.t2_id + Int64(1) Filter: t1.t1_int > Int32(0)
1088
+ 04)------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1089
+ 05)------SubqueryAlias: __correlated_sq_1
1090
+ 06)--------Projection: CAST(t2.t2_id AS Int64) + Int64(1)
1091
+ 07)----------TableScan: t2 projection=[t2_id]
1095
1092
1096
1093
query ITI rowsort
1097
1094
select t1.t1_id,
@@ -1113,13 +1110,11 @@ where t1.t1_id > 40 or exists (select * from t2 where t1.t1_id = t2.t2_id)
1113
1110
----
1114
1111
logical_plan
1115
1112
01)Projection: t1.t1_id, t1.t1_name, t1.t1_int
1116
- 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_1.__exists IS NOT NULL
1117
- 03)----Projection: t1.t1_id, t1.t1_name, t1.t1_int, __correlated_sq_1.__exists
1118
- 04)------Left Join: t1.t1_id = __correlated_sq_1.t2_id
1119
- 05)--------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1120
- 06)--------SubqueryAlias: __correlated_sq_1
1121
- 07)----------Projection: t2.t2_id, Boolean(true) AS __exists
1122
- 08)------------TableScan: t2 projection=[t2_id]
1113
+ 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_1.mark
1114
+ 03)----LeftMark Join: t1.t1_id = __correlated_sq_1.t2_id
1115
+ 04)------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1116
+ 05)------SubqueryAlias: __correlated_sq_1
1117
+ 06)--------TableScan: t2 projection=[t2_id]
1123
1118
1124
1119
query ITI rowsort
1125
1120
select t1.t1_id,
@@ -1142,13 +1137,11 @@ where t1.t1_id > 40 or not exists (select * from t2 where t1.t1_id = t2.t2_id)
1142
1137
----
1143
1138
logical_plan
1144
1139
01)Projection: t1.t1_id, t1.t1_name, t1.t1_int
1145
- 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_1.__exists IS NULL
1146
- 03)----Projection: t1.t1_id, t1.t1_name, t1.t1_int, __correlated_sq_1.__exists
1147
- 04)------Left Join: t1.t1_id = __correlated_sq_1.t2_id
1148
- 05)--------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1149
- 06)--------SubqueryAlias: __correlated_sq_1
1150
- 07)----------Projection: t2.t2_id, Boolean(true) AS __exists
1151
- 08)------------TableScan: t2 projection=[t2_id]
1140
+ 02)--Filter: t1.t1_id > Int32(40) OR NOT __correlated_sq_1.mark
1141
+ 03)----LeftMark Join: t1.t1_id = __correlated_sq_1.t2_id
1142
+ 04)------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1143
+ 05)------SubqueryAlias: __correlated_sq_1
1144
+ 06)--------TableScan: t2 projection=[t2_id]
1152
1145
1153
1146
query ITI rowsort
1154
1147
select t1.t1_id,
@@ -1170,16 +1163,14 @@ where t1.t1_id in (select t3.t3_id from t3) and (t1.t1_id > 40 or t1.t1_id in (s
1170
1163
----
1171
1164
logical_plan
1172
1165
01)Projection: t1.t1_id, t1.t1_name, t1.t1_int
1173
- 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_2.__exists IS NOT NULL
1174
- 03)----Projection: t1.t1_id, t1.t1_name, t1.t1_int, __correlated_sq_2.__exists
1175
- 04)------Left Join: t1.t1_id = __correlated_sq_2.t2_id Filter: t1.t1_int > Int32(0)
1176
- 05)--------LeftSemi Join: t1.t1_id = __correlated_sq_1.t3_id
1177
- 06)----------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1178
- 07)----------SubqueryAlias: __correlated_sq_1
1179
- 08)------------TableScan: t3 projection=[t3_id]
1180
- 09)--------SubqueryAlias: __correlated_sq_2
1181
- 10)----------Projection: t2.t2_id, Boolean(true) AS __exists
1182
- 11)------------TableScan: t2 projection=[t2_id]
1166
+ 02)--Filter: t1.t1_id > Int32(40) OR __correlated_sq_2.mark
1167
+ 03)----LeftMark Join: t1.t1_id = __correlated_sq_2.t2_id Filter: t1.t1_int > Int32(0)
1168
+ 04)------LeftSemi Join: t1.t1_id = __correlated_sq_1.t3_id
1169
+ 05)--------TableScan: t1 projection=[t1_id, t1_name, t1_int]
1170
+ 06)--------SubqueryAlias: __correlated_sq_1
1171
+ 07)----------TableScan: t3 projection=[t3_id]
1172
+ 08)------SubqueryAlias: __correlated_sq_2
1173
+ 09)--------TableScan: t2 projection=[t2_id]
1183
1174
1184
1175
query ITI rowsort
1185
1176
select t1.t1_id,
@@ -1192,6 +1183,18 @@ where t1.t1_id in (select t3.t3_id from t3) and (t1.t1_id > 40 or t1.t1_id in (s
1192
1183
22 b 2
1193
1184
44 d 4
1194
1185
1186
+ # Handle duplicate values in exists query
1187
+ query ITI rowsort
1188
+ select t1.t1_id,
1189
+ t1.t1_name,
1190
+ t1.t1_int
1191
+ from t1
1192
+ where t1.t1_id > 40 or exists (select * from t2 cross join t3 where t1.t1_id = t2.t2_id)
1193
+ ----
1194
+ 11 a 1
1195
+ 22 b 2
1196
+ 44 d 4
1197
+
1195
1198
# Nested subqueries
1196
1199
query ITI rowsort
1197
1200
select t1.t1_id,
0 commit comments