From 703ed5c14edce49e3dcfc4e24591a83cc39ecc0a Mon Sep 17 00:00:00 2001 From: yinyj17 Date: Wed, 14 Jun 2023 07:12:26 +0000 Subject: [PATCH] fix some replace expr bugs in optimizer --- src/sql/optimizer/ob_log_count.cpp | 6 +- src/sql/optimizer/ob_log_count.h | 3 +- src/sql/optimizer/ob_log_del_upd.cpp | 31 ++++---- src/sql/optimizer/ob_log_del_upd.h | 5 +- src/sql/optimizer/ob_log_distinct.cpp | 5 +- src/sql/optimizer/ob_log_distinct.h | 3 +- src/sql/optimizer/ob_log_err_log.cpp | 6 +- src/sql/optimizer/ob_log_err_log.h | 3 +- src/sql/optimizer/ob_log_exchange.cpp | 15 ++-- src/sql/optimizer/ob_log_exchange.h | 3 +- src/sql/optimizer/ob_log_expr_values.cpp | 5 +- src/sql/optimizer/ob_log_expr_values.h | 3 +- src/sql/optimizer/ob_log_for_update.cpp | 22 +++--- src/sql/optimizer/ob_log_for_update.h | 3 +- src/sql/optimizer/ob_log_group_by.cpp | 18 +++-- src/sql/optimizer/ob_log_group_by.h | 3 +- src/sql/optimizer/ob_log_insert.cpp | 11 ++- src/sql/optimizer/ob_log_insert.h | 3 +- src/sql/optimizer/ob_log_insert_all.cpp | 7 +- src/sql/optimizer/ob_log_insert_all.h | 3 +- src/sql/optimizer/ob_log_join.cpp | 21 +++--- src/sql/optimizer/ob_log_join.h | 3 +- src/sql/optimizer/ob_log_join_filter.cpp | 5 +- src/sql/optimizer/ob_log_join_filter.h | 3 +- src/sql/optimizer/ob_log_limit.cpp | 11 ++- src/sql/optimizer/ob_log_limit.h | 3 +- src/sql/optimizer/ob_log_merge.cpp | 15 ++-- src/sql/optimizer/ob_log_merge.h | 3 +- .../ob_log_optimizer_stats_gathering.cpp | 7 +- .../ob_log_optimizer_stats_gathering.h | 3 +- src/sql/optimizer/ob_log_plan.cpp | 51 +++++++------ src/sql/optimizer/ob_log_plan.h | 9 +-- src/sql/optimizer/ob_log_select_into.cpp | 5 +- src/sql/optimizer/ob_log_select_into.h | 3 +- src/sql/optimizer/ob_log_sort.cpp | 15 ++-- src/sql/optimizer/ob_log_sort.h | 3 +- src/sql/optimizer/ob_log_stat_collector.cpp | 5 +- src/sql/optimizer/ob_log_stat_collector.h | 3 +- src/sql/optimizer/ob_log_subplan_filter.cpp | 11 ++- src/sql/optimizer/ob_log_subplan_filter.h | 6 +- src/sql/optimizer/ob_log_table_scan.cpp | 41 +++++------ src/sql/optimizer/ob_log_table_scan.h | 9 +-- src/sql/optimizer/ob_log_window_function.cpp | 7 +- src/sql/optimizer/ob_log_window_function.h | 3 +- src/sql/optimizer/ob_logical_operator.cpp | 47 +++++------- src/sql/optimizer/ob_logical_operator.h | 12 ++-- .../resolver/expr/ob_raw_expr_replacer.cpp | 72 +++++++++++++++---- src/sql/resolver/expr/ob_raw_expr_replacer.h | 9 ++- 48 files changed, 268 insertions(+), 275 deletions(-) diff --git a/src/sql/optimizer/ob_log_count.cpp b/src/sql/optimizer/ob_log_count.cpp index 13bad9ae74..3fa692e143 100644 --- a/src/sql/optimizer/ob_log_count.cpp +++ b/src/sql/optimizer/ob_log_count.cpp @@ -180,12 +180,10 @@ int ObLogCount::get_plan_item_info(PlanText &plan_text, return ret; } -int ObLogCount::inner_replace_op_exprs( - const ObIArray> &to_replace_exprs) +int ObLogCount::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (NULL != rownum_limit_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, rownum_limit_expr_))) { + if (NULL != rownum_limit_expr_ && OB_FAIL(replace_expr_action(replacer, rownum_limit_expr_))) { LOG_WARN("failed to replace expr", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_count.h b/src/sql/optimizer/ob_log_count.h index d6c538b239..73010725a2 100644 --- a/src/sql/optimizer/ob_log_count.h +++ b/src/sql/optimizer/ob_log_count.h @@ -43,8 +43,7 @@ public: double &op_cost); virtual int get_op_exprs(ObIArray &all_exprs) override; virtual int is_my_fixed_expr(const ObRawExpr *expr, bool &is_fixed) override; - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; diff --git a/src/sql/optimizer/ob_log_del_upd.cpp b/src/sql/optimizer/ob_log_del_upd.cpp index 4ef0c82251..17e4061ccd 100644 --- a/src/sql/optimizer/ob_log_del_upd.cpp +++ b/src/sql/optimizer/ob_log_del_upd.cpp @@ -1405,25 +1405,24 @@ int ObLogDelUpd::print_outline_data(PlanText &plan_text) return ret; } -int ObLogDelUpd::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogDelUpd::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_dml_info_exprs(to_replace_exprs, get_index_dml_infos()))) { + if (OB_FAIL(replace_dml_info_exprs(replacer, get_index_dml_infos()))) { LOG_WARN("failed to replace dml info exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, view_check_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, view_check_exprs_))) { LOG_WARN("failed to replace view check exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, produced_trans_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, produced_trans_exprs_))) { LOG_WARN("failed to replace produced trans exprs", K(ret)); } else if (NULL != pdml_partition_id_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, pdml_partition_id_expr_))) { + OB_FAIL(replace_expr_action(replacer, pdml_partition_id_expr_))) { LOG_WARN("failed to replace pdml partition id expr", K(ret)); } return ret; } int ObLogDelUpd::replace_dml_info_exprs( - const common::ObIArray> &to_replace_exprs, + ObRawExprReplacer &replacer, const ObIArray &index_dml_infos) { int ret = OB_SUCCESS; @@ -1432,31 +1431,29 @@ int ObLogDelUpd::replace_dml_info_exprs( if (OB_ISNULL(index_dml_info)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, + } else if (OB_FAIL(replace_exprs_action(replacer, index_dml_info->column_convert_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, + } else if (OB_FAIL(replace_exprs_action(replacer, index_dml_info->ck_cst_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); } else if (NULL != index_dml_info->new_part_id_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, index_dml_info->new_part_id_expr_))) { + OB_FAIL(replace_expr_action(replacer, index_dml_info->new_part_id_expr_))) { LOG_WARN("failed to replace new parititon id expr", K(ret)); } else if (NULL != index_dml_info->old_part_id_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, index_dml_info->old_part_id_expr_))) { + OB_FAIL(replace_expr_action(replacer, index_dml_info->old_part_id_expr_))) { LOG_WARN("failed to replace old parititon id expr", K(ret)); } else if (NULL != index_dml_info->old_rowid_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, index_dml_info->old_rowid_expr_))) { + OB_FAIL(replace_expr_action(replacer, index_dml_info->old_rowid_expr_))) { LOG_WARN("failed to replace old rowid expr", K(ret)); } else if (NULL != index_dml_info->new_rowid_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, index_dml_info->new_rowid_expr_))) { + OB_FAIL(replace_expr_action(replacer, index_dml_info->new_rowid_expr_))) { LOG_WARN("failed to replace new rowid expr", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, - index_dml_info->column_old_values_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, index_dml_info->column_old_values_exprs_))) { LOG_WARN("failed to replace column old values exprs ", K(ret)); } for (int64_t i = 0; OB_SUCC(ret) && i < index_dml_info->assignments_.count(); ++i) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, - index_dml_info->assignments_.at(i).expr_))) { + if (OB_FAIL(replace_expr_action(replacer, index_dml_info->assignments_.at(i).expr_))) { LOG_WARN("failed to replace expr", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_del_upd.h b/src/sql/optimizer/ob_log_del_upd.h index 6037243b56..3e2c4f2083 100644 --- a/src/sql/optimizer/ob_log_del_upd.h +++ b/src/sql/optimizer/ob_log_del_upd.h @@ -323,10 +323,9 @@ public: virtual int allocate_expr_post(ObAllocExprContext &ctx) override; int extract_err_log_info(); static int generate_errlog_info(const ObDelUpdStmt &stmt, ObErrLogDefine &errlog_define); - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; int replace_dml_info_exprs( - const common::ObIArray> &to_replace_exprs, + ObRawExprReplacer &replacer, const ObIArray &index_dml_infos); protected: virtual int generate_rowid_expr_for_trigger() = 0; diff --git a/src/sql/optimizer/ob_log_distinct.cpp b/src/sql/optimizer/ob_log_distinct.cpp index ab2771ca85..5cd6f740a1 100644 --- a/src/sql/optimizer/ob_log_distinct.cpp +++ b/src/sql/optimizer/ob_log_distinct.cpp @@ -58,11 +58,10 @@ int ObLogDistinct::get_plan_item_info(PlanText &plan_text, } -int ObLogDistinct::inner_replace_op_exprs( - const ObIArray >&to_replace_exprs) +int ObLogDistinct::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if(OB_FAIL(replace_exprs_action(to_replace_exprs, distinct_exprs_))) { + if(OB_FAIL(replace_exprs_action(replacer, distinct_exprs_))) { SQL_OPT_LOG(WARN, "failed to replace agg exprs in distinct op", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_distinct.h b/src/sql/optimizer/ob_log_distinct.h index f3f2f82b7a..abe758a083 100644 --- a/src/sql/optimizer/ob_log_distinct.h +++ b/src/sql/optimizer/ob_log_distinct.h @@ -41,8 +41,7 @@ public: { return distinct_exprs_; } int set_distinct_exprs(const common::ObIArray &exprs) { return append(distinct_exprs_, exprs); } - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual uint64_t hash(uint64_t seed) const override; inline void set_hash_type() { algo_ = HASH_AGGREGATE; } diff --git a/src/sql/optimizer/ob_log_err_log.cpp b/src/sql/optimizer/ob_log_err_log.cpp index 0bf81b7d38..f307970c2c 100644 --- a/src/sql/optimizer/ob_log_err_log.cpp +++ b/src/sql/optimizer/ob_log_err_log.cpp @@ -146,12 +146,10 @@ int ObLogErrLog::get_op_exprs(ObIArray &all_exprs) return ret; } -int ObLogErrLog::inner_replace_op_exprs( - const ObIArray > &to_replace_exprs) +int ObLogErrLog::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, - get_err_log_define().err_log_value_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, get_err_log_define().err_log_value_exprs_))) { LOG_WARN("failed to replace err log value exprs", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_err_log.h b/src/sql/optimizer/ob_log_err_log.h index f86402015d..c5e8680925 100644 --- a/src/sql/optimizer/ob_log_err_log.h +++ b/src/sql/optimizer/ob_log_err_log.h @@ -37,8 +37,7 @@ public: virtual int is_my_fixed_expr(const ObRawExpr *expr, bool &is_fixed) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; private: ObErrLogDefine err_log_define_; const ObDelUpdStmt *del_upd_stmt_; diff --git a/src/sql/optimizer/ob_log_exchange.cpp b/src/sql/optimizer/ob_log_exchange.cpp index b68f045b5c..b80273f242 100644 --- a/src/sql/optimizer/ob_log_exchange.cpp +++ b/src/sql/optimizer/ob_log_exchange.cpp @@ -111,31 +111,30 @@ const char *ObLogExchange::get_name() const return result; } -int ObLogExchange::inner_replace_op_exprs(const common::ObIArray >&to_replace_exprs) +int ObLogExchange::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, repartition_keys_))) { + if (OB_FAIL(replace_exprs_action(replacer, repartition_keys_))) { LOG_WARN("failed to replace agg exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, repartition_sub_keys_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, repartition_sub_keys_))) { LOG_WARN("failed to replace agg exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, repartition_func_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, repartition_func_exprs_))) { LOG_WARN("failed to replace agg exprs", K(ret)); } else if (calc_part_id_expr_ != NULL - && OB_FAIL(replace_expr_action(to_replace_exprs, calc_part_id_expr_))) { + && OB_FAIL(replace_expr_action(replacer, calc_part_id_expr_))) { LOG_WARN("failed to replace calc part id expr", K(ret)); } else { for (int64_t i = 0; OB_SUCC(ret) && i < hash_dist_exprs_.count(); i++) { if (OB_ISNULL(hash_dist_exprs_.at(i).expr_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, - hash_dist_exprs_.at(i).expr_))) { + } else if (OB_FAIL(replace_expr_action(replacer, hash_dist_exprs_.at(i).expr_))) { LOG_WARN("failed to replace agg exprs", K(ret)); } else { /*do nothing*/ } } for(int64_t i = 0; OB_SUCC(ret) && i < sort_keys_.count(); ++i) { OrderItem &cur_order_item = sort_keys_.at(i); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_order_item.expr_))) { + if (OB_FAIL(replace_expr_action(replacer, cur_order_item.expr_))) { LOG_WARN("failed to resolve ref params in sort key ", K(cur_order_item), K(ret)); } else { /* Do nothing */ } } diff --git a/src/sql/optimizer/ob_log_exchange.h b/src/sql/optimizer/ob_log_exchange.h index 16f5ac183d..e02c994226 100644 --- a/src/sql/optimizer/ob_log_exchange.h +++ b/src/sql/optimizer/ob_log_exchange.h @@ -204,8 +204,7 @@ private: const common::ObIArray &drop_expr_idxs, bool &is_need); private: - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; private: // the 'partition key' expressions diff --git a/src/sql/optimizer/ob_log_expr_values.cpp b/src/sql/optimizer/ob_log_expr_values.cpp index 69676cc71a..a703c92e7d 100644 --- a/src/sql/optimizer/ob_log_expr_values.cpp +++ b/src/sql/optimizer/ob_log_expr_values.cpp @@ -490,11 +490,10 @@ bool ObLogExprValues::contain_array_binding_param() const return bret; } -int ObLogExprValues::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogExprValues::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, value_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, value_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_expr_values.h b/src/sql/optimizer/ob_log_expr_values.h index 739b2ad41f..25648129a2 100644 --- a/src/sql/optimizer/ob_log_expr_values.h +++ b/src/sql/optimizer/ob_log_expr_values.h @@ -68,8 +68,7 @@ class ObLogExprValues : public ObLogicalOperator int extract_err_log_info(); int mark_probably_local_exprs(); int allocate_dummy_output(); - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; diff --git a/src/sql/optimizer/ob_log_for_update.cpp b/src/sql/optimizer/ob_log_for_update.cpp index 6e0b8b3679..e8726a8814 100644 --- a/src/sql/optimizer/ob_log_for_update.cpp +++ b/src/sql/optimizer/ob_log_for_update.cpp @@ -308,7 +308,7 @@ bool ObLogForUpdate::is_multi_table_skip_locked() return is_multi_table_skip_locked; } -int ObLogForUpdate::inner_replace_op_exprs(const common::ObIArray > &to_replace_exprs) +int ObLogForUpdate::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; for (int64_t i = 0; OB_SUCC(ret) && i < index_dml_info_.count(); ++i) { @@ -316,31 +316,27 @@ int ObLogForUpdate::inner_replace_op_exprs(const common::ObIArrayck_cst_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, dml_info->ck_cst_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); } else if (NULL != dml_info->new_part_id_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, dml_info->new_part_id_expr_))) { + OB_FAIL(replace_expr_action(replacer, dml_info->new_part_id_expr_))) { LOG_WARN("failed to replace new parititon id expr", K(ret)); } else if (NULL != dml_info->old_part_id_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, dml_info->old_part_id_expr_))) { + OB_FAIL(replace_expr_action(replacer, dml_info->old_part_id_expr_))) { LOG_WARN("failed to replace old parititon id expr", K(ret)); } else if (NULL != dml_info->old_rowid_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, dml_info->old_rowid_expr_))) { + OB_FAIL(replace_expr_action(replacer, dml_info->old_rowid_expr_))) { LOG_WARN("failed to replace old rowid expr", K(ret)); } else if (NULL != dml_info->new_rowid_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, dml_info->new_rowid_expr_))) { + OB_FAIL(replace_expr_action(replacer, dml_info->new_rowid_expr_))) { LOG_WARN("failed to replace new rowid expr", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, - dml_info->column_convert_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, dml_info->column_convert_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, - dml_info->column_old_values_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, dml_info->column_old_values_exprs_))) { LOG_WARN("failed to replace column old values exprs ", K(ret)); } for (int64_t j = 0; OB_SUCC(ret) && j < dml_info->assignments_.count(); ++j) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, - dml_info->assignments_.at(j).expr_))) { + if (OB_FAIL(replace_expr_action(replacer, dml_info->assignments_.at(j).expr_))) { LOG_WARN("failed to replace expr", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_for_update.h b/src/sql/optimizer/ob_log_for_update.h index 23018acb6e..b9ce667825 100644 --- a/src/sql/optimizer/ob_log_for_update.h +++ b/src/sql/optimizer/ob_log_for_update.h @@ -48,8 +48,7 @@ public: void set_is_multi_part_dml(bool is_multi_part_dml) { is_multi_part_dml_ = is_multi_part_dml; } bool is_gi_above() const { return gi_charged_; } void set_gi_above(bool gi_above) { gi_charged_ = gi_above; } - virtual int inner_replace_op_exprs( - const common::ObIArray > &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; protected: diff --git a/src/sql/optimizer/ob_log_group_by.cpp b/src/sql/optimizer/ob_log_group_by.cpp index 8548df252d..43a153ab8d 100644 --- a/src/sql/optimizer/ob_log_group_by.cpp +++ b/src/sql/optimizer/ob_log_group_by.cpp @@ -442,39 +442,37 @@ int ObLogGroupBy::get_gby_output_exprs(ObIArray &output_exprs) return ret; } -int ObLogGroupBy::inner_replace_op_exprs( - const ObIArray >&to_replace_exprs) +int ObLogGroupBy::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_group_by_exprs()))) { + if (OB_FAIL(replace_exprs_action(replacer, get_group_by_exprs()))) { LOG_WARN("failed to extract subplan params in log group by exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_rollup_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_rollup_exprs()))) { LOG_WARN("failed to extract subplan params in log rollup exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_aggr_funcs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_aggr_funcs()))) { LOG_WARN("failed to extract subplan params in log agg funcs", K(ret)); } else { for(int64_t i = 0; OB_SUCC(ret) && i < rollup_adaptive_info_.sort_keys_.count(); ++i) { OrderItem &cur_order_item = rollup_adaptive_info_.sort_keys_.at(i); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_order_item.expr_))) { + if (OB_FAIL(replace_expr_action(replacer, cur_order_item.expr_))) { LOG_WARN("failed to resolve ref params in sort key ", K(cur_order_item), K(ret)); } else { /* Do nothing */ } } for(int64_t i = 0; OB_SUCC(ret) && i < rollup_adaptive_info_.ecd_sort_keys_.count(); ++i) { OrderItem &cur_order_item = rollup_adaptive_info_.ecd_sort_keys_.at(i); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_order_item.expr_))) { + if (OB_FAIL(replace_expr_action(replacer, cur_order_item.expr_))) { LOG_WARN("failed to resolve ref params in sort key ", K(cur_order_item), K(ret)); } else { /* Do nothing */ } } } if (OB_SUCC(ret) && is_three_stage_aggr()) { - if (OB_FAIL(replace_exprs_action(to_replace_exprs, three_stage_info_.distinct_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, three_stage_info_.distinct_exprs_))) { LOG_WARN("failed to replace three stage info distinct exprs", K(ret)); } else { for(int64_t i = 0; OB_SUCC(ret) && i < three_stage_info_.distinct_aggr_batch_.count(); ++i) { ObDistinctAggrBatch &distinct_batch = three_stage_info_.distinct_aggr_batch_.at(i); for (int64_t j = 0; OB_SUCC(ret) && j < distinct_batch.mocked_params_.count(); ++j) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, - distinct_batch.mocked_params_.at(j).first))) { + if (OB_FAIL(replace_expr_action(replacer, distinct_batch.mocked_params_.at(j).first))) { LOG_WARN("failed to replace distinct expr", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_group_by.h b/src/sql/optimizer/ob_log_group_by.h index 1164680199..a1cf514c1f 100644 --- a/src/sql/optimizer/ob_log_group_by.h +++ b/src/sql/optimizer/ob_log_group_by.h @@ -218,8 +218,7 @@ public: VIRTUAL_TO_STRING_KV(K_(group_exprs), K_(rollup_exprs), K_(aggr_exprs), K_(algo), K_(distinct_card), K_(is_push_down)); private: - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int allocate_granule_post(AllocGIContext &ctx) override; virtual int allocate_granule_pre(AllocGIContext &ctx) override; int create_fd_item_from_select_list(ObFdItemSet *fd_item_set); diff --git a/src/sql/optimizer/ob_log_insert.cpp b/src/sql/optimizer/ob_log_insert.cpp index 8ac2b07b4a..9d72c54407 100644 --- a/src/sql/optimizer/ob_log_insert.cpp +++ b/src/sql/optimizer/ob_log_insert.cpp @@ -477,17 +477,16 @@ int ObLogInsert::generate_multi_part_partition_id_expr() return ret; } -int ObLogInsert::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogInsert::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(ObLogDelUpd::inner_replace_op_exprs(to_replace_exprs))) { + if (OB_FAIL(ObLogDelUpd::inner_replace_op_exprs(replacer))) { LOG_WARN("failed to replace op exprs", K(ret)); } else if (is_replace() && - OB_FAIL(replace_dml_info_exprs(to_replace_exprs, get_replace_index_dml_infos()))) { + OB_FAIL(replace_dml_info_exprs(replacer, get_replace_index_dml_infos()))) { LOG_WARN("failed to replace dml info exprs", K(ret)); } else if (get_insert_up() && - OB_FAIL(replace_dml_info_exprs(to_replace_exprs, get_insert_up_index_dml_infos()))) { + OB_FAIL(replace_dml_info_exprs(replacer, get_insert_up_index_dml_infos()))) { LOG_WARN("failed to replace dml info exprs", K(ret)); } else if (NULL != constraint_infos_) { for (int64_t i = 0; OB_SUCC(ret) && i < constraint_infos_->count(); ++i) { @@ -501,7 +500,7 @@ int ObLogInsert::inner_replace_op_exprs( } else if (expr->is_virtual_generated_column()) { ObRawExpr *&dependant_expr = static_cast( expr)->get_dependant_expr(); - if (OB_FAIL(replace_expr_action(to_replace_exprs, dependant_expr))) { + if (OB_FAIL(replace_expr_action(replacer, dependant_expr))) { LOG_WARN("failed to push back generate replace pair", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_insert.h b/src/sql/optimizer/ob_log_insert.h index 14b2584c84..6e70b5e2fc 100644 --- a/src/sql/optimizer/ob_log_insert.h +++ b/src/sql/optimizer/ob_log_insert.h @@ -95,8 +95,7 @@ public: { return constraint_infos_; } - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; protected: diff --git a/src/sql/optimizer/ob_log_insert_all.cpp b/src/sql/optimizer/ob_log_insert_all.cpp index bc982c0bb9..955d9939fb 100644 --- a/src/sql/optimizer/ob_log_insert_all.cpp +++ b/src/sql/optimizer/ob_log_insert_all.cpp @@ -200,21 +200,20 @@ int ObLogInsertAll::get_op_exprs(ObIArray &all_exprs) // return ret; // } -int ObLogInsertAll::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogInsertAll::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; if (OB_ISNULL(insert_all_table_info_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpect null", K(ret)); - } else if (OB_FAIL(ObLogInsert::inner_replace_op_exprs(to_replace_exprs))) { + } else if (OB_FAIL(ObLogInsert::inner_replace_op_exprs(replacer))) { LOG_WARN("failed to replace op exprs", K(ret)); } for (int64_t i = 0; OB_SUCC(ret) && i < insert_all_table_info_->count(); ++i) { if (OB_ISNULL(insert_all_table_info_->at(i))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get null table info", K(ret), K(i)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, + } else if (OB_FAIL(replace_exprs_action(replacer, insert_all_table_info_->at(i)->when_cond_exprs_))) { LOG_WARN("failed to replace expr", K(ret)); } else { /*do nothing*/ } diff --git a/src/sql/optimizer/ob_log_insert_all.h b/src/sql/optimizer/ob_log_insert_all.h index ef58170819..981dca2d2d 100644 --- a/src/sql/optimizer/ob_log_insert_all.h +++ b/src/sql/optimizer/ob_log_insert_all.h @@ -48,8 +48,7 @@ public: { insert_all_table_info_ = insert_all_table_info; } inline const common::ObIArray *get_insert_all_table_info() const { return insert_all_table_info_; } - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; protected: virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; diff --git a/src/sql/optimizer/ob_log_join.cpp b/src/sql/optimizer/ob_log_join.cpp index add86ad82b..a9fc22efe7 100644 --- a/src/sql/optimizer/ob_log_join.cpp +++ b/src/sql/optimizer/ob_log_join.cpp @@ -246,36 +246,35 @@ int ObLogJoin::get_plan_item_info(PlanText &plan_text, return ret; } -int ObLogJoin::inner_replace_op_exprs( - const ObIArray >&to_replace_exprs) +int ObLogJoin::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_join_conditions()))) { + if (OB_FAIL(replace_exprs_action(replacer, get_join_conditions()))) { LOG_WARN("failed to extract subplan params in log join_conditions", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_join_filters()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_join_filters()))) { LOG_WARN("failed to extract subplan params in log join_filters", K(ret)); } else { int64_t N = get_nl_params().count(); for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) { ObRawExpr *&cur_expr = get_nl_params().at(i)->get_ref_expr(); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_expr))) { + if (OB_FAIL(replace_expr_action(replacer, cur_expr))) { LOG_WARN("failed to extract subplan params in log join_filters", K(ret)); } else { /* Do nothing */ } } } // add extra replace expr if (OB_SUCC(ret) && (CONNECT_BY_JOIN == join_type_)) { - if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_connect_by_root_exprs()))) { + if (OB_FAIL(replace_exprs_action(replacer, get_connect_by_root_exprs()))) { LOG_WARN("failed to replace connect by root exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_sys_connect_by_path_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_sys_connect_by_path_exprs()))) { LOG_WARN("failed to replace sys connect by path exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_prior_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_prior_exprs()))) { LOG_WARN("failed to replace prior exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_connect_by_pseudo_columns()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_connect_by_pseudo_columns()))) { LOG_WARN("failed to replace connect by pseudo columns", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_connect_by_prior_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_connect_by_prior_exprs()))) { LOG_WARN("failed to replace connect by prior exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_connect_by_extra_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_connect_by_extra_exprs()))) { LOG_WARN("failed to replace sys connect by extra exprs", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_join.h b/src/sql/optimizer/ob_log_join.h index 5afea87939..322aa00451 100644 --- a/src/sql/optimizer/ob_log_join.h +++ b/src/sql/optimizer/ob_log_join.h @@ -100,8 +100,7 @@ namespace sql common::ObIArray &get_join_filters() { return join_filters_; } - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; const common::ObIArray &get_merge_directions() const { return merge_directions_; } int set_merge_directions(const common::ObIArray &merge_directions) { diff --git a/src/sql/optimizer/ob_log_join_filter.cpp b/src/sql/optimizer/ob_log_join_filter.cpp index b0fdf74fa8..7af5d4255a 100644 --- a/src/sql/optimizer/ob_log_join_filter.cpp +++ b/src/sql/optimizer/ob_log_join_filter.cpp @@ -67,11 +67,10 @@ uint64_t ObLogJoinFilter::hash(uint64_t seed) const return seed; } -int ObLogJoinFilter::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogJoinFilter::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, join_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, join_exprs_))) { LOG_WARN("failed to replace join exprs", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_join_filter.h b/src/sql/optimizer/ob_log_join_filter.h index 0aa460aaec..6e6f51a564 100644 --- a/src/sql/optimizer/ob_log_join_filter.h +++ b/src/sql/optimizer/ob_log_join_filter.h @@ -98,8 +98,7 @@ common::ObIArray &get_join_filter_exprs_for_update() inline void set_is_no_shared_partition_join_filter() { filter_type_ = JoinFilterSharedType::NONSHARED_PARTITION_JOIN_FILTER; } JoinFilterSharedType get_filter_type() { return filter_type_; } - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; private: diff --git a/src/sql/optimizer/ob_log_limit.cpp b/src/sql/optimizer/ob_log_limit.cpp index 3afbbae58d..338795ad2e 100644 --- a/src/sql/optimizer/ob_log_limit.cpp +++ b/src/sql/optimizer/ob_log_limit.cpp @@ -198,22 +198,21 @@ int ObLogLimit::get_plan_item_info(PlanText &plan_text, return ret; } -int ObLogLimit::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogLimit::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (NULL != limit_expr_ && OB_FAIL(replace_expr_action(to_replace_exprs, limit_expr_))) { + if (NULL != limit_expr_ && OB_FAIL(replace_expr_action(replacer, limit_expr_))) { LOG_WARN("failed to replace limit expr", K(ret)); - } else if (NULL != offset_expr_ && OB_FAIL(replace_expr_action(to_replace_exprs, offset_expr_))) { + } else if (NULL != offset_expr_ && OB_FAIL(replace_expr_action(replacer, offset_expr_))) { LOG_WARN("failed to replace offset expr", K(ret)); - } else if (NULL != percent_expr_ && OB_FAIL(replace_expr_action(to_replace_exprs, percent_expr_))) { + } else if (NULL != percent_expr_ && OB_FAIL(replace_expr_action(replacer, percent_expr_))) { LOG_WARN("failed to replace percent expr", K(ret)); } 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 (OB_FAIL(replace_expr_action(to_replace_exprs, order_items_.at(i).expr_))) { + } else if (OB_FAIL(replace_expr_action(replacer, order_items_.at(i).expr_))) { LOG_WARN("failed to adjust order expr with onetime", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_limit.h b/src/sql/optimizer/ob_log_limit.h index 0763f5fdae..c09d278c4f 100644 --- a/src/sql/optimizer/ob_log_limit.h +++ b/src/sql/optimizer/ob_log_limit.h @@ -70,8 +70,7 @@ namespace sql { return is_fetch_with_ties_; } - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; private: diff --git a/src/sql/optimizer/ob_log_merge.cpp b/src/sql/optimizer/ob_log_merge.cpp index 53d17ff3fc..94a4f1cb34 100644 --- a/src/sql/optimizer/ob_log_merge.cpp +++ b/src/sql/optimizer/ob_log_merge.cpp @@ -377,23 +377,22 @@ int ObLogMerge::gen_location_constraint(void *ctx) return ret; } -int ObLogMerge::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogMerge::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(ObLogDelUpd::inner_replace_op_exprs(to_replace_exprs))) { + if (OB_FAIL(ObLogDelUpd::inner_replace_op_exprs(replacer))) { LOG_WARN("failed to replace op exprs", K(ret)); - } else if (OB_FAIL(replace_dml_info_exprs(to_replace_exprs, get_update_infos()))) { + } else if (OB_FAIL(replace_dml_info_exprs(replacer, get_update_infos()))) { LOG_WARN("failed to replace update dml info exprs"); - } else if (OB_FAIL(replace_dml_info_exprs(to_replace_exprs, get_delete_infos()))) { + } else if (OB_FAIL(replace_dml_info_exprs(replacer, get_delete_infos()))) { LOG_WARN("failed to replace delete dml info exprs"); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, + } else if (OB_FAIL(replace_exprs_action(replacer, static_cast(my_dml_plan_).get_insert_condition()))) { LOG_WARN("failed to replace insert condition exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, + } else if (OB_FAIL(replace_exprs_action(replacer, static_cast(my_dml_plan_).get_update_condition()))) { LOG_WARN("failed to replace update condition exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, + } else if (OB_FAIL(replace_exprs_action(replacer, static_cast(my_dml_plan_).get_delete_condition()))) { LOG_WARN("failed to replace delete condition exprs", K(ret)); } diff --git a/src/sql/optimizer/ob_log_merge.h b/src/sql/optimizer/ob_log_merge.h index 410322c300..5453f446ad 100644 --- a/src/sql/optimizer/ob_log_merge.h +++ b/src/sql/optimizer/ob_log_merge.h @@ -52,8 +52,7 @@ public: ObIArray &get_delete_infos() { return index_del_infos_; } const common::ObIArray &get_equal_infos() const { return equal_infos_; } int set_equal_infos(const ObIArray &equal_infos) { return equal_infos_.assign(equal_infos); } - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; protected: diff --git a/src/sql/optimizer/ob_log_optimizer_stats_gathering.cpp b/src/sql/optimizer/ob_log_optimizer_stats_gathering.cpp index d8702d01d8..daebb54b3a 100644 --- a/src/sql/optimizer/ob_log_optimizer_stats_gathering.cpp +++ b/src/sql/optimizer/ob_log_optimizer_stats_gathering.cpp @@ -148,13 +148,12 @@ int ObLogOptimizerStatsGathering::get_target_osg_id(uint64_t &target_id) return ret; } -int ObLogOptimizerStatsGathering::inner_replace_op_exprs(const common::ObIArray > &to_replace_exprs) +int ObLogOptimizerStatsGathering::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, col_conv_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, col_conv_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, generated_column_exprs_))) { + } else if (OB_FAIL(replace_exprs_action(replacer, generated_column_exprs_))) { LOG_WARN("failed to replace exprs", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_optimizer_stats_gathering.h b/src/sql/optimizer/ob_log_optimizer_stats_gathering.h index 3b9b15d690..a9364a9bcc 100644 --- a/src/sql/optimizer/ob_log_optimizer_stats_gathering.h +++ b/src/sql/optimizer/ob_log_optimizer_stats_gathering.h @@ -64,8 +64,7 @@ public: virtual int est_cost() override; virtual int get_op_exprs(ObIArray &all_exprs) override; - int inner_replace_op_exprs( - const common::ObIArray > &to_replace_exprs) override; + int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; inline void set_table_id(uint64_t table_id) { table_id_ = table_id; }; inline uint64_t get_table_id() { return table_id_; }; diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 1a38b3d5f2..f6b2e4ad84 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -103,7 +103,6 @@ ObLogPlan::ObLogPlan(ObOptimizerContext &ctx, const ObDMLStmt *stmt) log_op_factory_(allocator_), candidates_(), group_replaced_exprs_(), - window_function_replaced_exprs_(), stat_partition_id_expr_(nullptr), query_ref_(NULL), root_(NULL), @@ -160,6 +159,11 @@ void ObLogPlan::destory() onetime_copier_->~ObRawExprCopier(); onetime_copier_ = NULL; } + group_replacer_.destroy(); + window_function_replacer_.destroy(); + gen_col_replacer_.destroy(); + onetime_replacer_.destroy(); + stat_gather_replacer_.destroy(); } double ObLogPlan::get_optimization_cost() @@ -6314,14 +6318,14 @@ int ObLogPlan::perform_window_function_pushdown(ObLogicalOperator *op) LOG_WARN("failed to build_common_aggr_expr", K(ret)); } else if (FALSE_IT(static_cast(new_wf_expr)->set_agg_expr( new_aggr_expr))) { - } else if (OB_FAIL(window_function_replaced_exprs_.push_back( - std::pair(window_exprs.at(i), new_wf_expr)))) { + } else if (OB_FAIL(window_function_replacer_.add_replace_expr(window_exprs.at(i), + new_wf_expr))) { LOG_WARN("failed to push back pushdown aggr", K(ret)); } } } } - if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(window_function_replaced_exprs_))) { + if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(window_function_replacer_))) { LOG_WARN("failed to replace generated aggr expr", K(ret)); } return ret; @@ -6370,6 +6374,9 @@ int ObLogPlan::perform_group_by_pushdown(ObLogicalOperator *op) for (int64_t k = 0; k < group_replaced_exprs_.count(); ++k) { if (group_replaced_exprs_.at(k).first == from) { group_replaced_exprs_.at(k).second = to; + if (OB_FAIL(group_replacer_.add_replace_expr(from, to))) { + LOG_WARN("failed to add replace expr", K(ret)); + } break; } } @@ -6377,7 +6384,7 @@ int ObLogPlan::perform_group_by_pushdown(ObLogicalOperator *op) } } } - if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(group_replaced_exprs_))) { + if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(group_replacer_))) { LOG_WARN("failed to replace generated aggr expr", K(ret)); } } @@ -6413,6 +6420,8 @@ int ObLogPlan::try_to_generate_pullup_aggr(ObAggFunRawExpr *old_aggr, static_cast(group_replaced_exprs_.at(i).second), new_aggr))) { LOG_WARN("failed to generate pullup aggr expr", K(ret)); + } else if (OB_FAIL(group_replacer_.add_replace_expr(old_aggr, new_aggr, true))) { + LOG_WARN("failed to add replace expr" ,K(ret)); } else { group_replaced_exprs_.at(i).second = new_aggr; break; @@ -11232,7 +11241,7 @@ int ObLogPlan::replace_generate_column_exprs(ObLogicalOperator *op) LOG_WARN("failed to generate replace generated tsc expr", K(ret)); } else if (OB_FAIL(scan_op->generate_ddl_output_column_ids())) { LOG_WARN("fail to generate ddl output column ids"); - } else if (OB_FAIL(scan_op->replace_gen_col_op_exprs(gen_col_replaced_exprs_))) { + } else if (OB_FAIL(scan_op->replace_gen_col_op_exprs(gen_col_replacer_))) { LOG_WARN("failed to replace generated tsc expr", K(ret)); } if (OB_SUCC(ret) && EXTERNAL_TABLE == scan_op->get_table_type()) { @@ -11257,13 +11266,13 @@ int ObLogPlan::replace_generate_column_exprs(ObLogicalOperator *op) LOG_WARN("fail to generate insert replace exprs pair"); } else if (OB_FAIL(generate_old_column_values_exprs(insert_op))) { LOG_WARN("fail to generate index dml info column old values exprs"); - } else if (OB_FAIL(insert_op->replace_op_exprs(gen_col_replaced_exprs_))) { + } else if (OB_FAIL(insert_op->replace_op_exprs(gen_col_replacer_))) { LOG_WARN("failed to replace generated exprs", K(ret)); } } else { if (OB_FAIL(generate_old_column_values_exprs(op))) { LOG_WARN("fail to generate index dml info column old values exprs"); - } else if (OB_FAIL(op->replace_op_exprs(gen_col_replaced_exprs_))) { + } else if (OB_FAIL(op->replace_op_exprs(gen_col_replacer_))) { LOG_WARN("failed to replace generated exprs", K(ret)); } } @@ -11379,8 +11388,7 @@ int ObLogPlan::generate_tsc_replace_exprs_pair(ObLogTableScan *op) } } } - if (OB_SUCC(ret) && OB_FAIL(gen_col_replaced_exprs_.push_back( - std::pair(expr, dependant_expr)))) { + if (OB_SUCC(ret) && OB_FAIL(gen_col_replacer_.add_replace_expr(expr, dependant_expr))) { LOG_WARN("failed to push back generate replace pair", K(ret)); } } @@ -11401,8 +11409,7 @@ int ObLogPlan::generate_ins_replace_exprs_pair(ObLogDelUpd *op) if (expr->is_virtual_generated_column()) { ObRawExpr *dependant_expr = static_cast( expr)->get_dependant_expr(); - if (OB_FAIL(gen_col_replaced_exprs_.push_back( - std::pair(expr, dependant_expr)))) { + if (OB_FAIL(gen_col_replacer_.add_replace_expr(expr, dependant_expr))) { LOG_WARN("failed to push back generate replace pair", K(ret)); } } @@ -11489,11 +11496,11 @@ int ObLogPlan::adjust_final_plan_info(ObLogicalOperator *&op) OB_ISNULL(child_plan = op->get_child(i)->get_plan())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("child expr is null", K(ret)); - } else if (OB_FAIL(append(plan->group_replaced_exprs_, - child_plan->group_replaced_exprs_))) { + } else if (OB_FAIL(plan->group_replacer_.append_replace_exprs( + child_plan->group_replacer_))) { LOG_WARN("failed to append group replaced exprs", K(ret)); - } else if (OB_FAIL(append(plan->window_function_replaced_exprs_, - child_plan->window_function_replaced_exprs_))) { + } else if (OB_FAIL(plan->window_function_replacer_.append_replace_exprs( + child_plan->window_function_replacer_))) { LOG_WARN("failed to append window_function_replaced_exprs", K(ret)); } } @@ -13221,11 +13228,11 @@ int ObLogPlan::perform_adjust_onetime_expr(ObLogicalOperator *op) } else if (OB_FAIL(init_onetime_replaced_exprs_if_needed())) { LOG_WARN("faile to init onetime replaced exprs", K(ret)); } else if (NULL != (subplan_filter = dynamic_cast(op))) { - if (OB_FAIL(subplan_filter->replace_nested_subquery_exprs(onetime_replaced_exprs_))) { + if (OB_FAIL(subplan_filter->replace_nested_subquery_exprs(onetime_replacer_))) { LOG_WARN("failed to replace nested subquery exprs", K(ret)); } } - if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(onetime_replaced_exprs_))) { + if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(onetime_replacer_))) { LOG_WARN("failed to replace onetime subquery", K(ret)); } return ret; @@ -13241,6 +13248,8 @@ int ObLogPlan::init_onetime_replaced_exprs_if_needed() LOG_WARN("onetime expr copier is null", K(ret)); } else if (OB_FAIL(onetime_copier_->get_copied_exprs(onetime_replaced_exprs_))) { LOG_WARN("failed to get copied exprs", K(ret)); + } else if (OB_FAIL(onetime_replacer_.add_replace_exprs(onetime_replaced_exprs_))) { + LOG_WARN("failed to add replace exprs", K(ret)); } return ret; } @@ -13755,8 +13764,8 @@ int ObLogPlan::perform_gather_stat_replace(ObLogicalOperator *op) LOG_WARN("get unexpected null", K(group_by_expr), K(stat_partition_id_expr_), K(stat_table_scan_)); } else if (T_FUN_SYS_CALC_PARTITION_ID != group_by_expr->get_expr_type()) { // do nothing - } else if (OB_FAIL(stat_gather_replaced_exprs_.push_back( - std::pair(group_by_expr, stat_partition_id_expr_)))) { + } else if (OB_FAIL(stat_gather_replacer_.add_replace_expr(group_by_expr, + stat_partition_id_expr_))) { LOG_WARN("failed to push back replaced expr", K(ret)); } else if (group_by_expr->get_partition_id_calc_type() == CALC_IGNORE_SUB_PART) { stat_table_scan_->set_tablet_id_type(1); @@ -13765,7 +13774,7 @@ int ObLogPlan::perform_gather_stat_replace(ObLogicalOperator *op) } } } - if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(stat_gather_replaced_exprs_))) { + if (OB_SUCC(ret) && OB_FAIL(op->replace_op_exprs(stat_gather_replacer_))) { LOG_WARN("failed to replace generated aggr expr", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_plan.h b/src/sql/optimizer/ob_log_plan.h index 6b36f89534..1225123055 100644 --- a/src/sql/optimizer/ob_log_plan.h +++ b/src/sql/optimizer/ob_log_plan.h @@ -1742,11 +1742,12 @@ protected: // member variable ObLogOperatorFactory log_op_factory_; All_Candidate_Plans candidates_; common::ObSEArray, 4, common::ModulePageAllocator, true > group_replaced_exprs_; - common::ObSEArray, 4, common::ModulePageAllocator, true > - window_function_replaced_exprs_; - common::ObSEArray, 4, common::ModulePageAllocator, true > gen_col_replaced_exprs_; - common::ObSEArray, 1, common::ModulePageAllocator, true > stat_gather_replaced_exprs_; + ObRawExprReplacer group_replacer_; + ObRawExprReplacer window_function_replacer_; + ObRawExprReplacer gen_col_replacer_; + ObRawExprReplacer onetime_replacer_; // used for gather statistic begin + ObRawExprReplacer stat_gather_replacer_; ObRawExpr* stat_partition_id_expr_; ObLogTableScan* stat_table_scan_; // used for gather statistics end diff --git a/src/sql/optimizer/ob_log_select_into.cpp b/src/sql/optimizer/ob_log_select_into.cpp index a264f894cf..72525d02df 100644 --- a/src/sql/optimizer/ob_log_select_into.cpp +++ b/src/sql/optimizer/ob_log_select_into.cpp @@ -68,11 +68,10 @@ int ObLogSelectInto::get_op_exprs(ObIArray &all_exprs) return ret; } -int ObLogSelectInto::inner_replace_op_exprs( - const ObIArray > &to_replace_exprs) +int ObLogSelectInto::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, select_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, select_exprs_))) { LOG_WARN("failed to replace select exprs", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_select_into.h b/src/sql/optimizer/ob_log_select_into.h index 5880a1a95c..8adc909ed6 100644 --- a/src/sql/optimizer/ob_log_select_into.h +++ b/src/sql/optimizer/ob_log_select_into.h @@ -102,8 +102,7 @@ public: virtual int est_cost() override; virtual int compute_plan_type() override; virtual int get_op_exprs(ObIArray &all_exprs) override; - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs); + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer); private: ObItemType into_type_; common::ObObj outfile_name_; diff --git a/src/sql/optimizer/ob_log_sort.cpp b/src/sql/optimizer/ob_log_sort.cpp index cd849423ce..ca87535348 100644 --- a/src/sql/optimizer/ob_log_sort.cpp +++ b/src/sql/optimizer/ob_log_sort.cpp @@ -211,34 +211,33 @@ int ObLogSort::get_plan_item_info(PlanText &plan_text, return ret; } -int ObLogSort::inner_replace_op_exprs( - const ObIArray > &to_replace_exprs) +int ObLogSort::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; int64_t N = sort_keys_.count(); - if (NULL != topn_expr_ && OB_FAIL(replace_expr_action(to_replace_exprs, topn_expr_))) { + if (NULL != topn_expr_ && OB_FAIL(replace_expr_action(replacer, topn_expr_))) { LOG_WARN("failed to replace topn expr", K(ret)); } else if (NULL != topk_limit_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, topk_limit_expr_))) { + OB_FAIL(replace_expr_action(replacer, topk_limit_expr_))) { LOG_WARN("failed to replace topk limit expr", K(ret)); } else if (NULL != topk_offset_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, topk_offset_expr_))) { + OB_FAIL(replace_expr_action(replacer, topk_offset_expr_))) { LOG_WARN("failed to replace topk offset expr", K(ret)); } for(int64_t i = 0; OB_SUCC(ret) && i < N; ++i) { OrderItem &cur_order_item = sort_keys_.at(i); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_order_item.expr_))) { + if (OB_FAIL(replace_expr_action(replacer, cur_order_item.expr_))) { LOG_WARN("failed to resolve ref params in sort key ", K(cur_order_item), K(ret)); } else { /* Do nothing */ } } for(int64_t i = 0; OB_SUCC(ret) && i < encode_sortkeys_.count(); ++i) { OrderItem &cur_order_item = encode_sortkeys_.at(i); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_order_item.expr_))) { + if (OB_FAIL(replace_expr_action(replacer, cur_order_item.expr_))) { LOG_WARN("failed to resolve ref params in sort key ", K(cur_order_item), K(ret)); } else { /* Do nothing */ } } if (OB_SUCC(ret) && part_cnt_ > 0) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, hash_sortkey_.expr_))) { + if (OB_FAIL(replace_expr_action(replacer, hash_sortkey_.expr_))) { LOG_WARN("failed to resolve ref params of hash sortkey", K(hash_sortkey_), K(ret)); } else { /* Do nothing */ } } diff --git a/src/sql/optimizer/ob_log_sort.h b/src/sql/optimizer/ob_log_sort.h index 387a6d5074..fc0f076455 100644 --- a/src/sql/optimizer/ob_log_sort.h +++ b/src/sql/optimizer/ob_log_sort.h @@ -101,8 +101,7 @@ namespace sql virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; protected: - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs); + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer); private: OrderItem hash_sortkey_; common::ObSEArray sort_keys_; diff --git a/src/sql/optimizer/ob_log_stat_collector.cpp b/src/sql/optimizer/ob_log_stat_collector.cpp index 3bd898e080..de23e1748b 100644 --- a/src/sql/optimizer/ob_log_stat_collector.cpp +++ b/src/sql/optimizer/ob_log_stat_collector.cpp @@ -55,15 +55,14 @@ int ObLogStatCollector::get_op_exprs(ObIArray &all_exprs) return ret; } -int ObLogStatCollector::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogStatCollector::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; for (int64_t i = 0; OB_SUCC(ret) && i < sort_keys_.count(); i++) { if (OB_ISNULL(sort_keys_.at(i).expr_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, sort_keys_.at(i).expr_))) { + } else if (OB_FAIL(replace_expr_action(replacer, sort_keys_.at(i).expr_))) { LOG_WARN("failed to replace sort key expr", K(ret)); } } diff --git a/src/sql/optimizer/ob_log_stat_collector.h b/src/sql/optimizer/ob_log_stat_collector.h index e1ab77a354..d626551d71 100644 --- a/src/sql/optimizer/ob_log_stat_collector.h +++ b/src/sql/optimizer/ob_log_stat_collector.h @@ -39,8 +39,7 @@ public: void set_is_none_partition(bool flag) { is_none_partition_ = flag; } bool get_is_none_partition() { return is_none_partition_; } virtual int get_op_exprs(ObIArray &all_exprs) override; - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; private: common::ObSEArray sort_keys_; bool is_none_partition_; diff --git a/src/sql/optimizer/ob_log_subplan_filter.cpp b/src/sql/optimizer/ob_log_subplan_filter.cpp index 3e25e6e213..bb44bd7533 100644 --- a/src/sql/optimizer/ob_log_subplan_filter.cpp +++ b/src/sql/optimizer/ob_log_subplan_filter.cpp @@ -584,16 +584,14 @@ int ObLogSubPlanFilter::allocate_startup_expr_post() return ret; } -int ObLogSubPlanFilter::inner_replace_op_exprs( - const ObIArray > &to_replace_exprs) +int ObLogSubPlanFilter::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; for (int64_t i = 0; OB_SUCC(ret) && i < exec_params_.count(); ++i) { if (OB_ISNULL(exec_params_.at(i))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("exec param is null", K(ret)); - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, - exec_params_.at(i)->get_ref_expr()))) { + } else if (OB_FAIL(replace_expr_action(replacer, exec_params_.at(i)->get_ref_expr()))) { LOG_WARN("failed to replace expr action", K(ret)); } } @@ -614,8 +612,7 @@ int ObLogSubPlanFilter::allocate_subquery_id() return ret; } -int ObLogSubPlanFilter::replace_nested_subquery_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogSubPlanFilter::replace_nested_subquery_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; ObLogPlan *plan = NULL; @@ -627,7 +624,7 @@ int ObLogSubPlanFilter::replace_nested_subquery_exprs( ObRawExpr *expr = subquery_exprs_.at(i); if (ObOptimizerUtil::find_item(plan->get_onetime_query_refs(), expr)) { // do not replace onetime expr ref query, only adjust nested subquery - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, expr))) { + } else if (OB_FAIL(replace_expr_action(replacer, expr))) { LOG_WARN("failed to replace nested subquery expr", K(ret)); } else if (expr == subquery_exprs_.at(i)) { // do nothing diff --git a/src/sql/optimizer/ob_log_subplan_filter.h b/src/sql/optimizer/ob_log_subplan_filter.h index 659c7a400b..cf49f17d4b 100644 --- a/src/sql/optimizer/ob_log_subplan_filter.h +++ b/src/sql/optimizer/ob_log_subplan_filter.h @@ -85,8 +85,7 @@ public: int get_exists_style_exprs(ObIArray &subquery_exprs); - virtual int inner_replace_op_exprs( - const ObIArray >&to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; void set_update_set(bool update_set) { update_set_ = update_set; } @@ -113,8 +112,7 @@ public: int allocate_subquery_id(); - int replace_nested_subquery_exprs( - const common::ObIArray> &to_replace_exprs); + int replace_nested_subquery_exprs(ObRawExprReplacer &replacer); virtual int get_plan_item_info(PlanText &plan_text, ObSqlPlanItem &plan_item) override; diff --git a/src/sql/optimizer/ob_log_table_scan.cpp b/src/sql/optimizer/ob_log_table_scan.cpp index 26f801c225..bdbd9530e9 100644 --- a/src/sql/optimizer/ob_log_table_scan.cpp +++ b/src/sql/optimizer/ob_log_table_scan.cpp @@ -363,26 +363,25 @@ int ObLogTableScan::generate_access_exprs() } -int ObLogTableScan::replace_gen_col_op_exprs( - const ObIArray >&to_replace_exprs) +int ObLogTableScan::replace_gen_col_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; if (is_index_scan() && !(get_index_back())) { // do nothing. - } else if (0 < to_replace_exprs.count()) { + } else if (!replacer.empty()) { FOREACH_CNT_X(it, get_op_ordering(), OB_SUCC(ret)) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, it->expr_))) { + if (OB_FAIL(replace_expr_action(replacer, it->expr_))) { LOG_WARN("replace agg expr failed", K(ret)); } } if (OB_FAIL(ret)) { - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_output_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_output_exprs()))) { LOG_WARN("failed to replace agg expr", K(ret)); } else if (NULL != limit_offset_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, limit_count_expr_))) { + OB_FAIL(replace_expr_action(replacer, limit_count_expr_))) { LOG_WARN("failed to replace limit count expr", K(ret)); } else if (NULL != limit_offset_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, limit_offset_expr_))) { + OB_FAIL(replace_expr_action(replacer, limit_offset_expr_))) { LOG_WARN("failed to replace limit offset expr ", K(ret)); } else { for (int64_t i = 0; OB_SUCC(ret) && i < pushdown_aggr_exprs_.count(); ++i) { @@ -391,7 +390,7 @@ int ObLogTableScan::replace_gen_col_op_exprs( if (OB_ISNULL(pushdown_aggr_expr->get_param_expr(j))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("param_expr is NULL", K(j), K(ret)); - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, + } else if (OB_FAIL(replace_expr_action(replacer, pushdown_aggr_expr->get_param_expr(j)))) { LOG_WARN("Fail to replace push down aggr expr", K(i), K(j), K(ret)); } @@ -401,18 +400,18 @@ int ObLogTableScan::replace_gen_col_op_exprs( // Scenario processing without index table. if (OB_SUCC(ret) && !get_index_back()) { if (NULL != part_expr_ && - OB_FAIL(replace_expr_action(to_replace_exprs, part_expr_))) { + OB_FAIL(replace_expr_action(replacer, part_expr_))) { LOG_WARN("failed to replace part expr ", K(ret)); - } else if (NULL != subpart_expr_ && OB_FAIL(replace_expr_action(to_replace_exprs, + } else if (NULL != subpart_expr_ && OB_FAIL(replace_expr_action(replacer, subpart_expr_))) { LOG_WARN("failed to replace subpart expr ", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_filter_exprs()))) { + } else if (OB_FAIL(replace_exprs_action(replacer, get_filter_exprs()))) { LOG_WARN("failed to replace agg expr", K(ret)); } } // Index back to table scene processing if (OB_SUCC(ret) && get_index_back()) { - if (OB_FAIL(replace_index_back_pushdown_filters(to_replace_exprs))) { + if (OB_FAIL(replace_index_back_pushdown_filters(replacer))) { LOG_WARN("failed to replace pushdown exprs", K(ret)); } } @@ -420,22 +419,21 @@ int ObLogTableScan::replace_gen_col_op_exprs( return ret; } -int ObLogTableScan::replace_index_back_pushdown_filters( - const ObIArray >&to_replace_exprs) +int ObLogTableScan::replace_index_back_pushdown_filters(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; ObIArray &filters = get_filter_exprs(); const auto &flags = get_filter_before_index_flags(); if (get_contains_fake_cte() || is_virtual_table(get_ref_table_id())) { // nonpushdown need replace. - if (OB_FAIL(replace_exprs_action(to_replace_exprs, filters))) { + if (OB_FAIL(replace_exprs_action(replacer, filters))) { LOG_WARN("failed to replace agg expr", K(ret)); } } else { for (int64_t i = 0; OB_SUCC(ret) && i < filters.count(); ++i) { if (filters.at(i)->has_flag(CNT_PL_UDF)) { // nonpushdown need replace. - if (OB_FAIL(replace_expr_action(to_replace_exprs, filters.at(i)))) { + if (OB_FAIL(replace_expr_action(replacer, filters.at(i)))) { LOG_WARN("failed to replace agg expr", K(ret)); } } else if (!get_index_back()) { @@ -446,13 +444,13 @@ int ObLogTableScan::replace_index_back_pushdown_filters( } else if (flags.at(i)) { if (get_index_back() && get_is_index_global() && filters.at(i)->has_flag(CNT_SUB_QUERY)) { // lookup_pushdown need replace. - if (OB_FAIL(replace_expr_action(to_replace_exprs, filters.at(i)))) { + if (OB_FAIL(replace_expr_action(replacer, filters.at(i)))) { LOG_WARN("failed to replace agg expr", K(ret)); } } else { // scan_pushdown no need replace. } - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, filters.at(i)))) { + } else if (OB_FAIL(replace_expr_action(replacer, filters.at(i)))) { LOG_WARN("failed to replace agg expr", K(ret)); } } @@ -1658,14 +1656,13 @@ int ObLogTableScan::set_query_ranges(ObIArray &ranges, return ret; } -int ObLogTableScan::inner_replace_op_exprs( - const ObIArray > &to_replace_exprs) +int ObLogTableScan::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (OB_FAIL(replace_exprs_action(to_replace_exprs, access_exprs_))) { + if (OB_FAIL(replace_exprs_action(replacer, access_exprs_))) { LOG_WARN("failed to replace_expr_action", K(ret)); } else if (calc_part_id_expr_ != NULL && - OB_FAIL(replace_expr_action(to_replace_exprs, calc_part_id_expr_))) { + OB_FAIL(replace_expr_action(replacer, calc_part_id_expr_))) { LOG_WARN("failed to replace calc part id expr", K(ret)); } return ret; diff --git a/src/sql/optimizer/ob_log_table_scan.h b/src/sql/optimizer/ob_log_table_scan.h index ba9454d121..e1ba7f18ec 100644 --- a/src/sql/optimizer/ob_log_table_scan.h +++ b/src/sql/optimizer/ob_log_table_scan.h @@ -345,8 +345,7 @@ public: { is_multi_part_table_scan_ = multi_part_tsc; } bool get_is_multi_part_table_scan() { return is_multi_part_table_scan_; } int set_query_ranges(ObIArray &ranges, ObIArray &ss_ranges); - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; inline common::ObIArray &get_filter_before_index_flags() { return filter_before_index_back_; } inline const common::ObIArray &get_filter_before_index_flags() const { return filter_before_index_back_; } inline ObRawExpr *get_limit_expr() { return limit_count_expr_; } @@ -461,13 +460,11 @@ public: inline bool has_index_lookup_filter() { return has_index_lookup_filter_; } inline void set_has_index_lookup_filter(bool has_index_lookup_filter) { has_index_lookup_filter_ = has_index_lookup_filter; } int generate_ddl_output_column_ids(); - int replace_gen_col_op_exprs( - const ObIArray >&to_replace_exprs); + int replace_gen_col_op_exprs(ObRawExprReplacer &replacer); int extract_pushdown_filters(ObIArray &nonpushdown_filters, ObIArray &scan_pushdown_filters, ObIArray &lookup_pushdown_filters); - int replace_index_back_pushdown_filters( - const ObIArray >&to_replace_exprs); + int replace_index_back_pushdown_filters(ObRawExprReplacer &replacer); int extract_virtual_gen_access_exprs(ObIArray &access_exprs, uint64_t scan_table_id); int adjust_print_access_info(ObIArray &access_exprs); diff --git a/src/sql/optimizer/ob_log_window_function.cpp b/src/sql/optimizer/ob_log_window_function.cpp index 6e49846235..b4788a2c90 100644 --- a/src/sql/optimizer/ob_log_window_function.cpp +++ b/src/sql/optimizer/ob_log_window_function.cpp @@ -429,12 +429,11 @@ int ObLogWindowFunction::print_used_hint(PlanText &plan_text) return ret; } -int ObLogWindowFunction::inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) +int ObLogWindowFunction::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; FOREACH_X(key, sort_keys_, OB_SUCC(ret)) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, key->expr_))) { + if (OB_FAIL(replace_expr_action(replacer, key->expr_))) { LOG_WARN("replace expr failed", K(ret)); } } @@ -444,7 +443,7 @@ int ObLogWindowFunction::inner_replace_op_exprs( if (OB_ISNULL(win_expr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("win expr is null", K(ret)); - } else if (OB_FAIL(replace_expr_action(to_replace_exprs, win_expr))) { + } else if (OB_FAIL(replace_expr_action(replacer, win_expr))) { LOG_WARN("replace expr failed", K(ret)); } else if (win_expr == win_exprs_.at(i)) { // do nothing diff --git a/src/sql/optimizer/ob_log_window_function.h b/src/sql/optimizer/ob_log_window_function.h index 3e4d652907..7c8eafac48 100644 --- a/src/sql/optimizer/ob_log_window_function.h +++ b/src/sql/optimizer/ob_log_window_function.h @@ -59,8 +59,7 @@ namespace sql virtual int allocate_granule_pre(AllocGIContext &ctx) override; int get_win_partition_intersect_exprs(ObIArray &win_exprs, ObIArray &win_part_exprs); - virtual int inner_replace_op_exprs( - const common::ObIArray> &to_replace_exprs) override; + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer) override; void set_single_part_parallel(bool v) { single_part_parallel_ = v; } bool is_single_part_parallel() const { return single_part_parallel_; } void set_ragne_dist_parallel(bool v) { range_dist_parallel_ = v; } diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index aa3eec17c4..2900ba5c4d 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -3478,34 +3478,32 @@ int ObLogicalOperator::check_stmt_can_be_packed(const ObDMLStmt *stmt, bool &nee return ret; } -int ObLogicalOperator::replace_op_exprs( - const ObIArray >&to_replace_exprs) +int ObLogicalOperator::replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; - if (0 < to_replace_exprs.count()) { + if (!replacer.empty()) { FOREACH_CNT_X(it, get_op_ordering(), OB_SUCC(ret)) { - if (OB_FAIL(replace_expr_action(to_replace_exprs, it->expr_))) { - LOG_WARN("replace agg expr failed", K(ret)); + if (OB_FAIL(replace_expr_action(replacer, it->expr_))) { + LOG_WARN("replace expr failed", K(ret)); } } if (OB_FAIL(ret)) { - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_filter_exprs()))) { - LOG_WARN("failed to replace agg expr", K(ret)); - } else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_output_exprs()))) { - LOG_WARN("failed to replace agg expr", K(ret)); - } else if (OB_FAIL(inner_replace_op_exprs(to_replace_exprs))) { - LOG_WARN("failed to inner replace agg expr", K(ret)); + } else if (OB_FAIL(replace_exprs_action(replacer, get_filter_exprs()))) { + LOG_WARN("failed to replace expr", K(ret)); + } else if (OB_FAIL(replace_exprs_action(replacer, get_output_exprs()))) { + LOG_WARN("failed to replace expr", K(ret)); + } else if (OB_FAIL(inner_replace_op_exprs(replacer))) { + LOG_WARN("failed to inner replace expr", K(ret)); } else { /* Do nothing */ } } else { /* Do nothing */ } return ret; } -int ObLogicalOperator::inner_replace_op_exprs( - const ObIArray >&to_replace_exprs) +int ObLogicalOperator::inner_replace_op_exprs(ObRawExprReplacer &replacer) { int ret = OB_SUCCESS; //do operator specific - UNUSED(to_replace_exprs); + UNUSED(replacer); return ret; } @@ -3513,34 +3511,27 @@ int ObLogicalOperator::inner_replace_op_exprs( * pair: orig_expr new_expr */ int ObLogicalOperator::replace_exprs_action( - const ObIArray >&to_replace_exprs, + ObRawExprReplacer &replacer, ObIArray &dest_exprs) { int ret = OB_SUCCESS; - int64_t src_num = to_replace_exprs.count(); int64_t dest_num = dest_exprs.count(); - if (src_num > 0) { + if (!replacer.empty()) { for (int64_t i = 0; OB_SUCC(ret) && i < dest_num; ++i) { ObRawExpr *&cur_expr = dest_exprs.at(i); - if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_expr))) { - LOG_WARN("failed to do replace agg expr action", K(ret)); + if (OB_FAIL(replace_expr_action(replacer, cur_expr))) { + LOG_WARN("failed to do replace expr action", K(ret)); } else { /* Do nothing */ } } } else { /* Do nothing */ } return ret; } -int ObLogicalOperator::replace_expr_action( - const ObIArray >&to_replace_exprs, - ObRawExpr *&dest_expr) +int ObLogicalOperator::replace_expr_action(ObRawExprReplacer &replacer, ObRawExpr *&dest_expr) { int ret = OB_SUCCESS; - int64_t src_num = to_replace_exprs.count(); - if (src_num > 0) { - ObRawExprReplacer replacer; - if (OB_FAIL(replacer.add_replace_exprs(to_replace_exprs))) { - LOG_WARN("failed to add replaced exprs"); - } else if (OB_FAIL(replacer.replace(dest_expr))) { + if (!replacer.empty()) { + if (OB_FAIL(replacer.replace(dest_expr))) { LOG_WARN("failed to replace expr", K(ret)); } else if (replacer.get_replace_happened()) { ObSQLSessionInfo *session_info = get_plan()->get_optimizer_context().get_session_info(); diff --git a/src/sql/optimizer/ob_logical_operator.h b/src/sql/optimizer/ob_logical_operator.h index ba964aad99..392dbd9ec0 100644 --- a/src/sql/optimizer/ob_logical_operator.h +++ b/src/sql/optimizer/ob_logical_operator.h @@ -1530,8 +1530,7 @@ public: /* * replace exprs which will be returned by get_op_exprs during allocating expr */ - int replace_op_exprs( - const common::ObIArray >&to_replace_exprs); + int replace_op_exprs(ObRawExprReplacer &replacer); // check if this operator is some kind of table scan. // the default return value is false @@ -1693,12 +1692,9 @@ protected: void do_project_pruning(common::ObIArray &exprs, PPDeps &deps); int try_add_remove_const_exprs(); - virtual int inner_replace_op_exprs( - const common::ObIArray >&to_replace_exprs); - int replace_exprs_action(const common::ObIArray >&to_replace_exprs, - common::ObIArray &dest_exprs); - int replace_expr_action(const common::ObIArray >&to_replace_exprs, - ObRawExpr *&dest_expr); + virtual int inner_replace_op_exprs(ObRawExprReplacer &replacer); + int replace_exprs_action(ObRawExprReplacer &replacer, common::ObIArray &dest_exprs); + int replace_expr_action(ObRawExprReplacer &replacer, ObRawExpr *&dest_expr); int explain_print_partitions(ObTablePartitionInfo &table_partition_info, char *buf, int64_t &buf_len, int64_t &pos); diff --git a/src/sql/resolver/expr/ob_raw_expr_replacer.cpp b/src/sql/resolver/expr/ob_raw_expr_replacer.cpp index 52c30430fb..0fd55dc10f 100644 --- a/src/sql/resolver/expr/ob_raw_expr_replacer.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_replacer.cpp @@ -27,6 +27,16 @@ ObRawExprReplacer::ObRawExprReplacer() ObRawExprReplacer::~ObRawExprReplacer() {} +void ObRawExprReplacer::destroy() +{ + if (to_exprs_.created()) { + to_exprs_.destroy(); + } + if (expr_replace_map_.created()) { + expr_replace_map_.destroy(); + } +} + int ObRawExprReplacer::replace(ObRawExpr *&expr) { int ret = OB_SUCCESS; @@ -310,27 +320,23 @@ bool ObRawExprReplacer::skip_child(ObRawExpr &expr) } int ObRawExprReplacer::add_replace_expr(ObRawExpr *from_expr, - ObRawExpr *to_expr) + ObRawExpr *to_expr, + bool overwrite /*false*/) { int ret = OB_SUCCESS; bool is_existed = false; if (OB_ISNULL(from_expr) || OB_ISNULL(to_expr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected null expr", KP(from_expr), KP(to_expr), K(ret)); - } else if (OB_UNLIKELY(!expr_replace_map_.created())) { - if (OB_FAIL(expr_replace_map_.create(64, ObModIds::OB_SQL_COMPILE))) { - LOG_WARN("failed to create expr map", K(ret)); - } else if (OB_FAIL(to_exprs_.create(64))) { - LOG_WARN("failed to create expr set", K(ret)); - } - } - if (OB_FAIL(ret)) { - } else if (OB_FAIL(check_from_expr_existed(from_expr, to_expr, is_existed))) { + } else if (OB_FAIL(try_init_expr_map(DEFAULT_BUCKET_SIZE))) { + LOG_WARN("failed to init expr map", K(ret)); + } else if (OB_FAIL(check_from_expr_existed(from_expr, to_expr, overwrite, is_existed))) { LOG_WARN("failed to check from expr existed", K(ret)); } else if (is_existed) { // do not add duplicated replace expr } else if (OB_FAIL(expr_replace_map_.set_refactored(reinterpret_cast(from_expr), - reinterpret_cast(to_expr)))) { + reinterpret_cast(to_expr), + overwrite))) { LOG_WARN("failed to add replace expr into map", K(ret)); } else if (OB_FAIL(to_exprs_.set_refactored(reinterpret_cast(to_expr)))) { LOG_WARN("failed to add replace expr into set", K(ret)); @@ -345,6 +351,8 @@ int ObRawExprReplacer::add_replace_exprs(const ObIArray &from_exprs if (OB_UNLIKELY(from_exprs.count() != to_exprs.count())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("expr size mismatch", K(from_exprs.count()), K(to_exprs.count()), K(ret)); + } else if (OB_FAIL(try_init_expr_map(from_exprs.count()))) { + LOG_WARN("failed to init expr map", K(ret)); } for (int64_t i = 0; OB_SUCC(ret) && i < from_exprs.count(); ++i) { if (OB_FAIL(add_replace_expr(from_exprs.at(i), to_exprs.at(i)))) { @@ -358,6 +366,9 @@ int ObRawExprReplacer::add_replace_exprs( const ObIArray> &to_replace_exprs) { int ret = OB_SUCCESS; + if (OB_FAIL(try_init_expr_map(to_replace_exprs.count()))) { + LOG_WARN("failed to init expr map", K(ret)); + } for (int64_t i = 0; OB_SUCC(ret) && i < to_replace_exprs.count(); ++i) { if (OB_FAIL(add_replace_expr(to_replace_exprs.at(i).first, to_replace_exprs.at(i).second))) { LOG_WARN("failed to add replace expr", K(ret)); @@ -366,8 +377,39 @@ int ObRawExprReplacer::add_replace_exprs( return ret; } +int ObRawExprReplacer::append_replace_exprs(const ObRawExprReplacer &other) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(try_init_expr_map(other.expr_replace_map_.size()))) { + LOG_WARN("failed to init expr map", K(ret)); + } + for (auto it = other.expr_replace_map_.begin(); + OB_SUCC(ret) && it != other.expr_replace_map_.end(); ++it) { + if (OB_FAIL(add_replace_expr(reinterpret_cast(it->first), + reinterpret_cast(it->second)))) { + LOG_WARN("failed to push back from to expr", K(ret)); + } + } + return ret; +} + +int ObRawExprReplacer::try_init_expr_map(int64_t bucket_size) +{ + int ret = OB_SUCCESS; + if (OB_UNLIKELY(!expr_replace_map_.created())) { + bucket_size = MAX(bucket_size, DEFAULT_BUCKET_SIZE); + if (OB_FAIL(expr_replace_map_.create(bucket_size, ObModIds::OB_SQL_COMPILE))) { + LOG_WARN("failed to create expr map", K(ret)); + } else if (OB_FAIL(to_exprs_.create(bucket_size))) { + LOG_WARN("failed to create expr set", K(ret)); + } + } + return ret; +} + int ObRawExprReplacer::check_from_expr_existed(const ObRawExpr *from_expr, const ObRawExpr *to_expr, + const bool overwrite, bool &is_existed) { int ret = OB_SUCCESS; @@ -377,8 +419,12 @@ int ObRawExprReplacer::check_from_expr_existed(const ObRawExpr *from_expr, } else if (!is_existed) { // do nothing } else if (OB_UNLIKELY(old_expr != to_expr)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("conflict expr replace rules", K(ret), KPC(from_expr), KPC(to_expr), KPC(old_expr)); + if (overwrite) { + is_existed = false; + } else { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("conflict expr replace rules", K(ret), KPC(from_expr), KPC(to_expr), KPC(old_expr)); + } } return ret; } diff --git a/src/sql/resolver/expr/ob_raw_expr_replacer.h b/src/sql/resolver/expr/ob_raw_expr_replacer.h index 5c2ce1b1c4..b3c8d6e9c9 100644 --- a/src/sql/resolver/expr/ob_raw_expr_replacer.h +++ b/src/sql/resolver/expr/ob_raw_expr_replacer.h @@ -35,6 +35,7 @@ public: ObRawExprReplacer(); virtual ~ObRawExprReplacer(); + void destroy(); int replace(ObRawExpr *&expr); virtual int visit(ObConstRawExpr &expr) override; virtual int visit(ObExecParamRawExpr &expr) override; @@ -56,17 +57,23 @@ public: bool get_replace_happened() const { return replace_happened_; } void set_skip_bool_param_mysql(bool skip) { skip_bool_param_mysql_ = skip; } bool is_skip_bool_param_mysql() { return skip_bool_param_mysql_; } + bool empty() const { return !expr_replace_map_.created(); } int add_replace_expr(ObRawExpr *from_expr, - ObRawExpr *to_expr); + ObRawExpr *to_expr, + bool overwrite = false); int add_replace_exprs(const ObIArray &from_exprs, const ObIArray &to_exprs); int add_replace_exprs(const ObIArray> &to_replace_exprs); + int append_replace_exprs(const ObRawExprReplacer &other); private: // types and constants + static const int64_t DEFAULT_BUCKET_SIZE = 64; private: + int try_init_expr_map(int64_t bucket_size); int check_from_expr_existed(const ObRawExpr *from_expr, const ObRawExpr *to_expr, + const bool overwrite, bool &is_existed); int check_skip_expr(const ObRawExpr &expr, bool &skip_expr); int check_need_replace(const ObRawExpr *old_expr,