diff --git a/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp b/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp index e4e4039efbf..32f53ecfeb9 100644 --- a/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp +++ b/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp @@ -175,6 +175,7 @@ MinMaxIndexPtr MinMaxIndex::read(const IDataType & type, ReadBuffer & buf, size_ + " vs. actual: " + std::to_string(bytes_read), Errors::DeltaTree::Internal); } + // NOLINTNEXTLINE (modernize-make-shared), std::make_shared does not support private constructor return MinMaxIndexPtr(new MinMaxIndex(has_null_marks, has_value_marks, std::move(minmaxes))); } @@ -249,10 +250,13 @@ RSResult MinMaxIndex::checkNullableEqual(size_t pack_index, const Field & value, size_t pos = pack_index * 2; size_t prev_offset = pos == 0 ? 0 : offsets[pos - 1]; // todo use StringRef instead of String - auto min = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + // When using String, we should use reinterpret_cast(&chars[prev_offset]) instead of chars[prev_offset] + // so that it will call constructor `constexpr basic_string( const CharT* s, const Allocator& alloc = Allocator())` + // rather than `constexpr basic_string( size_type count, CharT ch, const Allocator& alloc = Allocator() );` + auto min = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); pos = pack_index * 2 + 1; prev_offset = offsets[pos - 1]; - auto max = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + auto max = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); return RoughCheck::checkEqual(value, type, min, max); } return RSResult::Some; @@ -312,10 +316,13 @@ RSResult MinMaxIndex::checkEqual(size_t pack_index, const Field & value, const D size_t pos = pack_index * 2; size_t prev_offset = pos == 0 ? 0 : offsets[pos - 1]; // todo use StringRef instead of String - auto min = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + // When using String, we should use reinterpret_cast(&chars[prev_offset]) instead of chars[prev_offset] + // so that it will call constructor `constexpr basic_string( const CharT* s, const Allocator& alloc = Allocator())` + // rather than `constexpr basic_string( size_type count, CharT ch, const Allocator& alloc = Allocator() );` + auto min = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); pos = pack_index * 2 + 1; prev_offset = offsets[pos - 1]; - auto max = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + auto max = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); return RoughCheck::checkEqual(value, type, min, max); } return RSResult::Some; @@ -378,10 +385,13 @@ RSResult MinMaxIndex::checkNullableGreater(size_t pack_index, const Field & valu size_t pos = pack_index * 2; size_t prev_offset = pos == 0 ? 0 : offsets[pos - 1]; // todo use StringRef instead of String - auto min = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + // When using String, we should use reinterpret_cast(&chars[prev_offset]) instead of chars[prev_offset] + // so that it will call constructor `constexpr basic_string( const CharT* s, const Allocator& alloc = Allocator())` + // rather than `constexpr basic_string( size_type count, CharT ch, const Allocator& alloc = Allocator() );` + auto min = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); pos = pack_index * 2 + 1; prev_offset = offsets[pos - 1]; - auto max = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + auto max = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); return RoughCheck::checkGreater(value, type, min, max); } return RSResult::Some; @@ -441,10 +451,13 @@ RSResult MinMaxIndex::checkGreater(size_t pack_index, const Field & value, const size_t pos = pack_index * 2; size_t prev_offset = pos == 0 ? 0 : offsets[pos - 1]; // todo use StringRef instead of String - auto min = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + // When using String, we should use reinterpret_cast(&chars[prev_offset]) instead of chars[prev_offset] + // so that it will call constructor `constexpr basic_string( const CharT* s, const Allocator& alloc = Allocator())` + // rather than `constexpr basic_string( size_type count, CharT ch, const Allocator& alloc = Allocator() );` + auto min = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); pos = pack_index * 2 + 1; prev_offset = offsets[pos - 1]; - auto max = String(chars[prev_offset], offsets[pos] - prev_offset - 1); + auto max = String(reinterpret_cast(&chars[prev_offset]), offsets[pos] - prev_offset - 1); return RoughCheck::checkGreater(value, type, min, max); } return RSResult::Some;