Skip to content

[Bug]: prepared REGEXP rebinding ignores runtime text override and reports incorrect charset mismatch #29465

Closed

Description

@XuPeng-SH

Summary

Prepared REGEXP expression rebinding ignores RuntimeStringText when the parameter's static source type is VARBINARY. Nested consumers can incorrectly fail with MySQL error 3995, even though the parameter executor and vector interpret the same value as text.

Discovered during the systematic review of #29462 (original performance issue #29429). This is a separate inherited correctness issue; the affected ResetParamRefRule.preparedExecutionParamType logic predates this review's source-binding prototype.

Reproduction evidence

A deterministic planner regression was added locally in pkg/sql/plan/prepared_binding_test.go, TestPreparedRegexpRuntimeTextOverride:

  1. Build PREPARE domain_override FROM 'select regexp_substr(left(?, 1), ''a'')' using the normal prepared planner.
  2. Call the existing FillValuesOfParamsInPlanWithSpecialization with a ParamValue containing Value: "abc", SourceType: VARBINARY, HasSourceType: true, and RuntimeStringDomain: RuntimeStringText.
  3. Actual: Character set 'binary' cannot be used in conjunction with 'utf8mb4_general_ci' in call to regexp_substr.
  4. Expected: bind successfully; the parameter vector's explicit text override takes precedence over the static string family, so the nested LEFT result is text.

The regression failed before the shared domain resolver extraction on the PR review worktree. This evidence is at the planner API boundary; an end-to-end SQL client reproduction has not yet been validated.

Root cause

ParamExpressionExecutor.Eval propagates the parameter vector's runtime string domain. Vector.GetIsBinaryStringAt gives an explicit text override precedence over static VARBINARY. In contrast, preparedExecutionParamType selects VARBINARY from SourceType/IsBinaryString without honoring that override. The nested REGEXP compatibility check consequently sees a different domain from execution.

Fix / validation plan

Use the same metadata-only domain resolver in the existing rebind path and the new source-binding path, honoring explicit runtime overrides before static string-family fallbacks. Preserve the distinction between direct markers, nested expression results, NULL markers, and untyped NULL literals. Add tests for both override directions, derived columns, and fixed binary/text peers.

Related PR: #29462. Fix and complete integration validation are in progress; this issue is not yet claimed resolved.

Activity

  1. self-assigned this
    on Sep 29, 2026
  2. added a commit that references this issue on Sep 29, 2026
    a36da7f
  3. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:干净源码 worktree;定向 Go UT/集成回归(涉及 Proxy/CN 的路径使用对应组件级并发与协议模拟)
    • 测试日期:2026-10-02

    原问题验证

    在上述 commit 运行 issue 对应的定向回归。prepared REGEXP 在 runtime text override 后使用实际 text domain;合法重绑不再误报 charset mismatch。

    Happy Path 覆盖

    覆盖文本/二进制 source、nested/derived expression 和重复执行。

    Unhappy Path 覆盖

    覆盖 binary charset mismatch、typed/bare NULL 与 domain 切换;只有真实不兼容输入报错。

    白盒验证

    关联修复 #29462 已进入当前 main。直接执行并检查的定向测试为:pkg/sql/plan/prepared_binding_test.go::TestPreparedRegexpRuntimeTextOverride 及 regexp execute-rebind tests。

    回归测试

    本问题依赖内部故障注入、并发时序、catalog/optimizer 状态或多组件协议边界,无法由普通 SQL golden 稳定构造,因此不放入 MOTR;回归保留在 MatrixOne UT/BVT 层。对应定向测试在精确 commit 上通过,且未修改用户工作区。

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 定向测试:pkg/sql/plan/prepared_binding_test.go::TestPreparedRegexpRuntimeTextOverride 及 regexp execute-rebind tests
    • 当前结果:prepared REGEXP 在 runtime text override 后使用实际 text domain;合法重绑不再误报 charset mismatch。
    • 关联 PR:#29462

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions