[CP] add new parameter used to control spm intead of sys variable
This commit is contained in:
parent
98a5eb0549
commit
4c3343960f
@ -1061,6 +1061,31 @@ bool ObConfigSQLTlsVersionChecker::check(const ObConfigItem &t) const
|
||||
0 == tmp_str.case_compare("TLSV1.3");
|
||||
}
|
||||
|
||||
bool ObSqlPlanManagementModeChecker::check(const ObConfigItem &t) const
|
||||
{
|
||||
const ObString tmp_str(t.str());
|
||||
return get_spm_mode_by_string(tmp_str) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* return spm mode
|
||||
* -1 represent invalid mode
|
||||
* 0 represent disable spm
|
||||
* 1 represent online evolve mode
|
||||
*/
|
||||
int64_t ObSqlPlanManagementModeChecker::get_spm_mode_by_string(const common::ObString &string)
|
||||
{
|
||||
int64_t spm_mode = -1;
|
||||
if (string.empty()) {
|
||||
spm_mode = -1;
|
||||
} else if (0 == string.case_compare("Disable")) {
|
||||
spm_mode = 0;
|
||||
} else if (0 == string.case_compare("OnlineEvolve")) {
|
||||
spm_mode = 1;
|
||||
}
|
||||
return spm_mode;
|
||||
}
|
||||
|
||||
int ObModeConfigParserUitl::parse_item_to_kv(char *item, ObString &key, ObString &value, const char* delim)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
@ -758,6 +758,18 @@ private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObConfigSQLSpillCompressionCodecChecker);
|
||||
};
|
||||
|
||||
class ObSqlPlanManagementModeChecker
|
||||
: public ObConfigChecker
|
||||
{
|
||||
public:
|
||||
ObSqlPlanManagementModeChecker() {}
|
||||
virtual ~ObSqlPlanManagementModeChecker() {}
|
||||
bool check(const ObConfigItem &t) const;
|
||||
static int64_t get_spm_mode_by_string(const common::ObString &string);
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObSqlPlanManagementModeChecker);
|
||||
};
|
||||
|
||||
class ObModeConfigParserUitl
|
||||
{
|
||||
public:
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "share/ls/ob_ls_status_operator.h"//get max ls id
|
||||
#include "share/ob_tenant_info_proxy.h"//update max ls id
|
||||
#include "ob_upgrade_utils.h"
|
||||
#include "share/config/ob_config_helper.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
@ -1307,6 +1308,8 @@ int ObUpgradeFor4320Processor::post_upgrade()
|
||||
LOG_WARN("fail to check inner stat", KR(ret));
|
||||
} else if (OB_FAIL(post_upgrade_for_reset_compat_version())) {
|
||||
LOG_WARN("fail to reset compat version", KR(ret));
|
||||
} else if (OB_FAIL(post_upgrade_for_spm())) {
|
||||
LOG_WARN("failed to post upgrade for spm", KR(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1359,6 +1362,58 @@ int ObUpgradeFor4320Processor::try_reset_version(const uint64_t tenant_id, const
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObUpgradeFor4320Processor::post_upgrade_for_spm()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t start = ObTimeUtility::current_time();
|
||||
ObSchemaGetterGuard schema_guard;
|
||||
const ObSysVariableSchema *var_schema = NULL;
|
||||
const ObSysVarSchema *spm_var = NULL;
|
||||
common::ObObj var_value;
|
||||
ObString sql("alter system set sql_plan_management_mode = 'OnlineEvolve';");
|
||||
int64_t affected_rows = 0;
|
||||
|
||||
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(tenant_id_));
|
||||
if (tenant_config.is_valid()) {
|
||||
int64_t spm_mode = ObSqlPlanManagementModeChecker::get_spm_mode_by_string(
|
||||
tenant_config->sql_plan_management_mode.get_value_string());
|
||||
if (0 == spm_mode) {
|
||||
if (OB_ISNULL(schema_service_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null ptr", K(ret));
|
||||
} else if (OB_FAIL(schema_service_->get_tenant_schema_guard(tenant_id_, schema_guard))) {
|
||||
LOG_WARN("failed to get schema guard", K(ret));
|
||||
} else if (OB_FAIL(schema_guard.get_sys_variable_schema(tenant_id_, var_schema))) {
|
||||
LOG_WARN("fail to get sys variable schema", KR(ret), K_(tenant_id));
|
||||
} else if (OB_NOT_NULL(var_schema)) {
|
||||
ObArenaAllocator alloc("UpgradeAlloc", OB_MALLOC_NORMAL_BLOCK_SIZE, tenant_id_);
|
||||
if (OB_FAIL(var_schema->get_sysvar_schema(ObSysVarClassType::SYS_VAR_OPTIMIZER_USE_SQL_PLAN_BASELINES,
|
||||
spm_var))) {
|
||||
LOG_WARN("failed to get sysvar schema", K(ret));
|
||||
} else if (OB_ISNULL(spm_var)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get null sysvar schema", K(ret));
|
||||
} else if (OB_FAIL(spm_var->get_value(&alloc, NULL, var_value))) {
|
||||
LOG_WARN("failed to get sys variable value", K(ret));
|
||||
} else if (!var_value.get_bool()) {
|
||||
// do nothing
|
||||
} else if (OB_ISNULL(sql_proxy_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null ptr", K(ret));
|
||||
} else if (OB_FAIL(sql_proxy_->write(tenant_id_, sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("execute sql failed", K(ret), K(sql));
|
||||
} else {
|
||||
LOG_TRACE("execute sql", KR(ret), K(tenant_id_), K(sql), K(affected_rows));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO("set spm parameter based on sys variable", K(tenant_id_), K(var_value), "cost", ObTimeUtility::current_time() - start);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* =========== 4310 upgrade processor end ============= */
|
||||
|
||||
/* =========== special upgrade processor end ============= */
|
||||
|
@ -255,6 +255,7 @@ public:
|
||||
private:
|
||||
int post_upgrade_for_reset_compat_version();
|
||||
int try_reset_version(const uint64_t tenant_id, const char *var_name);
|
||||
int post_upgrade_for_spm();
|
||||
};
|
||||
|
||||
/* =========== special upgrade processor end ============= */
|
||||
|
@ -2015,3 +2015,9 @@ DEF_INT(_ob_pl_compile_max_concurrency, OB_CLUSTER_PARAMETER, "4", "[0,)",
|
||||
DEF_BOOL(_enable_compatible_monotonic, OB_CLUSTER_PARAMETER, "True",
|
||||
"Control whether to enable cross-server monotonic compatible(data_version) mode",
|
||||
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
|
||||
DEF_STR_WITH_CHECKER(sql_plan_management_mode, OB_TENANT_PARAMETER, "Disable",
|
||||
common::ObSqlPlanManagementModeChecker,
|
||||
"Specifies how spm work."
|
||||
"\"Disable\" represent disable spm (default value)."
|
||||
"\"OnlineEvolve\" represent evolve plan online.",
|
||||
ObParameterAttr(Section::TENANT, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
|
||||
|
@ -5105,7 +5105,7 @@ OB_NOINLINE int ObSql::handle_physical_plan(const ObString &trimed_stmt,
|
||||
LOG_WARN("get null physical plan", K(ret), K(result.get_physical_plan()), K(baseline_item));
|
||||
} else if (result.get_physical_plan()->get_plan_hash_value() == baseline_item->get_plan_hash_value()) {
|
||||
pc_ctx.need_evolution_ = true;
|
||||
if (spm_ctx.cur_baseline_not_enable_ || !spm_ctx.capture_baseline_) {
|
||||
if (spm_ctx.cur_baseline_not_enable_) {
|
||||
spm_ctx.spm_stat_ = ObSpmCacheCtx::SpmStat::STAT_ACCEPT_BASELINE_PLAN;
|
||||
} else {
|
||||
spm_ctx.spm_stat_ = ObSpmCacheCtx::SpmStat::STAT_ADD_BASELINE_PLAN;
|
||||
|
@ -9997,7 +9997,7 @@ int ObLogPlan::check_enable_plan_expiration(bool &enable) const
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *session = NULL;
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool use_spm = false;
|
||||
int64_t spm_mode = 0;
|
||||
#endif
|
||||
enable = false;
|
||||
if (OB_ISNULL(get_stmt()) ||
|
||||
@ -10007,9 +10007,9 @@ int ObLogPlan::check_enable_plan_expiration(bool &enable) const
|
||||
} else if (!get_stmt()->is_select_stmt()) {
|
||||
// do nothing
|
||||
#ifdef OB_BUILD_SPM
|
||||
} else if (OB_FAIL(session->get_use_plan_baseline(use_spm))) {
|
||||
} else if (OB_FAIL(session->get_spm_mode(spm_mode))) {
|
||||
LOG_WARN("failed to check is spm enabled", K(ret));
|
||||
} else if (use_spm) {
|
||||
} else if (spm_mode > 0) {
|
||||
// do nothing
|
||||
#endif
|
||||
} else if (optimizer_context_.get_phy_plan_type() != OB_PHY_PLAN_LOCAL &&
|
||||
|
@ -32,9 +32,6 @@ int ObPCVSet::init(ObILibCacheCtx &ctx, const ObILibCacheObject *obj)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo* sess;
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool is_spm_on = false;
|
||||
#endif
|
||||
ObPlanCacheCtx &pc_ctx = static_cast<ObPlanCacheCtx&>(ctx);
|
||||
const ObPlanCacheObject *cache_obj = static_cast<const ObPlanCacheObject*>(obj);
|
||||
if (is_inited_) {
|
||||
@ -46,12 +43,6 @@ int ObPCVSet::init(ObILibCacheCtx &ctx, const ObILibCacheObject *obj)
|
||||
} else if (NULL == (sess = pc_ctx.sql_ctx_.session_info_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_PC_LOG(WARN, "session info is null", K(ret));
|
||||
#ifdef OB_BUILD_SPM
|
||||
} else if (OB_FAIL(sess->get_use_plan_baseline(is_spm_on))) {
|
||||
LOG_WARN("fail to get spm config");
|
||||
} else if (FALSE_IT(is_spm_closed_ = (!is_spm_on))) {
|
||||
// do nothing
|
||||
#endif
|
||||
} else if (NULL == (pc_alloc_ = lib_cache_->get_pc_allocator())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid plan cache allocator", K_(pc_alloc), K(ret));
|
||||
@ -119,9 +110,6 @@ int ObPCVSet::inner_get_cache_obj(ObILibCacheCtx &ctx,
|
||||
{
|
||||
UNUSED(key);
|
||||
int ret = OB_SUCCESS;
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool is_spm_on = false;
|
||||
#endif
|
||||
ObPlanCacheObject *plan = NULL;
|
||||
ObPlanCacheCtx &pc_ctx = static_cast<ObPlanCacheCtx&>(ctx);
|
||||
if (PC_PS_MODE == pc_ctx.mode_ || PC_PL_MODE == pc_ctx.mode_) {
|
||||
@ -162,13 +150,6 @@ int ObPCVSet::inner_get_cache_obj(ObILibCacheCtx &ctx,
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("unexpected null schema guard",
|
||||
K(ret), K(pc_ctx.sql_ctx_.schema_guard_), K(pc_ctx.sql_ctx_.session_info_));
|
||||
#ifdef OB_BUILD_SPM
|
||||
} else if (OB_FAIL(pc_ctx.sql_ctx_.session_info_->get_use_plan_baseline(is_spm_on))) {
|
||||
LOG_WARN("failed to get spm status", K(ret));
|
||||
} else if (is_spm_closed_ != (!is_spm_on)) {
|
||||
// spm param is altered
|
||||
ret = OB_OLD_SCHEMA_VERSION;
|
||||
#endif
|
||||
} else {
|
||||
ObSEArray<PCVSchemaObj, 4> schema_array;
|
||||
//plan cache匹配临时表应该始终使用用户创建的session才能保证语义的正确性
|
||||
|
@ -68,12 +68,7 @@ public:
|
||||
normal_parse_const_cnt_(0),
|
||||
min_cluster_version_(0),
|
||||
plan_num_(0),
|
||||
#ifndef OB_BUILD_SPM
|
||||
need_check_gen_tbl_col_(false)
|
||||
#else
|
||||
need_check_gen_tbl_col_(false),
|
||||
is_spm_closed_(false)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
virtual ~ObPCVSet()
|
||||
@ -102,7 +97,6 @@ public:
|
||||
int deep_copy_sql(const common::ObString &sql);
|
||||
int check_contains_table(uint64_t db_id, common::ObString tab_name, bool &contains);
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool get_spm_closed() const { return is_spm_closed_; }
|
||||
int get_evolving_evolution_task(EvolutionPlanList &evo_task_list);
|
||||
#endif
|
||||
|
||||
@ -137,9 +131,6 @@ private:
|
||||
int64_t plan_num_;
|
||||
common::ObSEArray<common::ObString, 4> sql_ids_;
|
||||
bool need_check_gen_tbl_col_;
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool is_spm_closed_;
|
||||
#endif
|
||||
common::ObFixedArray<PCColStruct, common::ObIAllocator> col_field_arr_;
|
||||
};
|
||||
|
||||
|
@ -173,9 +173,6 @@ ObPlanCacheValue::ObPlanCacheValue()
|
||||
sessid_(OB_INVALID_ID),
|
||||
sess_create_time_(0),
|
||||
contain_sys_name_table_(false),
|
||||
#ifdef OB_BUILD_SPM
|
||||
is_spm_closed_(false),
|
||||
#endif
|
||||
need_param_(true),
|
||||
is_nested_sql_(false),
|
||||
is_batch_execute_(false),
|
||||
@ -268,9 +265,6 @@ int ObPlanCacheValue::init(ObPCVSet *pcv_set, const ObILibCacheObject *cache_obj
|
||||
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
|
||||
stmt_type_ = plan->get_stmt_type();
|
||||
need_param_ = plan->need_param();
|
||||
is_nested_sql_ = ObSQLUtils::is_nested_sql(&pc_ctx.exec_ctx_);
|
||||
@ -476,8 +470,7 @@ int ObPlanCacheValue::choose_plan(ObPlanCacheCtx &pc_ctx,
|
||||
//检查在pcv中缓存的该sql涉及的view 及 table的version,
|
||||
//如果不为最新的,在plan cache层会删除该value,并重新add plan
|
||||
//TODO shengle 此处拷贝需要想办法处理掉
|
||||
bool enable_baseline = false;
|
||||
bool captrue_baseline = false;
|
||||
int64_t spm_mode = 0;
|
||||
bool need_check_schema = (schema_array.count() != 0);
|
||||
if (schema_array.count() == 0 && stored_schema_objs_.count() == 0) {
|
||||
need_check_schema = true;
|
||||
@ -494,11 +487,9 @@ int ObPlanCacheValue::choose_plan(ObPlanCacheCtx &pc_ctx,
|
||||
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));
|
||||
} else if (OB_FAIL(session->get_capture_plan_baseline(captrue_baseline))) {
|
||||
LOG_WARN("failed to capture plan baseline", K(ret));
|
||||
} else if (enable_baseline || captrue_baseline) {
|
||||
} else if (OB_FAIL(session->get_spm_mode(spm_mode))) {
|
||||
LOG_WARN("fail to get spm mode", K(ret));
|
||||
} else if (spm_mode > 0) {
|
||||
if (OB_FAIL(ob_write_string(pc_ctx.allocator_,
|
||||
constructed_sql_,
|
||||
pc_ctx.sql_ctx_.spm_ctx_.bl_key_.constructed_sql_))) {
|
||||
|
@ -407,9 +407,6 @@ private:
|
||||
uint64_t sess_create_time_;
|
||||
// wether this pcv's plans contains sys table (oracle mode)
|
||||
bool contain_sys_name_table_;
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool is_spm_closed_;
|
||||
#endif
|
||||
|
||||
bool need_param_;
|
||||
//at present, if a SQL is in nested sql, it is forced to use DAS plan
|
||||
|
@ -1341,16 +1341,16 @@ int ObSqlPlanSet::init_new_set(const ObPlanCacheCtx &pc_ctx,
|
||||
need_try_plan_ = 0;
|
||||
has_duplicate_table_ = false;
|
||||
#ifdef OB_BUILD_SPM
|
||||
bool is_spm_on = false;
|
||||
int64_t spm_mode = 0;
|
||||
#endif
|
||||
const ObSQLSessionInfo *session_info = sql_ctx.session_info_;
|
||||
if (OB_ISNULL(session_info)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid null plan cache or session info", K(ret), K(session_info));
|
||||
#ifdef OB_BUILD_SPM
|
||||
} else if (OB_FAIL(session_info->get_use_plan_baseline(is_spm_on))) {
|
||||
LOG_WARN("failed to get spm configs", K(ret));
|
||||
} else if (FALSE_IT(is_spm_closed_ = (!is_spm_on))) {
|
||||
} else if (OB_FAIL(session_info->get_spm_mode(spm_mode))) {
|
||||
LOG_WARN("failed to get spm mode", K(ret));
|
||||
} else if (FALSE_IT(is_spm_closed_ = (0 == spm_mode))) {
|
||||
// do nothing
|
||||
#endif
|
||||
} else if (OB_ISNULL(pc_malloc_)) {
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "observer/ob_sql_client_decorator.h"
|
||||
#include "ob_sess_info_verify.h"
|
||||
#include "share/schema/ob_schema_utils.h"
|
||||
#include "share/config/ob_config_helper.h"
|
||||
|
||||
using namespace oceanbase::sql;
|
||||
using namespace oceanbase::common;
|
||||
@ -625,6 +626,26 @@ bool ObSQLSessionInfo::is_spf_mlj_group_rescan_enabled() const
|
||||
return bret;
|
||||
}
|
||||
|
||||
int ObSQLSessionInfo::get_spm_mode(int64_t &spm_mode) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
spm_mode = 0;
|
||||
int64_t tenant_id = get_effective_tenant_id();
|
||||
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(tenant_id));
|
||||
if (tenant_config.is_valid()) {
|
||||
spm_mode = ObSqlPlanManagementModeChecker::get_spm_mode_by_string(
|
||||
tenant_config->sql_plan_management_mode.get_value_string());
|
||||
if (0 == spm_mode) {
|
||||
bool sysvar_use_baseline = false;
|
||||
get_use_plan_baseline(sysvar_use_baseline);
|
||||
if (sysvar_use_baseline) {
|
||||
spm_mode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObSQLSessionInfo::destroy(bool skip_sys_var)
|
||||
{
|
||||
if (is_inited_) {
|
||||
|
@ -1236,6 +1236,7 @@ public:
|
||||
int is_adj_index_cost_enabled(bool &enabled, int64_t &stats_cost_percent) const;
|
||||
bool is_spf_mlj_group_rescan_enabled() const;
|
||||
int is_preserve_order_for_pagination_enabled(bool &enabled) const;
|
||||
int get_spm_mode(int64_t &spm_mode) const;
|
||||
|
||||
ObSessionDDLInfo &get_ddl_info() { return ddl_info_; }
|
||||
const ObSessionDDLInfo &get_ddl_info() const { return ddl_info_; }
|
||||
|
@ -257,7 +257,6 @@ struct ObSpmCacheCtx : public ObILibCacheCtx
|
||||
offset_(-1),
|
||||
check_execute_status_(false),
|
||||
is_retry_for_spm_(false),
|
||||
capture_baseline_(false),
|
||||
new_plan_hash_(0),
|
||||
baseline_guard_(PLAN_BASELINE_HANDLE),
|
||||
spm_stat_(STAT_INVALID),
|
||||
@ -326,7 +325,6 @@ struct ObSpmCacheCtx : public ObILibCacheCtx
|
||||
bool check_execute_status_;
|
||||
bool is_retry_for_spm_;
|
||||
char sql_id_[common::OB_MAX_SQL_ID_LENGTH + 1];
|
||||
bool capture_baseline_;
|
||||
uint64_t new_plan_hash_;
|
||||
ObCacheObjGuard baseline_guard_;
|
||||
SpmStat spm_stat_;
|
||||
|
@ -216,6 +216,7 @@ server_permanent_offline_time
|
||||
spill_compression_codec
|
||||
sql_login_thread_count
|
||||
sql_net_thread_count
|
||||
sql_plan_management_mode
|
||||
sql_protocol_min_tls_version
|
||||
sql_work_area
|
||||
ssl_client_authentication
|
||||
|
Loading…
x
Reference in New Issue
Block a user