Skip to content

Commit

Permalink
perf: ScalarExpression::check_or optimize implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Sep 25, 2023
1 parent 69bb3b4 commit 4b899ec
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/expression/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ struct ReplaceUnary {
}

impl ScalarExpression {
pub fn exist_column(&self, col_id: &ColumnId) -> bool {
match self {
ScalarExpression::ColumnRef(col) => col.id == Some(*col_id),
ScalarExpression::Alias { expr, .. } => expr.exist_column(col_id),
ScalarExpression::TypeCast { expr, .. } => expr.exist_column(col_id),
ScalarExpression::IsNull { expr } => expr.exist_column(col_id),
ScalarExpression::Unary { expr, .. } => expr.exist_column(col_id),
ScalarExpression::Binary { left_expr, right_expr, .. } => {
left_expr.exist_column(col_id) || right_expr.exist_column(col_id)
}
_ => false
}
}

fn unpack_val(&self) -> Option<ValueRef> {
match self {
ScalarExpression::Constant(val) => Some(val.clone()),
Expand Down Expand Up @@ -559,13 +573,7 @@ impl ScalarExpression {
op: &BinaryOperator,
binary: ConstantBinary
) -> Option<ConstantBinary> {
let check_func = |expr: &ScalarExpression, col_id: &ColumnId| {
expr.referenced_columns()
.iter()
.find(|col| col.id == Some(*col_id))
.is_some()
};
if matches!(op, BinaryOperator::Or) && check_func(right_expr, col_id) {
if matches!(op, BinaryOperator::Or) && right_expr.exist_column(col_id) {
return None
}

Expand Down

0 comments on commit 4b899ec

Please sign in to comment.