[dbms_stats]: bugfix for online optimizer stats gather.
This commit is contained in:
@ -1929,13 +1929,13 @@ int ObLoadDataDirectImpl::init_execute_param()
|
||||
if (OB_ISNULL(session = ctx_->get_my_session())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is null", KR(ret));
|
||||
} else if (OB_FAIL(session->get_sys_variable(SYS_VAR_ONLINE_OPT_STAT_GATHER, obj))) {
|
||||
} else if (OB_FAIL(session->get_sys_variable(SYS_VAR__OPTIMIZER_GATHER_STATS_ON_LOAD, obj))) {
|
||||
LOG_WARN("fail to get sys variable", K(ret));
|
||||
} else if (OB_FAIL(hint.get_value(ObLoadDataHint::APPEND, append))) {
|
||||
LOG_WARN("fail to get value of APPEND", K(ret));
|
||||
} else if (OB_FAIL(hint.get_value(ObLoadDataHint::GATHER_OPTIMIZER_STATISTICS, gather_optimizer_statistics))) {
|
||||
LOG_WARN("fail to get value of APPEND", K(ret));
|
||||
} else if ((append != 0) || (gather_optimizer_statistics != 0) || obj.get_bool()) {
|
||||
} else if (((append != 0) || (gather_optimizer_statistics != 0)) && obj.get_bool()) {
|
||||
execute_param_.online_opt_stat_gather_ = true;
|
||||
} else {
|
||||
execute_param_.online_opt_stat_gather_ = false;
|
||||
|
||||
@ -605,7 +605,8 @@ int ObInsertValueGenerator::init(ObSQLSessionInfo &session,
|
||||
int ObLoadDataSPImpl::gen_insert_columns_names_buff(ObExecContext &ctx,
|
||||
const ObLoadArgument &load_args,
|
||||
ObIArray<ObLoadTableColumnDesc> &insert_infos,
|
||||
ObString &data_buff)
|
||||
ObString &data_buff,
|
||||
bool need_online_osg)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
@ -641,7 +642,8 @@ int ObLoadDataSPImpl::gen_insert_columns_names_buff(ObExecContext &ctx,
|
||||
if (OB_FAIL(ObLoadDataUtils::build_insert_sql_string_head(load_args.dupl_action_,
|
||||
load_args.combined_name_,
|
||||
insert_column_names,
|
||||
insert_stmt))) {
|
||||
insert_stmt,
|
||||
need_online_osg))) {
|
||||
LOG_WARN("gen insert sql column_names failed", K(ret));
|
||||
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), insert_stmt.string(), data_buff))) {
|
||||
LOG_WARN("fail to write string", K(ret));
|
||||
@ -2419,14 +2421,17 @@ int ObLoadDataSPImpl::ToolBox::build_calc_partid_expr(ObExecContext &ctx,
|
||||
ObSqlString insert_sql;
|
||||
ObSEArray<ObString, 16> column_names;
|
||||
ObLoadArgument &load_args = load_stmt.get_load_arguments();
|
||||
bool need_online_osg = false;
|
||||
|
||||
for (int i = 0; OB_SUCC(ret) && i < insert_infos.count(); ++i) {
|
||||
OZ (column_names.push_back(insert_infos.at(i).column_name_));
|
||||
}
|
||||
OZ (ObLoadDataUtils::check_need_opt_stat_gather(ctx, load_stmt, need_online_osg));
|
||||
OZ (ObLoadDataUtils::build_insert_sql_string_head(load_args.dupl_action_,
|
||||
load_args.combined_name_,
|
||||
column_names,
|
||||
insert_sql));
|
||||
insert_sql,
|
||||
need_online_osg));
|
||||
OZ (insert_sql.append(" VALUES("));
|
||||
for (int i = 0; OB_SUCC(ret) && i < insert_infos.count(); ++i) {
|
||||
if (i != 0) {
|
||||
@ -2583,6 +2588,7 @@ int ObLoadDataSPImpl::ToolBox::init(ObExecContext &ctx, ObLoadDataStmt &load_stm
|
||||
ObIODOpt opt;
|
||||
ObIODOpts iod_opts;
|
||||
ObBackupIoAdapter util;
|
||||
bool need_online_osg = false;
|
||||
|
||||
iod_opts.opts_ = &opt;
|
||||
iod_opts.opt_cnt_ = 0;
|
||||
@ -2616,9 +2622,12 @@ int ObLoadDataSPImpl::ToolBox::init(ObExecContext &ctx, ObLoadDataStmt &load_stm
|
||||
LOG_WARN("fail to init data_trimer", K(ret));
|
||||
} else if (OB_FAIL(gen_load_table_column_desc(ctx, load_stmt, insert_infos))) {
|
||||
LOG_WARN("fail to build load table column desc", K(ret));
|
||||
} else if (OB_FAIL(ObLoadDataUtils::check_need_opt_stat_gather(ctx, load_stmt, need_online_osg))) {
|
||||
LOG_WARN("fail to check need online stats gather", K(ret));
|
||||
} else if (OB_FAIL(gen_insert_columns_names_buff(ctx, load_args,
|
||||
insert_infos,
|
||||
insert_stmt_head_buff))) {
|
||||
insert_stmt_head_buff,
|
||||
need_online_osg))) {
|
||||
LOG_WARN("fail to gen insert column names buff", K(ret));
|
||||
} else if (OB_FAIL(data_frag_mgr.init(ctx, load_args.table_id_))) {
|
||||
LOG_WARN("fail to init data frag mgr", K(ret));
|
||||
|
||||
@ -795,7 +795,8 @@ private:
|
||||
static int gen_insert_columns_names_buff(ObExecContext &ctx,
|
||||
const ObLoadArgument &load_args,
|
||||
common::ObIArray<ObLoadTableColumnDesc> &insert_infos,
|
||||
common::ObString &data_buff);
|
||||
common::ObString &data_buff,
|
||||
bool need_online_osg = false);
|
||||
// disallow copy
|
||||
DISALLOW_COPY_AND_ASSIGN(ObLoadDataSPImpl);
|
||||
// function members
|
||||
|
||||
@ -26,11 +26,13 @@ const char ObLoadDataUtils::NULL_VALUE_FLAG = '\xff';
|
||||
int ObLoadDataUtils::build_insert_sql_string_head(ObLoadDupActionType insert_mode,
|
||||
const ObString &table_name,
|
||||
const ObIArray<ObString> &insert_keys,
|
||||
ObSqlString &insertsql_keys)
|
||||
ObSqlString &insertsql_keys,
|
||||
bool need_gather_opt_stat)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
static const char *replace_stmt = "replace into ";
|
||||
static const char *insert_stmt = "insert into ";
|
||||
static const char *insert_stmt_gather_opt_stat = "insert /*+GATHER_OPTIMIZER_STATISTICS*/ into ";
|
||||
static const char *insert_ignore_stmt = "insert ignore into ";
|
||||
|
||||
const char *stmt_head = NULL;
|
||||
@ -41,9 +43,14 @@ int ObLoadDataUtils::build_insert_sql_string_head(ObLoadDupActionType insert_mod
|
||||
case ObLoadDupActionType::LOAD_IGNORE:
|
||||
stmt_head = insert_ignore_stmt;
|
||||
break;
|
||||
case ObLoadDupActionType::LOAD_STOP_ON_DUP:
|
||||
stmt_head = insert_stmt;
|
||||
case ObLoadDupActionType::LOAD_STOP_ON_DUP: {
|
||||
if (need_gather_opt_stat) {
|
||||
stmt_head = insert_stmt_gather_opt_stat;
|
||||
} else {
|
||||
stmt_head = insert_stmt;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("not suppport insert mode", K(insert_mode));
|
||||
@ -365,6 +372,32 @@ int ObLoadDataUtils::check_session_status(ObSQLSessionInfo &session, int64_t res
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLoadDataUtils::check_need_opt_stat_gather(ObExecContext &ctx,
|
||||
ObLoadDataStmt &load_stmt,
|
||||
bool &need_opt_stat_gather)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *session = nullptr;
|
||||
const ObLoadDataHint &hint = load_stmt.get_hints();
|
||||
ObObj obj;
|
||||
int64_t append = 0;
|
||||
int64_t gather_optimizer_statistics = 0;
|
||||
need_opt_stat_gather = false;
|
||||
if (OB_ISNULL(session = ctx.get_my_session())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is null", KR(ret));
|
||||
} else if (OB_FAIL(session->get_sys_variable(share::SYS_VAR__OPTIMIZER_GATHER_STATS_ON_LOAD, obj))) {
|
||||
LOG_WARN("fail to get sys variable", K(ret));
|
||||
} else if (OB_FAIL(hint.get_value(ObLoadDataHint::APPEND, append))) {
|
||||
LOG_WARN("fail to get value of APPEND", K(ret));
|
||||
} else if (OB_FAIL(hint.get_value(ObLoadDataHint::GATHER_OPTIMIZER_STATISTICS, gather_optimizer_statistics))) {
|
||||
LOG_WARN("fail to get value of APPEND", K(ret));
|
||||
} else if (((append != 0) || (gather_optimizer_statistics != 0)) && obj.get_bool()) {
|
||||
need_opt_stat_gather = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/////////////////
|
||||
|
||||
ObGetAllJobStatusOp::ObGetAllJobStatusOp()
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
#include "lib/string/ob_sql_string.h"
|
||||
#include "lib/hash/ob_hashmap.h"
|
||||
#include "common/object/ob_object.h"
|
||||
#include "sql/resolver/cmd/ob_load_data_stmt.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
|
||||
#ifndef OCEANBASE_SQL_ENGINE_CMD_LOAD_DATA_UTILS_H_
|
||||
#define OCEANBASE_SQL_ENGINE_CMD_LOAD_DATA_UTILS_H_
|
||||
@ -148,7 +150,13 @@ public:
|
||||
static int build_insert_sql_string_head(ObLoadDupActionType insert_mode,
|
||||
const common::ObString &table_name,
|
||||
const common::ObIArray<common::ObString> &insert_keys,
|
||||
common::ObSqlString &insertsql_keys);
|
||||
common::ObSqlString &insertsql_keys,
|
||||
bool need_gather_opt_stat = false);
|
||||
|
||||
static int check_need_opt_stat_gather(ObExecContext &ctx,
|
||||
ObLoadDataStmt &load_stmt,
|
||||
bool &need_opt_stat_gather);
|
||||
|
||||
static int append_values_in_remote_process(int64_t table_column_count,
|
||||
int64_t append_values_count,
|
||||
const ObExprValueBitSet &expr_bitset,
|
||||
|
||||
@ -100,7 +100,6 @@ int ObCreateTableExecutor::prepare_ins_arg(ObCreateTableStmt &stmt,
|
||||
bool is_set_subquery = false;
|
||||
bool is_oracle_mode = lib::is_oracle_mode();
|
||||
bool no_osg_hint = false;
|
||||
bool osg_hint = false;
|
||||
bool online_sys_var = false;
|
||||
const ObString &db_name = stmt.get_database_name();
|
||||
const ObString &tab_name = stmt.get_table_name();
|
||||
@ -122,11 +121,10 @@ int ObCreateTableExecutor::prepare_ins_arg(ObCreateTableStmt &stmt,
|
||||
} else {
|
||||
//get hint
|
||||
no_osg_hint = select_stmt->get_query_ctx()->get_global_hint().has_no_gather_opt_stat_hint();
|
||||
osg_hint = select_stmt->get_query_ctx()->get_global_hint().has_gather_opt_stat_hint();
|
||||
|
||||
//get system variable
|
||||
ObObj online_sys_var_obj;
|
||||
if (OB_FAIL(OB_FAIL(my_session->get_sys_variable(SYS_VAR_ONLINE_OPT_STAT_GATHER, online_sys_var_obj)))) {
|
||||
if (OB_FAIL(OB_FAIL(my_session->get_sys_variable(SYS_VAR__OPTIMIZER_GATHER_STATS_ON_LOAD, online_sys_var_obj)))) {
|
||||
LOG_WARN("fail to get sys var", K(ret));
|
||||
} else {
|
||||
online_sys_var = online_sys_var_obj.get_bool();
|
||||
@ -136,7 +134,7 @@ int ObCreateTableExecutor::prepare_ins_arg(ObCreateTableStmt &stmt,
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos1,
|
||||
(!no_osg_hint && (online_sys_var || osg_hint))
|
||||
(!no_osg_hint && online_sys_var)
|
||||
? "insert /*+GATHER_OPTIMIZER_STATISTICS*/ into %c%.*s%c.%c%.*s%c"
|
||||
: "insert /*+NO_GATHER_OPTIMIZER_STATISTICS*/ into %c%.*s%c.%c%.*s%c",
|
||||
sep_char,
|
||||
|
||||
Reference in New Issue
Block a user