Skip to content

Commit

Permalink
minmax: fix copy index data in a wrong way (#8302) (#8304)
Browse files Browse the repository at this point in the history
close #8301
  • Loading branch information
ti-chi-bot authored Nov 3, 2023
1 parent 9dca4d2 commit ca4dcf5
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,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<const char *>(&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<const char *>(&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<const char *>(&chars[prev_offset]), offsets[pos] - prev_offset - 1);
return RoughCheck::checkEqual<String>(value, type, min, max);
}
return RSResult::Some;
Expand Down Expand Up @@ -312,10 +315,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<const char *>(&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<const char *>(&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<const char *>(&chars[prev_offset]), offsets[pos] - prev_offset - 1);
return RoughCheck::checkEqual<String>(value, type, min, max);
}
return RSResult::Some;
Expand Down Expand Up @@ -378,10 +384,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<const char *>(&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<const char *>(&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<const char *>(&chars[prev_offset]), offsets[pos] - prev_offset - 1);
return RoughCheck::checkGreater<String>(value, type, min, max);
}
return RSResult::Some;
Expand Down Expand Up @@ -441,10 +450,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<const char *>(&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<const char *>(&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<const char *>(&chars[prev_offset]), offsets[pos] - prev_offset - 1);
return RoughCheck::checkGreater<String>(value, type, min, max);
}
return RSResult::Some;
Expand Down Expand Up @@ -507,6 +519,9 @@ RSResult MinMaxIndex::checkNullableGreaterEqual(size_t pack_index, const Field &
size_t pos = pack_index * 2;
size_t prev_offset = pos == 0 ? 0 : offsets[pos - 1];
// todo use StringRef instead of String
// When using String, we should use reinterpret_cast<const char *>(&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<const char *>(&chars[prev_offset]), offsets[pos] - prev_offset - 1);
pos = pack_index * 2 + 1;
prev_offset = offsets[pos - 1];
Expand Down Expand Up @@ -570,6 +585,9 @@ RSResult MinMaxIndex::checkGreaterEqual(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
// When using String, we should use reinterpret_cast<const char *>(&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<const char *>(&chars[prev_offset]), offsets[pos] - prev_offset - 1);
pos = pack_index * 2 + 1;
prev_offset = offsets[pos - 1];
Expand Down

0 comments on commit ca4dcf5

Please sign in to comment.