[CP] commit the existing trans in the current session before processing optimizer stats

This commit is contained in:
wangt1xiuyi 2024-05-17 03:14:06 +00:00 committed by ob-robot
parent be64e455e4
commit a15dce076a
7 changed files with 154 additions and 36 deletions

View File

@ -32,6 +32,7 @@
#include "share/stat/ob_opt_stat_gather_stat.h"
#include "sql/engine/expr/ob_expr_uuid.h"
#include "sql/privilege_check/ob_ora_priv_check.h"
#include "sql/ob_result_set.h"
namespace oceanbase
{
@ -76,6 +77,8 @@ int ObDbmsStats::gather_table_stats(ObExecContext &ctx, ParamStore &params, ObOb
int64_t start_time = ObTimeUtility::current_time();
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_ISNULL(ctx.get_my_session()) || OB_ISNULL(ctx.get_task_executor_ctx())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error", K(ret), K(ctx.get_my_session()), K(ctx.get_task_executor_ctx()));
@ -176,6 +179,8 @@ int ObDbmsStats::gather_schema_stats(ObExecContext &ctx, ParamStore &params, ObO
int64_t start_time = ObTimeUtility::current_time();
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_ISNULL(ctx.get_my_session()) || OB_ISNULL(ctx.get_task_executor_ctx())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error", K(ret), K(ctx.get_my_session()), K(ctx.get_task_executor_ctx()));
@ -309,6 +314,8 @@ int ObDbmsStats::gather_index_stats(ObExecContext &ctx, ParamStore &params, ObOb
empty_cascade.set_null();
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (lib::is_oracle_mode() && !params.at(11).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("table name shouldn't be specified in gather index stats", K(ret));
@ -528,6 +535,8 @@ int ObDbmsStats::set_table_stats(ObExecContext &ctx, ParamStore &params, ObObj &
param.table_param_.allocator_ = &ctx.get_allocator();
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_set_table_info(ctx,
params.at(0),
params.at(1),
@ -606,6 +615,8 @@ int ObDbmsStats::set_column_stats(sql::ObExecContext &ctx,
param.table_param_.allocator_ = &ctx.get_allocator();
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (params.at(2).is_null() && !params.at(1).is_null()) {
//do nothing
} else if (OB_FAIL(parse_set_column_stats(ctx,
@ -700,6 +711,8 @@ int ObDbmsStats::set_index_stats(ObExecContext &ctx, ParamStore &params, ObObj &
number::ObNumber num_nummicroblks;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (lib::is_oracle_mode() && !params.at(22).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("table name shouldn't be specified in gather index stats", K(ret));
@ -786,6 +799,8 @@ int ObDbmsStats::delete_table_stats(ObExecContext &ctx, ParamStore &params, ObOb
bool cascade_indexes = false;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -866,6 +881,8 @@ int ObDbmsStats::delete_column_stats(ObExecContext &ctx, ParamStore &params, ObO
bool only_histogram = false;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -941,6 +958,8 @@ int ObDbmsStats::delete_schema_stats(ObExecContext &ctx, ParamStore &params, ObO
ObSEArray<uint64_t, 4> table_ids;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry delete schema stats is not allowed", K(ret));
@ -1029,6 +1048,8 @@ int ObDbmsStats::delete_index_stats(ObExecContext &ctx, ParamStore &params, ObOb
bool only_histogram = false;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (lib::is_oracle_mode() && !params.at(10).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("table name shouldn't be specified in gather index stats", K(ret));
@ -1289,6 +1310,8 @@ int ObDbmsStats::export_table_stats(ObExecContext &ctx, ParamStore &params, ObOb
const share::schema::ObTableSchema *table_schema = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -1367,6 +1390,8 @@ int ObDbmsStats::export_column_stats(sql::ObExecContext &ctx,
stat_param.cascade_ = true;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -1427,6 +1452,8 @@ int ObDbmsStats::export_schema_stats(ObExecContext &ctx, ParamStore &params, ObO
ObString tmp_str;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry export schema stats is not allowed", K(ret));
@ -1506,6 +1533,8 @@ int ObDbmsStats::export_index_stats(ObExecContext &ctx, ParamStore &params, ObOb
const share::schema::ObTableSchema *table_schema = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (lib::is_oracle_mode() && !params.at(6).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("table name shouldn't be specified in gather index stats", K(ret));
@ -1615,6 +1644,8 @@ int ObDbmsStats::import_table_stats(ObExecContext &ctx, ParamStore &params, ObOb
const share::schema::ObTableSchema *table_schema = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -1712,6 +1743,8 @@ int ObDbmsStats::import_column_stats(sql::ObExecContext &ctx,
stat_param.cascade_ = true;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -1783,6 +1816,8 @@ int ObDbmsStats::import_schema_stats(ObExecContext &ctx, ParamStore &params, ObO
ObSEArray<uint64_t, 4> table_ids;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry import schema stats is not allowed", K(ret));
@ -1885,6 +1920,8 @@ int ObDbmsStats::import_index_stats(ObExecContext &ctx, ParamStore &params, ObOb
const share::schema::ObTableSchema *table_schema = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (lib::is_oracle_mode() && !params.at(8).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("table name shouldn't be specified in gather index stats", K(ret));
@ -2009,6 +2046,8 @@ int ObDbmsStats::lock_table_stats(sql::ObExecContext &ctx,
ObString stat_type_str;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -2060,6 +2099,8 @@ int ObDbmsStats::lock_partition_stats(sql::ObExecContext &ctx,
stat_param.stattype_ = StatTypeLocked::PARTITION_ALL_TYPE;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (params.at(2).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("partition not specified", K(ret));
@ -2108,6 +2149,8 @@ int ObDbmsStats::lock_schema_stats(sql::ObExecContext &ctx,
ObSEArray<uint64_t, 4> table_ids;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry lock schema stats is not allowed", K(ret));
@ -2218,6 +2261,8 @@ int ObDbmsStats::unlock_table_stats(sql::ObExecContext &ctx,
stat_param.stattype_ = StatTypeLocked::TABLE_ALL_TYPE;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -2270,6 +2315,8 @@ int ObDbmsStats::unlock_partition_stats(sql::ObExecContext &ctx,
stat_param.stattype_ = StatTypeLocked::PARTITION_ALL_TYPE;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (params.at(2).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("partition not specified", K(ret));
@ -2394,6 +2441,8 @@ int ObDbmsStats::restore_table_stats(sql::ObExecContext &ctx,
int64_t specify_time = 0;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx,
params.at(0),
params.at(1),
@ -2500,6 +2549,8 @@ int ObDbmsStats::restore_schema_stats(sql::ObExecContext &ctx,
int64_t specify_time = 0;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry restore schema stats is not allowed", K(ret));
@ -2585,6 +2636,8 @@ int ObDbmsStats::purge_stats(sql::ObExecContext &ctx,
int64_t specify_time = -1;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (lib::is_oracle_mode()) {
if (!params.at(0).is_null() && !params.at(0).is_timestamp_tz()) {
ret = OB_INVALID_ARGUMENT;
@ -2643,6 +2696,8 @@ int ObDbmsStats::alter_stats_history_retention(sql::ObExecContext &ctx,
double retention_tmp = 0.0; // bugfix:
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (!params.at(0).is_null() && OB_FAIL(params.at(0).get_number(num_retention))) {
LOG_WARN("failed to get epc", K(ret));
} else if (!params.at(0).is_null() &&
@ -2764,6 +2819,8 @@ int ObDbmsStats::reset_global_pref_defaults(sql::ObExecContext &ctx,
UNUSED(result);
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(ObDbmsStatsPreferences::reset_global_pref_defaults(ctx))) {
LOG_WARN("failed to reset global pref defaults");
} else {/*do nothing*/}
@ -2838,6 +2895,8 @@ int ObDbmsStats::set_global_prefs(sql::ObExecContext &ctx,
ObStatPrefs *stat_pref = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (!params.at(0).is_null() && OB_FAIL(params.at(0).get_string(opt_name))) {
LOG_WARN("failed to get string", K(ret), K(params.at(0)));
} else if (!params.at(0).is_null() &&
@ -2892,6 +2951,8 @@ int ObDbmsStats::set_schema_prefs(sql::ObExecContext &ctx,
ObStatPrefs *stat_pref = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry set schema stats is not allowed", K(ret));
@ -2956,6 +3017,8 @@ int ObDbmsStats::set_table_prefs(sql::ObExecContext &ctx,
bool use_size_auto = false;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx, params.at(0), params.at(1), dummy_param, param))) {
LOG_WARN("failed to get string", K(ret));
} else if (OB_FAIL(table_ids.push_back(param.table_id_))) {
@ -3015,6 +3078,8 @@ int ObDbmsStats::delete_schema_prefs(sql::ObExecContext &ctx,
ObStatPrefs *stat_pref = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (ctx.get_my_session()->get_is_in_retry()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("retry delete schema stats is not allowed", K(ret));
@ -3067,6 +3132,8 @@ int ObDbmsStats::delete_table_prefs(sql::ObExecContext &ctx,
ObStatPrefs *stat_pref = NULL;
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(parse_table_part_info(ctx, params.at(0), params.at(1), dummy_param, param))) {
LOG_WARN("failed to get string", K(ret));
} else if (OB_FAIL(table_ids.push_back(param.table_id_))) {
@ -5369,6 +5436,8 @@ int ObDbmsStats::gather_database_stats_job_proc(sql::ObExecContext &ctx,
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
ret = OB_SUCCESS;
LOG_INFO("auto gather database statistics abort because of statistic table is unwriteable");
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (!ctx.get_my_session()->is_user_session() && no_auto_gather) {
//do nothing
LOG_INFO("auto gather stat abort because of the trace point and not user seesion",
@ -6341,6 +6410,8 @@ int ObDbmsStats::gather_system_stats(sql::ObExecContext &ctx,
LOG_WARN("failed to check is unix connection", K(ret));
} else if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(check_system_stat_table_ready(session->get_effective_tenant_id()))) {
LOG_WARN("failed to check system stat table ready", K(ret));
} else if (OB_FAIL(ObDbmsStatsExecutor::gather_system_stats(ctx, session->get_effective_tenant_id()))) {
@ -6373,6 +6444,8 @@ int ObDbmsStats::delete_system_stats(sql::ObExecContext &ctx,
LOG_WARN("failed to check is unix connection", K(ret));
} else if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(check_system_stat_table_ready(session->get_effective_tenant_id()))) {
LOG_WARN("failed to check system stat table ready", K(ret));
} else if (OB_FAIL(ObDbmsStatsExecutor::delete_system_stats(ctx, session->get_effective_tenant_id()))) {
@ -6411,6 +6484,8 @@ int ObDbmsStats::set_system_stats(sql::ObExecContext &ctx,
LOG_WARN("failed to check is unix connection", K(ret));
} else if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(check_system_stat_table_ready(session->get_effective_tenant_id()))) {
LOG_WARN("failed to check system stat table ready", K(ret));
} else if (2 != params.count()) {
@ -6544,6 +6619,7 @@ int ObDbmsStats::check_system_stat_table_ready(int64_t tenant_id)
* @param result
* @return int
*/
int ObDbmsStats::copy_table_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result)
@ -6560,6 +6636,8 @@ int ObDbmsStats::copy_table_stats(sql::ObExecContext &ctx,
dummy_part_name.set_null();
if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (GET_MIN_CLUSTER_VERSION() < CLUSTER_VERSION_4_2_2_0) {
//do nothing
} else if (OB_FAIL(parse_table_part_info(ctx,

View File

@ -23,6 +23,7 @@
#include "share/stat/ob_stat_item.h"
#include "share/schema/ob_part_mgr_util.h"
#include "sql/engine/expr/ob_expr_lob_utils.h"
#include "sql/ob_result_set.h"
#ifdef OB_BUILD_ORACLE_PL
#include "pl/sys_package/ob_json_pl_utils.h"
@ -1274,6 +1275,24 @@ int ObDbmsStatsUtils::check_all_cols_range_skew(const ObIArray<ObColumnStatParam
return ret;
}
int ObDbmsStatsUtils::implicit_commit_before_gather_stats(sql::ObExecContext &ctx)
{
int ret = OB_SUCCESS;
uint64_t optimizer_features_enable_version = 0;
if (OB_ISNULL(ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(ctx.get_my_session()));
} else if (OB_FAIL(ctx.get_my_session()->get_optimizer_features_enable_version(optimizer_features_enable_version))) {
LOG_WARN("failed to get_optimizer_features_enable_version", K(ret));
} else if (optimizer_features_enable_version < COMPAT_VERSION_4_2_4 ||
(optimizer_features_enable_version >= COMPAT_VERSION_4_3_0 &&
optimizer_features_enable_version < COMPAT_VERSION_4_3_2)) {
//do nothing
} else if (OB_FAIL(ObResultSet::implicit_commit_before_cmd_execute(*ctx.get_my_session(), ctx, stmt::T_ANALYZE))) {
LOG_WARN("failed to implicit commit before cmd execute", K(ret));
} else {/*do nothing*/}
return ret;
}
}
}

View File

@ -181,6 +181,8 @@ public:
static int check_all_cols_range_skew(const ObIArray<ObColumnStatParam> &column_params,
ObIArray<ObOptStat> &opt_stats);
static int implicit_commit_before_gather_stats(sql::ObExecContext &ctx);
private:
static int batch_write(share::schema::ObSchemaGetterGuard *schema_guard,
const uint64_t tenant_id,

View File

@ -407,6 +407,8 @@ int ObStatsEstimator::do_estimate(uint64_t tenant_id,
static_cast<observer::ObInnerSQLConnectionPool*>(sql_proxy->get_pool());
sqlclient::ObISQLConnection *conn = NULL;
session->set_inner_session();
//
session->set_autocommit(true);
SMART_VAR(ObMySQLProxy::MySQLResult, proxy_result) {
sqlclient::ObMySQLResult *client_result = NULL;
if (OB_FAIL(pool->acquire(session, conn, lib::is_oracle_mode()))) {

View File

@ -58,6 +58,8 @@ int ObAnalyzeExecutor::execute(ObExecContext &ctx, ObAnalyzeStmt &stmt)
GCTX.is_standby_cluster()) {
ret = OB_NOT_SUPPORTED;
LOG_USER_ERROR(OB_NOT_SUPPORTED, "analyze table during restore or standby cluster");
} else if (OB_FAIL(ObDbmsStatsUtils::implicit_commit_before_gather_stats(ctx))) {
LOG_WARN("failed to implicit commit before gather stats", K(ret));
} else if (OB_FAIL(stmt.fill_table_stat_params(ctx, params))) {
LOG_WARN("failed to fill table stat param", K(ret));
} else {

View File

@ -254,44 +254,56 @@ int ObResultSet::on_cmd_execute()
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid inner state", K(cmd_));
} else if (cmd_->cause_implicit_commit()) {
if (my_session_.is_in_transaction() && my_session_.associated_xa()) {
int tmp_ret = OB_SUCCESS;
transaction::ObTxDesc *tx_desc = my_session_.get_tx_desc();
const transaction::ObXATransID xid = my_session_.get_xid();
const transaction::ObGlobalTxType global_tx_type = tx_desc->get_global_tx_type(xid);
if (transaction::ObGlobalTxType::XA_TRANS == global_tx_type) {
// commit is not allowed in xa trans
ret = OB_TRANS_XA_ERR_COMMIT;
LOG_WARN("COMMIT is not allowed in a xa trans", K(ret), K(xid), K(global_tx_type),
KPC(tx_desc));
} else if (transaction::ObGlobalTxType::DBLINK_TRANS == global_tx_type) {
transaction::ObTransID tx_id;
if (OB_FAIL(ObTMService::tm_commit(get_exec_context(), tx_id))) {
LOG_WARN("fail to do commit for dblink trans", K(ret), K(tx_id), K(xid),
K(global_tx_type));
}
my_session_.restore_auto_commit();
const bool force_disconnect = false;
if (OB_UNLIKELY(OB_SUCCESS != (tmp_ret = my_session_.get_dblink_context().clean_dblink_conn(force_disconnect)))) {
LOG_WARN("dblink transaction failed to release dblink connections", K(tmp_ret), K(tx_id), K(xid));
}
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected global trans type", K(ret), K(xid), K(global_tx_type), KPC(tx_desc));
if (OB_FAIL(implicit_commit_before_cmd_execute(my_session_,
get_exec_context(),
cmd_->get_cmd_type()))) {
LOG_WARN("failed to implicit commit before cmd execute", K(ret));
}
}
return ret;
}
int ObResultSet::implicit_commit_before_cmd_execute(ObSQLSessionInfo &session_info,
ObExecContext &exec_ctx,
const int cmd_type)
{
int ret = OB_SUCCESS;
if (session_info.is_in_transaction() && session_info.associated_xa()) {
int tmp_ret = OB_SUCCESS;
transaction::ObTxDesc *tx_desc = session_info.get_tx_desc();
const transaction::ObXATransID xid = session_info.get_xid();
const transaction::ObGlobalTxType global_tx_type = tx_desc->get_global_tx_type(xid);
if (transaction::ObGlobalTxType::XA_TRANS == global_tx_type) {
// commit is not allowed in xa trans
ret = OB_TRANS_XA_ERR_COMMIT;
LOG_WARN("COMMIT is not allowed in a xa trans", K(ret), K(xid), K(global_tx_type),
KPC(tx_desc));
} else if (transaction::ObGlobalTxType::DBLINK_TRANS == global_tx_type) {
transaction::ObTransID tx_id;
if (OB_FAIL(ObTMService::tm_commit(exec_ctx, tx_id))) {
LOG_WARN("fail to do commit for dblink trans", K(ret), K(tx_id), K(xid),
K(global_tx_type));
}
session_info.restore_auto_commit();
const bool force_disconnect = false;
if (OB_UNLIKELY(OB_SUCCESS != (tmp_ret = session_info.get_dblink_context().clean_dblink_conn(force_disconnect)))) {
LOG_WARN("dblink transaction failed to release dblink connections", K(tmp_ret), K(tx_id), K(xid));
}
get_exec_context().set_need_disconnect(false);
} else {
// implicit end transaction and start transaction will not clear next scope transaction settings by:
// a. set by `set transaction read only`
// b. set by `set transaction isolation level XXX`
const int cmd_type = cmd_->get_cmd_type();
bool keep_trans_variable = (cmd_type == stmt::T_START_TRANS);
if (OB_FAIL(ObSqlTransControl::implicit_end_trans(get_exec_context(), false, NULL, !keep_trans_variable))) {
LOG_WARN("fail end implicit trans on cmd execute", K(ret));
} else if (my_session_.need_recheck_txn_readonly() && my_session_.get_tx_read_only()) {
ret = OB_ERR_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION;
LOG_WARN("cmd can not execute because txn is read only", K(ret), K(cmd_type));
}
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected global trans type", K(ret), K(xid), K(global_tx_type), KPC(tx_desc));
}
exec_ctx.set_need_disconnect(false);
} else {
// implicit end transaction and start transaction will not clear next scope transaction settings by:
// a. set by `set transaction read only`
// b. set by `set transaction isolation level XXX`
bool keep_trans_variable = (cmd_type == stmt::T_START_TRANS);
if (OB_FAIL(ObSqlTransControl::implicit_end_trans(exec_ctx, false, NULL, !keep_trans_variable))) {
LOG_WARN("fail end implicit trans on cmd execute", K(ret));
} else if (session_info.need_recheck_txn_readonly() && session_info.get_tx_read_only()) {
ret = OB_ERR_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION;
LOG_WARN("cmd can not execute because txn is read only", K(ret), K(cmd_type));
}
}
return ret;

View File

@ -333,6 +333,9 @@ public:
obmysql::ObMySQLField &mfield);
void set_close_fail_callback(ObFunction<void(const int, int&)> func) { close_fail_cb_ = func; }
void set_will_retry() { will_retry_ = true; }
static int implicit_commit_before_cmd_execute(ObSQLSessionInfo &session_info,
ObExecContext &exec_ctx,
const int cmd_type);
private:
// types and constants
static const int64_t TRANSACTION_SET_VIOLATION_MAX_RETRY = 3;