Skip to content

Commit

Permalink
fallback & normal then clause do not need to be const
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhseh committed Jan 24, 2024
1 parent 217629c commit 6da06fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
17 changes: 6 additions & 11 deletions src/expr/impl/src/scalar/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,16 @@ impl Expression for ConstantLookupExpression {
let column = input.column_at(column_len - 1);

for i in 0..input_len {
if let Some(expr) = self.arms.get(column.datum_at(i).as_ref().unwrap()) {
// Now we assume that the expr in `arms` is const
// Also be separated out of the scoping context
builder.append(expr.eval_row(&OwnedRow::empty()).await.unwrap().as_ref());
let datum = column.datum_at(i);
let owned_row = OwnedRow::new(vec![datum]);

if let Some(expr) = self.arms.get(datum.as_ref().unwrap()) {
builder.append(expr.eval_row(&owned_row).await.unwrap().as_ref());
} else {
// Otherwise this should goes to the fallback arm
// The fallback arm should also be const
if let Some(ref fallback) = self.fallback {
builder.append(
fallback
.eval_row(&OwnedRow::empty())
.await
.unwrap()
.as_ref(),
);
builder.append(fallback.eval_row(&owned_row).await.unwrap().as_ref());
} else {
builder.append_null();
}
Expand Down
14 changes: 1 addition & 13 deletions src/frontend/src/binder/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,6 @@ impl Binder {
}

for (condition, result) in zip_eq_fast(conditions, results_expr) {
// If the result expression is not const
// we will also not conduct the optimization
if !result.is_const() {
return false;
}

if let Expr::Value(_) = condition.clone() {
let Ok(input) = self.bind_expr_inner(condition.clone()) else {
return false;
Expand All @@ -519,13 +513,7 @@ impl Binder {

// The fallback arm for case-when expression
if let Some(expr) = fallback {
// We assume fallback arm must be const
// to enable optimization (if exists)
if expr.is_const() {
constant_lookup_inputs.push(expr);
} else {
return false;
}
constant_lookup_inputs.push(expr);
}

true
Expand Down

0 comments on commit 6da06fd

Please sign in to comment.