Skip to content

Commit c2f561d

Browse files
authored
Merge pull request #10602 from xudong963/fix_mark_join
fix: incorrectly remove mark index
2 parents 46a0fb8 + 88a1630 commit c2f561d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/query/sql/src/planner/optimizer/rule/rewrite/filter_join/mark_join_to_semi_join.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ pub fn convert_mark_to_semi_join(s_expr: &SExpr) -> Result<SExpr> {
3232
}
3333

3434
let mark_index = join.marker_index.unwrap();
35+
let mut find_mark_index = false;
3536

3637
// remove mark index filter
3738
for (idx, predicate) in filter.predicates.iter().enumerate() {
3839
if let ScalarExpr::BoundColumnRef(col) = predicate {
3940
if col.column.index == mark_index {
41+
find_mark_index = true;
4042
filter.predicates.remove(idx);
4143
break;
4244
}
@@ -51,6 +53,11 @@ pub fn convert_mark_to_semi_join(s_expr: &SExpr) -> Result<SExpr> {
5153
}
5254
}
5355

56+
if !find_mark_index {
57+
// To be conservative, we do not convert
58+
return Ok(s_expr.clone());
59+
}
60+
5461
join.join_type = match join.join_type {
5562
JoinType::LeftMark => JoinType::RightSemi,
5663
JoinType::RightMark => JoinType::LeftSemi,

tests/sqllogictests/suites/query/subquery.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) ORDER BY c_id
3939
4 TX
4040
6 FL
4141

42+
query IT
43+
SELECT * FROM c, o WHERE c.c_id = o.c_id AND (EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) OR EXISTS(SELECT * FROM o where o.ship = c.bill)) ORDER BY c_id
44+
----
45+
1 CA 10 1 CA
46+
1 CA 20 1 CA
47+
1 CA 30 1 CA
48+
2 TX 40 2 CA
49+
2 TX 50 2 TX
50+
2 TX 60 2 NULL
51+
4 TX 70 4 WY
52+
4 TX 80 4 NULL
53+
6 FL 90 6 WA
54+
4255
query IT
4356
SELECT * FROM c WHERE NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) ORDER BY c_id
4457
----

0 commit comments

Comments
 (0)