Skip to content

Commit

Permalink
using cache only validity is none
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesdevil committed Oct 8, 2023
1 parent 67f887d commit bd6f37d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/query/expression/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ impl<'a> Evaluator<'a> {
#[cfg(debug_assertions)]
self.check_expr(expr);

let is_validity_none = validity.is_none();

// try get result from cache
if !matches!(expr, Expr::ColumnRef {..} | Expr::Constant{..}) && let Some(cached_values) = &self.cached_values {
if !matches!(expr, Expr::ColumnRef {..} | Expr::Constant{..}) && is_validity_none && let Some(cached_values) = &self.cached_values {
if let Some(cached_result) = cached_values.borrow().get(expr) {
return Ok(cached_result.clone());
}
Expand Down Expand Up @@ -235,13 +237,11 @@ impl<'a> Evaluator<'a> {
}

// Do not cache `ColumnRef` and `Constant`
if !matches!(expr, Expr::ColumnRef {..} | Expr::Constant{..}) && let Some(cached_values) = &self.cached_values {
if !matches!(expr, Expr::ColumnRef {..} | Expr::Constant{..}) && is_validity_none && let Some(cached_values) = &self.cached_values {
if let Ok(r) = &result {
// Prepare data that lock used.
let expr_cloned = expr.clone();
let result_cloned = r.clone();

// Acquire the write lock and insert the value.
if let Entry::Vacant(v) = cached_values.borrow_mut().entry(expr_cloned) {
v.insert(result_cloned);
}
Expand Down

0 comments on commit bd6f37d

Please sign in to comment.