Fix position seek bug for varchar short key (#1167)
This commit is contained in:
@ -154,11 +154,24 @@ inline int Field::index_cmp(char* left, char* right) const {
|
||||
Slice* l_slice = reinterpret_cast<Slice*>(left + 1);
|
||||
Slice* r_slice = reinterpret_cast<Slice*>(right + 1);
|
||||
|
||||
if (r_slice->size + OLAP_STRING_MAX_BYTES > _index_size) {
|
||||
if (r_slice->size + OLAP_STRING_MAX_BYTES > _index_size
|
||||
|| l_slice->size + OLAP_STRING_MAX_BYTES > _index_size) {
|
||||
// 如果field的实际长度比short key长,则仅比较前缀,确保相同short key的所有block都被扫描,
|
||||
// 否则,可以直接比较short key和field
|
||||
int compare_size = _index_size - OLAP_STRING_MAX_BYTES;
|
||||
// l_slice size and r_slice size may be less than compare_size
|
||||
// so calculate the min of the three size as new compare_size
|
||||
compare_size = std::min(std::min(compare_size, (int)l_slice->size), (int)r_slice->size);
|
||||
res = strncmp(l_slice->data, r_slice->data, compare_size);
|
||||
if (res == 0) {
|
||||
if (l_slice->size < r_slice->size) {
|
||||
res = -1;
|
||||
} else if (l_slice->size > r_slice->size) {
|
||||
res = 1;
|
||||
} else {
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = l_slice->compare(*r_slice);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user