Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix position seek bug for varchar short key #1167

Merged
merged 1 commit into from
May 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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