Skip to content

[Compatibility]: REGEXP multiline mode ignores CR and Unicode line separators #30210

Closed

Description

@Ariznawlll

Environment

  • MatrixOne server build: 2ce4e58af6f03b943ee288ffad81012766cf830a
  • MySQL: 8.0.46
  • Both sessions use utf8mb4; the same expressions were repeated three times with identical results.

Actual behavior

MySQL's REGEXP_LIKE(..., 'm') treats CR (0D), NEL (C285), LINE SEPARATOR (E280A8), and PARAGRAPH SEPARATOR (E280A9) as line terminators. MatrixOne's multiline mode recognizes LF and CRLF, but does not start a new line after those other separators. The Unix-only u control confirms that the MySQL behavior is specifically tied to multiline mode rather than input encoding.

Separator UTF-8 bytes MySQL m MatrixOne m MySQL mu MatrixOne mu
CR 0D 1 0 0 0
LF 0A 1 1 1 1
CRLF 0D0A 1 1 1 1
NEL C285 1 0 0 0
LINE SEPARATOR E280A8 1 0 0 0
PARAGRAPH SEPARATOR E280A9 1 0 0 0

The smallest reproducer is:

SELECT REGEXP_LIKE(
  CONCAT('a', CONVERT(0x0D USING utf8mb4), 'b'),
  '^b', 'm'
);

MySQL returns 1; MatrixOne returns 0.

The same mismatch is visible through the other positional entry points:

SELECT REGEXP_INSTR(
  CONCAT('a', CONVERT(0x0D USING utf8mb4), 'b'), '^b', 1, 1, 0, 'm'
);
SELECT HEX(REGEXP_SUBSTR(
  CONCAT('a', CONVERT(0x0D USING utf8mb4), 'b'), '^b', 1, 1, 'm'
));
SELECT HEX(REGEXP_REPLACE(
  CONCAT('a', CONVERT(0x0D USING utf8mb4), 'b'), '^b', 'X', 1, 0, 'm'
));

For these three expressions MySQL returns 3, 62 (b), and 610D58; MatrixOne returns 0, NULL, and 610D62 (the input unchanged).

Expected behavior

For MySQL-compatible multiline matching, m should recognize the same line terminators as MySQL. mu should continue restricting line boundaries to Unix LF semantics.

Existing issue distinction

This is not the missing match_type overload / u acceptance tracked by closed #28304 (implemented by PR #28794): MatrixOne accepts these arguments and handles LF/CRLF correctly. It is also distinct from the ICU lookaround, backreference, and capture-template cases in closed #28305; this report is specifically about multiline line-terminator classification.

MySQL 8.0 documents m as recognizing line terminators and u as Unix-only line endings: https://dev.mysql.com/doc/refman/8.0/en/regexp.html

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added theissue type on Oct 14, 2026
  3. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    QA follow-up on PR #30646 at head e5732336ef2811dfe87cd1eaa8ea8683911da285.

    A source cross-check confirms two remaining risks from the latest PR review. regexpRowNeedsRegexp2 scans each subject for wide terminators before matching, so even an anchored LF-only prefix match pays an O(subject length) pre-scan on every row. Also, subjects above regexp2MaxSubjectBytes deliberately fall back to LF-only RE2 semantics, which still misses the CR/NEL/LS/PS behavior this issue reports. These conflict with the issue's compatibility/performance expectations; the submitted PR review has the detailed counterexamples and measurements.

    Please keep the review findings open until the full supported input domain and ordinary REGEXP cost are addressed. This is a static source confirmation; I could not rerun the Go/SQL reproductions here because the Go toolchain and MatrixOne service are unavailable.

  4. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    PR #30646 最新 head 8aea7e744fb3a4e09199452958084f9e57809bb1 的增量核对:按行求值修复了此前的终止符和普通锚点 admission 反例,但这两个边界仍需保留在 #30210 的验证范围内。

    • 性能,需在新 head 复测: regexpWideMultilineRoute 在进入 RE2 前调用 regexpWideMultilineSubjectNeedsICU;对 LF-only 文本,该函数仍要完整扫描 subject 才能确认没有 CR/NEL/LS/PS。它在 builtInRegexpPredicate 的行循环内调用,因此普通 ^alpha + 多行文本即使首部立即匹配,也要先逐行付出 O(subject bytes) 的探测成本。新实现已避免 regexp2 重编译,但源码不能支持“LF-only 零额外扫描”的结论。请在当前 head 对短路命中和不命中两类长 subject 做 head/base 对照基准。
    • 大输入语义: 若 pattern 可匹配行终结符,subject 超过 regexp2MaxSubjectBytes 会走 regexpRouteWideTooLarge 并报“不支持”。例如带 m 的 pattern 含 . 时,超过 1 MiB 的合法 TEXT 不再得到 multiline 结果。相比静默退化这是更明确的失败,但仍未覆盖该 issue 的兼容语义;请明确决定支持方式或记录限制。

    以上是基于当前 PR 源码的静态核对,我没有在此环境重跑 Go/SQL 或基准。请勿据此把前述性能/大输入边界标记为已验证关闭。

  5. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    QA follow-up for PR #30646, latest head 6c133a627fdbcf8e0529037bc8dae8acc01af8ba.

    The latest author update says the six round-4 counterexamples are fixed and the full regexp package passes at 0afd6504f7 after merging main. I have not rerun those tests. One compatibility boundary still appears intentionally unsupported: the PR states that wide-multiline patterns capable of consuming a line terminator return an error when the subject exceeds 1 MiB. For example, a long TEXT containing CR/NEL with a multiline pattern such as \\s (or a dotall pattern) can fail with “wide multiline REGEXP … not supported” instead of evaluating under the line-terminator contract tracked here. The issue's expected behavior has no size qualifier.

    Please either support that valid-input case, or explicitly resolve/document the product limit and cover the threshold boundary in public SQL tests. This is a static finding from the current PR description/review evidence, not a locally executed SQL reproduction.

  6. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    QA follow-up for PR #30646 at head 6c133a627fdbcf8e0529037bc8dae8acc01af8ba — static source review found residual risks in the wide-multiline path.

    1. regexpWideMultilineRoute is called inside the vector row loop, and regexpWideLineAdmissible parses the same pattern on every row even when the pattern is constant and the matcher is cached. This adds per-row O(pattern length) parser work.
    2. regexpWideLike scans each complete line via wideMultilineNextLine before matching; a long single-line subject with an immediate anchored-prefix match still cannot short-circuit.

    The PR's latest submitted review for this head additionally reports five reproductions: (a) multi-line REGEXP_REPLACE can exceed the existing 64 MiB result limit (reported result: 75,497,481 bytes); (b) a 32 KiB single-line ^alpha predicate was measured at 13.931 ms versus 47.909 µs on merge-base; (c) ^a\\s on a 16 KiB subject can fail regexp2's 8 MiB evaluation budget, with a new >1 MiB rejection on larger input; (d) REGEXP_REPLACE skips valid matches on leading/interior empty lines; and (e) end-anchor replacements after trailing CR/NEL/LS/PS omit the true end-of-subject match. These are findings/evidence reported by the PR review, not reproductions I ran in this workspace.

    Please keep this issue open and include the pattern-per-row cost, long first-line hit/miss, size/admission boundaries, empty-line replacement, terminal-dollar, and aggregate output-size limit in the next regression pass. I could not run Go, SQL, or head/base benchmarks locally because this workspace lacks a MatrixOne checkout, Go toolchain, and MatrixOne service.

  7. added
    severity/s0
    ai-easy
    and removed on Oct 24, 2026
  8. XuPeng-SH commented on Oct 25, 2026

    @XuPeng-SH
    Contributor

    Fresh-round local SQL validation on the isolated service built from aeaa273daf588a9988ba423915d3ae6b8c82124a (binary SHA-256 450363d5ec5e693bdd7ded44565b3b0ab1addcb807d3f9569c5d5eedeb1486e4) now passes the issue's reported matrix. For CR/LF/CRLF/NEL/LS/PS, ^b in m matched after each; mu matched only after LF/CRLF. LIKE, INSTR, SUBSTR and REPLACE returned the expected position/value/replacement on all six text cases; binary NEL matched only in m. I also checked terminal $ replacements/second-occurrence positions on CR, CRLF, NEL, LS and PS; leading/interior empty-line replacements; a cross-CR \s case on a >1 MiB subject through all four SQL functions; and the 64 MiB aggregate replacement guard (single 8 MiB replacement returned its length, nine replacements correctly returned Error 20301 at 67,108,864 bytes). Disposable databases were dropped. This verifies SQL semantics and the original reproduction on one isolated single-CN service. I did not run a matched base/head prefix-performance benchmark, so this is not a general performance claim. Fixture/log: round2-30646-regexp-wide-matrix-pattern-cast.sql / round2-aeaa273-30646-regexp-wide-matrix-pattern-cast.log, round2-30646-regexp-terminal-boundaries.sql / round2-aeaa273-30646-regexp-terminal-boundaries.log, and round2-30646-regexp-replace-budget.sql / round2-aeaa273-30646-regexp-replace-budget.log.

  9. gouhongshen commented on Oct 25, 2026

    @gouhongshen
    Contributor

    PR #31125 is trying to fix this issue.

  10. gouhongshen commented on Oct 25, 2026

    @gouhongshen
    Contributor

    PR #31125 has merged and is awaiting manual validation. The issue remains open.

  11. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main;commit:5fe08a3307e246e1ab9951ab690b50557af0f509,隔离编译二进制对应此 SHA,服务 git_version()=5fe08a3307

    • 部署方式:macOS arm64;独立持久化数据目录,单进程 LogService/TN/CN,MySQL 协议端口 6001;此前相同 SHA 的 SQL 矩阵也在隔离双 CN+Proxy 上通过

    • 测试日期:2026-10-26

    • 修复:PR #31125 已 MERGED,merge commit 在此官方 main 的祖先链。

    原问题验证

    原始六种分隔符 CR、LF、CRLF、NEL、U+2028、U+2029 在 REGEXP_LIKE(...,'^b','m') 下均实际返回 1;mu 只在 LF/CRLF 返回 1。原始 CR 路径的 REGEXP_INSTR=3、REGEXP_SUBSTR HEX=62、REGEXP_REPLACE HEX=610D58。三组新库 3/3,MOTR 重复后 9/9。

    Happy Path 覆盖

    1. 1,100,000 个 x 后接 CR/b(输入超过 1 MiB)时,LIKE=1、INSTR=1,100,003、SUBSTR=62、REPLACE 最后一字节=X。2. 末尾 CR 的 $ 全量替换输出 HEX=61580D58,覆盖末尾锚点。

    Unhappy Path 覆盖

    1. mu Unix-only 对 CR/NEL/LS/PS 均不误匹配,防止扩展 m 时破坏标志语义;没有触发大文本超限错误。

    白盒验证

    定向 Go 测试 go test ./pkg/sql/plan/function -run 'TestRegexpMultiline|TestReviewWideLine' -count=3 -timeout=6m 在当前完整 SHA 上通过,覆盖分类、宽行分隔、空行、末尾锚点、输出上限等;未做修复前后匹配性能基准,因此不声称性能提升。

    回归测试

    已加入 MOTR #278 的 script/14_issue_regression/issue_20261026_recent_assigned_sql.py 和配对 .out。本地 MOTR 定向 --repeat 3 成功 3/3,脚本每次使用三组独立数据库运行本 issue 场景,故计 9/9。完整 suite 与远端 CI 未运行。

    测试证据

    MOTR 回归脚本;本地定向记录 /private/tmp/mo-qa-new-20261026-ROza73/motr-278/var/log/run-1792983499457134000;脚本使用精确值、类型、行数和错误码断言。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easyarea/compatibilitykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions