From 6c172afeaec4e0d8e2431a8a2a3835e07023e55f Mon Sep 17 00:00:00 2001 From: zzg19950727 <1071026277@qq.com> Date: Tue, 21 May 2024 05:21:40 +0000 Subject: [PATCH] fix online stat gather plan bug --- src/sql/optimizer/ob_del_upd_log_plan.cpp | 9 +++--- src/sql/optimizer/ob_del_upd_log_plan.h | 3 +- src/sql/optimizer/ob_insert_log_plan.cpp | 38 +++++++++++++++++++++-- src/sql/optimizer/ob_insert_log_plan.h | 5 +++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/sql/optimizer/ob_del_upd_log_plan.cpp b/src/sql/optimizer/ob_del_upd_log_plan.cpp index d0051c265..c0294b0c8 100644 --- a/src/sql/optimizer/ob_del_upd_log_plan.cpp +++ b/src/sql/optimizer/ob_del_upd_log_plan.cpp @@ -1179,7 +1179,9 @@ int ObDelUpdLogPlan::create_pdml_insert_plan(ObLogicalOperator *&top, } else if (OB_FAIL(allocate_exchange_as_top(top, exch_info))) { LOG_WARN("failed to allocate exchange as top", K(ret)); } else if (osg_info != NULL && - OB_FAIL(allocate_optimizer_stats_gathering_as_top(top, *osg_info))) { + OB_FAIL(allocate_optimizer_stats_gathering_as_top(top, + *osg_info, + OSG_TYPE::GATHER_OSG))) { LOG_WARN("failed to allocate optimizer stats gathering"); } else if (OB_FAIL(allocate_pdml_insert_as_top(top, is_index_maintenance, @@ -1194,7 +1196,8 @@ int ObDelUpdLogPlan::create_pdml_insert_plan(ObLogicalOperator *&top, } int ObDelUpdLogPlan::allocate_optimizer_stats_gathering_as_top(ObLogicalOperator *&old_top, - OSGShareInfo &info) + OSGShareInfo &info, + OSG_TYPE type) { int ret = OB_SUCCESS; ObLogOptimizerStatsGathering *osg = NULL; @@ -1206,8 +1209,6 @@ int ObDelUpdLogPlan::allocate_optimizer_stats_gathering_as_top(ObLogicalOperator ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to allocate sequence operator", K(ret)); } else { - OSG_TYPE type = old_top->need_osg_merge() ? OSG_TYPE::MERGE_OSG : - old_top->is_sharding() ? OSG_TYPE::GATHER_OSG : OSG_TYPE::NORMAL_OSG; osg->set_child(ObLogicalOperator::first_child, old_top); osg->set_osg_type(type); osg->set_table_id(info.table_id_); diff --git a/src/sql/optimizer/ob_del_upd_log_plan.h b/src/sql/optimizer/ob_del_upd_log_plan.h index 838dc5da9..697c3efee 100644 --- a/src/sql/optimizer/ob_del_upd_log_plan.h +++ b/src/sql/optimizer/ob_del_upd_log_plan.h @@ -245,7 +245,8 @@ protected: virtual int generate_normal_raw_plan() override; virtual int generate_dblink_raw_plan() override; int allocate_optimizer_stats_gathering_as_top(ObLogicalOperator *&old_top, - OSGShareInfo &info); + OSGShareInfo &info, + OSG_TYPE type); private: DISALLOW_COPY_AND_ASSIGN(ObDelUpdLogPlan); diff --git a/src/sql/optimizer/ob_insert_log_plan.cpp b/src/sql/optimizer/ob_insert_log_plan.cpp index 4bdc5c1a1..d92a24cc9 100644 --- a/src/sql/optimizer/ob_insert_log_plan.cpp +++ b/src/sql/optimizer/ob_insert_log_plan.cpp @@ -498,6 +498,31 @@ int ObInsertLogPlan::build_lock_row_flag_expr(ObConstRawExpr *&lock_row_flag_exp return ret; } +int ObInsertLogPlan::get_osg_type(bool is_multi_part_dml, + ObShardingInfo *insert_table_sharding, + int64_t distributed_method, + OSG_TYPE &type) +{ + int ret = OB_SUCCESS; + type = OSG_TYPE::NORMAL_OSG; + if (DIST_PARTITION_WISE == distributed_method || + DIST_PULL_TO_LOCAL == distributed_method) { + //need merge stats + type = OSG_TYPE::GATHER_OSG; + } else if (DIST_BASIC_METHOD == distributed_method) { + if (is_multi_part_dml) { + type = OSG_TYPE::NORMAL_OSG; + } else if (OB_ISNULL(insert_table_sharding)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpect null sharding", K(ret)); + } else if (insert_table_sharding->is_remote()) { + //need merge stats + type = OSG_TYPE::GATHER_OSG; + } + } + return ret; +} + int ObInsertLogPlan::create_insert_plans(ObIArray &candi_plans, ObTablePartitionInfo *insert_table_part, ObShardingInfo *insert_table_sharding, @@ -511,6 +536,7 @@ int ObInsertLogPlan::create_insert_plans(ObIArray &candi_plans, ObExchangeInfo exch_info; bool is_multi_part_dml = false; CandidatePlan candi_plan; + OSG_TYPE osg_type = OSG_TYPE::NORMAL_OSG; int64_t inherit_sharding_index = OB_INVALID_INDEX; ObShardingInfo *insert_op_sharding = NULL; ObSEArray input_shardings; @@ -533,9 +559,16 @@ int ObInsertLogPlan::create_insert_plans(ObIArray &candi_plans, LOG_WARN("failed to get best insert plan method", K(ret)); } else if (0 == distributed_methods) { /*do nothing*/ + } else if (osg_info != NULL && + OB_FAIL(get_osg_type(is_multi_part_dml, + insert_table_sharding, + distributed_methods, + osg_type))) { + LOG_WARN("failed to get osg type", K(ret)); } else if (osg_info != NULL && OB_FAIL(allocate_optimizer_stats_gathering_as_top(candi_plan.plan_tree_, - *osg_info))) { + *osg_info, + osg_type))) { LOG_WARN("failed to allocate sequence as top", K(ret)); } else if (DIST_PULL_TO_LOCAL == distributed_methods) { if (OB_FAIL(allocate_exchange_as_top(candi_plan.plan_tree_, exch_info))) { @@ -1598,7 +1631,8 @@ int ObInsertLogPlan::candi_allocate_optimizer_stats_merge(OSGShareInfo *osg_info LOG_WARN("failed to allocate exchange as top", K(ret)); } else if (OB_FAIL(allocate_optimizer_stats_gathering_as_top( best_candidates.at(i).plan_tree_, - *osg_info))) { + *osg_info, + OSG_TYPE::MERGE_OSG))) { LOG_WARN("failed to allocate sequence as top", K(ret)); } } diff --git a/src/sql/optimizer/ob_insert_log_plan.h b/src/sql/optimizer/ob_insert_log_plan.h index 4b6ffc72d..4eadbd3a8 100644 --- a/src/sql/optimizer/ob_insert_log_plan.h +++ b/src/sql/optimizer/ob_insert_log_plan.h @@ -71,6 +71,11 @@ protected: int candi_allocate_pdml_insert(OSGShareInfo *osg_info); int candi_allocate_optimizer_stats_merge(OSGShareInfo *osg_info); + int get_osg_type(bool is_multi_part_dml, + ObShardingInfo *insert_table_sharding, + int64_t distributed_method, + OSG_TYPE &type); + virtual int get_best_insert_dist_method(ObLogicalOperator &top, ObTablePartitionInfo *insert_table_partition, ObShardingInfo *insert_table_sharding,