Skip to content

[Bug]: Functional indexes reject deterministic expressions outside the supported whitelist #31448

Closed

Description

@Ariznawlll

Description

MatrixOne's functional index feature only accepts a narrow, undocumented whitelist of functions — and the acceptance boundary is bizarre: LOWER(col) is accepted while UPPER(col) is rejected with:

ERROR 20105 (HY000): not supported: functional index expression must have session-independent semantics

UPPER is exactly as "session-independent" as LOWER. Probed matrix (all on CREATE INDEX ... ((f(col))) over otherwise-indexable VARCHAR columns):

expression accepted?
LOWER(email) ✓
UPPER(payload) ✗ "session-independent semantics"
SUBSTRING(name,1,10) ✗
LEFT(name,10) (via LEFT) ✗
MD5(email) ✗
CRC32(payload) ✗
HEX(email) ✗
REVERSE(payload) ✗
LENGTH(payload) ✗
CONCAT(email,'.io') ✗

MySQL 8.0.13+ accepts any deterministic expression in a functional index (all of the above work, including cross-column expressions). #28053 (closed) covered the JSON-expression variant of this gap; this report covers the ordinary scalar-function whitelist, including the LOWER-yes/UPPER-no asymmetry that cannot be explained by any determinism rule.

Two extra problems:

  1. The error message is misleading — none of the rejected functions are session-dependent (no NOW/CURDATE/USER involved). The real reason is an internal whitelist, but the message blames determinism.
  2. There appears to be no documentation of which expressions are supported.

Reproduction

CREATE TABLE fimark (id INT PRIMARY KEY, email VARCHAR(50), payload VARCHAR(200));
CREATE INDEX ok  ON fimark ((LOWER(email)));     -- works
CREATE INDEX bad ON fimark ((UPPER(payload)));  -- ERROR 20105 session-independent semantics
-- same for MD5/CRC32/HEX/REVERSE/LENGTH/CONCAT/SUBSTRING/LEFT

Impact

  • Migration blockers: schemas using MySQL functional indexes over hashing (MD5 lookups), case-folding (UPPER), or substring keys fail to import with a confusing error.
  • The LOWER/UPPER asymmetry means the "supported" set is effectively undiscoverable without trial-and-error.
  • Hot-path lookups like WHERE MD5(email) = ? or WHERE UPPER(name) = ? degrade to full scans.

Expected behavior

Accept any deterministic, session-independent scalar expression matching MySQL's functional index semantics; at minimum, align the whitelist with MySQL 8.0's allowed set and document it, and fix the error message to state the actual limitation.

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. XuPeng-SH commented on Nov 9, 2026

    @XuPeng-SH
    Contributor

    Consolidating #32313 here as another deterministic expression rejected by the same functional-index eligibility gate. At main commit c668, functionalExpressionEligible is the shared DDL check; CAST(JSON_EXTRACT(j, ... ) AS INT) is outside the whitelist and returns the same “session-independent semantics” error. Preserve this JSON case alongside still-rejected scalar expressions such as MD5/CONCAT. The code at c668 already admits UPPER, so the canonical title has been broadened to describe the remaining whitelist gap. Keep generated-column predicate matching (#32113) and unique functional-index enforcement (#31442) separate.

  5. changed the title [-][Bug]: Functional index whitelist rejects UPPER/MD5/CONCAT (LOWER works)[/-] [+][Bug]: Functional indexes reject deterministic expressions outside the supported whitelist[/+] on Nov 9, 2026
  6. gouhongshen commented on Nov 9, 2026

    @gouhongshen
    Contributor

    Existing-fix audit

    Assessment: partially fixed

    Fixed evidence

    PR #29472, commit c2c1031, adds functional-index support with both lower and upper in functionalExpressionEligible. pkg/sql/plan/functional_index_test.go:TestFunctionalIndexOwnershipAfterDropColumn builds an index containing UPPER(name). The same commit supplies docs/design/20260929-functional-index-initial-support.md, which explicitly lists the supported expression boundary. Both code and documentation remain in origin/main@bf086489bae357159b53f8bcdfc04082ca55b210.

    Remaining problems

    1. Ordinary scalar functional indexes still reject SUBSTRING, LEFT, MD5, CRC32, HEX, REVERSE, LENGTH, and CONCAT over otherwise eligible columns; investigate safe admission with focused DDL and index-versus-scan proof.
    2. The consolidated expression CAST(JSON_EXTRACT(j, constant_path) AS INT) remains rejected by the eligibility gate; preserve it as a separate numeric JSON functional-index case.
    3. Unsupported deterministic expressions still receive 'functional index expression must have session-independent semantics'; distinguish unsupported expression coverage from actual session dependence and document the resulting supported boundary.
  7. gouhongshen commented on Nov 9, 2026

    @gouhongshen
    Contributor

    Split follow-up for the un-fixed portion: #32437.

  8. XuPeng-SH commented on Nov 12, 2026

    @XuPeng-SH
    Contributor

    QA 交接补漏:本单旧“部分修复”记录的三个剩余项已全部拆入 #32437,由 #32510 合入 main,merge SHA 7376adec177d075d4469ad3442cb704d2650d492。本轮重读原单全部 3 条评论、拆分单全部评论及合并范围;未发现额外未完成开发 follow-up 或当前适用反例。旧部分修复结论不再作为永久阻塞。

    已有证据:#32437 的 QA 评论 #32437 (comment) 报告在官方 main@4760bcaa 双 CN 各 3 轮标准 BVT 每轮 271/271,执行计划 48/48,prepared 数值 JSON 查询各轮 66/66,并已关闭该拆分单。作者另报告最终 plan/tree、sqlintegration、诊断负例与两轮 271/271 BVT。上述均为既有作者/QA 报告,不是本轮重新运行测试。

    请 QA 对原单作最终范围确认:八类 scalar、numeric JSON CAST、诊断三类区分及文档边界,保留 FORCE/IGNORE 对照、NULL/溢出、更新回滚、LIKE/COPY/rename 和 prepared 回归。并非宣称任意确定性函数均获支持:未列入函数仍拒绝,left(name,-1) 保留 residual-only,显式 CAST 不匹配,旧持久化文本不迁移;旧版本升级回放/生产负载未由本轮测试。转交唯一 Ariznawlll,保持 issue 开放,不替代 QA 验收或自动关闭。

  9. Ariznawlll commented on Nov 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试结论

    通过:本单已确认的函数索引扩展、诊断和持久化修复范围,在最新 main 测试通过。 支持范围仍是文档列出的有限集合,不表示支持 MySQL 的全部确定性表达式;例如 SHA1 仍按设计拒绝。

    测试版本与环境

    • 修复:PR #32510,目标 main;设计文档的支持边界。
    • 官方 main b9c06b27b0d7384ca31ce67edd43f764152d56d2;Linux/amd64 隔离环境,两个 CN 的 git_version() 均核对为该 SHA。

    黑盒测试(Happy / Unhappy)

    CI 43204052558 的 14_issue_regression.issue_31448_scalar_indexes 在两个 CN 各执行 3 轮,均 3/3 通过。

    • Happy:UPPER、SUBSTRING、LEFT、REVERSE、MD5、CRC32、HEX、LENGTH、CONCAT 创建函数索引成功;各函数的 FORCE INDEX 和 IGNORE INDEX 查询结果与预期一致。
    • 数据变更:更新索引源列、删除后回滚,强制走索引与忽略索引结果仍一致;包含 NULL 源值。
    • Unhappy:未支持的 SHA1 索引被拒绝且返回预期错误码 20105;随后表仍可查询、数据未变化。

    白盒测试(Happy / Unhappy)

    同一 CI 在相同 SHA 上执行 11 个 planner 根测试,各重复 3 次,全部通过。覆盖函数准入与负例、CHAR 绑定、匹配与残余过滤、字节稳定性、表达式持久化及标识符重写、round-trip 防护、不支持表达式与非确定性函数的诊断优先级。测试包含 RAND / NOW、错误参数和未支持函数等负例。

    回归与范围

    SQL 回归已加入 MOTR PR #329,标记为 main,等待合入;planner 白盒回归由修复 PR 自带。上面的结果仅针对指定测试步骤,不表示整个 CI 作业全绿:作业含独立 #31568 历史 golden 差异,取得目标步骤证据后主动取消了后续步骤。本次未验证生产规模工作负载,也未宣称所有确定性函数均可建索引。

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions