From d0fbe382665d54d9b81e2aaab158d80e21876e98 Mon Sep 17 00:00:00 2001 From: Mryange Date: Thu, 30 Apr 2026 14:45:16 +0800 Subject: [PATCH] upd --- be/src/core/packed_int128.h | 8 --- be/src/storage/types.h | 135 ++---------------------------------- 2 files changed, 4 insertions(+), 139 deletions(-) diff --git a/be/src/core/packed_int128.h b/be/src/core/packed_int128.h index f8ac745b3af97a..d504407d2caad1 100644 --- a/be/src/core/packed_int128.h +++ b/be/src/core/packed_int128.h @@ -51,12 +51,4 @@ struct PackedUInt128 { uint128_t value; } __attribute__((packed)); - -// unalign address directly casted to int128 will core dump -inline int128_t get_int128_from_unalign(const void* address) { - int128_t value = 0; - memcpy(&value, address, sizeof(int128_t)); - return value; -} - } // namespace doris diff --git a/be/src/storage/types.h b/be/src/storage/types.h index 81fec759089b8f..ab7d787385b43d 100644 --- a/be/src/storage/types.h +++ b/be/src/storage/types.h @@ -67,7 +67,6 @@ TypeInfoPtr create_dynamic_type_info_ptr(const TypeInfo* type_info); class TypeInfo { public: virtual ~TypeInfo() = default; - virtual int cmp(const void* left, const void* right) const = 0; virtual void set_to_max(void* buf) const = 0; virtual void set_to_min(void* buf) const = 0; @@ -79,8 +78,6 @@ class TypeInfo { class ScalarTypeInfo : public TypeInfo { public: - int cmp(const void* left, const void* right) const override { return _cmp(left, right); } - void set_to_max(void* buf) const override { _set_to_max(buf); } void set_to_min(void* buf) const override { _set_to_min(buf); } size_t size() const override { return _size; } @@ -89,15 +86,12 @@ class ScalarTypeInfo : public TypeInfo { template ScalarTypeInfo(TypeTraitsClass t) - : _cmp(TypeTraitsClass::cmp), - _set_to_max(TypeTraitsClass::set_to_max), + : _set_to_max(TypeTraitsClass::set_to_max), _set_to_min(TypeTraitsClass::set_to_min), _size(TypeTraitsClass::size), _field_type(TypeTraitsClass::type) {} private: - int (*_cmp)(const void* left, const void* right); - void (*_set_to_max)(void* buf); void (*_set_to_min)(void* buf); @@ -113,51 +107,6 @@ class ArrayTypeInfo : public TypeInfo { : _item_type_info(std::move(item_type_info)), _item_size(_item_type_info->size()) {} ~ArrayTypeInfo() override = default; - int cmp(const void* left, const void* right) const override { - auto l_value = reinterpret_cast(left); - auto r_value = reinterpret_cast(right); - size_t l_length = l_value->length(); - size_t r_length = r_value->length(); - size_t cur = 0; - - if (!l_value->has_null() && !r_value->has_null()) { - while (cur < l_length && cur < r_length) { - int result = _item_type_info->cmp((uint8_t*)(l_value->data()) + cur * _item_size, - (uint8_t*)(r_value->data()) + cur * _item_size); - if (result != 0) { - return result; - } - ++cur; - } - } else { - while (cur < l_length && cur < r_length) { - if (l_value->is_null_at(cur)) { - if (!r_value->is_null_at(cur)) { // left is null & right is not null - return -1; - } - } else if (r_value->is_null_at(cur)) { // left is not null & right is null - return 1; - } else { // both are not null - int result = - _item_type_info->cmp((uint8_t*)(l_value->data()) + cur * _item_size, - (uint8_t*)(r_value->data()) + cur * _item_size); - if (result != 0) { - return result; - } - } - ++cur; - } - } - - if (l_length < r_length) { - return -1; - } else if (l_length > r_length) { - return 1; - } else { - return 0; - } - } - void set_to_max(void* buf) const override { DCHECK(false) << "set_to_max of list is not implemented."; } @@ -184,31 +133,6 @@ class MapTypeInfo : public TypeInfo { _value_type_info(std::move(value_type_info)) {} ~MapTypeInfo() override = default; - int cmp(const void* left, const void* right) const override { - auto l_value = reinterpret_cast(left); - auto r_value = reinterpret_cast(right); - uint32_t l_size = l_value->size(); - uint32_t r_size = r_value->size(); - if (l_size < r_size) { - return -1; - } else if (l_size > r_size) { - return 1; - } else { - // now we use collection value in array to pack map k-v - auto l_k = reinterpret_cast(l_value->key_data()); - auto l_v = reinterpret_cast(l_value->value_data()); - auto r_k = reinterpret_cast(r_value->key_data()); - auto r_v = reinterpret_cast(r_value->value_data()); - auto key_arr = new ArrayTypeInfo(create_static_type_info_ptr(_key_type_info.get())); - auto val_arr = new ArrayTypeInfo(create_static_type_info_ptr(_value_type_info.get())); - if (int kc = key_arr->cmp(l_k, r_k) != 0) { - return kc; - } else { - return val_arr->cmp(l_v, r_v); - } - } - } - void set_to_max(void* buf) const override { DCHECK(false) << "set_to_max of list is not implemented."; } @@ -238,50 +162,6 @@ class StructTypeInfo : public TypeInfo { } ~StructTypeInfo() override = default; - int cmp(const void* left, const void* right) const override { - auto l_value = reinterpret_cast(left); - auto r_value = reinterpret_cast(right); - uint32_t l_size = l_value->size(); - uint32_t r_size = r_value->size(); - uint32_t cur = 0; - - if (!l_value->has_null() && !r_value->has_null()) { - while (cur < l_size && cur < r_size) { - int result = - _type_infos[cur]->cmp(l_value->child_value(cur), r_value->child_value(cur)); - if (result != 0) { - return result; - } - ++cur; - } - } else { - while (cur < l_size && cur < r_size) { - if (l_value->is_null_at(cur)) { - if (!r_value->is_null_at(cur)) { // left is null & right is not null - return -1; - } - } else if (r_value->is_null_at(cur)) { // left is not null & right is null - return 1; - } else { // both are not null - int result = _type_infos[cur]->cmp(l_value->child_value(cur), - r_value->child_value(cur)); - if (result != 0) { - return result; - } - } - ++cur; - } - } - - if (l_size < r_size) { - return -1; - } else if (l_size > r_size) { - return 1; - } else { - return 0; - } - } - void set_to_max(void* buf) const override { DCHECK(false) << "set_to_max of list is not implemented."; } @@ -487,20 +367,13 @@ template struct BaseFieldTypeTraits : public CppTypeTraits { using CppType = typename CppTypeTraits::CppType; - static inline CppType get_cpp_type_value(const void* address) { - if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_LARGEINT) { - return get_int128_from_unalign(address); - } - return *reinterpret_cast(address); - } - static inline void set_cpp_type_value(void* address, const CppType& value) { - memcpy(address, &value, sizeof(CppType)); + unaligned_store(address, value); } static inline int cmp(const void* left, const void* right) { - CppType left_value = get_cpp_type_value(left); - CppType right_value = get_cpp_type_value(right); + CppType left_value = unaligned_load(left); + CppType right_value = unaligned_load(right); if (left_value < right_value) { return -1; } else if (left_value > right_value) {