Skip to content

fix(function): reject binary regexp operands and add match type overloads - #26724

Draft
ck89119 wants to merge 17 commits into
matrixorigin:mainfrom
ck89119:issue-25299-main
Draft

fix(function): reject binary regexp operands and add match type overloads#26724
ck89119 wants to merge 17 commits into
matrixorigin:mainfrom
ck89119:issue-25299-main

Conversation

@ck89119

@ck89119 ck89119 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25299

What this PR does / why we need it:

MySQL rejects statically typed binary-character-set operands used by REGEXP, NOT REGEXP, and the REGEXP_* functions with error 3995 (HY000). MatrixOne previously let the generic fixed-type matcher cast BINARY, VARBINARY, and BLOB operands to VARCHAR before regexp validation, so these expressions executed instead of failing.

This change:

  • validates static binary string operands after overload resolution but before implicit regexp casts;
  • shares the validation across the regexp operators and REGEXP_LIKE, REGEXP_INSTR, REGEXP_SUBSTR, and REGEXP_REPLACE;
  • returns MySQL-compatible error 3995 / SQLSTATE HY000, including the correct function name and operand order;
  • follows MySQL's PARAM_ITEM and NULL_ITEM exceptions, so SQL/binary-protocol prepared parameters, binary NULL, and explicit character casts remain valid;
  • keeps prepared execution on the existing reusable-plan path without a regexp-specific plan scan or extra deep copy;
  • adds the missing match_type overloads for REGEXP_INSTR, REGEXP_SUBSTR, and REGEXP_REPLACE, including c, i, m, n, and u behavior;
  • aligns optional-argument edge behavior with MySQL for UTF-8 character positions, newline modes, empty patterns, position/occurrence boundaries, return_option, and replacement capture expansion;
  • covers binary literals, expressions, columns, prepared parameters, NULL/empty/invalid-byte cases, and normal text controls.

An explicit empty match_type preserves MatrixOne's existing case-sensitive default. Matching MySQL's collation-derived default would require propagating collation metadata into the function executor and is outside this change.

Validation:

  • make build
  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/common/moerr ./pkg/sql/plan/function ./pkg/sql/plan ./pkg/frontend -count=1
  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/tests/issues -run '^TestIssue25299RegexpRejectsBinaryCharset$' -count=1 -timeout 5m
  • targeted distributed BVT: 114/114 passed
  • git diff --check
  • mo-self-review on the complete diff

@ck89119 ck89119 changed the title fix(plan): reject binary regexp operands fix(function): reject binary regexp operands and add match type overloads Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants