Skip to content

fix(sql): report explicit cast overflow warnings - #30297

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/cast-overflow-warnings-30265-30271
Oct 16, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/cast-overflow-warnings-30265-30271

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 15, 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:

What this PR does / why we need it:

Explicit CAST already clamps DECIMAL overflow and wraps/clamps string integer overflow, but silently discards the conversion diagnostics. Preserve these values and report warning 1264 for decimal clamping, 1105 for signed/unsigned complements, and 1292 for integer range truncation through the existing statement warning sink.

Propagate range status from the existing parsers to execution without reparsing. Numeric DECIMAL casts now honor the selection mask before conversion and warning publication. Existing warning probes retain warning-producing constant casts for execution; pure value helpers and numeric prepared-parameter semantics remain intact.

Earlier author validation on macOS arm64 (before the runtime-folding follow-up):

  • Owning function and rule package unit tests passed; targeted warning, selection/NULL, boundary and constant-folding regressions passed.
  • Incremental go vet, golangci-lint (0 issues), formatting and service build passed.
  • Full function/func_cast.test: 317/317 passed twice on one isolated standalone instance, with teardown checked between runs. Covers strict/non-strict modes, literal and column casts, warning retention/count, and SQL PREPARE reuse.
  • Nine MySQL protocol server-prepared executions passed exact value, warning-code/count and fresh-diagnostic checks.

Runtime execution also retains explicit DECIMAL casts as row-scoped conversions. Numeric literals and integer parameters transported as TEXT must not enter the folded-value cache or a statement diagnostic owner, so every evaluated row reports its range warning across batches and executor reuse. Silent implicit casts retain their folding path.

Validation on macOS arm64 (runtime-folding follow-up):

  • Owning colexec, function, rule and planner package tests passed.
  • Executor regressions passed for numeric source families, all DECIMAL widths, integer TEXT transport, selection masks, NULL, multiple batches, reset and filter/join diagnostic ownership.
  • A real one-CN MySQL protocol regression passed multirow numeric/string literal casts and six executions of one binary prepared statement, including NULL, safe-value and overflow recovery controls.
  • Formatting, incremental go vet and golangci-lint passed with 0 issues.

Scope: warning 1264 uses the existing function-layer target label decimal and local row ordinal. Existing interval constant-normalization shortcuts and lexical negative-zero diagnostics are unchanged. Existing unsigned negative-overflow modulo values are preserved; the warning is classified from the original magnitude. No new persistent state or native dependencies; no extra parsing is added solely for diagnostics.

Please leave both issues open for reporter verification after merge. CI results are pending.

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

@mergify mergify Bot added the kind/bug Something isn't working label Oct 15, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Oct 15, 2026
@iamlinjunhong
iamlinjunhong force-pushed the fix/cast-overflow-warnings-30265-30271 branch from 66c2eac to d94c2ad Compare October 15, 2026 17:58
@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: d94c2ad7a72f319f3b6f9568e4d91cb87901a466

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: d94c2ad7a72f319f3b6f9568e4d91cb87901a466

Assessment: request_changes

Reviewed the complete six-file delta. Reusing conversion status and the existing warning sink is sound, but runtime constant folding still suppresses numeric DECIMAL overflow warnings.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P2 pkg/sql/plan/function/func_cast.go:181: Evaluate SELECT CAST(1000 AS DECIMAL(5,2)) FROM t across multiple selected rows or batches.
    Impact: The runtime executor folds the numeric cast once and caches its value, emitting only one warning instead of one per evaluated row. Subsequent batches emit none, underreporting SHOW WARNINGS and @@warning_count.
    Evidence: The SQL-planner/executor probe TestReviewCastRangeRows produced one warning for two selected rows and still one after another three rows. The equivalent string-cast control produced two, then five. Runtime folding protection in evalExpression.go only recognizes string-to-numeric casts; finishFolding caches this newly warning-producing numeric cast. Extend that protection and add an executor-level regression. Reproduction: attempt-1/integration-probes.log and checks/1792093610906286491-2.json (exit 1), under /home/xupeng/.local/state/mo-bot/jobs/0079365f5ddb91dbe55c3805.

Validation:

  • Function and rule package suites passed with -count=1 and the supplied test executor; owning-tests.jsonl matches receipt checks/1792093454742119298-2.json (exit 0).

  • Both changed prepared-planner tests and six independent prepared integer/string controls passed. The numeric-row counterexample failed while its string control passed.

  • Preflight passed. Verified 192 native inputs and 62 artifacts, then ran the current Makefile build owner. evidence-audit.json reconciles commands, source fingerprints, exits and retained logs; the source checkout remains clean.

  • The frozen evidence records successful UT, SCA, shared-build and BVT jobs. Warning classification was also checked against the MySQL conversion implementation.

Limitations:

  • The counterexample exercises SQL planning and the production expression executor, not a running protocol server. Author-reported BVT and protocol runs have no retained local artifacts in the supplied evidence.

  • No performance benchmark was run. Source review found no additional parsing or I/O on ordinary paths; warning rows add formatting and sink calls.

  • Linked issue bodies were not supplied; their stated contracts were assessed through the frozen PR description and source.

@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a9e8d97c24fe31eb2ef15c8627ca5abb914e9b26

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: a9e8d97c24fe31eb2ef15c8627ca5abb914e9b26

Assessment: approve

Reviewed the complete 17-file delta and supplied review history. No actionable findings remain. Conversion status and the existing warning sink preserve row-level diagnostics without reparsing. Silent DECIMAL256 constants reuse the existing scalar-vector representation, preserving temporal statement ownership and prepared-plan correctness. All three historical warning-count regressions are closed.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Isolation preflight passed. Built native prerequisites through the repository Makefile from 192 verified current-revision inputs; source remained unchanged.

  • Full function, rule, plan and colexec suites passed with -count=1 and -vet=all: 6,060 passing test roots. Seven unrelated ONNX tests were skipped.

  • TestPreparedNumericTemporalContracts passed through a real one-CN MySQL frontend, including masks, NULLs, prepared reuse, temporal ownership and empty/inactive controls. Independent probes passed for scalar-vector consumers, numeric parameter semantics and 18 binary prepared temporal-join executions.

  • Matched base/head runtime benchmarks over 8,192 safe prepared rows measured explicit casts at 9.855 ns cached versus 319.285 μs and 26,281 bytes per evaluation. The implicit control remained approximately 9 ns. This quantifies the intentional cost of retaining per-row evaluation.

  • Commands, source fingerprints, exits, overlays and retained logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/ed0d2e6a4a2401fe1622e464/attempt-1/evidence-audit.json. Final audit receipt checks/1792171644380752314-4.json exited 0.

Limitations:

  • Linked issue bodies were absent; their declared contracts were assessed through the frozen PR description, comments and regression sources.

  • No independent multi-CN, historical-version or mo-tester replay was performed. The supplied CI snapshot reports successful enabled BVT jobs without raw case logs.

  • Performance measurements cover expression execution, not end-to-end SQL throughput or concurrency. No live MySQL differential run was performed.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 17:28 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-10-16 18:20 UTC · at 728780bacfad85ddf1db69f36879af62d7ebab5d

This pull request spent 52 minutes 13 seconds in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 21:37 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-10-16 22:57 UTC · at 1b654c753bf02afa3b0d13708a0df48a99c7d4b0

This pull request spent 1 hour 19 minutes 56 seconds in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 1b654c75 Deployed Oct 16, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants