From 2d1316649a4a6670169cd330fffe8d3e9199466e Mon Sep 17 00:00:00 2001 From: coolfishchen Date: Mon, 8 Jan 2024 02:42:55 +0000 Subject: [PATCH] [CP] fix bug of NO_GATHER_OPTIMIZER_STATISTICS no affect --- .../engine/cmd/ob_table_direct_insert_ctx.cpp | 1 + .../engine/cmd/ob_table_direct_insert_ctx.h | 11 ++++++++++- src/sql/optimizer/ob_insert_log_plan.cpp | 18 ++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/sql/engine/cmd/ob_table_direct_insert_ctx.cpp b/src/sql/engine/cmd/ob_table_direct_insert_ctx.cpp index 2620c50fb4..648ef727c4 100644 --- a/src/sql/engine/cmd/ob_table_direct_insert_ctx.cpp +++ b/src/sql/engine/cmd/ob_table_direct_insert_ctx.cpp @@ -78,6 +78,7 @@ int ObTableDirectInsertCtx::init(ObExecContext *exec_ctx, param.max_error_row_count_ = 0; param.dup_action_ = sql::ObLoadDupActionType::LOAD_STOP_ON_DUP; param.sql_mode_ = sql_mode; + param.online_opt_stat_gather_ = is_online_gather_statistics_; if (OB_FAIL(table_load_instance_->init(param, store_column_idxs, load_exec_ctx_))) { LOG_WARN("failed to init direct loader", KR(ret)); } else { diff --git a/src/sql/engine/cmd/ob_table_direct_insert_ctx.h b/src/sql/engine/cmd/ob_table_direct_insert_ctx.h index bfe680b449..ab34331081 100644 --- a/src/sql/engine/cmd/ob_table_direct_insert_ctx.h +++ b/src/sql/engine/cmd/ob_table_direct_insert_ctx.h @@ -33,7 +33,8 @@ public: : load_exec_ctx_(nullptr), table_load_instance_(nullptr), is_inited_(false), - is_direct_(false) {} + is_direct_(false), + is_online_gather_statistics_(false) {} ~ObTableDirectInsertCtx(); TO_STRING_KV(K_(is_inited)); public: @@ -44,6 +45,13 @@ public: bool get_is_direct() const { return is_direct_; } void set_is_direct(bool is_direct) { is_direct_ = is_direct; } + bool get_is_online_gather_statistics() const { + return is_online_gather_statistics_; + } + + void set_is_online_gather_statistics(const bool is_online_gather_statistics) { + is_online_gather_statistics_ = is_online_gather_statistics; + } private: int init_store_column_idxs(const uint64_t tenant_id, const uint64_t table_id, @@ -53,6 +61,7 @@ private: observer::ObTableLoadInstance *table_load_instance_; bool is_inited_; bool is_direct_; //indict whether the plan is direct load plan including insert into append and load data direct + bool is_online_gather_statistics_; }; } // namespace observer } // namespace oceanbase diff --git a/src/sql/optimizer/ob_insert_log_plan.cpp b/src/sql/optimizer/ob_insert_log_plan.cpp index 1c13cf889b..1293398749 100644 --- a/src/sql/optimizer/ob_insert_log_plan.cpp +++ b/src/sql/optimizer/ob_insert_log_plan.cpp @@ -95,8 +95,22 @@ int ObInsertLogPlan::generate_normal_raw_plan() LOG_WARN("failed to compute dml parallel", K(ret)); } else if (use_pdml() && OB_FAIL(set_is_direct_insert())) { LOG_WARN("failed to set is direct insert", K(ret)); - } else if (!is_direct_insert() && OB_FAIL(check_need_online_stats_gather(need_osg))) { - LOG_WARN("fail to check wether we need optimizer stats gathering operator", K(ret)); + } + if (OB_SUCC(ret)) { + bool tmp_need_osg = false; + if (OB_FAIL(check_need_online_stats_gather(tmp_need_osg))) { + LOG_WARN("fail to check wether we need optimizer stats gathering operator", K(ret)); + } else { + if (is_direct_insert()) { + get_optimizer_context().get_exec_ctx()->get_table_direct_insert_ctx() + .set_is_online_gather_statistics(tmp_need_osg); + } else { + need_osg = tmp_need_osg; + } + } + } + if (OB_FAIL(ret)) { + //pass } else if (need_osg && OB_FAIL(generate_osg_share_info(osg_info))) { LOG_WARN("failed to generate osg share info"); } else if (need_osg && OB_ISNULL(osg_info)) {