From 0b24d8baa92ab85d92a2f15c1b4b8c80e3acf0ab Mon Sep 17 00:00:00 2001 From: Jack Drogon Date: Thu, 26 Oct 2023 15:19:35 +0800 Subject: [PATCH] Refactor is_acting_on_a_slot Signed-off-by: Jack Drogon --- be/src/vec/exec/scan/vscan_node.cpp | 12 ++++++++++-- be/src/vec/exprs/vexpr.h | 16 ---------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/be/src/vec/exec/scan/vscan_node.cpp b/be/src/vec/exec/scan/vscan_node.cpp index 602f5074eb168b..02378e9d2109d8 100644 --- a/be/src/vec/exec/scan/vscan_node.cpp +++ b/be/src/vec/exec/scan/vscan_node.cpp @@ -65,6 +65,15 @@ #include "vec/runtime/vdatetime_value.h" namespace doris::vectorized { +namespace { +bool is_acting_on_a_slot(const VExpr& expr) { + const auto& children = expr.children(); + auto is_a_slot = std::any_of(children.begin(), children.end(), + [](const auto& child) { return is_acting_on_a_slot(*child); }); + + return is_a_slot ? true : (expr.node_type() == TExprNodeType::SLOT_REF); +} +} // namespace #define RETURN_IF_PUSH_DOWN(stmt, status) \ if (pdt == PushDownType::UNACCEPTABLE) { \ @@ -420,8 +429,7 @@ Status VScanNode::_normalize_conjuncts() { RETURN_IF_ERROR(_normalize_predicate(conjunct->root(), conjunct.get(), new_root)); if (new_root) { conjunct->set_root(new_root); - if (_should_push_down_common_expr() && - VExpr::is_acting_on_a_slot(conjunct->root())) { + if (_should_push_down_common_expr() && is_acting_on_a_slot(*(conjunct->root()))) { // We need to make sure conjunct is acting on a slot before push it down. // Or it will not be executed by SegmentIterator::_vec_init_lazy_materialization _common_expr_ctxs_push_down.emplace_back(conjunct); diff --git a/be/src/vec/exprs/vexpr.h b/be/src/vec/exprs/vexpr.h index 3f7cb7ed5930c8..64d389bd005359 100644 --- a/be/src/vec/exprs/vexpr.h +++ b/be/src/vec/exprs/vexpr.h @@ -76,22 +76,6 @@ class VExpr { return block->columns() - 1; } - static bool is_acting_on_a_slot(const VExprSPtr& expr) { - const auto& children = expr->children(); - const size_t children_size = children.size(); - - for (size_t i = 0; i < children_size; ++i) { - // If any child expr acts on a column slot - // return true immediately. - if (is_acting_on_a_slot(children[i])) { - return true; - } - } - - // This is a leaf expression. - return expr->node_type() == TExprNodeType::SLOT_REF; - } - VExpr(const TExprNode& node); VExpr(const VExpr& vexpr); VExpr(const TypeDescriptor& type, bool is_slotref, bool is_nullable);