Remove some rowkey functions (#17)
* Remove some rowkey functions Signed-off-by: disksing <i@disksing.com> * add comment about return code Signed-off-by: disksing <i@disksing.com>
This commit is contained in:
parent
a26b60e7a4
commit
00b843a3c7
61
deps/oblib/src/common/object/ob_object.cpp
vendored
61
deps/oblib/src/common/object/ob_object.cpp
vendored
@ -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<const unsigned char*>(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:
|
||||
*
|
||||
|
1
deps/oblib/src/common/object/ob_object.h
vendored
1
deps/oblib/src/common/object/ob_object.h
vendored
@ -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;
|
||||
|
34
deps/oblib/src/common/rowkey/ob_rowkey.h
vendored
34
deps/oblib/src/common/rowkey/ob_rowkey.h
vendored
@ -189,7 +189,9 @@ public:
|
||||
if (obj_ptr_ == rhs.obj_ptr_) {
|
||||
cmp = static_cast<int32_t>(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<int32_t>(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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user