diff --git a/dbms/src/Storages/Transaction/Collator.cpp b/dbms/src/Storages/Transaction/Collator.cpp index 1b0221a6829..d11d693a8a4 100644 --- a/dbms/src/Storages/Transaction/Collator.cpp +++ b/dbms/src/Storages/Transaction/Collator.cpp @@ -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(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 == '_') diff --git a/tests/fullstack-test/expr/like.test b/tests/fullstack-test/expr/like.test index af76095d157..5f13c7a8159 100644 --- a/tests/fullstack-test/expr/like.test +++ b/tests/fullstack-test/expr/like.test @@ -38,4 +38,29 @@ mysql> set @@tidb_isolation_read_engines='tiflash'; select * from test.t where ' | a | b | +------+------+ | aaaa | %a% | -+------+------+ \ No newline at end of file ++------+------+ + +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 | ++------+