fix master failed case

This commit is contained in:
Larry955
2023-05-17 14:11:29 +00:00
committed by ob-robot
parent 29be7ce8ce
commit 088e14bdc0
4 changed files with 27 additions and 21 deletions

View File

@ -193,6 +193,7 @@ ObOptColumnStat::ObOptColumnStat()
histogram_(), histogram_(),
last_analyzed_(0), last_analyzed_(0),
cs_type_(CS_TYPE_INVALID), cs_type_(CS_TYPE_INVALID),
total_col_len_(0),
inner_allocator_("ObOptColumnStat"), inner_allocator_("ObOptColumnStat"),
allocator_(inner_allocator_) allocator_(inner_allocator_)
{ {
@ -217,6 +218,7 @@ ObOptColumnStat::ObOptColumnStat(ObIAllocator &allocator)
histogram_(), histogram_(),
last_analyzed_(0), last_analyzed_(0),
cs_type_(CS_TYPE_INVALID), cs_type_(CS_TYPE_INVALID),
total_col_len_(0),
inner_allocator_("ObOptColumnStat"), inner_allocator_("ObOptColumnStat"),
allocator_(allocator) allocator_(allocator)
{ {
@ -245,6 +247,7 @@ void ObOptColumnStat::reset()
llc_bitmap_ = NULL; llc_bitmap_ = NULL;
last_analyzed_ = 0; last_analyzed_ = 0;
cs_type_ = CS_TYPE_INVALID; cs_type_ = CS_TYPE_INVALID;
total_col_len_ = 0;
histogram_.reset(); histogram_.reset();
} }
@ -297,6 +300,7 @@ int ObOptColumnStat::deep_copy(const ObOptColumnStat &src)
last_analyzed_ = src.last_analyzed_; last_analyzed_ = src.last_analyzed_;
cs_type_ = src.cs_type_; cs_type_ = src.cs_type_;
llc_bitmap_size_ = src.llc_bitmap_size_; llc_bitmap_size_ = src.llc_bitmap_size_;
total_col_len_ = src.total_col_len_;
if (OB_FAIL(ob_write_obj(allocator_, src.min_value_, min_value_))) { if (OB_FAIL(ob_write_obj(allocator_, src.min_value_, min_value_))) {
LOG_WARN("deep copy min_value_ failed.", K_(src.min_value), K(ret)); LOG_WARN("deep copy min_value_ failed.", K_(src.min_value), K(ret));
} else if (OB_FAIL(ob_write_obj(allocator_, src.max_value_, max_value_))) { } else if (OB_FAIL(ob_write_obj(allocator_, src.max_value_, max_value_))) {
@ -330,6 +334,7 @@ int ObOptColumnStat::deep_copy(const ObOptColumnStat &src, char *buf, const int6
avg_length_ = src.avg_length_; avg_length_ = src.avg_length_;
last_analyzed_ = src.last_analyzed_; last_analyzed_ = src.last_analyzed_;
cs_type_ = src.cs_type_; cs_type_ = src.cs_type_;
total_col_len_ = src.total_col_len_;
if (!src.is_valid() || nullptr == buf || size <= 0) { if (!src.is_valid() || nullptr == buf || size <= 0) {
ret = OB_INVALID_ARGUMENT; ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arguments.", K(src), KP(buf), K(size), K(ret)); LOG_WARN("invalid arguments.", K(src), KP(buf), K(size), K(ret));
@ -394,10 +399,10 @@ int ObOptColumnStat::merge_column_stat(const ObOptColumnStat &other)
LOG_TRACE("succeed to merge min/max val", K(min_value_), K(max_value_), LOG_TRACE("succeed to merge min/max val", K(min_value_), K(max_value_),
K(other.get_min_value()), K(other.get_max_value())); K(other.get_min_value()), K(other.get_max_value()));
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
// merge avg len before update number null/not null
merge_avg_len(other.get_avg_len(), other.get_num_not_null() + other.get_num_null());
add_num_null(other.get_num_null()); add_num_null(other.get_num_null());
add_num_not_null(other.get_num_not_null()); add_num_not_null(other.get_num_not_null());
add_col_len(other.get_total_col_len());
calc_avg_len();
if (get_llc_bitmap_size() == other.get_llc_bitmap_size()) { if (get_llc_bitmap_size() == other.get_llc_bitmap_size()) {
ObGlobalNdvEval::update_llc(get_llc_bitmap(), other.get_llc_bitmap()); ObGlobalNdvEval::update_llc(get_llc_bitmap(), other.get_llc_bitmap());
} }
@ -424,6 +429,7 @@ OB_DEF_SERIALIZE(ObOptColumnStat) {
MEMCPY(buf + pos, llc_bitmap_, llc_bitmap_size_); MEMCPY(buf + pos, llc_bitmap_, llc_bitmap_size_);
pos += llc_bitmap_size_; pos += llc_bitmap_size_;
} }
OB_UNIS_ENCODE(total_col_len_);
return ret; return ret;
} }
@ -443,6 +449,7 @@ OB_DEF_SERIALIZE_SIZE(ObOptColumnStat) {
object_type_); object_type_);
if (llc_bitmap_size_ !=0) if (llc_bitmap_size_ !=0)
len += llc_bitmap_size_; len += llc_bitmap_size_;
OB_UNIS_ADD_LEN(total_col_len_);
return len; return len;
} }
@ -464,6 +471,7 @@ OB_DEF_DESERIALIZE(ObOptColumnStat) {
memcpy(llc_bitmap_, buf + pos, llc_bitmap_size_); memcpy(llc_bitmap_, buf + pos, llc_bitmap_size_);
pos += llc_bitmap_size_; pos += llc_bitmap_size_;
} }
OB_UNIS_DECODE(total_col_len_);
return ret; return ret;
} }

View File

@ -263,8 +263,16 @@ public:
void set_num_not_null(int64_t num_not_null) { num_not_null_ = num_not_null; } void set_num_not_null(int64_t num_not_null) { num_not_null_ = num_not_null; }
int64_t get_num_not_null() const { return num_not_null_; } int64_t get_num_not_null() const { return num_not_null_; }
void add_num_null(int64_t num_null) { num_null_ += num_null; }
void add_num_not_null(int64_t num_not_null) { num_not_null_ += num_not_null; }
int64_t get_num_rows() const { return num_null_ + num_not_null_; }
void set_avg_len(int64_t avg_len) { avg_length_ = avg_len; } void set_avg_len(int64_t avg_len) { avg_length_ = avg_len; }
int64_t get_avg_len() const { return avg_length_; } int64_t get_avg_len() const { return avg_length_; }
// only used for osg
void calc_avg_len() { avg_length_ = (get_num_rows() != 0) ? int64_t(round(total_col_len_ * 1.0 / get_num_rows())) : 0; }
int64_t get_stat_level() const { return object_type_; } int64_t get_stat_level() const { return object_type_; }
void set_stat_level(int64_t object_type) { object_type_ = object_type; } void set_stat_level(int64_t object_type) { object_type_ = object_type; }
@ -301,17 +309,9 @@ public:
&& num_null_ >= 0; && num_null_ >= 0;
} }
void add_num_null(int64_t num_null) { num_null_ += num_null; } void add_col_len(int64_t len) { total_col_len_ += len; }
int64_t get_total_col_len() const { return total_col_len_; }
void add_num_not_null(int64_t num_not_null) { num_not_null_ += num_not_null; }
void merge_avg_len(int64_t avg_len, int64_t num_rows)
{
SQL_LOG(DEBUG, "MERGE avg len", K(column_id_), K(partition_id_), K(avg_len), K(avg_length_), K(num_not_null_), K(num_null_), K(num_rows));
if (num_not_null_ + num_null_ + num_rows != 0) {
avg_length_ = (avg_length_ * (num_not_null_ + num_null_) + avg_len * num_rows) / (num_not_null_ + num_null_+ num_rows);
}
}
int merge_column_stat(const ObOptColumnStat &other); int merge_column_stat(const ObOptColumnStat &other);
common::ObCollationType get_collation_type() const { return cs_type_; } common::ObCollationType get_collation_type() const { return cs_type_; }
@ -329,6 +329,7 @@ public:
K_(num_not_null), K_(num_not_null),
K_(avg_length), K_(avg_length),
K_(cs_type), K_(cs_type),
K_(total_col_len),
K_(llc_bitmap_size), K_(llc_bitmap_size),
K_(llc_bitmap), K_(llc_bitmap),
K_(histogram)); K_(histogram));
@ -353,6 +354,7 @@ protected:
/** last analyzed time */ /** last analyzed time */
int64_t last_analyzed_; int64_t last_analyzed_;
common::ObCollationType cs_type_; common::ObCollationType cs_type_;
int64_t total_col_len_;
common::ObArenaAllocator inner_allocator_; common::ObArenaAllocator inner_allocator_;
common::ObIAllocator &allocator_; common::ObIAllocator &allocator_;
}; };

View File

@ -159,9 +159,7 @@ int ObOptOSGColumnStat::merge_column_stat(const ObOptOSGColumnStat &other)
other.max_val_.cmp_func_))) { other.max_val_.cmp_func_))) {
LOG_WARN("failed to inner merge min val"); LOG_WARN("failed to inner merge min val");
} else { } else {
// merge avg len before update number null/not null col_stat_->add_col_len(other.col_stat_->get_total_col_len());
col_stat_->merge_avg_len(other.col_stat_->get_avg_len(),
other.col_stat_->get_num_not_null() + other.col_stat_->get_num_null());
col_stat_->add_num_null(other.col_stat_->get_num_null()); col_stat_->add_num_null(other.col_stat_->get_num_null());
col_stat_->add_num_not_null(other.col_stat_->get_num_not_null()); col_stat_->add_num_not_null(other.col_stat_->get_num_not_null());
if (col_stat_->get_llc_bitmap_size() == other.col_stat_->get_llc_bitmap_size()) { if (col_stat_->get_llc_bitmap_size() == other.col_stat_->get_llc_bitmap_size()) {
@ -182,8 +180,8 @@ int ObOptOSGColumnStat::update_column_stat_info(const ObDatum *datum,
LOG_WARN("get unexpected null"); LOG_WARN("get unexpected null");
} else if (OB_FAIL(calc_col_len(*datum, meta, col_len))) { } else if (OB_FAIL(calc_col_len(*datum, meta, col_len))) {
LOG_WARN("failed to calc col len", K(datum), K(meta)); LOG_WARN("failed to calc col len", K(datum), K(meta));
} else if (OB_FALSE_IT(col_stat_->merge_avg_len(col_len, 1))) { } else if (OB_FALSE_IT(col_stat_->add_col_len(col_len))) {
// avg len should be set at the very begining // do nothing
} else if (datum->is_null()) { } else if (datum->is_null()) {
col_stat_->add_num_null(1); col_stat_->add_num_null(1);
} else { } else {

View File

@ -229,7 +229,6 @@ int ObDirectLoadTabletMergeCtx::collect_sql_statistics(
for (int64_t i = 0; OB_SUCC(ret) && i < col_cnt; ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < col_cnt; ++i) {
int64_t col_id = param_.is_heap_table_ ? i + 1 : i; int64_t col_id = param_.is_heap_table_ ? i + 1 : i;
int64_t row_count = 0; int64_t row_count = 0;
int64_t avg_len = 0;
ObOptOSGColumnStat *osg_col_stat = nullptr; ObOptOSGColumnStat *osg_col_stat = nullptr;
if (OB_FAIL(sql_statistics.allocate_col_stat(osg_col_stat))) { if (OB_FAIL(sql_statistics.allocate_col_stat(osg_col_stat))) {
LOG_WARN("fail to allocate table stat", KR(ret)); LOG_WARN("fail to allocate table stat", KR(ret));
@ -251,7 +250,6 @@ int ObDirectLoadTabletMergeCtx::collect_sql_statistics(
LOG_WARN("fail to merge column stat", KR(ret)); LOG_WARN("fail to merge column stat", KR(ret));
} else { } else {
row_count += task_array_.at(j)->get_row_count(); row_count += task_array_.at(j)->get_row_count();
avg_len += osg_col_stat->col_stat_->get_avg_len();
} }
} }
// scan fast heap table // scan fast heap table
@ -271,12 +269,12 @@ int ObDirectLoadTabletMergeCtx::collect_sql_statistics(
LOG_WARN("fail to merge column stat", KR(ret)); LOG_WARN("fail to merge column stat", KR(ret));
} else { } else {
row_count += fast_heap_table_array.at(j)->get_row_count(); row_count += fast_heap_table_array.at(j)->get_row_count();
avg_len += osg_col_stat->col_stat_->get_avg_len();
} }
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
table_row_cnt = row_count; table_row_cnt = row_count;
table_avg_len += avg_len; osg_col_stat->col_stat_->calc_avg_len();
table_avg_len += osg_col_stat->col_stat_->get_avg_len();
osg_col_stat->col_stat_->set_table_id(param_.target_table_id_); osg_col_stat->col_stat_->set_table_id(param_.target_table_id_);
osg_col_stat->col_stat_->set_partition_id(target_partition_id_); osg_col_stat->col_stat_->set_partition_id(target_partition_id_);
osg_col_stat->col_stat_->set_stat_level(stat_level); osg_col_stat->col_stat_->set_stat_level(stat_level);