Skip to content

Feature Not Supported: LIKE ESCAPE syntax not supported #23104

Closed

Description

@dengn

Description

MatrixOne does not support the LIKE ... ESCAPE syntax for specifying custom escape characters in LIKE pattern matching. When attempting to use the ESCAPE clause, MatrixOne returns a SQL syntax error.

Error Message

ERROR 1064 (HY000): SQL parser error: You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. syntax error near "ESCAPE"

Affected Cases

This issue affects 1 test case from our boundary testing on the industry_radar_test database.

Failing SQL Statements

Example 1: LIKE with ESCAPE

SELECT * FROM company WHERE full_name LIKE '%\%' ESCAPE '' LIMIT 10;

Error: ERROR 1064 (HY000): SQL parser error: syntax error near "ESCAPE"

Expected Behavior

In MySQL, the LIKE ... ESCAPE syntax is fully supported. It allows you to specify a custom escape character for pattern matching, which is useful when you need to match literal special characters.

Example MySQL syntax:

-- Match strings containing literal '%'
SELECT * FROM table WHERE column LIKE '%\%' ESCAPE '\';

-- Match strings containing literal '_'
SELECT * FROM table WHERE column LIKE '%\_' ESCAPE '\';

-- Custom escape character
SELECT * FROM table WHERE column LIKE '%#%' ESCAPE '#';

Impact

  • MySQL Compatibility: LIKE ESCAPE is a standard MySQL feature
  • Functionality: Users cannot match literal special characters in LIKE patterns
  • Migration: Applications using LIKE ESCAPE will fail when migrating to MatrixOne
  • Workaround: Users must use alternative methods (e.g., REGEXP) which may have different semantics

Use Cases

LIKE ESCAPE is commonly used for:

  1. Matching Literal Special Characters: Matching strings that contain literal '%' or '_' characters
  2. Custom Escape Sequences: Using custom escape characters for specific pattern matching needs
  3. Data Validation: Validating data that may contain special characters

Workaround

As a temporary workaround, users can:

  1. Use REGEXP instead of LIKE (if the pattern is simple enough)
  2. Use string functions to escape special characters before matching
  3. Use application-level pattern processing

However, these workarounds:

  • May have different semantics
  • May be less efficient
  • May not be equivalent in all cases

Suggested Fix

  1. Parser Update: Update the SQL parser to recognize the ESCAPE clause in LIKE expressions
  2. Pattern Processing: Implement escape character processing in LIKE pattern matching
  3. Documentation: Update documentation to reflect support for LIKE ESCAPE
  4. Testing: Add comprehensive tests for various ESCAPE scenarios

Related MySQL Documentation

Activity

  1. added
    priority/p1
    on May 18, 2026
  2. added this to the MO-202605 milestone on May 18, 2026
  3. added
    kind/bug
    severity/s1
    on Jul 2, 2026
  4. Ariznawlll commented on Jul 2, 2026

    @Ariznawlll
    Collaborator

    Updated verification on latest main (0e8602b78) against MySQL 8.0.45:

    The parser now accepts LIKE ... ESCAPE, but behavior is still not MySQL-compatible.

    create table t_str(id int primary key, s varchar(20));
    insert into t_str values (1,'a_b'),(2,'a%b'),(3,'abc');
    
    select id from t_str where s like 'a$_b' escape '$' order by id;
    select 'a_b' like 'a##_b' escape '##';

    MySQL result:

    -- custom escape matches the literal underscore row
    1
    
    -- multi-character ESCAPE is rejected
    ERROR 1210 (HY000): Incorrect arguments to ESCAPE
    

    MatrixOne result:

    -- custom escape returns no rows
    (empty)
    
    -- multi-character ESCAPE is accepted and returns 0
    0
    

    So this issue is no longer just "syntax not supported"; it also needs runtime semantics for custom escape matching and validation of the ESCAPE argument length.

  5. Ariznawlll commented on Jul 22, 2026

    @Ariznawlll
    Collaborator

    最新 main 回归补充(2026-07-22,基线 c0486a2446c84c6dd6bf142494fe85243877ddc5):该问题还会使 prepared statement 的 ESCAPE 参数丢失。

    CREATE TABLE e(id INT PRIMARY KEY, s VARCHAR(40));
    INSERT INTO e VALUES(1,'alpha'),(2,'a_beta'),(3,'gamma');
    
    PREPARE p FROM 'SELECT id FROM e WHERE s LIKE ? ESCAPE ? ORDER BY id';
    SET @pat='a\\_%', @esc='\\';
    EXECUTE p USING @pat,@esc;
    • MatrixOne 把该语句识别为只有 1 个参数,传入 MySQL 所需的 2 个参数时返回 Incorrect arguments to EXECUTE。
    • 只传 @pat 时 MatrixOne 反而执行成功,说明 ESCAPE 后的参数没有进入 prepared 参数列表。
    • 只有 ESCAPE 参数的变体 s LIKE 'a\\_%' ESCAPE ? 被识别为 0 个参数。
    • MySQL 8.0.45 正确要求并使用 ESCAPE 参数。

    代码路径也与现象一致:ComparisonExpr 保留 Escape AST,但 bindComparisonExpr 构造 LIKE 函数时只绑定 Left 和 Right,没有绑定 Escape。因此此 prepared 差异仍归属于本 issue,不另开重复单。

  6. VioletQwQ-0 commented on Jul 30, 2026

    @VioletQwQ-0
    Collaborator

    QA handoff after merge of #26429.

    QA Decision

    • required: yes
    • reason: This changes user-visible MySQL compatibility semantics for LIKE/NOT LIKE/ILIKE/NOT ILIKE ESCAPE, including prepared parameters, NULL/empty/Unicode escapes, and NO_BACKSLASH_ESCAPES.
    • production_entrypoint: SQL predicate binding and vector execution for explicit ESCAPE expressions.
    • automated_terminal_coverage: exact PR head 7f8447f1daf8884fc06d9655e9a542f89c88fe55 passed Ubuntu UT, arm64 SCA, UT coverage, PROXY BVT, PESSIMISTIC BVT, and Utils Coverage. Canonical coverage is in test/distributed/cases/operator/like_operator.sql.
    • remaining_validation: verify the deployed build against MySQL for custom, empty, Unicode, NULL, prepared, SQL-mode, invalid multi-character, and row-dependent ESCAPE cases. The post-merge TKE image build is currently in progress.

    Merge evidence

    Pass expectation: supported direct and prepared ESCAPE expressions match MySQL results, NULL disables escaping without propagating NULL from the ESCAPE operand, and invalid explicit ESCAPE arguments return the expected error.

    Fail expectation: any parser/binder parameter loss, custom/Unicode matching mismatch, SQL-mode mismatch, unexpected NULL result, or acceptance of invalid multi-character/row-dependent escapes should fail verification and be reported with the tested build and exact SQL/result.

  7. VioletQwQ-0 commented on Jul 30, 2026

    @VioletQwQ-0
    Collaborator

    Post-merge CI update for #26429:

    This provides deployed regression evidence for the merged head, but it does not replace the remaining MySQL compatibility checks listed in the QA handoff. The issue should remain open and assigned to QA until those direct/prepared ESCAPE scenarios receive an explicit PASS or FAIL result.

  8. Ariznawlll commented on Aug 5, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:607a9263616ea883ac02c052529d2aa4c62ac051
    • 部署方式:本地单 LOG + TN + CN;另启隔离 MySQL 8.0.45 对照
    • 测试日期:2026-08-05

    原问题验证

    原 LIKE ESCAPE 语句及标量等价断言在 MO/MySQL 各执行 3 次,普通自定义 escape、%/_ 转义、空/NULL 边界均未再出现解析或错误结果问题。

    Happy Path 覆盖

    1. 自定义 escape 字符转义 %、_ 和 escape 字符自身,结果与 MySQL 一致。
    2. Unicode escape、prepared statement 中的 ESCAPE 参数、NO_BACKSLASH_ESCAPES 模式均通过 3/3。
    3. NULL ESCAPE 按三值逻辑返回 NULL;普通 LIKE 控制正常。

    Unhappy Path 覆盖

    1. 多字符 escape、逐行变化的 escape 和 prepared 空 escape 均被 MO/MySQL 拒绝,3/3 稳定。
    2. 每次错误后连接仍可继续执行 SELECT,无数据副作用。

    白盒验证

    LIKE/ESCAPE、SQL mode 和 NULL escape 的 4 组聚焦 Go 测试通过。该路径不涉及并发生命周期,未执行 -race。

    回归测试

    MatrixOne test/distributed/cases/operator/like_operator.sql 已覆盖 LIKE/ILIKE、escape、NULL、模式和错误路径,未重复加入 motr。

    测试结论

    测试通过。

  9. Ariznawlll commented on Aug 5, 2026

    @Ariznawlll
    Collaborator

    motr 回归补充

    已将本 issue 的公开 SQL 回归加入 motr PR #75:

    • 用例:issue_23104_like_escape.test
    • 覆盖:自定义/Unicode/NULL ESCAPE、表查询、prepared ESCAPE 参数、多字符和逐行 ESCAPE 拒绝、失败后会话可用性。
    • 修复前 0e8602b78cbfc13236ec3122f0ffb50f51ff61ef:prepared ESCAPE 参数丢失,执行返回 Incorrect arguments to EXECUTE,用例失败。
    • 最新 main@607a9263616ea883ac02c052529d2aa4c62ac051:连续 3 轮通过,69/69 条语句成功。

    完整 14_issue_regression 执行结果为 143 success、2 configured skip、1 个无关既有失败(#25992,invalid allocation account)。

  10. removed
    severity/s1
    on Aug 6, 2026
  11. Ariznawlll commented on Aug 9, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:08770e1beeb23239c91165492f2fe85243a3c66a
    • 部署方式:本地隔离单 CN/单 TN/LogService
    • 测试日期:2026-08-09

    原问题验证

    当前 main 的自定义 LIKE ... ESCAPE '#' 可分别精确匹配字面 %、_ 和 escape 自身;基本原始路径连续 3/3 与 MySQL 一致。

    Happy Path 覆盖

    1. '%#%%' ESCAPE '#' 仅匹配 pct%literal。
    2. '%#_%' ESCAPE '#' 仅匹配 under_score。
    3. '%##%' ESCAPE '#' 仅匹配 hash#tag。
    4. 现有 motr case 额外通过 Unicode escape、NULL escape、SQL PREPARE 的 escape 参数。

    Unhappy Path 覆盖

    1. 双字符 ESCAPE 'xx' 以 20301 Incorrect arguments to ESCAPE 正常拒绝。
    2. 拒绝后原表保持 4 行,随后查询可用。
    3. 现有 motr case 还覆盖列值作为 ESCAPE 的非法形态。

    白盒验证

    不适用:parser 与运行时参数检查均由公开 SQL 和已有 prepared case 覆盖。

    回归测试

    已有 motr/suites/14_issue_regression/t/issue_23104_like_escape.test;当前 main 的 14_issue_regression suite 中该 case 成功。此次未重复新增同功能文件。

    测试证据

    • 原始自定义转义路径:3/3 成功。
    • 非法 escape:3/3 正确拒绝且数据不变。
    • 现有 motr case:23 条语句成功。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugkind/featurephase/testingpriority/p1

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions