Repository navigation
fix: support diagnostic count compatibility - #28738
Conversation
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? |
f8a5969 to
74b90e4
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed current head 74b90e4 against main d191706. COMMENT only for this self-authored PR.
[P2] Preserve the preceding diagnostic counts for expressions, not only a syntactically pure count-variable SELECT (pkg/frontend/mysql_cmd_executor.go:isDiagnosticCountSelect/resetDiagnosticsForStatement).
Counterexample: create a primary-key table containing (1); run INSERT IGNORE INTO t VALUES (1); SELECT @@warning_count + 1;. The preceding warning count is 1, so MySQL returns 2. This PR deliberately classifies the SELECT as nondiagnostic and resets the sole counter before its variable getter runs, returning 1 instead. Likewise SELECT @@warning_count LIMIT 1 or SELECT @@warning_count FROM dual loses the preceding count. The added classification UT explicitly encodes these exclusions, so it does not catch the compatibility failure.
MySQL applies DA_KEEP_COUNTS when the diagnostic variable is itemized anywhere in the statement, snapshots the old counts, and clears the active area independently: https://github.com/mysql/mysql-server/blob/8.4/sql/parse_tree_items.cc#L607-L628 and https://github.com/mysql/mysql-server/blob/8.4/sql/sql_error.cc#L491-L533. Please introduce a statement-owned preceding-count snapshot for these variable reads, while resetting the active diagnostics before execution, rather than broadening a deferred-clear whitelist (which would erase conditions produced by the new statement). Cover expression/LIMIT forms and preservation of newly generated diagnostics, including prepared execution.
Reviewed the parser/AST/generated action changes, independent saturating totals versus bounded retained messages, read-only session-variable registration, SHOW filtering before LIMIT, effective prepared statement classification, and reset/reuse paths. No additional concrete blocker identified. Ordinary compatibility-fix design scope; no new persistent/wire format. Evidence: source-derived counterexample and upstream implementation comparison; reused the reported focused parser/frontend tests and SQL probe, but did not independently execute SQL/native suites or wait for CI.
74b90e4 to
95a5eb7
Compare
95a5eb7 to
d2cda14
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed e941343 against main e2580f9. COMMENT only for this self-authored PR. No remaining concrete blocker found; the previous P2 is closed.
The AST allowlist/deferred-reset approach is gone. Each top-level statement captures the preceding scalar totals before normal diagnostics reset; ResolveVariable reads that snapshot for session diagnostic variables, independent of expression shape. Thus a preceding duplicate warning followed by SELECT @@warning_count + 1 yields 2, while warnings generated by the SELECT remain in the live area for the next statement. Effective prepared-statement classification, per-generation clearing, request-exit cleanup and ExecCtx.Close prevent carrying a snapshot into a later execution. The focused test explicitly distinguishes old snapshot counts from a newly appended live warning, and the SQL regression covers arithmetic and prepared EXECUTE.
Also reviewed SHOW parser/AST/generated actions, read-only session/global scope checks, independent saturating totals versus bounded retained records, severity filtering before LIMIT, zero/invalid limits and unsigned count metadata. The change adds constant-sized statement state and one bounded session-count read per top-level statement; no per-row diagnostic copy, new worker/wait, persistent format or distributed aggregate-state change. Ordinary compatibility-fix design scope.
Evidence: full source/change-map review and prior-finding closure, with reported focused frontend and race results reused where applicable. The distributed regression is present, but I did not independently execute SQL/native suites or infer execution success from its expected-output file. No CI wait.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed current head e941343 against base e2580f9. No P0/P1/P2/P3 findings. The statement-owned diagnostic snapshot is captured before the normal reset and resolved at execution time for session warning_count/error_count, including expression, LIMIT, and prepared-execution paths; SHOW filtering and bounded diagnostic retention remain separate from total counts. Local targeted tests were blocked by missing MatrixOne CGo prerequisites (libmo.dylib and roaring/xxhash/usearch/jemalloc headers); this approval is based on the complete static diff/call-chain review and the CI gate already verified by the watcher.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28682 ## What this PR does / why we need it: Adds MySQL-compatible `SHOW COUNT(*) WARNINGS`, `SHOW COUNT(*) ERRORS`, `@@warning_count`, and `@@error_count`. Diagnostic totals are independent from the bounded records retained by `SHOW WARNINGS` and `SHOW ERRORS`; `LIMIT` is applied after severity filtering. Diagnostic variables use a per-statement scalar snapshot, so expressions and prepared `EXECUTE` read the preceding statement's counts while diagnostics generated by the current statement remain available to the next statement. The AST-shape allowlist and delayed full reset were removed, with parser, frontend, and distributed regression coverage added. ## Validation - Rebased onto `origin/main` at `efb2c5084957ac90273a3f625668fc6a784562c4`. - Focused frontend tests passed with `mo-cgo-test`. - Focused frontend diagnostic tests passed with `-race`. - Incremental `golangci-lint --new-from-rev=origin/main` passed with 0 issues. - Distributed diagnostic-count BVT is included in `test/distributed/cases/dml/issue_28682_diagnostic_count.{test,result}`. - `git diff --check` passed. - GPT-6 medium final review passed: `MO-ISSUE-TO-PR-FINAL-REVIEW-G6M-20260912-28738-46-47-r2`. The historical Multi-CN BVT/coverage failures were Docker registry reset and missing coverage-producer infrastructure failures; they did not execute the changed test path and are unrelated to this implementation.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28682 ## What this PR does / why we need it: Adds MySQL-compatible `SHOW COUNT(*) WARNINGS`, `SHOW COUNT(*) ERRORS`, `@@warning_count`, and `@@error_count`. Diagnostic totals are independent from the bounded records retained by `SHOW WARNINGS` and `SHOW ERRORS`; `LIMIT` is applied after severity filtering. Diagnostic variables use a per-statement scalar snapshot, so expressions and prepared `EXECUTE` read the preceding statement's counts while diagnostics generated by the current statement remain available to the next statement. The AST-shape allowlist and delayed full reset were removed, with parser, frontend, and distributed regression coverage added. ## Validation - Rebased onto `origin/main` at `efb2c5084957ac90273a3f625668fc6a784562c4`. - Focused frontend tests passed with `mo-cgo-test`. - Focused frontend diagnostic tests passed with `-race`. - Incremental `golangci-lint --new-from-rev=origin/main` passed with 0 issues. - Distributed diagnostic-count BVT is included in `test/distributed/cases/dml/issue_28682_diagnostic_count.{test,result}`. - `git diff --check` passed. - GPT-6 medium final review passed: `MO-ISSUE-TO-PR-FINAL-REVIEW-G6M-20260912-28738-46-47-r2`. The historical Multi-CN BVT/coverage failures were Docker registry reset and missing coverage-producer infrastructure failures; they did not execute the changed test path and are unrelated to this implementation.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28682 ## What this PR does / why we need it: Adds MySQL-compatible `SHOW COUNT(*) WARNINGS`, `SHOW COUNT(*) ERRORS`, `@@warning_count`, and `@@error_count`. Diagnostic totals are independent from the bounded records retained by `SHOW WARNINGS` and `SHOW ERRORS`; `LIMIT` is applied after severity filtering. Diagnostic variables use a per-statement scalar snapshot, so expressions and prepared `EXECUTE` read the preceding statement's counts while diagnostics generated by the current statement remain available to the next statement. The AST-shape allowlist and delayed full reset were removed, with parser, frontend, and distributed regression coverage added. ## Validation - Rebased onto `origin/main` at `efb2c5084957ac90273a3f625668fc6a784562c4`. - Focused frontend tests passed with `mo-cgo-test`. - Focused frontend diagnostic tests passed with `-race`. - Incremental `golangci-lint --new-from-rev=origin/main` passed with 0 issues. - Distributed diagnostic-count BVT is included in `test/distributed/cases/dml/issue_28682_diagnostic_count.{test,result}`. - `git diff --check` passed. - GPT-6 medium final review passed: `MO-ISSUE-TO-PR-FINAL-REVIEW-G6M-20260912-28738-46-47-r2`. The historical Multi-CN BVT/coverage failures were Docker registry reset and missing coverage-producer infrastructure failures; they did not execute the changed test path and are unrelated to this implementation.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28682
What this PR does / why we need it:
Adds MySQL-compatible
SHOW COUNT(*) WARNINGS,SHOW COUNT(*) ERRORS,@@warning_count, and@@error_count.Diagnostic totals are independent from the bounded records retained by
SHOW WARNINGSandSHOW ERRORS;LIMITis applied after severity filtering.Diagnostic variables use a per-statement scalar snapshot, so expressions and
prepared
EXECUTEread the preceding statement's counts while diagnosticsgenerated by the current statement remain available to the next statement.
The AST-shape allowlist and delayed full reset were removed, with parser,
frontend, and distributed regression coverage added.
Validation
origin/mainatefb2c5084957ac90273a3f625668fc6a784562c4.mo-cgo-test.-race.golangci-lint --new-from-rev=origin/mainpassed with 0 issues.test/distributed/cases/dml/issue_28682_diagnostic_count.{test,result}.git diff --checkpassed.MO-ISSUE-TO-PR-FINAL-REVIEW-G6M-20260912-28738-46-47-r2.The historical Multi-CN BVT/coverage failures were Docker registry reset and
missing coverage-producer infrastructure failures; they did not execute the
changed test path and are unrelated to this implementation.