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
10 changes: 3 additions & 7 deletions src/query/sql/src/planner/binder/scalar_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub enum JoinPredicate<'a> {
Both {
left: &'a ScalarExpr,
right: &'a ScalarExpr,
equal: bool,
op: ComparisonOp,
},
Other(&'a ScalarExpr),
}
Expand All @@ -130,18 +130,14 @@ impl<'a> JoinPredicate<'a> {
let left = &func.arguments[0];
let right = &func.arguments[1];
if satisfied_by(left, left_prop) && satisfied_by(right, right_prop) {
return Self::Both {
left,
right,
equal: op == ComparisonOp::Equal,
};
return Self::Both { left, right, op };
}

if satisfied_by(right, left_prop) && satisfied_by(left, right_prop) {
return Self::Both {
left: right,
right: left,
equal: op == ComparisonOp::Equal,
op,
};
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/query/sql/src/planner/optimizer/heuristic/decorrelate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::plans::AggregateFunction;
use crate::plans::AggregateMode;
use crate::plans::BoundColumnRef;
use crate::plans::CastExpr;
use crate::plans::ComparisonOp;
use crate::plans::EvalScalar;
use crate::plans::Filter;
use crate::plans::FunctionCall;
Expand Down Expand Up @@ -161,8 +162,10 @@ impl SubqueryRewriter {
non_equi_conditions.push(pred.clone());
}

JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both {
left, right, op, ..
} => {
if op == ComparisonOp::Equal {
if left.data_type()?.eq(&right.data_type()?) {
left_conditions.push(left.clone());
right_conditions.push(right.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::optimizer::RelExpr;
use crate::optimizer::RuleID;
use crate::optimizer::SExpr;
use crate::planner::binder::wrap_cast;
use crate::plans::ComparisonOp;
use crate::plans::Filter;
use crate::plans::Join;
use crate::plans::JoinType;
Expand Down Expand Up @@ -153,8 +154,8 @@ pub fn try_push_down_filter_join(
}
JoinPredicate::Other(_) => original_predicates.push(predicate),

JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
let left_type = left.data_type()?;
let right_type = right.data_type()?;
let join_key_type = common_super_type(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::optimizer::rule::TransformResult;
use crate::optimizer::RelExpr;
use crate::optimizer::RuleID;
use crate::optimizer::SExpr;
use crate::plans::ComparisonOp;
use crate::plans::Join;
use crate::plans::JoinType;
use crate::plans::PatternPlan;
Expand Down Expand Up @@ -170,8 +171,8 @@ impl Rule for RuleExchangeJoin {
JoinPredicate::Right(pred) => {
join_6_preds.push(pred.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_4.left_conditions.push(left.clone());
join_4.right_conditions.push(right.clone());
} else {
Expand All @@ -197,9 +198,9 @@ impl Rule for RuleExchangeJoin {
join_5.non_equi_conditions.push(predicate.clone());
}
JoinPredicate::Both {
left, right, equal, ..
left, right, op, ..
} => {
if equal {
if op == ComparisonOp::Equal {
join_5.left_conditions.push(left.clone());
join_5.right_conditions.push(right.clone());
} else {
Expand All @@ -221,8 +222,8 @@ impl Rule for RuleExchangeJoin {
// TODO(leiysky): push down the predicate
join_6.non_equi_conditions.push(predicate.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_6.left_conditions.push(left.clone());
join_6.right_conditions.push(right.clone());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::optimizer::rule::TransformResult;
use crate::optimizer::RelExpr;
use crate::optimizer::RuleID;
use crate::optimizer::SExpr;
use crate::plans::ComparisonOp;
use crate::plans::Join;
use crate::plans::JoinType;
use crate::plans::PatternPlan;
Expand Down Expand Up @@ -146,12 +147,12 @@ impl Rule for RuleLeftAssociateJoin {
JoinPredicate::Right(pred) => {
join_4_preds.push(pred.clone());
}
JoinPredicate::Both { left, right, equal } => {
if !equal {
join_3.non_equi_conditions.push(predicate.clone());
} else {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_3.left_conditions.push(left.clone());
join_3.right_conditions.push(right.clone());
} else {
join_3.non_equi_conditions.push(predicate.clone());
}
}
JoinPredicate::Other(pred) => {
Expand All @@ -172,8 +173,8 @@ impl Rule for RuleLeftAssociateJoin {
// TODO(leiysky): push down the predicate
join_4.non_equi_conditions.push(predicate.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_4.left_conditions.push(left.clone());
join_4.right_conditions.push(right.clone());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::optimizer::rule::TransformResult;
use crate::optimizer::RelExpr;
use crate::optimizer::RuleID;
use crate::optimizer::SExpr;
use crate::plans::ComparisonOp;
use crate::plans::Join;
use crate::plans::JoinType;
use crate::plans::PatternPlan;
Expand Down Expand Up @@ -144,8 +145,8 @@ impl Rule for RuleLeftExchangeJoin {
// TODO(leiysky): push down the predicate
join_3.non_equi_conditions.push(pred.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_3.left_conditions.push(left.clone());
join_3.right_conditions.push(right.clone());
} else {
Expand All @@ -170,8 +171,8 @@ impl Rule for RuleLeftExchangeJoin {
// TODO(leiysky): push down the predicate
join_4.non_equi_conditions.push(predicate.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_4.left_conditions.push(left.clone());
join_4.right_conditions.push(right.clone());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::optimizer::rule::TransformResult;
use crate::optimizer::RelExpr;
use crate::optimizer::RuleID;
use crate::optimizer::SExpr;
use crate::plans::ComparisonOp;
use crate::plans::Join;
use crate::plans::JoinType;
use crate::plans::PatternPlan;
Expand Down Expand Up @@ -142,8 +143,8 @@ impl Rule for RuleRightAssociateJoin {
JoinPredicate::Left(pred) => {
join_4_preds.push(pred.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_3.left_conditions.push(left.clone());
join_3.right_conditions.push(right.clone());
} else {
Expand All @@ -168,8 +169,8 @@ impl Rule for RuleRightAssociateJoin {
// TODO(leiysky): push down the predicate
join_4.non_equi_conditions.push(predicate.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_4.left_conditions.push(left.clone());
join_4.right_conditions.push(right.clone());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::optimizer::rule::TransformResult;
use crate::optimizer::RelExpr;
use crate::optimizer::RuleID;
use crate::optimizer::SExpr;
use crate::plans::ComparisonOp;
use crate::plans::Join;
use crate::plans::JoinType;
use crate::plans::PatternPlan;
Expand Down Expand Up @@ -142,8 +143,8 @@ impl Rule for RuleRightExchangeJoin {
JoinPredicate::Right(pred) => {
join_4_preds.push(pred.clone());
}
JoinPredicate::Both { left, right, equal } => {
if equal {
JoinPredicate::Both { left, right, op } => {
if op == ComparisonOp::Equal {
join_3.left_conditions.push(left.clone());
join_3.right_conditions.push(right.clone());
} else {
Expand Down