diff --git a/src/observer/dbms_scheduler/ob_dbms_sched_job_utils.cpp b/src/observer/dbms_scheduler/ob_dbms_sched_job_utils.cpp index 8db650152a..5e386d033e 100644 --- a/src/observer/dbms_scheduler/ob_dbms_sched_job_utils.cpp +++ b/src/observer/dbms_scheduler/ob_dbms_sched_job_utils.cpp @@ -32,7 +32,7 @@ #include "observer/ob_server_struct.h" #include "sql/session/ob_sql_session_mgr.h" #include "share/schema/ob_schema_getter_guard.h" - +#include "share/stat/ob_dbms_stats_maintenance_window.h" namespace oceanbase { @@ -299,6 +299,11 @@ int ObDBMSSchedJobUtils::init_env( job_info.get_tenant_id(), job_info.get_powner(), user_infos)); OZ (schema_guard.get_database_schema( job_info.get_tenant_id(), job_info.get_cowner(), database_schema)); + if (OB_SUCC(ret) && + user_infos.count() > 1 && + ObDbmsStatsMaintenanceWindow::is_stats_job(job_info.get_job_name())) { + OZ(ObDbmsStatsMaintenanceWindow::reset_opt_stats_user_infos(user_infos)); + } OV (1 == user_infos.count(), OB_ERR_UNEXPECTED, K(job_info), K(user_infos)); CK (OB_NOT_NULL(user_info = user_infos.at(0))); CK (OB_NOT_NULL(user_info)); diff --git a/src/share/stat/ob_dbms_stats_maintenance_window.cpp b/src/share/stat/ob_dbms_stats_maintenance_window.cpp index 32dc06e4cb..69470a6e38 100644 --- a/src/share/stat/ob_dbms_stats_maintenance_window.cpp +++ b/src/share/stat/ob_dbms_stats_maintenance_window.cpp @@ -538,6 +538,31 @@ int ObDbmsStatsMaintenanceWindow::check_date_validate(const ObString &job_name, return ret; } +int ObDbmsStatsMaintenanceWindow::reset_opt_stats_user_infos(ObIArray &user_infos) +{ + int ret = OB_SUCCESS; + if (user_infos.count() > 1) { + //bug: + //resver the minimum user id to execute + const ObUserInfo *minimum_user_info = user_infos.at(0); + for (int64_t i = 1; OB_SUCC(ret) && i < user_infos.count(); ++i) { + if (OB_ISNULL(minimum_user_info) || OB_ISNULL(user_infos.at(i))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected error", K(ret), K(minimum_user_info), K(user_infos.at(i))); + } else if (minimum_user_info->get_user_id() > user_infos.at(i)->get_user_id()) { + minimum_user_info = user_infos.at(i); + } else {/*do nothing*/} + } + if (OB_SUCC(ret)) { + user_infos.reset(); + if (OB_FAIL(user_infos.push_back(minimum_user_info))) { + LOG_WARN("failed to push back", K(ret)); + } + } + } + return ret; +} + } // namespace common } // namespace oceanbase diff --git a/src/share/stat/ob_dbms_stats_maintenance_window.h b/src/share/stat/ob_dbms_stats_maintenance_window.h index ccca65545a..307e157010 100644 --- a/src/share/stat/ob_dbms_stats_maintenance_window.h +++ b/src/share/stat/ob_dbms_stats_maintenance_window.h @@ -57,6 +57,8 @@ public: static bool is_stats_job(const ObString &job_name); + static int reset_opt_stats_user_infos(ObIArray &user_infos); + private: static int get_window_job_info(const int64_t current_time, const int64_t nth_window, diff --git a/src/share/stat/ob_dbms_stats_preferences.cpp b/src/share/stat/ob_dbms_stats_preferences.cpp index 4d9e0eee46..166e10858d 100644 --- a/src/share/stat/ob_dbms_stats_preferences.cpp +++ b/src/share/stat/ob_dbms_stats_preferences.cpp @@ -787,6 +787,7 @@ int ObCascadePrefs::check_pref_value_validity(ObTableStatParam *param/*default n int ObDegreePrefs::check_pref_value_validity(ObTableStatParam *param/*default null*/) { int ret = OB_SUCCESS; + int64_t degree = 1; if (!pvalue_.empty()) { ObObj src_obj; ObObj dest_obj; @@ -796,19 +797,20 @@ int ObDegreePrefs::check_pref_value_validity(ObTableStatParam *param/*default nu number::ObNumber num_degree; if (OB_FAIL(ObObjCaster::to_type(ObNumberType, cast_ctx, src_obj, dest_obj))) { LOG_WARN("failed to type", K(ret), K(src_obj)); - } else if (OB_ISNULL(param)) { } else if (OB_FAIL(dest_obj.get_number(num_degree))) { LOG_WARN("failed to get degree", K(ret)); - } else if (OB_FAIL(num_degree.extract_valid_int64_with_trunc(param->degree_))) { + } else if (OB_FAIL(num_degree.extract_valid_int64_with_trunc(degree))) { LOG_WARN("extract_valid_int64_with_trunc failed", K(ret), K(num_degree)); } else {/*do noting*/} - if (OB_FAIL(ret)) { - ret = OB_ERR_DBMS_STATS_PL; - LOG_WARN("Illegal degree", K(ret), K(pvalue_)); - LOG_USER_ERROR(OB_ERR_DBMS_STATS_PL, "Illegal degree"); + } + if (OB_SUCC(ret)) { + if (param != NULL) { + param->degree_ = degree; } - } else if (param != NULL) { - param->degree_ = 1; + } else { + ret = OB_ERR_DBMS_STATS_PL; + LOG_WARN("Illegal degree", K(ret), K(pvalue_)); + LOG_USER_ERROR(OB_ERR_DBMS_STATS_PL, "Illegal degree"); } return ret; } diff --git a/src/sql/optimizer/ob_dynamic_sampling.cpp b/src/sql/optimizer/ob_dynamic_sampling.cpp index 5a8ffddc15..5228d00b5f 100644 --- a/src/sql/optimizer/ob_dynamic_sampling.cpp +++ b/src/sql/optimizer/ob_dynamic_sampling.cpp @@ -1311,12 +1311,13 @@ int ObDynamicSamplingUtils::get_ds_table_param(ObOptimizerContext &ctx, table_meta->get_ref_table_id(), ds_table_param.degree_))) { LOG_WARN("failed to get ds table degree", K(ret)); + } else if (OB_FAIL(get_dynamic_sampling_max_timeout(ctx, ds_table_param.max_ds_timeout_))) { + LOG_WARN("failed to get dynamic sampling max timeout", K(ret)); } else { ds_table_param.tenant_id_ = ctx.get_session_info()->get_effective_tenant_id(); ds_table_param.table_id_ = table_meta->get_ref_table_id(); ds_table_param.ds_level_ = ds_level; ds_table_param.sample_block_cnt_ = sample_block_cnt; - ds_table_param.max_ds_timeout_ = get_dynamic_sampling_max_timeout(ctx); ds_table_param.is_virtual_table_ = is_virtual_table(table_meta->get_ref_table_id()) && !share::is_oracle_mapping_real_virtual_table(table_meta->get_ref_table_id()); ds_table_param.db_name_ = table_item->database_name_; @@ -1510,18 +1511,24 @@ const ObDSResultItem *ObDynamicSamplingUtils::get_ds_result_item(ObDSResultItemT return item; } -int64_t ObDynamicSamplingUtils::get_dynamic_sampling_max_timeout(ObOptimizerContext &ctx) +int ObDynamicSamplingUtils::get_dynamic_sampling_max_timeout(ObOptimizerContext &ctx, + int64_t &max_ds_timeout) { - int64_t max_ds_timeout = THIS_WORKER.get_timeout_remain(); - max_ds_timeout = max_ds_timeout / 10;//default ds time can't exceed 10% of current sql remain timeout - omt::ObTenantConfigGuard tenant_config(TENANT_CONF(ctx.get_session_info()->get_effective_tenant_id())); - if (tenant_config.is_valid()) { - int64_t ds_maximum_time = tenant_config->_optimizer_ads_time_limit * 1000000; - if (max_ds_timeout > ds_maximum_time) {//can't exceed the max ds timeout for single table - max_ds_timeout = ds_maximum_time; + int ret = OB_SUCCESS; + if (OB_FAIL(THIS_WORKER.check_status())) { + LOG_WARN("failed to check status", K(ret)); + } else { + max_ds_timeout = THIS_WORKER.get_timeout_remain(); + max_ds_timeout = max_ds_timeout / 10;//default ds time can't exceed 10% of current sql remain timeout + omt::ObTenantConfigGuard tenant_config(TENANT_CONF(ctx.get_session_info()->get_effective_tenant_id())); + if (tenant_config.is_valid()) { + int64_t ds_maximum_time = tenant_config->_optimizer_ads_time_limit * 1000000; + if (max_ds_timeout > ds_maximum_time) {//can't exceed the max ds timeout for single table + max_ds_timeout = ds_maximum_time; + } } } - return max_ds_timeout; + return ret; } int ObDynamicSamplingUtils::add_failed_ds_table_list(const uint64_t table_id, diff --git a/src/sql/optimizer/ob_dynamic_sampling.h b/src/sql/optimizer/ob_dynamic_sampling.h index 711cb50a96..0546d49d4a 100644 --- a/src/sql/optimizer/ob_dynamic_sampling.h +++ b/src/sql/optimizer/ob_dynamic_sampling.h @@ -368,7 +368,8 @@ public: uint64_t index_id, const ObIArray &ds_result_items); - static int64_t get_dynamic_sampling_max_timeout(ObOptimizerContext &ctx); + static int get_dynamic_sampling_max_timeout(ObOptimizerContext &ctx, + int64_t &max_ds_timeout); static int add_failed_ds_table_list(const uint64_t table_id, const common::ObIArray &used_part_id, diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 1a565b93a2..bcb48cc45d 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -14432,20 +14432,26 @@ int ObLogPlan::perform_gather_stat_replace(ObLogicalOperator *op) } } else { if (NULL != (group_by = dynamic_cast(op))) { - if (group_by->get_rollup_exprs().empty() && group_by->get_group_by_exprs().count() == 1) { - ObRawExpr* group_by_expr = group_by->get_group_by_exprs().at(0); - if (OB_ISNULL(group_by_expr) || OB_ISNULL(stat_partition_id_expr_) || OB_ISNULL(stat_table_scan_)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("get unexpected null", K(group_by_expr), K(stat_partition_id_expr_), K(stat_table_scan_)); - } else if (T_FUN_SYS_CALC_PARTITION_ID != group_by_expr->get_expr_type()) { - // do nothing - } else if (OB_FAIL(stat_gather_replacer_.add_replace_expr(group_by_expr, - stat_partition_id_expr_))) { - LOG_WARN("failed to push back replaced expr", K(ret)); - } else if (group_by_expr->get_partition_id_calc_type() == CALC_IGNORE_SUB_PART) { - stat_table_scan_->set_tablet_id_type(1); - } else { - stat_table_scan_->set_tablet_id_type(2); + if (group_by->get_rollup_exprs().empty() && group_by->get_group_by_exprs().count() > 0) { + //bug: + bool found_it = false;//expected only one T_FUN_SYS_CALC_PARTITION_ID in gather stats. + for (int64_t i = 0; OB_SUCC(ret) && !found_it && i < group_by->get_group_by_exprs().count(); ++i) { + ObRawExpr* group_by_expr = group_by->get_group_by_exprs().at(i); + if (OB_ISNULL(group_by_expr) || OB_ISNULL(stat_partition_id_expr_) || OB_ISNULL(stat_table_scan_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(group_by_expr), K(stat_partition_id_expr_), K(stat_table_scan_)); + } else if (T_FUN_SYS_CALC_PARTITION_ID != group_by_expr->get_expr_type()) { + // do nothing + } else if (OB_FAIL(stat_gather_replacer_.add_replace_expr(group_by_expr, + stat_partition_id_expr_))) { + LOG_WARN("failed to push back replaced expr", K(ret)); + } else if (group_by_expr->get_partition_id_calc_type() == CALC_IGNORE_SUB_PART) { + stat_table_scan_->set_tablet_id_type(1); + found_it = true; + } else { + stat_table_scan_->set_tablet_id_type(2); + found_it = true; + } } } }