Repository navigation
fix(function): recognize MySQL line terminators in REGEXP multiline mode - #31125
Conversation
MatrixOne's REGEXP_LIKE/INSTR/SUBSTR/REPLACE multiline ('m') mode only
treated LF and CRLF as line boundaries, while MySQL 8.0 also recognizes
CR, NEL (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR
(U+2029) as line terminators. The 'mu' (Unix-only) mode was and stays
LF-only.
Vendor the dlclark/regexp2 engine (fork github.com/XuPeng-SH/regexp2
@718f43e031fe = v1.10.0 + fastclock patch, MIT) under
pkg/sql/plan/function/internal/regexp2 with attribution in README /
ATTRIB / LICENSE / PROVENANCE, add the MatrixOne-owned linemode
classifier for the wide line-terminator set (with atomic CRLF), add the
pkg/sql/plan/function/internal/regexpclass engine classifier that routes
patterns between the pinned Go RE2 copy and regexp2, and wire the wide
terminator set through both engines and the four SQL entry points
(REGEXP_LIKE/INSTR/SUBSTR/REPLACE) behind the ' m' flag while keeping
'mu' Unix-only. Vendored sources are reconciled with the repository's
license-header, err-check and configured staticcheck policies;
.licenserc.yml exempts the 23 upstream files individually.
Design: docs/design/20261024-30210-regexp-multiline-line-terminators.md
Related to matrixorigin#30210.
27fca82 to
379e87f
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 379e87f1e0749af895190a2a3a273e03e0af5019
Assessment: request_changes
The mandatory design-review gate remains open. This change introduces a substantial pattern-classification subsystem shared by two regex engines, but the supplied evidence does not establish approval of the implemented design revision. Full implementation approval is deferred.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
- P2
docs/design/20261024-30210-regexp-multiline-line-terminators.md:3: Validation requirement: this architectural change adds 3,458 lines of non-vendored classifier production code and changes candidate-start policy across RE2 and regexp2, triggering the repository's design-first review contract.
Impact: Implementation approval requires a traceable design approval decision. Provide the distinct design-review record for the exact implemented revision, resolve any blockers, and reconcile the pending status before resuming implementation review.
Evidence: Rev 10 explicitly says 'pending design review'. Its SHA-256, 5dcab7b28d863dbec65e003b5db3503fdbc3ee1c1374d4622e9ae737bf3315b4, matches the PR body. The body says it was independently reviewed locally but supplies no approval decision or review record; evidence.json contains no reviews or local_validation gates.
Validation:
-
Verified the assigned head, merge-base, unchanged checkout, 77-file inventory and exact design hash.
-
Design audit exited 0; checks/1792947942110056164-4.json matches design-gate-audit.log and the frozen source fingerprint.
-
Frozen CI reports successful build, UT, SCA, coverage and selected BVT checks. These do not establish design approval.
-
Audit details: /home/xupeng/.local/state/mo-bot/jobs/da9075f02ec07249c6606269/attempt-1/review-record.json.
Limitations:
-
The repository contract at .agents/skills/mo-dev/references/feature-design-review.md requires a traceable 'reviewed revision and approval decision' and directs reviewers to 'stop the implementation approval path' when the gate fails.
-
Full implementation/test review, native provenance reconciliation and behavioral/performance validation remain outstanding. No fresh product tests were run and no runtime defect is asserted.
…trixorigin#31125) The design-stage review of design Rev 10 (sha256 5dcab7b2...) closed with decision PASS on 2026-10-25, after Rev 1-9 each received design-stage REQUEST_CHANGES whose findings were verified and addressed per revision. The document Status header still read "pending design review" and the PR carried no traceable approval record, which the external review on PR matrixorigin#31125 flagged as an open design-review gate. Rev 11 records the complete decision chain in a new "Design review record" section and updates the Status header. It is a status-record-only revision: outside the Status paragraph, the new section and the Rev 11 change-log entry, the document is identical to the approved Rev 10, so the PASS applies unchanged to the implemented revision. Rev 11 sha256: 88b073910fb37bbc7cb7c5f931239e255116b348bb930a980a6d0d366763ec2d.
|
Addressing the design-gate finding (P2, Decision: the design-review gate is satisfied; the traceability gap is now closed in-tree. The finding is correct on the publication side: the Status header still read "pending design review" and the body cited no review record, so the approval was not traceable from the PR. The design-stage review itself was distinct, complete, and keyed to the exact implemented revision:
Publication fix delivered in No product code, tests, or validation semantics changed in |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 843ef39b189218318da277ce78e943f70ecb1057
Assessment: approve
Reviewed the complete delta, linked issue, review concerns, callers and validation. The design appropriately keeps line assertions in the engines and shares compile-time classification, preserving original subject offsets and removing admission-inflating anchor rewrites. The published design approval matches the prior document revision. No actionable introduced defects remain; the measured wide-line performance cost is an accepted correctness tradeoff.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Verified clean frozen HEAD and supplied patch, 200 native build inputs, and all 27 vendored upstream provenance hashes. Final audit passed: checks/1792955861453676165-5.json and audit-review-final.log.
-
Engine and classifier suites passed; classifier and regexp2 race tests passed. Receipts: 1792954960327164749-3.json and 1792955732686901503-3.json.
-
Built native prerequisites through the repository Makefile using exact candidate inputs. SQL regexp, operator and wide-line tests passed, covering offsets, replacement, routing and admission boundaries. Receipts: 1792955548199700155-4.json and 1792955845423684145-4.json.
-
Independent ICU 76.1 comparison passed 17,530 RE2 cases. Regexp2 discrepancies were investigated with pinned-upstream controls and attributed to existing lazy-empty-loop behavior, not counted as a parity pass.
-
Five-sample base/head benchmarks measured approximately 30–31% slower long wide-line scans, 12% slower short wide-line matching, and 12–31% higher wide compilation time. Sampled Unix-line and prefix-rejection paths remained near base; warm matching added no allocations.
-
Command, source, exit and log reconciliation is retained in /home/xupeng/.local/state/mo-bot/jobs/30a82aee1f27ba74878f0bc9/attempt-1/review-record.json.
Limitations:
-
Independent oracle execution used ICU 76.1, not the author's ICU 77.1 environment; it does not establish universal ICU equivalence.
-
No fresh live-server BVT run. Frozen matching-head CI metadata reports successful UT, native builds and BVT, but raw CI logs and author artifacts were unavailable.
-
Initial oracle timeout and native setup failures were diagnostic failures, followed by successful bounded validation. Benchmarks are local microbenchmarks, not end-to-end SQL throughput measurements.
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 1 hour 18 minutes in the queue, including 55 minutes 51 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #30210
What this PR does / why we need it:
Root cause
MySQL 8.0 multiline (
m) mode treats LF, CR, CRLF, NEL (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) as line terminators, so^bmatches after any of them. MatrixOne'sREGEXP_LIKE/REGEXP_INSTR/REGEXP_SUBSTR/REGEXP_REPLACErecognized only LF and CRLF:SELECT REGEXP_LIKE(CONCAT('a', CONVERT(0x0D USING utf8mb4), 'b'), '^b', 'm')returned0where MySQL returns1(same mismatch forINSTR/SUBSTR/REPLACE, in both directions of position and replacement-byte semantics). The Unix-onlyuflag was and must remain LF-only.Exact changes
pkg/sql/plan/function/internal/regexp2: byte-pinned forkgithub.com/XuPeng-SH/regexp2@718f43e031fe(= dlclark/regexp2 v1.10.0 + fastclock patch, MIT; attribution and pre-rename SHA-256 inventory inLICENSE/ATTRIB/PROVENANCE). MatrixOne-owned additions:linemode.go/linemode_test.go(wide line-terminator classification, CRLF kept atomic,\nboundaries preserved formu) anderrors.go/syntax/errors.go(errString, required by the repository err-check gate). Upstream files carry line-policy fields so^/$assertion candidates honor the wide terminator set only when the MatrixOne multiline bit is set.pkg/sql/plan/function/internal/regexpclass: routes each pattern to the pinned Go RE2 copy (internal/regexp) or to regexp2, with native line-policy fields; RE2-eligible patterns keep their existing engine and gain the wide terminator set throughinternal/regexp/lines.go. Anchored-prefix fast paths are preserved.pkg/sql/plan/function/func_builtin_regexp.go+regexp_icu.go: the four SQL functions extendmto the full MySQL terminator set with original character positions and replacement bytes preserved;mustays Unix-only. The engine timeout message stays byte-identical (match timeout after %v on input %v, detected byregexp_icu.go).gofmt -s;.licenserc.ymlexempts exactly the 23 upstream files individually (MIT retained, no Apache text stamped onto upstream sources).docs/design/20261024-30210-regexp-multiline-line-terminators.md(Rev 11, SHA-25688b073910fb37bbc7cb7c5f931239e255116b348bb930a980a6d0d366763ec2d). Design-first review was distinct and complete before implementation review: Rev 1-9 received design-stage REQUEST_CHANGES from the independent local reviewer (each finding verified against primary sources and live ICU 77.1 measurement, addressed per revision in the document change log), and Rev 10 (SHA-2565dcab7b28d863dbec65e003b5db3503fdbc3ee1c1374d4622e9ae737bf3315b4) received the design-stage PASS on 2026-10-25 with no remaining blocking finding. Rev 11 is a status-record-only revision (design content identical to Rev 10 outside the Status paragraph, the new "Design review record" section and the Rev 11 change-log entry) that publishes the approval chain inside the document. Implementation-stage local reviews re-verified the invariant map against the code each round, retained the design PASS, and ended in approval; its two non-blocking P3 findings are addressed at this head (vendored-copy sync procedure + maintained-change inventory ininternal/regexp2/README.md/PROVENANCE, unseen-spelling cache-bound assertions ininternal/regexpclass/review_fixes_round9_test.go).regexp_multiline_test.go,regexp_wide_linesplit_review_test.go, conformance suites against Goregexp/syntax; BVT rows added totest/distributed/cases/operator/regexp_operator.test[.result]andtest/distributed/cases/function/func_regular_like.test[.result]covering all six separators xm/mux all four entry points.Proof (issue -> test)
6fb6531432aaand passes on this tree (same tests, same commands).m,mu} x {LIKE, INSTR, SUBSTR, REPLACE}, verifying exact positions and replacement bytes (m=1 for CR/NEL/LS/PS,mu=0 for them, LF/CRLF behavior unchanged).pkg/sql/plan/functionsuite, regexpclass/regexp/regexp2 suites, and race-detector runs are green; scaling benchmarks on >1 MiB inputs and anchored-prefix patterns show no regression vsmain.golangci-lint run -c .golangci.ymlon the affected closure reports 0 issues;make err-checkpasses; repo-widelicense-eye -c .licenserc.yml header checkreports 0 invalid files.Test commands
go test ./pkg/sql/plan/function -count=1(cgo env) — full function suite incl. the issue harness.go test ./pkg/sql/plan/function/internal/regexp/... ./pkg/sql/plan/function/internal/regexp2/... ./pkg/sql/plan/function/internal/regexpclass/... -count=1.go test -raceon the same closure (race belt) and package-level race runs for regexpclass.golangci-lint run -v -c .golangci.yml <4 packages>with the repositoryCGO_CFLAGS(golangci-lint 2.14.0, go1.27.1): 0 issues.make err-check: passes ("Does not find 'fmt.Errorf()', 'errors.New()','context.WithTimeout' and 'context.WithDeadline'").license-eye -c .licenserc.yml header check: 6877 files, 0 invalid.regexp_operatorandfunc_regular_likecases green; whole-run failures byte-identical to baseline after path normalization.Residual risks / notes
PROVENANCEpins pristine upstream hashes and enumerates every local change class;README.mddocuments the synchronization procedure so a re-vendor cannot silently drop the line-policy fields, assertion changes, or policy corrections.molintinformational observations remain (upstream Debug-onlyfmt.Printfinrunner.go); the tool exits 0 and the Makefile line is non-gating. Kept deliberately to minimize upstream divergence.Rebase notes (2026-10-25)
mainmerged #31079 (perf(regexp): skip terminal any-rune loops at EOF), which restructured the unanchored loop ininternal/regexp/backtrack.go(required-prefix admission beforebitState.reset, prefix re-scan at the loop bottom,markEndTextRepeatsEOF classification) and conflicted with this PR's CRLF-interior start suppression. The conflict was resolved semantically: upstream's loop structure is kept, and this PR's guard (lineMask && crlfBetween(i.context(pos))) now wraps the candidate match attempt inside the restructured loop — the same form as the NFA-path guard inexec.go. The upstream optimization is orthogonal: it classifies onlyInstRuneAny/InstRuneAnyNotNLloops that accept atEmptyEndText, and the wide line modes change line assertions only, never consuming instructions, so both changes compose without interaction.Post-rebase validation on the delivered head
379e87f1e0(base9dcd26be43, includes #31079):go build ./pkg/sql/plan/function/...exit 0;go test -count=1green forinternal/regexp(7.962s, incl. upstream #31079backtrack_test.goand this PR'slines_test.go),internal/regexpclass(4.709s) andinternal/regexp2(2.995s);go test -count=1 -run 'Regexp|REGEXP' ./pkg/sql/plan/function/green (15.940s, incl. upstreamregexp_regular_engine_test.goand this PR's multiline/line-split/review-round suites).