fix ObOptColumnStat serialize bug

This commit is contained in:
wangt1xiuyi 2023-09-21 02:40:16 +00:00 committed by ob-robot
parent 63af0e6566
commit d269ccd448
9 changed files with 38 additions and 20 deletions

View File

@ -319,7 +319,7 @@ int ObDbmsStatsExecutor::set_column_stats(ObExecContext &ctx,
} else if (OB_ISNULL(col_stat_handle.stat_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(col_stat_handle.stat_), K(ret));
} else if (OB_ISNULL(col_stat = OB_NEWx(ObOptColumnStat, alloc, (*alloc)))) {
} else if (OB_ISNULL(col_stat = ObOptColumnStat::malloc_new_column_stat(*alloc))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to create column stat", K(ret));
} else if (OB_FAIL(col_stat->deep_copy(*col_stat_handle.stat_))) {
@ -656,11 +656,10 @@ int ObDbmsStatsExecutor::init_opt_stat(ObIAllocator &allocator,
}
for (int64_t i = 0; OB_SUCC(ret) && i < param.column_params_.count(); ++i) {
ObOptColumnStat *&col_stat = stat.column_stats_.at(i);
if (OB_ISNULL(ptr = allocator.alloc(sizeof(ObOptColumnStat)))) {
if (OB_ISNULL(col_stat = ObOptColumnStat::malloc_new_column_stat(allocator))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("memory is not enough", K(ret), K(ptr));
} else {
col_stat = new (ptr) ObOptColumnStat(allocator);
col_stat->set_table_id(param.column_params_.at(i).need_basic_stat() ? param.table_id_: -1);
col_stat->set_partition_id(part_info.part_id_);
col_stat->set_stat_level(extra.type_);

View File

@ -1226,11 +1226,10 @@ int ObDbmsStatsExportImport::init_opt_stat(ObExecContext &ctx,
LOG_WARN("failed to get opt col stat", K(ret));
} else if (col_stat != NULL) {//find already exists opt column stat
/*do nothing*/
} else if (OB_ISNULL(ptr = param.allocator_->alloc(sizeof(ObOptColumnStat)))) {
} else if (OB_ISNULL(col_stat = ObOptColumnStat::malloc_new_column_stat(*param.allocator_))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("memory is not enough", K(ret), K(ptr));
} else {
col_stat = new (ptr) ObOptColumnStat(*param.allocator_);
col_stat->set_table_id(param.table_id_);
col_stat->set_partition_id(part_id);
col_stat->set_stat_level(type);

View File

@ -61,7 +61,6 @@ int ObDbmsStatsUtils::init_col_stats(ObIAllocator &allocator,
ObIArray<ObOptColumnStat*> &col_stats)
{
int ret = OB_SUCCESS;
void *ptr = NULL;
if (OB_UNLIKELY(col_cnt <= 0)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error, expected specify column cnt is great 0", K(ret), K(col_cnt));
@ -70,11 +69,9 @@ int ObDbmsStatsUtils::init_col_stats(ObIAllocator &allocator,
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < col_cnt; ++i) {
ObOptColumnStat *&col_stat = col_stats.at(i);
if (OB_ISNULL(ptr = allocator.alloc(sizeof(ObOptColumnStat)))) {
if (OB_ISNULL(col_stat = ObOptColumnStat::malloc_new_column_stat(allocator))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("memory is not enough", K(ret), K(ptr));
} else {
col_stat = new (ptr) ObOptColumnStat(allocator);
LOG_WARN("memory is not enough", K(ret), K(col_stat));
}
}
}

View File

@ -548,12 +548,10 @@ int ObIncrementalStatEstimator::derive_global_col_stat(ObExecContext &ctx,
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < column_cnt; ++i) {
ObOptColumnStat *col_stat = NULL;
void *ptr = NULL;
if (OB_ISNULL(ptr = alloc.alloc(sizeof(ObOptColumnStat)))) {
if (OB_ISNULL(col_stat = ObOptColumnStat::malloc_new_column_stat(alloc))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("memory is not enough", K(ret), K(ptr));
LOG_WARN("memory is not enough", K(ret), K(col_stat));
} else {
col_stat = new (ptr) ObOptColumnStat(alloc);
ObGlobalMinEval min_eval;
ObGlobalMaxEval max_eval;
ObGlobalNullEval null_eval;

View File

@ -438,6 +438,19 @@ int ObOptColumnStat::merge_min_max(ObObj &cur, const ObObj &other, bool is_cmp_m
return ret;
}
ObOptColumnStat *ObOptColumnStat::malloc_new_column_stat(common::ObIAllocator &allocator)
{
ObOptColumnStat *new_col_stat = OB_NEWx(ObOptColumnStat, (&allocator), allocator);
if (new_col_stat != NULL) {
if (OB_ISNULL(new_col_stat->get_llc_bitmap())) {
new_col_stat->~ObOptColumnStat();
allocator.free(new_col_stat);
new_col_stat = NULL;
}
}
return new_col_stat;
}
OB_DEF_SERIALIZE(ObOptColumnStat) {
int ret = OB_SUCCESS;
LST_DO_CODE(OB_UNIS_ENCODE,
@ -495,8 +508,13 @@ OB_DEF_DESERIALIZE(ObOptColumnStat) {
avg_length_,
object_type_);
if (llc_bitmap_size_ !=0 && data_len - pos >= llc_bitmap_size_) {
memcpy(llc_bitmap_, buf + pos, llc_bitmap_size_);
pos += llc_bitmap_size_;
if (OB_ISNULL(llc_bitmap_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(llc_bitmap_), K(llc_bitmap_size_), K(data_len), K(pos));
} else {
memcpy(llc_bitmap_, buf + pos, llc_bitmap_size_);
pos += llc_bitmap_size_;
}
}
OB_UNIS_DECODE(total_col_len_);
return ret;

View File

@ -317,6 +317,8 @@ public:
common::ObCollationType get_collation_type() const { return cs_type_; }
void set_collation_type(common::ObCollationType cs_type) { cs_type_ = cs_type; }
static ObOptColumnStat *malloc_new_column_stat(common::ObIAllocator &allocator);
TO_STRING_KV(K_(table_id),
K_(partition_id),
K_(column_id),

View File

@ -67,7 +67,7 @@ void ObOptOSGColumnStat::reset()
ObOptOSGColumnStat* ObOptOSGColumnStat::create_new_osg_col_stat(common::ObIAllocator &allocator)
{
ObOptOSGColumnStat *new_osg_col_stat = OB_NEWx(ObOptOSGColumnStat, (&allocator), allocator);
ObOptColumnStat *new_col_stat = OB_NEWx(ObOptColumnStat, (&allocator), allocator);
ObOptColumnStat *new_col_stat = ObOptColumnStat::malloc_new_column_stat(allocator);
if (OB_NOT_NULL(new_osg_col_stat) && OB_NOT_NULL(new_col_stat)) {
new_osg_col_stat->col_stat_ = new_col_stat;
} else {

View File

@ -566,6 +566,10 @@ int ObStatsEstimator::copy_hybrid_hist_stat(ObOptStat &src_opt_stat,
!src_col_stat->get_histogram().is_valid()) {
LOG_TRACE("no need copy histogram", K(src_col_stat->get_histogram()),
K(dst_col_stat->get_histogram()), K(i), K(j));
if (!src_col_stat->get_histogram().is_valid() &&
dst_col_stat->get_histogram().is_hybrid()) {
dst_col_stat->get_histogram().reset();
}
} else {
ObHistogram &src_hist = src_col_stat->get_histogram();
dst_col_stat->get_histogram().set_type(src_hist.get_type());

View File

@ -45,7 +45,7 @@ OB_DEF_DESERIALIZE(ObOptStatsGatherPieceMsg)
ObOptTableStat *tmp_stat = OB_NEWx(ObOptTableStat, (&arena_));
if (OB_ISNULL(tmp_stat)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to allocate memory");
LOG_WARN("failed to allocate memory", K(ret));
} else if (OB_FAIL(tmp_stat->deserialize(buf, data_len, pos))) {
LOG_WARN("deserialize datum store failed", K(ret), K(i));
} else if (OB_FAIL(table_stats_.push_back(tmp_stat))) {
@ -57,9 +57,10 @@ OB_DEF_DESERIALIZE(ObOptStatsGatherPieceMsg)
for (int64_t i = 0; OB_SUCC(ret) && i < size; ++i) {
int col_stat_size = 0;
OB_UNIS_DECODE(col_stat_size);
ObOptColumnStat *tmp_col_stat = OB_NEWx(ObOptColumnStat, (&arena_), arena_);
ObOptColumnStat *tmp_col_stat = ObOptColumnStat::malloc_new_column_stat(arena_);
if (OB_ISNULL(tmp_col_stat)) {
LOG_WARN("failed to create new col stat");
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to create new col stat", K(ret));
} else if (OB_FAIL(tmp_col_stat->deserialize(buf, data_len, pos))) {
LOG_WARN("deserialize datum store failed", K(ret), K(i));
} else if (OB_FAIL(column_stats_.push_back(tmp_col_stat))) {