Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ pub fn convert_mark_to_semi_join(s_expr: &SExpr) -> Result<SExpr> {
}

let mark_index = join.marker_index.unwrap();
let mut find_mark_index = false;

// remove mark index filter
for (idx, predicate) in filter.predicates.iter().enumerate() {
if let ScalarExpr::BoundColumnRef(col) = predicate {
if col.column.index == mark_index {
find_mark_index = true;
filter.predicates.remove(idx);
break;
}
Expand All @@ -51,6 +53,11 @@ pub fn convert_mark_to_semi_join(s_expr: &SExpr) -> Result<SExpr> {
}
}

if !find_mark_index {
// To be conservative, we do not convert
return Ok(s_expr.clone());
}

join.join_type = match join.join_type {
JoinType::LeftMark => JoinType::RightSemi,
JoinType::RightMark => JoinType::LeftSemi,
Expand Down
13 changes: 13 additions & 0 deletions tests/sqllogictests/suites/query/subquery.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) ORDER BY c_id
4 TX
6 FL

query IT
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
----
1 CA 10 1 CA
1 CA 20 1 CA
1 CA 30 1 CA
2 TX 40 2 CA
2 TX 50 2 TX
2 TX 60 2 NULL
4 TX 70 4 WY
4 TX 80 4 NULL
6 FL 90 6 WA

query IT
SELECT * FROM c WHERE NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) ORDER BY c_id
----
Expand Down