fix sql_statistics bug

This commit is contained in:
yongshige
2023-02-08 10:46:29 +08:00
committed by ob-robot
parent ce4f8fa607
commit 134dfc14b4
7 changed files with 58 additions and 14 deletions

View File

@ -1882,11 +1882,19 @@ int ObLoadDataDirectImpl::init_execute_param()
}
// need_sort_
if (OB_SUCC(ret)) {
int64_t append = 0;
int64_t enable_direct = 0;
int64_t hint_need_sort = 0;
if (OB_FAIL(hint.get_value(ObLoadDataHint::NEED_SORT, hint_need_sort))) {
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::ENABLE_DIRECT, enable_direct))) {
LOG_WARN("fail to get value of ENABLE_DIRECT", K(ret));
} else if (OB_FAIL(hint.get_value(ObLoadDataHint::NEED_SORT, hint_need_sort))) {
LOG_WARN("fail to get value of NEED_SORT", KR(ret), K(hint));
} else {
} else if (enable_direct != 0) {
execute_param_.need_sort_ = hint_need_sort > 0 ? true : false;
} else {
execute_param_.need_sort_ = true;
}
}
// sql_mode_
@ -1904,6 +1912,8 @@ int ObLoadDataDirectImpl::init_execute_param()
}
// online_opt_stat_gather_
if (OB_SUCC(ret)) {
int64_t append = 0;
int64_t gather_optimizer_statistics = 0 ;
ObSQLSessionInfo *session = nullptr;
ObObj obj;
if (OB_ISNULL(session = ctx_->get_my_session())) {
@ -1911,17 +1921,31 @@ int ObLoadDataDirectImpl::init_execute_param()
LOG_WARN("session is null", KR(ret));
} else if (OB_FAIL(session->get_sys_variable(SYS_VAR_ONLINE_OPT_STAT_GATHER, 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()) {
execute_param_.online_opt_stat_gather_ = true;
} else {
execute_param_.online_opt_stat_gather_ = obj.get_bool();
execute_param_.online_opt_stat_gather_ = false;
}
}
// max_error_rows_
if (OB_SUCC(ret)) {
int64_t append = 0;
int64_t enable_direct = 0;
int64_t hint_error_rows = 0;
if (OB_FAIL(hint.get_value(ObLoadDataHint::ERROR_ROWS, hint_error_rows))) {
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::ENABLE_DIRECT, enable_direct))) {
LOG_WARN("fail to get value of ENABLE_DIRECT", K(ret));
} else if (OB_FAIL(hint.get_value(ObLoadDataHint::ERROR_ROWS, hint_error_rows))) {
LOG_WARN("fail to get value of ERROR_ROWS", KR(ret), K(hint));
} else {
} else if (enable_direct != 0) {
execute_param_.max_error_rows_ = hint_error_rows;
} else {
execute_param_.max_error_rows_ = 0;
}
}
// data_access_param_

View File

@ -28,9 +28,12 @@ int ObLoadDataExecutor::check_is_direct_load(const ObLoadDataHint &load_hint, bo
{
int ret = OB_SUCCESS;
int64_t enable_direct = 0;
int64_t append = 0;
if (OB_FAIL(load_hint.get_value(ObLoadDataHint::ENABLE_DIRECT, enable_direct))) {
LOG_WARN("fail to get value of ENABLE_DIRECT", K(ret));
} else if ((enable_direct != 0) && GCONF._ob_enable_direct_load) {
} else if (OB_FAIL(load_hint.get_value(ObLoadDataHint::APPEND, append))) {
LOG_WARN("fail to get value of APPEND", K(ret));
} else if ((enable_direct != 0 || append != 0) && GCONF._ob_enable_direct_load) {
check_ret = true;
} else {
check_ret = false;

View File

@ -48,13 +48,10 @@ int ObTableDirectInsertCtx::init(ObExecContext *exec_ctx,
load_exec_ctx_->allocator_ = &(exec_ctx->get_allocator());
uint64_t sql_mode = 0;
ObSEArray<int64_t, 16> store_column_idxs;
ObObj obj;
if (OB_FAIL(init_store_column_idxs(MTL_ID(), table_id, store_column_idxs))) {
LOG_WARN("failed to init store column idxs", KR(ret));
} else if (OB_FAIL(exec_ctx->get_my_session()->get_sys_variable(SYS_VAR_SQL_MODE, sql_mode))) {
LOG_WARN("fail to get sys variable", KR(ret));
} else if (OB_FAIL(exec_ctx->get_my_session()->get_sys_variable(SYS_VAR_ONLINE_OPT_STAT_GATHER, obj))) {
LOG_WARN("fail to get sys variable", K(ret));
} else {
ObTableLoadParam param;
param.column_count_ = store_column_idxs.count();
@ -64,7 +61,7 @@ int ObTableDirectInsertCtx::init(ObExecContext *exec_ctx,
param.batch_size_ = 100;
param.session_count_ = parallel;
param.px_mode_ = true;
param.online_opt_stat_gather_ = obj.get_bool();
param.online_opt_stat_gather_ = false;
param.need_sort_ = true;
param.max_error_row_count_ = 0;
param.dup_action_ = sql::ObLoadDupActionType::LOAD_STOP_ON_DUP;

View File

@ -528,6 +528,18 @@ int ObLoadDataResolver::resolve_hints(const ParseNode &node)
}
break;
}
case T_APPEND: {
if (OB_FAIL(stmt_hints.set_value(ObLoadDataHint::APPEND, 1))) {
LOG_WARN("fail to set append", K(ret));
}
break;
}
case T_GATHER_OPTIMIZER_STATISTICS: {
if (OB_FAIL(stmt_hints.set_value(ObLoadDataHint::GATHER_OPTIMIZER_STATISTICS, 1))) {
LOG_WARN("fail to set gather optimizer statistics", K(ret));
}
break;
}
default:
ret = OB_ERR_HINT_UNKNOWN;
LOG_WARN("Unknown hint", "hint_name", get_type_name(hint_node->type_));

View File

@ -180,9 +180,11 @@ public:
PARALLEL_THREADS = 0, //parallel threads on the host server, for parsing and calc partition
BATCH_SIZE,
QUERY_TIMEOUT,
APPEND,
ENABLE_DIRECT,
NEED_SORT,
ERROR_ROWS,
GATHER_OPTIMIZER_STATISTICS,
TOTAL_INT_ITEM
};
enum StringHintItem {

View File

@ -6,6 +6,7 @@
#include "storage/direct_load/ob_direct_load_fast_heap_table_builder.h"
#include "share/stat/ob_opt_column_stat.h"
#include "share/stat/ob_stat_define.h"
#include "share/table/ob_table_load_define.h"
#include "storage/ddl/ob_direct_insert_sstable_ctx.h"
#include "storage/direct_load/ob_direct_load_fast_heap_table.h"
@ -100,7 +101,8 @@ int ObDirectLoadFastHeapTableBuilder::collect_obj(const ObDatumRow &datum_row)
datum_row.storage_datums_[i + ObMultiVersionRowkeyHelpper::get_extra_rowkey_col_cnt() + 1];
const ObColDesc &col_desc = param_.col_descs_->at(i + 1);
ObOptColumnStat *col_stat = column_stat_array_.at(i);
if (col_stat != nullptr) {
bool is_valid = ObColumnStatParam::is_valid_histogram_type(col_desc.col_type_.get_type());
if (col_stat != nullptr && is_valid) {
ObObj obj;
if (OB_FAIL(datum.to_obj_enhance(obj, col_desc.col_type_))) {
LOG_WARN("Failed to transform datum to obj", K(ret), K(i), K(datum_row.storage_datums_[i]));

View File

@ -11,6 +11,7 @@
#include "storage/direct_load/ob_direct_load_multiple_heap_table.h"
#include "storage/direct_load/ob_direct_load_merge_ctx.h"
#include "share/stat/ob_opt_column_stat.h"
#include "share/stat/ob_stat_define.h"
namespace oceanbase
{
@ -151,7 +152,8 @@ int ObDirectLoadPartitionMergeTask::collect_obj(const ObDatumRow &datum_row)
const ObStorageDatum &datum = datum_row.storage_datums_[i + extra_rowkey_cnt + 1];
const ObColDesc &col_desc = merge_param_->col_descs_->at(i + 1);
ObOptColumnStat *col_stat = column_stat_array_.at(i);
if (col_stat != nullptr) {
bool is_valid = ObColumnStatParam::is_valid_histogram_type(col_desc.col_type_.get_type());
if (col_stat != nullptr && is_valid) {
ObObj obj;
if (OB_FAIL(datum.to_obj_enhance(obj, col_desc.col_type_))) {
LOG_WARN("Failed to transform datum to obj", K(ret), K(i), K(datum_row.storage_datums_[i]));
@ -165,7 +167,8 @@ int ObDirectLoadPartitionMergeTask::collect_obj(const ObDatumRow &datum_row)
const ObStorageDatum &datum = datum_row.storage_datums_[i];
const ObColDesc &col_desc = merge_param_->col_descs_->at(i);
ObOptColumnStat *col_stat = column_stat_array_.at(i);
if (col_stat != nullptr) {
bool is_valid = ObColumnStatParam::is_valid_histogram_type(col_desc.col_type_.get_type());
if (col_stat != nullptr && is_valid) {
ObObj obj;
if (OB_FAIL(datum.to_obj_enhance(obj, col_desc.col_type_))) {
LOG_WARN("Failed to transform datum to obj", K(ret), K(i), K(datum_row.storage_datums_[i]));
@ -178,7 +181,8 @@ int ObDirectLoadPartitionMergeTask::collect_obj(const ObDatumRow &datum_row)
const ObStorageDatum &datum = datum_row.storage_datums_[i + extra_rowkey_cnt];
const ObColDesc &col_desc = merge_param_->col_descs_->at(i);
ObOptColumnStat *col_stat = column_stat_array_.at(i);
if (col_stat != nullptr) {
bool is_valid = ObColumnStatParam::is_valid_histogram_type(col_desc.col_type_.get_type());
if (col_stat != nullptr && is_valid) {
ObObj obj;
if (OB_FAIL(datum.to_obj_enhance(obj, col_desc.col_type_))) {
LOG_WARN("Failed to transform datum to obj", K(ret), K(i), K(datum_row.storage_datums_[i]));