fix like expression bug
This commit is contained in:
@ -732,35 +732,40 @@ int64_t ObExprLike::match_with_instr_mode(const ObString &text, const InstrInfo
|
|||||||
const char **instr_pos = instr_info.instr_starts_;
|
const char **instr_pos = instr_info.instr_starts_;
|
||||||
const uint32_t *instr_len = instr_info.instr_lengths_;
|
const uint32_t *instr_len = instr_info.instr_lengths_;
|
||||||
bool match = true;
|
bool match = true;
|
||||||
int64_t pos = 0;
|
int64_t idx = 0;
|
||||||
int64_t end = percent_sign_end ? instr_info.instr_cnt_ : instr_info.instr_cnt_ - 1;
|
int64_t idx_end = percent_sign_end ? instr_info.instr_cnt_ : instr_info.instr_cnt_ - 1;
|
||||||
// if not start with %, memcmp for first instr.
|
// if not start with %, memcmp for first instr.
|
||||||
if (!percent_sign_start) {
|
if (!percent_sign_start) {
|
||||||
|
if (text_len < instr_len[0]) {
|
||||||
|
match = false;
|
||||||
|
} else {
|
||||||
int cmp = MEMCMP(text_ptr, instr_pos[0], instr_len[0]);
|
int cmp = MEMCMP(text_ptr, instr_pos[0], instr_len[0]);
|
||||||
match = 0 == cmp;
|
match = 0 == cmp;
|
||||||
text_ptr += instr_len[0];
|
text_ptr += instr_len[0];
|
||||||
pos++;
|
text_len -= instr_len[0];
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// memmem for str surrounded by %
|
// memmem for str surrounded by %
|
||||||
for (; pos < end && match; pos++) {
|
for (; idx < idx_end && match; idx++) {
|
||||||
char *new_text = static_cast<char*>(MEMMEM(text_ptr, text_len, instr_pos[pos], instr_len[pos]));
|
char *new_text = static_cast<char*>(MEMMEM(text_ptr, text_len, instr_pos[idx], instr_len[idx]));
|
||||||
text_len -= new_text != NULL ? new_text - text_ptr + instr_len[pos] : 0;
|
text_len -= new_text != NULL ? new_text - text_ptr + instr_len[idx] : 0;
|
||||||
if (OB_UNLIKELY(text_len < 0)) {
|
if (OB_UNLIKELY(text_len < 0)) {
|
||||||
match = false;
|
match = false;
|
||||||
LOG_ERROR("unexpected result of memmem", K(text),
|
LOG_ERROR("unexpected result of memmem", K(text),
|
||||||
K(ObString(instr_len[pos], instr_pos[pos])));
|
K(ObString(instr_len[idx], instr_pos[idx])));
|
||||||
} else {
|
} else {
|
||||||
match = new_text != NULL;
|
match = new_text != NULL;
|
||||||
text_ptr = new_text + instr_len[pos];
|
text_ptr = new_text + instr_len[idx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if not end with %, memcmp for last instr
|
// if not end with %, memcmp for last instr
|
||||||
if (match && !percent_sign_end) {
|
if (match && !percent_sign_end) {
|
||||||
if (text_len < instr_len[pos]) {
|
if (text_len < instr_len[idx]) {
|
||||||
match = false;
|
match = false;
|
||||||
} else {
|
} else {
|
||||||
match = 0 == MEMCMP(text.ptr() + text.length() - instr_len[pos],
|
match = 0 == MEMCMP(text.ptr() + text.length() - instr_len[idx],
|
||||||
instr_pos[pos], instr_len[pos]);
|
instr_pos[idx], instr_len[idx]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = match ? 1 : 0;
|
res = match ? 1 : 0;
|
||||||
|
Reference in New Issue
Block a user