Skip to content

Commit 5c5cc57

Browse files
committed
fix: incorrectly remove mark index
1 parent 2e81662 commit 5c5cc57

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ 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 WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) OR EXISTS(SELECT * FROM o where o.ship = o.bill) ORDER BY c_id
44+
----
45+
46+
4247
query IT
4348
SELECT * FROM c WHERE NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) ORDER BY c_id
4449
----

0 commit comments

Comments
 (0)