Skip to content

Commit

Permalink
Revert "*: fix incorrect results when handling like with escape (p…
Browse files Browse the repository at this point in the history
…ingcap#5431)"

This reverts commit 794bfe8.
  • Loading branch information
solotzg committed Sep 19, 2022
1 parent 4543c9b commit c21f60b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
15 changes: 9 additions & 6 deletions dbms/src/Storages/Transaction/Collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ class Pattern : public ITiDBCollator::IPattern
tp = MatchType::Match;
if (offset < pattern.length())
{
// use next char to match
c = Collator::decodeChar(pattern.data(), offset);
}
else
{
// use `escape` to match
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)
}
}
}
else if (c == '_')
Expand Down
27 changes: 1 addition & 26 deletions tests/fullstack-test/expr/like.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,4 @@ 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 |
+------+
+------+------+

0 comments on commit c21f60b

Please sign in to comment.