Skip to content

fix: implement STATEMENT_DIGEST_TEXT - #27990

Closed
Lundomn wants to merge 27 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-23025-statement-digest-text
Closed

Lundomn wants to merge 27 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-23025-statement-digest-text

Conversation

@Lundomn

@Lundomn Lundomn commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

issue #23025

What this PR does / why we need it:

Summary

  • implement MySQL-compatible STATEMENT_DIGEST_TEXT
  • cover constants, lists, NULL, charset introducers, SQL modes, max_digest_length, and prepared/text protocol paths
  • add parser, function, error, differential, and distributed regression coverage

Previously reported validation

The inherited summary does not identify its tested commit. Retain it as historical evidence, rather than a PASS for the current remote head 1a9ade8f4d114f7982dd8cd11efd1a2c36e89e92. Canonical regression files are test/distributed/cases/function/func_statement_digest_text.sql and .result; current-head execution and review closure remain to be established.

  • parser/function/moerr tests
  • focused race and go vet
  • 187-case MySQL 8.0.42 differential: 0 mismatches
  • text and COM_STMT protocol E2E

Known environment limitations are documented in the task report: native make build requires unavailable cmake; lint target/tools and Java-based mo-tester are unavailable.

QA Decision

QA required: yes — public digest normalization and diagnostic disclosure depend on SQL mode, argument provenance and execution-setting transport. Verify the MySQL oracle matrix, charset/binary input, delimiters, truncation, prepared reuse and distributed settings on the delivered revision. The inherited summary above has no tested-SHA binding and cannot establish current-head acceptance.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head 159121e8370fd9ae11c022a650d8729dd41d04f1 against the implementation contract and MySQL 8.0.42's own source/tests. The parser/token work has useful differential coverage, but three reachable blockers remain:

  1. [P1 semantic persistence] The function is registered as deterministic/foldable although its result depends on runtime variables. Every overload leaves both volatile and realTimeRelated false, while StatementDigestText reads session sql_mode and global max_digest_length. MatrixOne can therefore constant-fold a literal call and, more seriously, checkExprForVolatileFunc permits it in generated columns. A stored generated value can then depend on mutable session/global state, contrary to MatrixOne's generated-column invariant and MySQL's explicit rejection of statement_digest_text in generated columns. Give the overload the correct non-foldable/runtime-related properties and cover generated-column rejection plus PREPARE/EXECUTE across a settings change.

  2. [P1 compatibility] Binary inputs are accepted even though MySQL rejects the binary character set. statementDigestTextFunction explicitly registers BINARY, VARBINARY, and BLOB, and the unit test requires them to succeed. MySQL 8.0.42's implementation calls is_supported_parser_charset and its official func_digest_errors.inc expects an undisclosed parse/function error for binary/geometry input; current MySQL additionally checks cs == my_charset_bin explicitly. Valid UTF-8 bytes in a blob currently return a digest in MO instead of the required error. Enforce the charset contract and test both valid-looking and arbitrary binary payloads.

  3. [P1 error confidentiality/compatibility] Vector.IsConst() is not MySQL's “literal” test. MySQL uses Item::basic_const_item(): only a literal may expose parser details; any expression, even one that folds to a constant vector, must use ER_UNDISCLOSED_PARSE_ERROR_IN_DIGEST_FN. This implementation will disclose for folded constant expressions because discloseParseError is based on vector shape. The official suite specifically expects statement_digest_text(statement_digest_text('SELECT 1, 2, 3')) to fail undisclosed. Preserve literal-vs-expression metadata from binding/planning instead of inferring it at vector execution, and add constant-expression/nested-function/subquery regressions.

Primary references:

  • MySQL 8.0.42 sql/item_strfunc.cc, Parse_error_anonymizer and Item_func_statement_digest_text
  • MySQL 8.0.42 mysql-test/include/func_digest_errors.inc
  • MySQL generated-column negative test for statement_digest_text

The 187-case output differential does not exercise these type, planner-property, and expression-origin contracts, so green normalization cases do not close them.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head 159121e8370fd9ae11c022a650d8729dd41d04f1, including the full diff, planner integration, parser behavior, and an independent differential run against MySQL 8.0.42. The existing focused unit and race tests pass, but targeted counterexamples expose four blocking compatibility/correctness gaps: generated-column/constant-fold semantics, error-detail disclosure after folding, missing canonical token aliases, and ANSI_QUOTES user-variable handling. I reproduced the generated-column acceptance with a temporary planner test and reproduced the output cases against MySQL 8.0.42; the temporary test and database container were removed afterward.

}
overloads := make([]overload, 0, len(stringTypes))
for i, typ := range stringTypes {
overloads = append(overloads, overload{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Register this function as non-deterministic/runtime-dependent. StatementDigestText reads session sql_mode and max_digest_length, but these overloads currently report both CannotFold() == false and IsRealTimeRelated() == false. On this exact head, a temporary planner regression for CREATE TABLE t (s TEXT, g TEXT GENERATED ALWAYS AS (statement_digest_text(s)) STORED) failed because buildGeneratedExpr returned no error; MySQL 8.0.42 rejects the same expression with ER 3763. MatrixOne materializes generated columns, so changing sql_mode or the digest-length setting can persist different g values for identical s, and a literal call can also be frozen at PREPARE time. Set the appropriate function properties and cover generated-column rejection plus PREPARE/EXECUTE across a setting change.

}
sqlMode := statementDigestSQLMode(proc)
maxDigestLength := statementDigestMaxLength(proc)
discloseParseError := parameters[0].IsConst() &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Vector.IsConst() describes the post-optimization vector shape, not whether the SQL argument was a literal. For example, MySQL 8.0.42 returns the generic ER 3677 for STATEMENT_DIGEST_TEXT(CONCAT('SELECT ', '?')), because an expression is not allowed to disclose parser details. MatrixOne's constant-fold rule first replaces CONCAT(...) with a constant vector; when digest evaluation fails, this condition then selects ER 3676 and exposes the underlying parser message. Preserve literal-vs-expression origin metadata through planning/execution and add folded-expression and nested-function regressions.

return "FIELDS"
case DISTINCT:
return "DISTINCTROW"
case CURRENT_TIMESTAMP, LOCALTIME, LOCALTIMESTAMP:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] The canonical alias table is incomplete, so valid statements produce a digest text different from MySQL. For SELECT CURRENT_DATE, CURRENT_TIME, SESSION_USER(), USER(), STD(a), VARIANCE(a) FROM t, MySQL 8.0.42 emits CURDATE, CURTIME, SYSTEM_USER, SYSTEM_USER, STDDEV_POP, and VAR_POP; this implementation leaves the original names (and treats several as quoted identifiers). Since STATEMENT_DIGEST() hashes this normalized text, semantically equivalent spellings split into different digest groups and MatrixOne cannot match MySQL monitoring output. Add the MySQL canonical mappings and differential cases for these aliases.

}
if typ == '@' && scanner.Pos < len(sql) {
quote := sql[scanner.Pos]
quotedUserVar := strings.TrimSpace(rawSource) == "@" && (quote == '\'' || quote == '"')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This treats a double quote after @ as a string delimiter even when ANSI_QUOTES makes it an identifier delimiter. With sql_mode=ANSI_QUOTES, STATEMENT_DIGEST_TEXT('SELECT @"odd name", "col" FROM t') replaces the user variable with @? here, while MySQL 8.0.42 preserves it as a quoted identifier (@ followed by odd name in backticks). Distinct quoted user variables are therefore collapsed into the same digest and the advertised MySQL-compatible text is wrong. Make this branch mode-aware and add the ANSI_QUOTES counterexample.

@Lundomn

Lundomn commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

请求一位独立 maintainer/reviewer 审阅设计文档 v6 与当前 head 0bd294d,重点确认解析准入、错误披露、分布式设置生命周期和 v58 兼容/灰度策略。审批后我会把 reviewer、审阅 commit 和审批链接记录到设计文档第 12 节。

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why this and #27988 is not one PR?

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT-6 medium deep review at exact head 4bb0db4.\n\nP1 — Required independent design approval remains missing. docs/design/statement_digest_text.md:533 identifies revision v9 as proposed and leaves the independent reviewer and reviewed commit pending; the companion RFC also leaves approval pending. This feature adds public SQL functions, diagnostic-disclosure rules, statement-setting transport, and a MORPC capability boundary, so the mandatory design-first gate blocks implementation approval.\n\nPlease record independent approval of the exact design revision, reviewed commit, and approval link. Existing implementation approvals do not approve the consolidated v9 design.\n\nExact-head CI reports successful Ubuntu UT, shared build, SCA, coverage, and multi-CN BVT jobs; upgrade checks are skipped. This review is design-gated and did not proceed to full implementation closure.

This branch was previously deployed

1 inactive deployment
ci — 33c23275 Deployed Oct 19, 2026 by Lundomn
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.

9 participants