adjust cmp method when merge min/max value for column stat

This commit is contained in:
Larry955
2023-07-11 09:18:38 +00:00
committed by ob-robot
parent 42a290cedb
commit 21b36b42c3
2 changed files with 37 additions and 9 deletions

View File

@ -390,15 +390,11 @@ int ObOptColumnStat::merge_column_stat(const ObOptColumnStat &other)
} else {
const ObObj &other_min = other.get_min_value();
const ObObj &other_max = other.get_max_value();
if (min_value_.is_null() || (!other_min.is_null() && other_min < min_value_)) {
ret = ob_write_obj(allocator_, other_min, min_value_);
}
if (OB_SUCC(ret) && (max_value_.is_null() || (!other_max.is_null() && other_max > max_value_))) {
ret = ob_write_obj(allocator_, other_max, 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()));
if (OB_SUCC(ret)) {
if (OB_FAIL(merge_min_max(min_value_, other_min, true))) {
LOG_WARN("failed to merge min value", K(other_min), K(min_value_));
} else if (OB_FAIL(merge_min_max(max_value_, other_max, false))) {
LOG_WARN("failed to merge max value", K(other_max), K(max_value_));
} else {
add_num_null(other.get_num_null());
add_num_not_null(other.get_num_not_null());
add_col_len(other.get_total_col_len());
@ -411,6 +407,37 @@ int ObOptColumnStat::merge_column_stat(const ObOptColumnStat &other)
return ret;
}
/**
* @brief
*
* @param cur
* @param other
* @param is_cmp_min true: merge min, false: merge max
* @return int
*/
int ObOptColumnStat::merge_min_max(ObObj &cur, const ObObj &other, bool is_cmp_min)
{
int ret = OB_SUCCESS;
int cmp = 0;
if (cur.is_null()) {
ret = ob_write_obj(allocator_, other, cur);
} else if (!other.is_null()) {
if (OB_FAIL(other.compare(cur, cmp))) {
LOG_WARN("failed to compare", K(other), K(cur), K(cmp));
} else if (is_cmp_min) {
if (cmp < 0) {
ret = ob_write_obj(allocator_, other, cur);
}
} else {
if (cmp > 0) {
ret = ob_write_obj(allocator_, other, cur);
}
}
}
LOG_TRACE("succeed to merge min/max val", K(ret), K(cur), K(other), K(is_cmp_min), K(cmp));
return ret;
}
OB_DEF_SERIALIZE(ObOptColumnStat) {
int ret = OB_SUCCESS;
LST_DO_CODE(OB_UNIS_ENCODE,

View File

@ -335,6 +335,7 @@ public:
K_(histogram));
private:
DISALLOW_COPY_AND_ASSIGN(ObOptColumnStat);
int merge_min_max(ObObj &cur, const ObObj &other, bool is_cmp_min);
protected:
uint64_t table_id_;
int64_t partition_id_;