Skip to content

Fix SQL compatibility regressions across aggregates, casts, and prepared DML - #32002

Merged
XuPeng-SH merged 17 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/issues-28562-28485-28230-28119-28024-27340-27332
Nov 22, 2026
Merged

XuPeng-SH merged 17 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/issues-28562-28485-28230-28119-28024-27340-27332

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • API-change
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Closes #28562, #28485, #28230, #28119, #28024, #27340, #27332.

What this PR does / why we need it:

  • Return SQL NULL when a finite DOUBLE input makes DEGREES overflow, and mark the result nullable for CTAS even when its source column is NOT NULL. Preserve CHAR PAD SPACE provenance through COALESCE and IFNULL keys.

  • Widen MEDIAN(DECIMAL(38,s)) to an exact DECIMAL(39,s+1) result and return SUM(INT) as DECIMAL(32,0), including the single-group reuse path.

  • Preserve prepared ENUM/SET parameter markers until the execution binding selects the label or numeric converter.

  • Apply DML assignment bounds and SQL-mode behavior to integer, DECIMAL, BINARY/VARBINARY, and DATE paths. Strict mode rejects invalid writes; non-strict and IGNORE adjust values and emit warnings. Preserve DATE text in strict VALUES assignments and clip rounded DECIMAL-to-integer values with 1264 warnings when adjustment is allowed. Keep safe literal fast paths and unchanged stored DECIMAL projections to preserve DML planning.

  • The CTAS TIMESTAMPADD unit and prepared DATE_ADD/DATE_SUB cases were already fixed on the earlier base; this PR verifies their status alongside the remaining consolidated fixes.

  • Release native test vectors, aggregate executors, and mpools when assertions fail. The merged MEDIAN flush-error fixture uses valid 37-digit inputs so it still exercises result ownership after DECIMAL(38,s) widening.

  • Preserve grouped outer-join domain pruning when bounded integer SUM now returns DECIMAL; keep unsafe bounds rejected. Update spill-recovery and dictionary-pipeline tests for the widened result type after merging upstream/main.

  • Handle signed magnitude overflow, exponent notation, negative unsigned strings, and out-of-range numeric prefixes with trailing text when non-strict or IGNORE integer assignment clamps to target bounds. Detect discarded DATE clock fields before fractional rounding, warn on DECIMAL scale loss for literal and quoted inputs, map precision 39–76 to Arrow Decimal256, and allow nested MEDIAN over Decimal256.

  • Accept Decimal256 values in APPROX_PERCENTILE, including the widened result of grouped MEDIAN(DECIMAL(38,s)) in stored views. Retain the decimal precision and scale and use the existing quantile sketch, rounding rule, and mergeable state format.

  • Include the original VALUES row in integer assignment range warnings, including MEDIUMINT.

Validation of the rebase and follow-up

  • Rebased the seven prior patches and the follow-up onto d88197a97fb. All eight patches match their pre-rebase diffs.
  • On the Linux x86-64 validation host, CGo-linked race passed in the 11 owning packages, along with the focused TestPR32002ReviewBoundaries. Incremental gofmt, diff check, go vet, golangci-lint, and molint passed.
  • MySQL protocol checks returned 2.0 from both a grouped DECIMAL median view and a derived table. An INSERT IGNORE into TINYINT stored 1,127 and reported warning 1264 at row 2. An isolated shutdown upgrade from v4.2.8 preserved the result of a stored percentile view over grouped DECIMAL medians.
  • The exact follow-up passed independent source review.

Earlier validation

  • After merging upstream main at 517e169538, complete CGo-linked tests passed for pkg/sql/plan/function and pkg/sql/plan (26.0s and 70.5s at that revision). The previously failing TestSQLTaskAlterAfterTriggerOnRealStorage passed three consecutive local runs with coverage instrumentation. CGo-configured -vet=all passed for both packages. Focused tests cover CTAS nullability, strict DATE VALUES rejection and valid-date control, and DECIMAL VALUES in strict, non-strict, and IGNORE modes. Direct DECIMAL assignment tests cover signed and unsigned targets, three DECIMAL widths, and rounding boundaries.
  • On the preceding head, complete CGo-linked tests passed for pkg/sql/colexec/aggexec, pkg/sql/colexec/group, and pkg/sql/compile; the focused dictionary-pipeline race regression passed. Earlier local SQL BVT and MySQL binary-protocol checks covered DML modes, aggregate types, CHAR keys, and prepared ENUM/SET.
  • On the preceding head, the CI rerun passed UT, shared build, ARM64 SCA, PROXY and PESSIMISTIC BVT, Python offline checks, Coverage, and CI Required. At that revision, the full function package, SQL service boundary regression, and CGo-configured vet for both affected packages pass. Those regressions check stored values and warnings for non-strict and strict IGNORE integer assignments, strict rejection, and in-range prefix controls.

Mixed VALUES diagnostics follow-up

  • Use the original SQL tuple number when producing assignment warnings in compact literal batches and singleton scalar-subquery branches. This includes prepared execution, dependent subqueries, and REPLACE. Reuse the existing VALUES ordinals and session warning sink, with no RPC schema change.
  • Deregister the Decimal256 percentile test pool after releasing its vectors and executors and checking its allocation count.
  • On host 57, MySQL protocol probes verified warning 1264 row numbers and stored values across branches, including dependent execution. A two-CN SQL regression checked sparse literal slots, prepared reuse, scalar cardinality error with no partial write, and duplicate-key REPLACE. The focused SQL and percentile tests passed under race. Incremental vet and lint passed against the PR merge base.

Integer assignment follow-up

  • Use one checked fast-path conversion for ordinary integer VALUES constants. Out-of-range radix literals go through the existing mode-aware assignment cast, which checks their full magnitude before narrowing. Keep opaque binary values and prepared byte parameters on their existing path.
  • Integer, text, DECIMAL and FLOAT assignment use the declared MEDIUMINT range and emit one range diagnostic for each clipped value. Preserve the original VALUES row number, previously valid quoted radix inputs, and ordinary and explicit casts.
  • Register MEDIAN fixture pool deletion independently of its allocation assertion.
  • Rebased onto e218f94. All nine prior commits are patch-equivalent. The before/after SQL comparison covers radix VALUES and INSERT SELECT, MEDIUMINT storage boundaries, strict rejection and lenient or IGNORE clipping. Additional checks cover parenthesized and wider-than-uint64 literals, BIT and UPDATE IGNORE.
  • Final Darwin arm64 validation passed the complete function race suite, the embedded SQL regression under race, scoped golangci-lint and molint. Eighteen before/after SQL protocol cases matched for prepared MYSQL_TYPE_BLOB and legacy quoted radix inputs.

DECIMAL radix assignment follow-up

  • Apply the existing DECIMAL precision, scale, and SQL-mode checks to hexadecimal and bit literals reaching INSERT SELECT or UPDATE at runtime. Convert the unsigned magnitude before applying the target scale. Reuse the existing assignment parser for all three DECIMAL widths, including unsigned targets.
  • A local two-CN SQL comparison reproduced 0x64 storing 10.0 and 0xffff storing 6553.5 in DECIMAL(4,1) on the previous head. The fixed build stores 100.0 for the first input, rejects the second in strict mode, and stores 999.9 with one warning 1264 in non-strict or IGNORE mode. The regression checks that strict rejection preserves the previously stored row.
  • The full function package passed under race. The embedded SQL regression and scoped static checks passed. All 32 prepared BLOB cases and the explicit CAST control returned identical results and warnings before and after the fix.
  • Rebased onto 03f5d055321e. All ten earlier patches are unchanged by rebase. The follow-up passed independent design and code review.

Vector rebase and radix assignment compatibility

  • Rebased onto 7f6729277e5a. The aggregate and VALUES operators follow upstream MPool and batch selection ownership while preserving Decimal256 MEDIAN and original VALUES warning ordinals.
  • Interpret explicit HEX and BIT literals as numeric magnitudes at DML binding. Existing catalog defaults and generated columns keep their scaled coefficient semantics. The prior Race, Coverage, and PESSIMISTIC failures all saw a BIT default stored as 51.0000 while its declared default was 0.0051.
  • On Linux x86-64, native Race validation covered the owning packages and the focused two-CN SQL regressions. Those tests check omitted and explicit defaults, generated columns, direct INSERT SELECT and VALUES, duplicate-key UPDATE, grouped and windowed SELECT with subtotal NULLs, direct and grouped SAMPLE slots, strict rejection and IGNORE warnings. Incremental static analysis passed for the changed package set.
  • In a clean shutdown and reopen test, old catalog definitions for a default and a stored generated column both produced 0.0051 when a new row was inserted on the rebased binary. The focused BVT passed all 45 statement comparisons with JDBC header comparison disabled. The Go SQL regression independently checked both column-default metadata surfaces.

Derived DECIMAL assignment and conflict-action columns

  • Rebased onto da97e91e194d, which removed the old vector binary flag. Use the upstream argument flag for integer and opaque binary inputs. Preserve DECIMAL coefficient conversion through projected binary CHAR/VARCHAR and pass the unsigned admission result to the outer cast as text.
  • Address the derived DECIMAL review. Use the destination precision before narrowing raw HEX/BIT coefficients in derived tables, CTEs, and explicit DML casts. Preserve the destination-scale interpretation for in-range legacy values and the existing opaque-binary decoder. Strict assignments reject overflow. Non-strict and IGNORE assignments clip and emit one range warning.
  • Keep assignment elision for proven same-type stored columns and for plain DECIMAL cells already checked by the VALUES binder. Preserve the physical slots that a conflict-update join overwrites with its affected-row and physical-change metadata.
  • Linux x86-64 validation on host 57 covered both two-CN MySQL protocol tests, complete plan/function/compile/colexec tests under race, and 16-package incremental gofmt, vet, golangci-lint and molint. The SQL regressions cover the three DECIMAL widths, both signed and unsigned targets, carrier overflow, the legacy default and generated-column controls, and duplicate-update affected rows of 2 then 0 with the untouched DECIMAL value retained.

Set-operation DECIMAL assignment follow-up

A standalone hexadecimal literal can supply its numeric magnitude to a DECIMAL assignment. A SQL set operation instead materializes the column in its resolved string domain. MySQL 8.0.45 rejects the reported binary UNION ALL in strict mode with 1366. IGNORE and non-strict mode store two zeros and report two 1366 warnings.

The shared set-column resolution materializes binary winners as VARBINARY or BLOB and applies implicit text winners. Width is bounded in bytes for binary results. Prepared type refresh uses the same rule. DECIMAL and UNSIGNED checks consume the completed set result, so DISTINCT, ORDER BY and LIMIT retain their own row semantics. Byte strings containing a spelling such as 0x10 follow the decimal text grammar. Direct literals and stored-definition decoding retain their original owners.

The rebase onto 46079446d00d carries all 14 previous patches. The 57 checks matched stored results and diagnostic codes for 19 cases against MySQL 8.0.45, including strict and IGNORE assignments, lexical and range failures, UNSIGNED DECIMAL256, stronger text collation, and atomic ODKU rejection. Seven CTAS domain checks, the CTE and prepared reuse, DISTINCT, LIMIT, and raw-byte controls also passed.

The two new planner and DECIMAL executor regressions passed under race. Incremental static checks for the PR's changed Go packages passed with zero findings. Validation used the new regressions and standalone SQL probes.

Set column metadata and diagnostics

The set planner measures literal byte lengths when it materializes a binary column. The shared literal constructor keeps the character width expected by ordinary string expressions. Normal and prepared set planning share the same byte bound calculation and collation resolution. This restores the existing CTAS and JDBC metadata while preserving the payload of HEX and BIT set branches.

DECIMAL assignment still consumes the completed set result under its resolved string domain. The reviewed UNION example rejects the whole strict write with 1366. With IGNORE it stores two zeros and emits one 1366 warning per value, matching the reported MySQL control. The existing diagnostic formatter now repairs malformed bytes in its bounded samples so clients can read both warnings.

Rebased on f3be95188736. The first 14 patches are equivalent and the metadata and warning changes are included in the final set column commit. Local two-CN JDBC comparison passed all 216 executed checks, including the four previously failing binary-function metadata checks in PROXY. One existing case was skipped by its BVT tag. The public SQL regression, focused warning race, and incremental lint passed. Full short race suites passed for planner and casts before the final warning formatter change, which has separate race coverage.

The publication lock test passed in local race runs on clean main and the final candidate. An earlier candidate run failed in a different subcase from the CI account-creation timeout. The new CI run will retest it in the Linux runner environment.

@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/XL Denotes a PR that changes [1000, 1999] lines label Nov 2, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Nov 2, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/XL Denotes a PR that changes [1000, 1999] lines labels Nov 2, 2026

@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: d0fa0bba8a15148e9a3dcf3a9d49fc129ed2c780

Assessment: request_changes

The PR reuses the existing assignment casts, aggregate executors, and warning sink. The maintained SQL tests pass for the previously reported derived DECIMAL, catalog default, and conflict-update cases. A top-level UNION ALL still loses the numeric meaning of direct hexadecimal literals before DECIMAL assignment.

Model: gpt-6.2-sol / xhigh

Session: 01a1feb0-0427-7772-9d89-786820ec84a5 · slot 1 · generation 2

  • P2 pkg/sql/plan/bind_insert.go:5494: Insert direct hexadecimal literals into a DECIMAL column with nonzero scale through a top-level UNION ALL. For example, insert SELECT 0x3e8 UNION ALL SELECT 0x64 into DECIMAL(4,1).
    Impact: Strict mode accepts the statement and stores 10.0,100.0 even though 0x3e8 represents 1000 and exceeds the destination range. INSERT IGNORE stores the same values and emits zero warnings. An equivalent UNION ALL using decimal integers rejects the strict write atomically.
    Evidence: The binder requires projectByAst to recover direct literals. The ordinary set-operation path at pkg/sql/plan/query_builder.go:5381 leaves that field empty, so assignment interprets the bytes as coefficients at the destination scale. The MySQL protocol probe confirmed the result and the strict single-branch and decimal-integer controls. Preserve the literal origin of each direct branch through assignment so the existing DECIMAL range checks apply, while preserving the established derived-table and stored-definition behavior. See closure-probe.jsonl and checks/1795325001157499619-2.json.

Validation:

  • Isolation preflight, native build and input fingerprint verification, and git diff --check completed successfully. Receipts and logs are retained in the diagnostic directory.

  • Selected race tests passed in pkg/container/types, pkg/sql/colexec/aggexec, pkg/sql/plan/function, and pkg/sql/plan. The integer assignment and catalog default SQL tests also passed under race. See focused-race.jsonl and checks/1795324854627434270-2.json.

  • TestPR32002ReviewBoundaries and TestIssue31161ColumnDefaultMetadata passed through the MySQL frontend on the non-race retry. See focused-sql.jsonl and checks/1795324954679419339-2.json.

  • The retained MySQL protocol probes confirmed the UNION ALL result and exercised stored FLOAT and DOUBLE rounding, FROM_DAYS operand types, and CHAR equality through INTERSECT and UNION. See boundary-probe-retry.jsonl, closure-probe.jsonl, and their receipts.

Limitations:

  • The broader SQL regression reached the three-minute test timeout under race while it was still running. The successful retry covered it without race instrumentation.

  • The frozen CI snapshot reports successful multi-CN BVT and offline Python checks. Live Arrow and shutdown-upgrade coverage rely on earlier evidence. The local rounding and FROM_DAYS probes exercised MatrixOne without a live MySQL reference comparison.

@XuPeng-SH

XuPeng-SH commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: b1bc02f6be5089846431ce076055e1eae802d0ac

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: b1bc02f6be5089846431ce076055e1eae802d0ac

Assessment: approve

The revised UNION path materializes radix literals as bytes before DECIMAL assignment, matching the supplied MySQL 8.0.45 control. Strict mode rejects invalid bytes atomically with error 1366. IGNORE stores zero and reports a warning for each invalid value. The fix reuses the shared set resolver, assignment casts, aggregate executors, and warning sink. Direct radix assignments and catalog defaults retain their established behavior.

Model: gpt-6.2-sol / xhigh

Session: 01a1feb0-0427-7772-9d89-786820ec84a5 · slot 1 · generation 2

Validation:

  • Focused planner, cast, and aggregate tests passed. See components-final.jsonl and checks/1795339938845628942-2.json.

  • The two-CN MySQL-protocol regression and an independent set-domain probe passed. They covered strict rejection, IGNORE warnings, nested sets, DISTINCT, LIMIT, and prepared rebinding. See sql-final.jsonl and checks/1795340088690051352-2.json.

  • The catalog-default metadata test reached PASS before its enclosing command timed out. See sql-retry.jsonl and checks/1795339993971529349-2.json.

  • Two offline Python tests passed, including conversion of widened MEDIAN results to Arrow Decimal256 values. See python-arrow-final.stdout and checks/1795339619560671119-2.json.

  • Verified the frozen 117-file delta, native inputs, clean checkout, and all 34 discussion entries. See validation-audit.log and discussion-assessment.json.

Limitations:

  • The broad local race run timed out. The successful local Go and SQL retries used ordinary instrumentation.

  • The distributed JDBC BVT and shutdown-upgrade results are author-reported. The local Python check exercised offline Arrow conversion.

@mergify

mergify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

18 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Sun 22 Nov, 17:36 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 17:54 · a2b88df

Reason

Pull request #32002 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — a2b88df5 Deployed Nov 22, 2026 by mergify[bot]
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

5 participants