Repository navigation
fix(plan): preserve CTAS output nullability on 4.1.6 hotfix - #32085
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on 6a945ba. The shared HashBuild/JoinMap and fallback direction is reasonable, and the follow-up addresses the earlier RANDOM_BYTES, incremental distinct-key admission, and cancellation counterexamples. Four issues remain in the implementation and its stated nullability coverage; each inline comment includes a concrete reproduction and suggested direction.
The optional-index budget now bounds index construction, but does not bound the probe workers' variable-length key buffers. The ROLLUP/GROUPING SETS issue is pre-existing and is called out separately as an uncovered case of the same CTAS nullability problem, not as a new regression.
Validation: I ran the relevant focused planner, function, HashBuild, LoopJoin, compile, and message tests successfully. Separate planner/operator counterexamples reproduced the error-behavior, probe-memory, and nullability issues; the nullability cases were also compared with the base. I did not independently rerun the full SQL BVT.
Current CI is also red: Proxy BVT reports a statement_info aggregation result mismatch; its relationship to this PR is not established. The UT job reports failure but its log endpoint returned 404, and coverage merge reports missing producer profiles rather than a calculated coverage verdict.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed exact head 1dd2bf61082bd4740e8069e82ccf44e228b3245e against 77052f8d1f9e6833ff5e5b41ae2343b5bcf0d152 on 4.1.6-hotfix. No confirmed in-scope findings remain.
The current code addresses the historical feedback on positive nullability proofs, RANDOM_BYTES volatility, optional-index admission/fallback, cancellation, evaluation order, probe scratch accounting, grouping-set outputs and common safe functions. The supplied discussion records contain no explicit author replies; commits and PR-description updates were not counted as replies. This is my first review.
Validation: inspected the complete change and relevant planner/compiler/operator/resource-owner paths, regression tests and SQL expectations. git diff --check and the prescribed PR artifact check passed. Decoding the generated protobuf descriptors confirmed that only HashBuild changed, adding field 19 (optional_index).
I attempted the focused CTAS/grouping, MARK, optional-index and hashmap tests, plus the grouping formatter test. They failed during compilation because local native dependencies are missing (jemalloc.h, xxhash.h, roaring.h, usearch.h); no test pass is claimed. Full SQL BVT and mixed-version execution were not run because this workspace lacks the required native build/runtime setup. The author's validation results were read but not independently reproduced.
The supplied exact-head CI snapshot is not all successful: Summary is success; Mergify Merge Queue and Mergify Merge Protections are neutral. These three checks provide no product-test verdict for this head.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on exact head 53cdb1286a80d9b1025bbac885207fddc7807bc9.
The follow-up addresses the previously reproduced cases for RANDOM_BYTES volatility, unsafe eager evaluation, incremental admission, cancellation, probe scratch and grouping-set output. Commit 53cdb12 also corrects the ROLLUP BVT expectation. The earlier request for systematic compatibility of safe function metadata remains incomplete. The inline comments document an additional concurrent-memory failure and the measured CTAS planning cost, with concrete directions and evidence.
Design gate: this change adds an optional shared-index lifecycle and changes the distributed pipeline wire contract across the compiler, HashBuild, LoopJoin and resource accounting. It meets the cross-boundary/protocol/lifecycle triggers in the feature and major-refactor design contract; the PR does not link an approved, versioned design. Please link or add a concise reviewed design covering ownership, concurrent memory bounds, fallback/error/cancel behavior, alternatives and measurable performance acceptance. An RFC or a new framework is not required.
Validation: I ran selected planner, function, HashBuild, LoopJoin, hashmap, parser and compiler tests with locally built matching native dependencies on 1dd2bf6. I also exercised a barrier-controlled concurrent build counterexample, baseline-versus-head planner checks, and SQL on that exact CI binary. The follow-up changes only five BVT expected rows, so the production code for those checks is unchanged. These checks are separate from the author's reported tests; I did not run production replay.
The previous head's second CI attempt failed both multi-CN BVT and UT. The BVT mismatch was the stale ROLLUP expectation now updated by 53cdb12. The UT report contains bootstrap deadline failures and other failed cases; I have not established that those UT failures are caused by this PR. CI for the new head remains pending.
|
@XuPeng-SH Thanks for the review. We have narrowed this PR in The broader changes were removed, not declared fixed:
Your CTAS planning-cost comment still applies. We retained the extra optimization pass to reuse final output inference rather than introduce a second CTAS-specific rule set. Reusing the source SELECT as the later INSERT plan is not a drop-in change: the target is created first, and the internal INSERT must bind with same-transaction DDL visibility, session and privilege context. The PR body now records that decision and fresh planner-only measurements: COUNT CTAS 0.261→0.931 ms / 1.14→3.73 MB; join/UNION CTAS 0.271→1.121 ms / 1.17→5.98 MB. These are not end-to-end latency figures. The known NOT IN performance risk also remains explicit: correct nullable UNION metadata selects this branch's loop MARK path; the earlier equivalent no-actual-NULL control measured roughly 25×/79× slowdowns at 3,000/6,000 probe rows. Moving it to #32263 does not establish that the performance concern is resolved or that this PR is merge-ready. For the narrowed candidate, planner UTs, whole planner-package static checks and independent SQL value/schema/constraint checks pass. CTAS BVT passes twice with 1,033 successes, zero failures and 30 unchanged skips per run. New-head CI and production deployment have not been verified. Please reassess the current narrowed diff and the retained planning/performance tradeoffs; the previous broader validation claims no longer describe this PR's final scope. |
… issue-20285-4.1.6-hotfix
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on exact head 84b005eac307b248d2371c36bc8d36d976e0fc86 against 77052f8d1f9e6833ff5e5b41ae2343b5bcf0d152.
Thank you for narrowing the change and for explicitly documenting what was removed and what remains open. The optional MARK index, its concurrent-memory issue, and the safe-function metadata regression are no longer present in the final diff. The previous design-document request applied to the removed shared-index/wire/lifecycle change and is withdrawn for this narrowed PR. The existing aggregate/window and grouping-extension gaps remain open as disclosed in #32264 and #32265; removing their fixes is not the same as resolving those baseline defects.
The current diff still introduces two blocking regressions: an unsound IFNULL non-null proof can silently lose groups or fail CTAS, and correct UNION nullability sends ordinary nullable NOT IN queries through this branch's quadratic MARK path. The inline comments contain reproductions and possible directions. A third inline comment records a pre-existing UNION result-type gap in the exact target scenario; it is not attributed to this PR.
The explanation for retaining one extra CTAS optimization pass is reasonable: reusing the existing output inference avoids a second rule set, while reusing the later INSERT plan has transactional and binding implications. The reported planner-only cost is real, but its ratios alone do not establish an end-to-end regression that should block this narrowed fix.
Validation: I ran the new focused planner tests with matching native dependencies, compared the volatile-expression planner and real SQL behavior against the base, tested the exact-head CI binary in an isolated single-CN instance, and checked UNION result types with MySQL 8.0.44. The SQL performance numbers below are local controls, not production measurements. I did not independently rerun the full BVT or production workload. The exact-head UT job has failed in six pkg/tests packages; its diagnostic output contains bootstrap and context timeouts, but I have not established the cause or a relationship to this PR. Other CI jobs are still running.
| for i, expr := range left.ProjectList { | ||
| projectList[i] = &plan.Expr{ | ||
| Typ: expr.Typ, | ||
| Typ: setOperationOutputType(nodeType, expr.Typ, right.ProjectList[i].Typ), |
There was a problem hiding this comment.
[P1] Correct nullable UNION metadata exposes a quadratic NOT IN path in ordinary SELECTs.
This change is semantically necessary: when either UNION input can emit NULL, NOT IN cannot be rewritten to a normal anti join. But on this branch MARK is implemented as LoopJoin, so existing queries that were fast on no-actual-NULL data can now be much slower as both sides grow. In an isolated exact-head SQL instance, 6000 probe rows and 3000 matching RHS rows with identical values in nullable vs NOT NULL extra tables took median 74.6 ms vs 3.0 ms over seven runs; EXPLAIN changed from RIGHT ANTI to MARK. The 3000-row nullable case took 20.7 ms. Your #32263 baseline comparison (0.890 ms to 70.680 ms at 6000 rows) independently records the same concern. These are local controls, not production latency claims. Adding an actual NULL correctly produces zero rows, so restoring the old false non-null annotation is not an acceptable fix.
Please address this regression as part of the same release, or coordinate the merge with #32263. Prefer a bounded NULL-aware membership path reusing the existing HashBuild/JoinMap and join lifecycle for proven-safe single-key equality, with the existing evaluator as fallback for other predicates. Preserve SQL NULL and empty-set behavior, evaluation/error semantics, cancellation, and bounded concurrent build/probe memory. The removed experimental index had a demonstrated accounting gap and should not simply be reinstated.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on exact head 84b6431912e19303ac351bfe6600fb2a2cf7ee6a, against 4.1.6-hotfix base 9bde0b078363cacfcfef47371426b41a193e487f.
-
[P1] Correct UNION nullability still exposes a substantial NOT IN regression. This change must not restore the old incorrect non-null proof: when a UNION input can produce NULL, MARK semantics are required. But the 4.1.6 branch executes this MARK as a nested loop. On the exact-head CI binary, with identical values and no actual NULLs, the existing 6,000-probe/3,000-RHS control returned the same count but changed from RIGHT ANTI to MARK: median 3.171 ms versus 75.743 ms over seven runs. At 3,000/1,500 rows, MARK took 21.400 ms. Adding a real NULL correctly returns zero. These are isolated single-CN measurements, not a production latency claim. The author independently reproduced the same regression. The original review comment remains open. #32315 is a separate proposed mitigation, but it is still open and its current CI has failures; it is not yet an established fix. Please coordinate a reviewed, validated bounded NULL-aware path before this change is independently merged/released, preserving NULL/empty-set behavior, evaluation order, cancellation and memory bounds.
-
[P2, pre-existing shared type defect affecting this fix's target] The enabled CTAS can materialize a numeric UNION as text. On the exact-head binary,
CREATE TABLE out AS SELECT 2 AS c UNION ALL SELECT 10 UNION ALL SELECT NULLsucceeds but createsc VARCHAR(65535);ORDER BY creturnsNULL, 10, 2. The PR'sCOUNT(*) UNION ALL SELECT NULLcase also producesVARCHAR(65535). The ordinary UNION type-reconciliation defect predates this PR; it is not a newly introduced SELECT regression. It nevertheless affects the result of the CTAS case this PR makes succeed, and the current test asserts nullability without the output type or numeric behavior. Please address it in the shared UNION type reconciliation, or explicitly identify and coordinate a concrete follow-up and document the target-scenario limitation; preserve the distinction between an untyped NULL and an explicitCAST(NULL AS CHAR). See the earlier detailed comment.
The narrowed diff removes the prior optional-index/wire implementation, so the earlier design gate and findings specific to that removed implementation do not apply here. The existing ROLLUP and general function/aggregate/window inference gaps are tracked separately by #32265 and #32264; deferral is not a fix. The extra CTAS optimization pass has a documented ownership/transaction rationale and its planner-only measurements do not independently establish an end-to-end blocker. The new RANDOM_BYTES flags address the prior volatile-source proof, and on the exact-head binary GROUP BY random_bytes(0) retained (NULL, 2) and DISTINCT retained NULL.
Validation: read the complete 10-file diff and review threads; exercised the above SQL on the exact-head CI build, with isolated test-owned data and a readiness check. Prior baseline/head evidence for the non-null and volatile controls was rechecked against the current relevant code. The exact-head multi-CN BVT and SCA checks succeeded, while its UT job failed with six reported cases and service/bootstrap context timeouts; I have not established whether those failures are caused by this PR. I did not independently rerun the full BVT or a production workload.
|
@XuPeng-SH To clarify the author's scope decision: the NOT IN/MARK performance work is owned by #32263 and the separate PR #32315, not by this PR. #32085 is intentionally limited to the direct CTAS nullability repair and the correctness/constraint regressions in its retained inference. Please do not use completion, review or CI status of #32315 as a blocking condition for #32085, or require its MARK implementation to be brought back into this PR. Please assess this PR on its scoped CTAS changes; review and delivery of the performance mitigation belong to #32315 separately. This is an explicit scope decision, not a claim that the measured NOT IN regression has disappeared or that #32315 is already validated/merged. The known risk remains documented and tracked. Any earlier statement from me making #32315 a mandatory merge/release prerequisite for this PR does not reflect the author's current decision and is withdrawn. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes on exact head 07d0031cb29bbce37b564208596df6504a01e82d against 4.1.6-hotfix 9bde0b078363cacfcfef47371426b41a193e487f. The inline comment describes a newly introduced persistent-schema regression for both IFNULL and COALESCE with a non-NULL literal fallback; the baseline rejects a later NULL insertion while this head accepts it. The actual 0/0.5 query values match, so checking only the source rows misses the changed constraint.
I considered the author's explicit scope decision on #32263/#32315: the observed quadratic NOT IN performance risk remains real and is not fixed by this PR, but I am not requiring the separate MARK implementation or its PR's completion as a condition of this review. Likewise, the numeric-UNION type issue is pre-existing, and the concrete reproduction and scope have now been documented in #32326, satisfying the tracking option in my prior review. Neither decision means those issues are solved.
The new conditional-expression changes were also challenged with CASE/IF branches that can introduce NULL. One outer-join/division case drops a NULL group and rejects CTAS on this head, but the exact target baseline has the same behavior; it is not reported as a new regression and belongs to the explicitly open #32264 scope. The previous candidate happened to avoid that particular pre-existing failure. The RANDOM_BYTES and unrelated safe conditional controls were included in the review.
Validation: compared isolated SQL executions on the exact-head CI binary and a CI binary whose tree is identical to the target base (head 7f99d53b, identical tree 4e40fa17). For 29 related left-join expressions, compared values, GROUP BY, DISTINCT, CTAS, and available schema. Independently verified the finding's result rows, schema, and subsequent NULL insertion on both versions; 0e0 and CAST(0 AS DOUBLE) are distinguishing controls. The full BVT and Go UT were not independently rerun. GitHub's latest UT, SCA and multi-CN BVT checks were still running at the time of this review.
| } | ||
| if impl.F.Func.ObjName == "coalesce" { | ||
| for _, arg := range impl.F.Args { | ||
| if lit := arg.GetLit(); lit != nil && !lit.Isnull { |
There was a problem hiding this comment.
[P2] Preserve the existing NOT NULL constraint for a safely converted constant fallback.
This public-path case changes the persisted schema even though every result is non-NULL:
CREATE TABLE l(id INT NOT NULL);
CREATE TABLE r(id INT NOT NULL, v INT NOT NULL);
INSERT INTO l VALUES (1),(2),(3);
INSERT INTO r VALUES (1,0),(3,2);
CREATE TABLE a AS SELECT IFNULL(1/r.v, 0) AS v
FROM l LEFT JOIN r ON l.id=r.id;
CREATE TABLE b AS SELECT COALESCE(1/r.v, 0) AS v
FROM l LEFT JOIN r ON l.id=r.id;
INSERT INTO a VALUES(NULL);
INSERT INTO b VALUES(NULL);Both versions select 0, 0, 0.5. On the exact target base, both result columns are DOUBLE NOT NULL and both INSERTs fail with 3819. On this head both become DOUBLE DEFAULT NULL and both INSERTs succeed. Replacing 0 with the same-type literal 0e0 retains NOT NULL on this head; explicitly spelling CAST(0 AS DOUBLE) also becomes nullable. Type reconciliation wraps a non-NULL literal in a cast, but the retained proof only recognizes a direct GetLit() (and the IFNULL structural proof also has restricted cast handling). This is a new constraint compatibility regression in the literal-fallback case this PR says it retains, distinct from the pre-existing possibility that 1/r.v itself returns NULL.
Please use a shared sound proof for converted constants that cannot yield NULL, while keeping arbitrary NULL-producing or volatile expressions conservative. Cover both IFNULL and COALESCE through CTAS schema and failed NULL insertion, with implicit/explicit casts, the direct same-type literal control, and the existing division/volatile negative controls.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: f9c7ac9de71b0091aba02ab779078ffb5aa694c9
Assessment: approve
No unresolved in-scope findings. The repair reuses final SELECT inference and a shared cast proof; the extra planning pass has a documented binding rationale. Prior converted-fallback constraint regressions are addressed.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 10 changed files, affected consumers, 23 discussion entries and linked issue context.
-
Receipt checks/1793982924187901723-3.json records audit exit 0: clean frozen source, 187 aligned SQL/result statements, 60 independent fixture value oracles and 33 expected NULL rejections. This was fixture analysis, not SQL execution.
-
Frozen CI: 12 successful, 13 skipped and 2 neutral checks; build, UT, SCA, coverage and proxy/pessimistic multi-CN BVT succeeded.
-
Reused author-reported affected-package tests, static checks, repeated CTAS/conditional BVT and SQL/baseline controls.
Limitations:
-
Extra planning cost and the known NOT IN/MARK slowdown remain documented; performance mitigation is separately owned by #32263/#32315.
-
Pre-existing inference, grouping and numeric UNION type gaps remain tracked by #32264/#32265/#32326.
-
No independent Go/service run or production replay; local_validation is empty and raw author runtime logs were not supplied.
What type of PR is this?
Which issue(s) this PR fixes:
Related to https://github.com/matrixorigin/matrixflow/issues/20285#issuecomment-6594984801
Fixes the reported CTAS error 3819 for UNION totals/footnotes containing NULL and null-extended outer-join outputs. It does not claim to resolve all application snapshot scheduling, retries, UI errors or the separate production Dispatch hang.
What this PR does / why we need it:
Scope decision: NOT IN/MARK performance work belongs to #32263 and the separate PR #32315, not this PR. The author requests that completion, review or CI status of #32315 not be used as a blocker for #32085. The known performance risk remains documented; this is not a claim that it is fixed. #32315 is currently open at
264f8842007f570c641f0122d77a2c33f635db85, not yet an established merged fix. This PR does not reinstate the removed experimental index.Historical coordination evidence, not revalidated for the latest CASE/IF guard: a temporary Go overlay combined the predecessor candidate's source (delivered as
117ed39adf) with #32315 at264f8842(no overlapping changed paths, no MARK code added to this PR). The message/loopjoin/HashBuild consumer tests pass (237 test-pass events). In isolated single-CN SQL with one warmup and seven measurements per case, 3,000/6,000 probe rows with no actual NULLs returned the same counts: loop MARK medians 19.935/72.711 ms versus combined-candidate 0.853/0.963 ms. Actual-NULL, all-NULL and empty-RHS controls pass, and the CASE/IF, RANDOM_BYTES and original CTAS value/schema/constraint controls pass on the combined binary. These are local exact-combination checks, not production latency, independent review, complete lifecycle validation or proof of remote CI success. The performance issue remains separately tracked; these checks do not make #32315 a merge prerequisite for this PR.Scope remains the direct CTAS repair and the dependencies required by its retained conditional-expression proofs: ten files, four production files. The earlier experimental MARK, wire, general function-proof and grouping-extension changes remain removed; their history is retained without force-pushing.
build_ddl.gois unchanged since the scope reduction;query_builder.goadditionally preserves already-established CASE/IF constraints during remapping without establishing new ones from branch type flags. The two additional production files contain RANDOM_BYTES volatility/NULL-output metadata, consumption of the existingPRODUCE_NULLcontract, a direct-execution folding correction. CASE/IF remapping is handled conservatively inquery_builder.go, not by adding a new shared positive proof.volatile=truefor both signed/unsigned RANDOM_BYTES overloads. The retained IFNULL same-source proof must reject repeated random evaluation, including nested CASE expressions and constant arguments. These outputs remain nullable; deterministic IFNULL and literal-fallback COALESCE controls retain their constraints.PRODUCE_NULLand haveDeduceNotNullablehonor that existing flag: non-NULL lengths can still produce NULL. The volatility-only correction was incomplete and exposed silent NULL-group loss. Both signed/unsigned overloads now retain the NULL group and the DISTINCT NULL row for lengths 0/1025, without restoring folding. No other function on this branch is newly annotated; this is not the broader function-proof redesign.RunFunctionDirectlydoes not convert volatile/real-time results to a constant vector. Its previousfold=trueinitialization would otherwise make the new metadata collapse a varying-input RANDOM_BYTES result to its first row. Ordinary constant folding remains tested.0.0representation (string literal → DECIMAL → DOUBLE). Literal fallback proof still requires a non-NULL literal at the bottom; columns/arbitrary functions cannot supply that proof. IFNULL peels only audited added casts and stops when it matches the original ISNULL source, then checks source volatility. This is a nullness proof, not a precision/losslessness claim. String-to-float/date, JSON and other CAST overloads remain unproven. Numeric overflow/conversion errors must still propagate; the proof neither evaluates expressions early nor guarantees precision or successful conversion. Controls cover0,CAST(0 AS DOUBLE),0e0,0.0, explicit DECIMAL128, numeric source with floating fallback, and varchar/char/text sources.Validation against target
9bde0b0783: Go 1.26.4 with matching native artifacts; full planner/function/colexec/group UTs pass (4,228 test-pass events). Deterministic red-to-green tests cover CTAS metadata, both executor overloads, direct execution, and the NULL-output contract, including negative signed lengths and uint64 overflow. Ordinary argument-based inference and explicit non-NULL producers retain controls. Changed-code coverage is 70/72 blocks (97.22%) and 108/110 statements (98.18%); the BOOL/BIT follow-up covers 6/6 blocks and 10/10 statements. Helper tests check 270 scalar/target pairs, including rejection of eight unimplemented pairs. Real CAST execution tests cover 290 admitted source/target configurations with 0/1/NULL inputs, including BOOL/BIT, fixed-width floating and CHAR/VARCHAR/TEXT targets. Overflow, narrow-text and narrow-BIT errors must propagate; BIT text results are checked as raw bytes rather than decimal formatting. All test-owned resources are released. Remapping tests explicitly assert that a false non-null flag can never become true, while real planner/SQL controls cover CASE, IF, nesting and NULL-producing result functions. Registry fields are outside that denominator and are checked through their consumers. Actualmake err-check, matching gofmt, whole affected-package vet/lint (including group/rule consumers; golangci-lint 2.6.2, no diff-line filtering), and target-base diff checks pass.A newly built final binary passes two normal CTAS BVT comparisons, each with 1,176 successes, zero failures and 30 unchanged skips; case-when passes twice (120/120), the expression group passes (573 successes, eight existing skips), and the existing RANDOM_BYTES-containing function case passes (71 successes, two existing skips). Independent SQL checks first reproduced the volatility-only candidate's empty GROUP BY/DISTINCT results for all four overload/length combinations despite two NULL projection rows. The fixed candidate returns
(NULL, 2)and one NULL row, agrees with an independent literal-NULL/count control, and passes COUNT/IS NULL/IS NOT NULL and direct nullable-CTAS checks. The original UNION/outer-join and IFNULL/COALESCE schema/value/constraint controls are rerun too. Independent SQL checks retain the constant-branch CASE/IF NOT NULL controls. They additionally reproduce the predecessor's division/REGEXP_SUBSTR failure for CASE and IF: projection contains NULL/7, GROUP BY and DISTINCT lose NULL, and CTAS fails with 3819. The fixed binary preserves both groups and DISTINCT rows, creates nullable CTAS outputs with the exact values, and accepts a subsequent NULL insertion. Implicit/nullable result branches remain nullable. For both IFNULL and COALESCE over1/r.von a left join, implicit integer0, explicitCAST(0 AS DOUBLE)and same-type0e0all produce 0/0/0.5, persist as DOUBLE NOT NULL, and reject subsequent NULL insertion with 3819. The independent old-head control reproduced the four converted-fallback columns accepting NULL while the two direct-literal controls rejected it. The previously missed0.0/explicit DECIMAL128 fallbacks andIFNULL(r.v,0e0)/IFNULL(r.s,'ok')now retain NOT NULL as well; independent SQL additionally checks char/text and an explicitly cast original string source. Every target rejects a subsequent NULL insertion with 3819, while preserving its exact values. The latest SQL coverage adds DECIMAL(10,2)/DECIMAL(38,2) source columns with IFNULL/COALESCE and FLOAT/UNSIGNED cast fallbacks. Seven old-head combinations reproduced the lost constraint; the already-correct DECIMAL128 IFNULL control stays correct. All eight fixed candidates retain NOT NULL and reject NULL insertion without changing their mathematical values. MixedCOALESCE(r.s,0)/IFNULL(r.s,0)/IFNULL(r.v,'ok')now also preserve NOT NULL, while the previously correctCOALESCE(r.v,'ok')remains a control. Independent SQL covers varchar/char/text source variants and confirms actual NULL rejection. BOOL/BIT source cases with zero fallbacks now also retain NOT NULL and reject NULL insertion with 3819; the previously correct BIT COALESCE control is retained. Actual values remain 0/0/1, and NULL-fallback controls still retain their NULL rows and allow NULL insertion. Dynamic division-to-text fallbacks and NULL-to-text fallbacks remain nullable rather than gaining a false constant proof. Dynamic division fallback, volatile sources and the prior CASE/IF NULL-group regressions remain negative controls. These cases do not depend on random sampling. Only independently checked generated result segments were accepted; old expectations/skips remain unchanged. Teardown and test-owned service exit are verified. Earlier exact-baseline 3819 reproduction and MySQL 8.0.45 controls remain applicable to the original UNION/outer-join cases; the reported exact-target baseline control for the new grouping regression was not independently rerun. No production replay.Costs and explicit limits: retaining the extra full SELECT optimization avoids a second CTAS-specific nullability rule set. Reusing that SELECT plan as the later INSERT plan is not a drop-in change: the target table is created first, and the internal INSERT is bound with same-transaction DDL visibility, session and privilege context. Previously recorded planner-only baseline/narrowed-candidate measurements (same fixture, setup excluded, 1,000 iterations × three) show median COUNT CTAS 0.261→0.931 ms / 1.14→3.73 MB, and join/UNION CTAS 0.271→1.121 ms / 1.17→5.98 MB. These were not remeasured for the volatility follow-up and are not end-to-end or production latencies. Preventing random-result folding restores per-row evaluation, not a performance optimization.
Separate hotfix follow-ups, intentionally not implemented here:
2 UNION ALL 10 UNION ALL NULLthen sorts as NULL,10,2 rather than numeric NULL,2,10. This is not fixed here, and successful CTAS/nullability checks do not imply full schema equivalence with MySQL. The separate shared fix must cover SELECT and CTAS types/numeric behavior while distinguishing untyped NULL from explicitCAST(NULL AS CHAR); [Bug]: tracker for remaining CTAS schema inconsistencies with MySQL #24436 and [Bug]: UNION common-type inference truncates later DATETIME and BINARY branches to the first string literal width #30722 are related but not substitutes for this exact acceptance boundary.The current head's CI has not been verified. Local validation does not establish overall merge readiness; this PR remains unmerged.