Add query hint: enable_rich_vector_format

This commit is contained in:
obdev
2024-02-09 17:47:22 +00:00
committed by ob-robot
parent 59fa4e7f0c
commit 1d31b939ec
9 changed files with 116 additions and 6 deletions

View File

@ -2312,7 +2312,17 @@ OB_INLINE int ObPlanCache::construct_plan_cache_key(ObSQLSessionInfo &session,
pc_key.namespace_ = ns;
pc_key.sys_vars_str_ = session.get_sys_var_in_pc_str();
pc_key.config_str_ = session.get_config_in_pc_str();
pc_key.use_rich_vector_format_ = session.use_rich_format();
// here we use `initial_use_rich_format` instead of `use_rich_format` as part of key
// consider scenario of binding outline:
// ```
// set _enable_rich_vector_format = true;
// create outline xx on select /*+opt_param('enable_rich_vector_format', 'false')*/ * from t on select * from t;
// select * from t;
// ```
// rich_format is forced off by hint, thus `use_rich_format() = false`, `initial_use_rich_format() = true`
// added plan's key will be `true + other_info`, same as key constructed for getting plan.
// if `use_rich_format()` is used as part of key, added plan's key will be `false + other_info`.
pc_key.use_rich_vector_format_ = session.initial_use_rich_format();
pc_key.is_weak_read_ = is_weak;
return ret;
}

View File

@ -179,7 +179,8 @@ ObPlanCacheValue::ObPlanCacheValue()
is_batch_execute_(false),
has_dynamic_values_table_(false),
stored_schema_objs_(pc_alloc_),
stmt_type_(stmt::T_MAX)
stmt_type_(stmt::T_MAX),
enable_rich_vector_format_(false)
{
MEMSET(sql_id_, 0, sizeof(sql_id_));
not_param_index_.set_attr(ObMemAttr(MTL_ID(), "NotParamIdex"));
@ -262,6 +263,7 @@ int ObPlanCacheValue::init(ObPCVSet *pcv_set, const ObILibCacheObject *cache_obj
sys_schema_version_ = plan->get_sys_schema_version();
tenant_schema_version_ = plan->get_tenant_schema_version();
sql_traits_ = pc_ctx.sql_traits_;
enable_rich_vector_format_ = static_cast<const ObPhysicalPlan *>(plan)->get_use_rich_format();
#ifdef OB_BUILD_SPM
is_spm_closed_ = pcv_set->get_spm_closed();
#endif
@ -476,6 +478,8 @@ int ObPlanCacheValue::choose_plan(ObPlanCacheCtx &pc_ctx,
if (schema_array.count() == 0 && stored_schema_objs_.count() == 0) {
need_check_schema = true;
}
ObBasicSessionInfo::ForceRichFormatStatus orig_rich_format_status = ObBasicSessionInfo::ForceRichFormatStatus::Disable;
bool orig_phy_ctx_rich_format = false;
if (stmt::T_NONE == pc_ctx.sql_ctx_.stmt_type_) {
//sql_ctx_.stmt_type_ != stmt::T_NONE means this calling in nested sql,
//can't cover the first stmt type in sql context
@ -484,6 +488,7 @@ int ObPlanCacheValue::choose_plan(ObPlanCacheCtx &pc_ctx,
if (OB_ISNULL(session = pc_ctx.exec_ctx_.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
SQL_PC_LOG(ERROR, "got session is NULL", K(ret));
} else if (FALSE_IT(orig_rich_format_status = session->get_force_rich_format_status())) {
} else if (FALSE_IT(session->set_stmt_type(stmt_type_))) {
} else if (OB_FAIL(session->get_use_plan_baseline(enable_baseline))) {
LOG_WARN("fail to get use plan baseline", K(ret));
@ -552,7 +557,12 @@ int ObPlanCacheValue::choose_plan(ObPlanCacheCtx &pc_ctx,
if (OB_SUCC(ret)) {
ObPhysicalPlanCtx *phy_ctx = pc_ctx.exec_ctx_.get_physical_plan_ctx();
if (NULL != phy_ctx) {
orig_phy_ctx_rich_format = phy_ctx->is_rich_format();
phy_ctx->set_original_param_cnt(phy_ctx->get_param_store().count());
phy_ctx->set_rich_format(enable_rich_vector_format_);
session->set_force_rich_format(enable_rich_vector_format_ ?
ObBasicSessionInfo::ForceRichFormatStatus::FORCE_ON :
ObBasicSessionInfo::ForceRichFormatStatus::FORCE_OFF);
if (OB_FAIL(phy_ctx->init_datum_param_store())) {
LOG_WARN("fail to init datum param store", K(ret));
}
@ -673,6 +683,15 @@ int ObPlanCacheValue::choose_plan(ObPlanCacheCtx &pc_ctx,
plan_out = plan;
pc_ctx.sql_traits_ = sql_traits_; //used for check read only
}
// reset force rich format status
if (NULL == plan) {
if (session != nullptr) {
session->set_force_rich_format(orig_rich_format_status);
}
if (pc_ctx.exec_ctx_.get_physical_plan_ctx() != nullptr) {
pc_ctx.exec_ctx_.get_physical_plan_ctx()->set_rich_format(orig_phy_ctx_rich_format);
}
}
return ret;
}
@ -1418,6 +1437,7 @@ void ObPlanCacheValue::reset()
}
}
stored_schema_objs_.reset();
enable_rich_vector_format_ = false;
pcv_set_ = NULL; //放最后,前面可能存在需要pcv_set
}

View File

@ -446,6 +446,7 @@ private:
*/
TplSqlConstCons tpl_sql_const_cons_;
//*********** end user-defined rules **************
bool enable_rich_vector_format_;
DISALLOW_COPY_AND_ASSIGN(ObPlanCacheValue);
};