[fix](merge-on-write) incorrect result caused by key range filter with pk (#31456)
This commit is contained in:
@ -1359,10 +1359,8 @@ Status SegmentIterator::_lookup_ordinal_from_pk_index(const RowCursor& key, bool
|
||||
DCHECK(pk_index_reader != nullptr);
|
||||
|
||||
std::string index_key;
|
||||
// when is_include is false, we shoudle append KEY_NORMAL_MARKER to the
|
||||
// encode key. Otherwise, we will get an incorrect upper bound.
|
||||
encode_key_with_padding<RowCursor, true>(
|
||||
&index_key, key, _segment->_tablet_schema->num_key_columns(), is_include, true);
|
||||
&index_key, key, _segment->_tablet_schema->num_key_columns(), is_include);
|
||||
if (index_key < _segment->min_key()) {
|
||||
*rowid = 0;
|
||||
return Status::OK();
|
||||
|
||||
@ -50,6 +50,8 @@ constexpr uint8_t KEY_NULL_FIRST_MARKER = 0x01;
|
||||
constexpr uint8_t KEY_NORMAL_MARKER = 0x02;
|
||||
// Used to represent maximal value for that field
|
||||
constexpr uint8_t KEY_MAXIMAL_MARKER = 0xFF;
|
||||
// Used to represent a value greater than the normal marker by 1, using by MoW
|
||||
constexpr uint8_t KEY_NORMAL_NEXT_MARKER = 0x03;
|
||||
|
||||
// Encode one row into binary according given num_keys.
|
||||
// A cell will be encoded in the format of a marker and encoded content.
|
||||
@ -57,21 +59,20 @@ constexpr uint8_t KEY_MAXIMAL_MARKER = 0xFF;
|
||||
// fill a marker and return. If padding_minimal is true, KEY_MINIMAL_MARKER will
|
||||
// be added, if padding_minimal is false, KEY_MAXIMAL_MARKER will be added.
|
||||
// If all num_keys are found in row, no marker will be added.
|
||||
// if padding_minimal is false and padding_normal_marker is true,
|
||||
// KEY_NORMAL_MARKER will be added.
|
||||
template <typename RowType, bool full_encode = false>
|
||||
template <typename RowType, bool is_mow = false>
|
||||
void encode_key_with_padding(std::string* buf, const RowType& row, size_t num_keys,
|
||||
bool padding_minimal, bool padding_normal_marker = false) {
|
||||
bool padding_minimal) {
|
||||
for (auto cid = 0; cid < num_keys; cid++) {
|
||||
auto field = row.schema()->column(cid);
|
||||
if (field == nullptr) {
|
||||
if (padding_minimal) {
|
||||
buf->push_back(KEY_MINIMAL_MARKER);
|
||||
} else {
|
||||
if (padding_normal_marker) {
|
||||
buf->push_back(KEY_NORMAL_MARKER);
|
||||
if (is_mow) {
|
||||
buf->push_back(KEY_NORMAL_NEXT_MARKER);
|
||||
} else {
|
||||
buf->push_back(KEY_MAXIMAL_MARKER);
|
||||
}
|
||||
buf->push_back(KEY_MAXIMAL_MARKER);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -82,7 +83,7 @@ void encode_key_with_padding(std::string* buf, const RowType& row, size_t num_ke
|
||||
continue;
|
||||
}
|
||||
buf->push_back(KEY_NORMAL_MARKER);
|
||||
if (full_encode) {
|
||||
if (is_mow) {
|
||||
field->full_encode_ascending(cell.cell_ptr(), buf);
|
||||
} else {
|
||||
field->encode_ascending(cell.cell_ptr(), buf);
|
||||
|
||||
Reference in New Issue
Block a user