Skip to content

Commit

Permalink
Fix position seek bug for varchar short key (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangpinghuang authored and imay committed May 16, 2019
1 parent b2e6391 commit 18e06d2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion be/src/olap/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 18e06d2

Please sign in to comment.