From 00b843a3c7b61211170d8694281d823d45c695d1 Mon Sep 17 00:00:00 2001 From: disksing Date: Fri, 9 Jul 2021 17:36:21 +0800 Subject: [PATCH] Remove some rowkey functions (#17) * Remove some rowkey functions Signed-off-by: disksing * add comment about return code Signed-off-by: disksing --- deps/oblib/src/common/object/ob_object.cpp | 61 ---------------------- deps/oblib/src/common/object/ob_object.h | 1 - deps/oblib/src/common/rowkey/ob_rowkey.h | 34 ++---------- 3 files changed, 3 insertions(+), 93 deletions(-) diff --git a/deps/oblib/src/common/object/ob_object.cpp b/deps/oblib/src/common/object/ob_object.cpp index 8bfc3c94f..41f59f6ed 100644 --- a/deps/oblib/src/common/object/ob_object.cpp +++ b/deps/oblib/src/common/object/ob_object.cpp @@ -638,67 +638,6 @@ int ObObj::check_collation_free_and_compare(const ObObj& other, int& cmp) const return ret; } -// TODO : remove this function -int ObObj::check_collation_free_and_compare(const ObObj& other) const -{ - int cmp = 0; - if (CS_TYPE_COLLATION_FREE != get_collation_type() && CS_TYPE_COLLATION_FREE != other.get_collation_type()) { - cmp = compare(other, CS_TYPE_INVALID); - } else if (is_null() || other.is_null() || is_min_value() || is_max_value() || other.is_min_value() || - other.is_max_value()) { - cmp = ObObjCmpFuncs::compare_nullsafe(*this, other, CS_TYPE_INVALID); - } else if (OB_UNLIKELY(get_collation_type() != other.get_collation_type()) || - CS_TYPE_COLLATION_FREE != get_collation_type() || get_type() != other.get_type() || !is_character_type()) { - LOG_ERROR("unexpected error, invalid argument", K(*this), K(other)); - right_to_die_or_duty_to_live(); - } else { - const int32_t lhs_len = get_val_len(); - const int32_t rhs_len = other.get_val_len(); - const int32_t cmp_len = std::min(lhs_len, rhs_len); - const bool is_oracle = lib::is_oracle_mode(); - bool need_skip_tail_space = false; - cmp = memcmp(get_string_ptr(), other.get_string_ptr(), cmp_len); - // if two strings only have different trailing spaces: - // 1. in oracle varchar mode, the strings are considered to be different, - // 2. in oracle char mode, the strings are considered to be same, - // 3. in mysql mode, the strings are considered to be different. - if (is_oracle) { - if (0 == cmp) { - if (!is_varying_len_char_type()) { - need_skip_tail_space = true; - } else if (lhs_len != cmp_len || rhs_len != cmp_len) { - cmp = lhs_len > cmp_len ? 1 : -1; - } - } - } else if (0 == cmp && (lhs_len != cmp_len || rhs_len != cmp_len)) { - need_skip_tail_space = true; - } - if (need_skip_tail_space) { - bool has_non_space = false; - const int32_t left_len = (lhs_len > cmp_len) ? lhs_len - cmp_len : rhs_len - cmp_len; - const char* ptr = (lhs_len > cmp_len) ? get_string_ptr() : other.get_string_ptr(); - const unsigned char* uptr = reinterpret_cast(ptr); - int32_t i = 0; - uptr += cmp_len; - for (; i < left_len; ++i) { - if (*(uptr + i) != ' ') { - has_non_space = true; - break; - } - } - if (has_non_space) { - // special behavior of mysql: a\1 < a, but ab > a - if (*(uptr + i) < ' ') { - cmp = lhs_len > cmp_len ? -1 : 1; - } else { - cmp = lhs_len > cmp_len ? 1 : -1; - } - } - } - } - return cmp; -} - /* * ATTENTION: * diff --git a/deps/oblib/src/common/object/ob_object.h b/deps/oblib/src/common/object/ob_object.h index 349eccead..374059d61 100644 --- a/deps/oblib/src/common/object/ob_object.h +++ b/deps/oblib/src/common/object/ob_object.h @@ -2041,7 +2041,6 @@ public: bool can_compare(const ObObj& other) const; inline bool strict_equal(const ObObj& other) const; int check_collation_free_and_compare(const ObObj& other, int& cmp) const; - int check_collation_free_and_compare(const ObObj& other) const; int compare(const ObObj& other, int& cmp) const; int compare(const ObObj& other) const; int compare(const ObObj& other, ObCollationType cs_type, int& cmp) const; diff --git a/deps/oblib/src/common/rowkey/ob_rowkey.h b/deps/oblib/src/common/rowkey/ob_rowkey.h index 12cc1dab8..19f6ed72c 100644 --- a/deps/oblib/src/common/rowkey/ob_rowkey.h +++ b/deps/oblib/src/common/rowkey/ob_rowkey.h @@ -189,7 +189,9 @@ public: if (obj_ptr_ == rhs.obj_ptr_) { cmp = static_cast(obj_cnt_ - rhs.obj_cnt_); } else { - cmp = compare_prefix(rhs); + // Ignore return code because this version of compare does not have + // return code. The whole function will be removed later. + compare_prefix(rhs, cmp); if (0 == cmp) { cmp = static_cast(obj_cnt_ - rhs.obj_cnt_); } @@ -227,36 +229,6 @@ public: return ret; } - // TODO : remove this function - OB_INLINE int compare_prefix(const ObRowkey& rhs) const - { - int cmp = 0; - int lv = 0; - int rv = 0; - // TODO remove disgusting loop, useless max min judge - if (is_min_row()) { - lv = -1; - } else if (is_max_row()) { - lv = 1; - } - if (rhs.is_min_row()) { - rv = -1; - } else if (rhs.is_max_row()) { - rv = 1; - } - if (0 == lv && 0 == rv) { - int64_t i = 0; - int64_t cmp_cnt = std::min(obj_cnt_, rhs.obj_cnt_); - for (; i < cmp_cnt && 0 == cmp; ++i) { - // TODO remove collation free check - cmp = obj_ptr_[i].check_collation_free_and_compare(rhs.obj_ptr_[i]); - } - } else { - cmp = lv - rv; - } - return cmp; - } - inline bool operator<(const ObRowkey& rhs) const { return compare(rhs) < 0;