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 incorrect results when handling like with escape #5431

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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: 6 additions & 9 deletions dbms/src/Storages/Transaction/Collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ class Pattern : public ITiDBCollator::IPattern
tp = MatchType::Match;
if (offset < pattern.length())
{
auto old_offset = offset;
c = Collator::decodeChar(pattern.data(), old_offset);
if (c == escape || c == '_' || c == '%')
offset = old_offset;
else
{
assert(escape >= 0);
c = static_cast<decltype(c)>(escape); // NOLINT(bugprone-signed-char-misuse)
}
// use next char to match
c = Collator::decodeChar(pattern.data(), offset);
}
else
{
// use `escape` to match
}
}
else if (c == '_')
Expand Down
27 changes: 26 additions & 1 deletion tests/fullstack-test/expr/like.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,29 @@ mysql> set @@tidb_isolation_read_engines='tiflash'; select * from test.t where '
| a | b |
+------+------+
| aaaa | %a% |
+------+------+
+------+------+

mysql> insert into test.t values ('1234', '');

mysql> set @@tidb_isolation_read_engines='tiflash'; select a from test.t where a like '1234' escape '4';
+------+
| a |
+------+
| 1234 |
+------+

mysql> set @@tidb_isolation_read_engines='tiflash'; select a from test.t where a like '1234' escape '2';

mysql> set @@tidb_isolation_read_engines='tiflash'; select a from test.t where a like '15234' escape '5';
+------+
| a |
+------+
| 1234 |
+------+

mysql> set @@tidb_isolation_read_engines='tiflash'; select a from test.t where a like '_223_' escape '2';
+------+
| a |
+------+
| 1234 |
+------+