File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
src/query/sql/src/planner/optimizer/rule/rewrite/filter_join
tests/sqllogictests/suites/query Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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
39394 TX
40406 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+
4247query IT
4348SELECT * FROM c WHERE NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) ORDER BY c_id
4449----
You can’t perform that action at this time.
0 commit comments