From 121cb80b19490284698447a9ddec7960c02cd974 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 7 Dec 2023 11:43:21 +0000 Subject: [PATCH] [CP] Fix the problem of still performing hard parsing when the SQL current limit reaches 0 --- src/sql/engine/ob_physical_plan.cpp | 4 +++- src/sql/ob_sql.cpp | 3 +++ src/sql/plan_cache/ob_plan_cache_struct.h | 7 +++++-- src/sql/plan_cache/ob_plan_set.cpp | 14 ++++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/sql/engine/ob_physical_plan.cpp b/src/sql/engine/ob_physical_plan.cpp index a2bde750e..16198b40c 100644 --- a/src/sql/engine/ob_physical_plan.cpp +++ b/src/sql/engine/ob_physical_plan.cpp @@ -692,7 +692,9 @@ int ObPhysicalPlan::inc_concurrent_num() } else { while(OB_SUCC(ret) && false == is_succ) { concurrent_num = ATOMIC_LOAD(&concurrent_num_); - if (concurrent_num >= max_concurrent_num_) { + if (0 == max_concurrent_num_) { + ret = OB_REACH_MAX_CONCURRENT_NUM; + } else if (concurrent_num >= max_concurrent_num_) { ret = OB_REACH_MAX_CONCURRENT_NUM; } else { new_num = concurrent_num + 1; diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index e21c8eeb0..b0c603544 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -4329,6 +4329,9 @@ int ObSql::pc_add_plan(ObPlanCacheCtx &pc_ctx, ret = plan_cache->add_plan(phy_plan, pc_ctx); } plan_added = (OB_SUCCESS == ret); + if (pc_ctx.is_max_curr_limit_) { + ret = OB_REACH_MAX_CONCURRENT_NUM; + } if (is_batch_exec) { // Batch optimization cannot continue for errors other than OB_SQL_PC_PLAN_DUPLICATE. diff --git a/src/sql/plan_cache/ob_plan_cache_struct.h b/src/sql/plan_cache/ob_plan_cache_struct.h index 07d8a779c..974842af6 100644 --- a/src/sql/plan_cache/ob_plan_cache_struct.h +++ b/src/sql/plan_cache/ob_plan_cache_struct.h @@ -386,7 +386,8 @@ struct ObPlanCacheCtx : public ObILibCacheCtx dynamic_param_info_list_(allocator), tpl_sql_const_cons_(allocator), need_retry_add_plan_(true), - insert_batch_opt_info_(allocator) + insert_batch_opt_info_(allocator), + is_max_curr_limit_(false) { fp_result_.pc_key_.mode_ = mode_; } @@ -459,7 +460,8 @@ struct ObPlanCacheCtx : public ObILibCacheCtx K(is_original_ps_mode_), K(new_raw_sql_), K(need_retry_add_plan_), - K(insert_batch_opt_info_) + K(insert_batch_opt_info_), + K(is_max_curr_limit_) ); PlanCacheMode mode_; //control use which variables to do match @@ -521,6 +523,7 @@ struct ObPlanCacheCtx : public ObILibCacheCtx // when schema version of cache node is old, whether remove this node and retry add cache obj. bool need_retry_add_plan_; ObInsertBatchOptInfo insert_batch_opt_info_; + bool is_max_curr_limit_; }; struct ObPlanCacheStat diff --git a/src/sql/plan_cache/ob_plan_set.cpp b/src/sql/plan_cache/ob_plan_set.cpp index 793a51530..e86f8e2a7 100644 --- a/src/sql/plan_cache/ob_plan_set.cpp +++ b/src/sql/plan_cache/ob_plan_set.cpp @@ -1206,7 +1206,18 @@ int ObSqlPlanSet::add_plan(ObPhysicalPlan &plan, candi_table_locs))) { LOG_WARN("fail to get physical locations", K(ret)); } else if (OB_FAIL(set_concurrent_degree(outline_param_idx, plan))) { - LOG_WARN("fail to check concurrent degree", K(ret)); + if (OB_REACH_MAX_CONCURRENT_NUM == ret && 0 == plan.get_max_concurrent_num()) { + pc_ctx.is_max_curr_limit_ = true; + ret = OB_SUCCESS; + } else { + LOG_WARN("fail to check concurrent degree", K(ret)); + } + } else { + // do nothing + } + + if (OB_FAIL(ret)) { + // do nothing } else { if (pc_ctx.exec_ctx_.get_physical_plan_ctx()->get_or_expand_transformed()) { need_try_plan_ |= TRY_PLAN_OR_EXPAND; @@ -1308,7 +1319,6 @@ int ObSqlPlanSet::add_plan(ObPhysicalPlan &plan, // } // } } - return ret; }