fix table level online_estimate_percent not work

This commit is contained in:
ChangerR 2024-07-12 11:01:09 +00:00 committed by ob-robot
parent f3c67ff2df
commit 4eec8a8049
10 changed files with 95 additions and 8 deletions

View File

@ -635,6 +635,8 @@ int ObTableLoadClientTask::init_instance()
if (OB_SUCC(ret)) {
if (online_opt_stat_gather &&
OB_FAIL(ObDbmsStatsUtils::get_sys_online_estimate_percent(exec_ctx_,
tenant_id,
table_id,
online_sample_percent))) {
LOG_WARN("failed to get sys online sample percent", K(ret));
} else {

View File

@ -1316,6 +1316,8 @@ int ObUpgradeFor4320Processor::post_upgrade()
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));
} else if (OB_FAIL(post_upgrade_for_online_estimate_percent())) {
LOG_WARN("failed to post upgrade for online estimate percent", KR(ret));
}
return ret;
}
@ -1420,6 +1422,33 @@ int ObUpgradeFor4320Processor::post_upgrade_for_spm()
return ret;
}
int ObUpgradeFor4320Processor::post_upgrade_for_online_estimate_percent()
{
int ret = OB_SUCCESS;
int64_t start = ObTimeUtility::current_time();
ObSqlString raw_sql;
int64_t affected_rows = 0;
bool is_primary_tenant = false;
if (sql_proxy_ == NULL) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("sql_proxy is null", K(ret), K(tenant_id_));
} else if (OB_FAIL(ObAllTenantInfoProxy::is_primary_tenant(sql_proxy_, tenant_id_, is_primary_tenant))) {
LOG_WARN("check is standby tenant failed", K(ret), K(tenant_id_));
} else if (!is_primary_tenant) {
LOG_INFO("tenant isn't primary standby, no refer to gather stats, skip", K(tenant_id_));
} else if (OB_FAIL(ObDbmsStatsPreferences::get_online_estimate_percent_for_upgrade(raw_sql))) {
LOG_WARN("failed to get extra stats perfs for upgrade", K(ret));
} else if (OB_FAIL(sql_proxy_->write(tenant_id_, raw_sql.ptr(), affected_rows))) {
LOG_WARN("failed to write", K(ret));
}
if (OB_FAIL(ret)) {
LOG_WARN("[UPGRADE] post upgrade for online estimate failed", KR(ret), K_(tenant_id));
} else {
LOG_INFO("[UPGRADE] post upgrade for online estimate succeed", K_(tenant_id));
} return ret;
}
/* =========== 4310 upgrade processor end ============= */
/* =========== special upgrade processor end ============= */

View File

@ -257,6 +257,7 @@ 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();
int post_upgrade_for_online_estimate_percent();
};
DEF_SIMPLE_UPGRARD_PROCESSER(4, 3, 3, 0)

View File

@ -41,6 +41,8 @@ namespace common {
#define INIT_GLOBAL_PREFS "REPLACE INTO %s(sname, sval1, sval2, spare4) VALUES %s;"
#define UPGRADE_GLOBAL_PREFS "INSERT IGNORE INTO %s(sname, sval1, sval2, spare4) VALUES %s;"
int ObDbmsStatsPreferences::reset_global_pref_defaults(ObExecContext &ctx)
{
int ret = OB_SUCCESS;
@ -1184,6 +1186,30 @@ int ObOnlineEstimatePercentPrefs::check_pref_value_validity(ObTableStatParam *pa
return ret;
}
int ObDbmsStatsPreferences::get_online_estimate_percent_for_upgrade(ObSqlString &raw_sql)
{
int ret = OB_SUCCESS;
const char *null_str = "NULL";
const char *time_str = "CURRENT_TIMESTAMP";
ObSqlString value_str;
ObOnlineEstimatePercentPrefs prefs;
if (OB_ISNULL(prefs.get_stat_pref_name()) || OB_ISNULL(prefs.get_stat_pref_for_update())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error", K(ret), K(prefs.get_stat_pref_name()),
K(prefs.get_stat_pref_for_update()));
} else if (OB_FAIL(value_str.append_fmt("('%s', %s, %s, '%s')",
prefs.get_stat_pref_name(),
null_str,
time_str,
prefs.get_stat_pref_for_update()))) {
LOG_WARN("failed to append", K(ret));
} else if (OB_FAIL(raw_sql.append_fmt(UPGRADE_GLOBAL_PREFS,
share::OB_ALL_OPTSTAT_GLOBAL_PREFS_TNAME,
value_str.ptr()))) {
LOG_WARN("failed to append fmt", K(ret));
}
return ret;
}
} // namespace common
} // namespace oceanbase

View File

@ -238,6 +238,7 @@ class ObOnlineEstimatePercentPrefs : public ObStatPrefs
virtual int check_pref_value_validity(ObTableStatParam *param = NULL) override;
virtual const char* get_stat_pref_name() const { return "ONLINE_ESTIMATE_PERCENT"; }
virtual const char* get_stat_pref_default_value() const { return "1";}
const char* get_stat_pref_for_update() const { return "100"; }
};
template <class T>
@ -284,6 +285,8 @@ public:
bool is_reset_prefs = false,
int64_t *expect_affected_rows = NULL);
static int get_online_estimate_percent_for_upgrade(ObSqlString &sql);
private:
static int do_get_prefs(ObExecContext &ctx,
ObIAllocator *allocator,

View File

@ -1381,7 +1381,9 @@ int ObDbmsStatsUtils::scale_col_stats(const uint64_t tenant_id,
}
int ObDbmsStatsUtils::get_sys_online_estimate_percent(sql::ObExecContext &ctx,
double &percent)
const uint64_t tenant_id,
const uint64_t table_id,
double &percent)
{
int ret = OB_SUCCESS;
ObTableStatParam stat_param;
@ -1389,6 +1391,8 @@ int ObDbmsStatsUtils::get_sys_online_estimate_percent(sql::ObExecContext &ctx,
ObSEArray<ObStatPrefs*, 4> stat_prefs;
ObOnlineEstimatePercentPrefs *tmp_pref = NULL;
stat_param.allocator_ = &tmp_alloc;
stat_param.tenant_id_ = tenant_id;
stat_param.table_id_ = table_id;
if (OB_FAIL(new_stat_prefs(*stat_param.allocator_, ctx.get_my_session(), ObString(), tmp_pref))) {
LOG_WARN("failed to new stat prefs", K(ret));
} else if (OB_FAIL(stat_prefs.push_back(tmp_pref))) {

View File

@ -192,7 +192,9 @@ public:
common::ObIArray<ObOptColumnStat*> &col_stats);
static int get_sys_online_estimate_percent(sql::ObExecContext &ctx,
double &percent);
const uint64_t tenant_id,
const uint64_t table_id,
double &percent);
private:
static int batch_write(share::schema::ObSchemaGetterGuard *schema_guard,
const uint64_t tenant_id,

View File

@ -2478,6 +2478,8 @@ int ObLoadDataDirectImpl::init_execute_context()
if (OB_SUCC(ret)) {
if (execute_param_.online_opt_stat_gather_ &&
OB_FAIL(ObDbmsStatsUtils::get_sys_online_estimate_percent(*ctx_,
execute_param_.tenant_id_,
execute_param_.table_id_,
online_sample_percent))) {
LOG_WARN("failed to get sys online sample percent", K(ret));
} else {
@ -2492,9 +2494,6 @@ int ObLoadDataDirectImpl::init_execute_context()
} else if (OB_FAIL(ObDDLUtil::get_temp_store_compress_type(
table_compressor_type, execute_param_.parallel_, load_param.compressor_type_))) {
LOG_WARN("fail to get tmp store compressor type", KR(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::get_sys_online_estimate_percent(*ctx_,
load_param.online_sample_percent_))) {
LOG_WARN("fail to get sys online estimate percent", KR(ret));
} else if (OB_FAIL(direct_loader_.init(load_param, execute_param_.column_ids_,
&execute_ctx_.exec_ctx_))) {
LOG_WARN("fail to init direct loader", KR(ret));

View File

@ -102,9 +102,7 @@ int ObInsertLogPlan::generate_normal_raw_plan()
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 (tmp_need_osg &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ >= COMPAT_VERSION_4_3_2 &&
OB_FAIL(ObDbmsStatsUtils::get_sys_online_estimate_percent(*get_optimizer_context().get_exec_ctx(),
online_sample_percent))) {
OB_FAIL(get_online_estimate_percent(online_sample_percent))) {
LOG_WARN("failed to get sys online sample percent", K(ret));
} else {
if (is_direct_insert()) {
@ -1755,3 +1753,25 @@ int ObInsertLogPlan::candi_allocate_optimizer_stats_merge(OSGShareInfo *osg_info
}
return ret;
}
int ObInsertLogPlan::get_online_estimate_percent(double &percent)
{
int ret = OB_SUCCESS;
percent = 100.;
const ObSQLSessionInfo *session_info = NULL;
if (OB_ISNULL(get_optimizer_context().get_exec_ctx()) ||
OB_ISNULL(session_info = get_optimizer_context().get_session_info()) ||
OB_ISNULL(get_stmt()) ||
OB_ISNULL(get_optimizer_context().get_query_ctx())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ < COMPAT_VERSION_4_3_2) {
// do nothing
} else if (OB_FAIL(ObDbmsStatsUtils::get_sys_online_estimate_percent(*get_optimizer_context().get_exec_ctx(),
session_info->get_effective_tenant_id(),
get_stmt()->get_insert_table_info().ref_table_id_,
percent))) {
LOG_WARN("failed to get sys online estimate percent", K(ret));
}
return ret;
}

View File

@ -129,6 +129,7 @@ protected:
int check_contain_non_onetime_expr(const ObRawExpr *expr, bool &contain);
int check_contain_non_onetime_expr(const ObIArray<ObRawExpr *> &exprs, bool &contain);
int get_online_estimate_percent(double &percent);
private:
int get_index_part_ids(const ObInsertTableInfo& table_info, const ObTableSchema *&data_table_schema, const ObTableSchema *&index_schema, ObIArray<uint64_t> &index_part_ids);
int generate_osg_share_info(OSGShareInfo *&info);