From bc26b2f1633665939f9ffce792163b430547e3eb Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 2 Jun 2022 10:10:55 +0800 Subject: [PATCH] [CP] remove const params in window function --- src/sql/optimizer/ob_select_log_plan.cpp | 16 +++++++++++ src/sql/optimizer/ob_select_log_plan.h | 1 + src/sql/resolver/expr/ob_raw_expr.cpp | 36 ++++++++++++++++++++++++ src/sql/resolver/expr/ob_raw_expr.h | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/sql/optimizer/ob_select_log_plan.cpp b/src/sql/optimizer/ob_select_log_plan.cpp index 5cb50e1433..7c4274448a 100644 --- a/src/sql/optimizer/ob_select_log_plan.cpp +++ b/src/sql/optimizer/ob_select_log_plan.cpp @@ -1719,6 +1719,20 @@ int ObSelectLogPlan::decide_sort_keys_for_runion( return ret; } +int ObSelectLogPlan::remove_const_in_window_functions(ObIArray &win_funcs) +{ + int ret = OB_SUCCESS; + for (int64_t i = 0; OB_SUCC(ret) && i < win_funcs.count(); ++i) { + if (OB_ISNULL(win_funcs.at(i))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(ret)); + } else if (OB_FAIL(win_funcs.at(i)->remove_const_params())) { + LOG_WARN("failed to remove const params in window function", K(ret)); + } + } + return ret; +} + int ObSelectLogPlan::candi_allocate_window_function() { int ret = OB_SUCCESS; @@ -1731,6 +1745,8 @@ int ObSelectLogPlan::candi_allocate_window_function() LOG_WARN("failed to append exprs", K(ret)); } else if (OB_FAIL(candi_allocate_subplan_filter_for_exprs(candi_subquery_exprs))) { LOG_WARN("failed to do allocate subplan filter", K(ret)); + } else if (OB_FAIL(remove_const_in_window_functions(stmt->get_window_func_exprs()))) { + LOG_WARN("failed to remove const in window functions", K(ret)); } else if (stmt->get_window_func_count() > 0) { ObSEArray winfunc_plans; CandidatePlan winfunc_plan; diff --git a/src/sql/optimizer/ob_select_log_plan.h b/src/sql/optimizer/ob_select_log_plan.h index cc430b55d3..640c3f571c 100644 --- a/src/sql/optimizer/ob_select_log_plan.h +++ b/src/sql/optimizer/ob_select_log_plan.h @@ -183,6 +183,7 @@ private: common::ObIArray& merge_keys); int candi_allocate_window_function(); + int remove_const_in_window_functions(ObIArray &win_funcs); int candi_allocate_temp_table_insert(); diff --git a/src/sql/resolver/expr/ob_raw_expr.cpp b/src/sql/resolver/expr/ob_raw_expr.cpp index e309c57779..2b9d4206af 100644 --- a/src/sql/resolver/expr/ob_raw_expr.cpp +++ b/src/sql/resolver/expr/ob_raw_expr.cpp @@ -3579,6 +3579,42 @@ int ObWindow::assign(const ObWindow& other) return ret; } +int ObWindow::remove_const_params() +{ + int ret = OB_SUCCESS; + int64_t cnt_part_expr = 0; + int64_t cnt_order_item = 0; + for (int64_t i = 0; OB_SUCC(ret) && i < partition_exprs_.count(); ++i) { + if (OB_ISNULL(partition_exprs_.at(i))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(ret)); + } else if (partition_exprs_.at(i)->has_const_or_const_expr_flag()) { + /*do nothing */ + } else { + partition_exprs_.at(cnt_part_expr++) = partition_exprs_.at(i); + } + } + for (int64_t i = 0; OB_SUCC(ret) && i < order_items_.count(); ++i) { + if (OB_ISNULL(order_items_.at(i).expr_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(ret)); + } else if (order_items_.at(i).expr_->has_const_or_const_expr_flag()) { + /*do nothing */ + } else { + order_items_.at(cnt_order_item++) = order_items_.at(i); + } + } + if (OB_SUCC(ret)) { + while (partition_exprs_.count() > cnt_part_expr) { + partition_exprs_.pop_back(); + } + while (order_items_.count() > cnt_order_item) { + order_items_.pop_back(); + } + } + return ret; +} + void ObWinFunRawExpr::clear_child() { func_type_ = T_MAX; diff --git a/src/sql/resolver/expr/ob_raw_expr.h b/src/sql/resolver/expr/ob_raw_expr.h index 13ea887dc3..bd6af0a54c 100644 --- a/src/sql/resolver/expr/ob_raw_expr.h +++ b/src/sql/resolver/expr/ob_raw_expr.h @@ -3759,8 +3759,8 @@ public: { return order_items_; } - int assign(const ObWindow &other); + int remove_const_params(); common::ObArray partition_exprs_; common::ObArray order_items_;