Skip to content

fix: support diagnostic count compatibility - #28738

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28682-diagnostic-count
Sep 12, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28682-diagnostic-count

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 11, 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:

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 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.

@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 →

@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Sep 11, 2026
@XuPeng-SH
XuPeng-SH force-pushed the codex/issue-28682-diagnostic-count branch from f8a5969 to 74b90e4 Compare September 11, 2026 15:19

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@XuPeng-SH
XuPeng-SH merged commit 931ae21 into matrixorigin:main Sep 12, 2026
29 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-28682-diagnostic-count branch September 12, 2026 04:38

@iamlinjunhong iamlinjunhong 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.

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.

VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.

This branch was previously deployed

1 inactive deployment
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.

[Compatibility]: SHOW COUNT(*) diagnostics and @@warning_count/@@error_count are unsupported

3 participants