Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Related to closed #26830 and tracker #24436. This explicitly tracks the remaining 4.1.6-hotfix function/aggregate/window nullability work, excluded from the narrowly scoped matrixflow #20285 fix in PR #32085.
Branch Name
4.1.6-hotfix
Commit ID
77052f8d1f9e6833ff5e5b41ae2343b5bcf0d152.
Other Environment Information
Isolated local MO built with Go 1.26.4 and matching native artifacts. Baseline and the earlier narrow PR candidate were tested independently; no production replay.
Actual Behavior
Non-NULL input does not imply a non-NULL result. These failures were reproduced on the exact baseline and the narrow CTAS candidate:
SELECT 1/yreturns NULL for y=0, but GROUP BY/DISTINCT can discard its NULL group and equivalent CTAS fails with 3819.- MAX over an empty non-null source returns NULL, but equivalent CTAS fails with 3819.
- LAG at the partition boundary returns NULL, but equivalent CTAS fails with 3819.
The related main-branch issue also documents JSON_EXTRACT missing paths, REGEXP_SUBSTR no-match, invalid UNHEX and other domain-NULL functions. Audit which fixes this hotfix branch actually needs; do not claim all listed families were freshly reproduced here.
Expected Behavior
Share sound function/overload non-null proofs across consumers. STRICT alone is not proof that an implementation cannot synthesize NULL. Preserve COUNT and existing constraints for genuinely safe functions; avoid replacing unsound inference with blanket nullability that silently removes constraints.
Steps to Reproduce
CREATE TABLE t(x INT, y INT NOT NULL);
INSERT INTO t VALUES(NULL,0),(0,1);
SELECT 1/y AS v FROM t ORDER BY v;
SELECT 1/y AS v,COUNT(*) AS c FROM t GROUP BY 1/y ORDER BY v;
SELECT DISTINCT 1/y AS v FROM t ORDER BY v;
CREATE TABLE division_result AS SELECT 1/y AS v FROM t;
CREATE TABLE empty_source(y INT NOT NULL);
SELECT MAX(y) FROM empty_source;
CREATE TABLE empty_max_result AS SELECT MAX(y) AS v FROM empty_source;
SELECT LAG(y) OVER(ORDER BY y) AS v FROM t ORDER BY v;
CREATE TABLE lag_result AS SELECT LAG(y) OVER(ORDER BY y) AS v FROM t;Expected division groups are (NULL,1) and (1,1); CTAS must materialize each legal NULL result rather than reject it through an inferred internal constraint.
Additional information
PR #32085's removed, unmerged broader implementation provides investigation history, not an approved backport. Its positive-proof inventory was incomplete: review #32085 (comment) showed REPLACE/MD5 CTAS columns losing NOT NULL and accepting NULL. These are compatibility requirements for a future inference redesign, not claimed baseline REPLACE/MD5 defects.
Acceptance: inventory implementations/overloads; test exact baseline-versus-candidate schema, values and NULL insertion constraints; include REPLACE/MD5 and other audited common functions, COALESCE with a refreshed non-null fallback, nullable outer-join inputs, volatile/unsafe-cast cases, domain-NULL controls, and full NULL groups. Do not maintain a CTAS-only second rule set or conflate non-nullness with safe evaluation reordering.
Activity
fix(plan): preserve CTAS output nullability on 4.1.6 hotfix (#32085)
[4.1.6-hotfix] fix(plan): infer result nullability from explicit proo…
slyunnn commentedon Nov 13, 2026
Regression and extended verification for #32264 (2026-11-13)
Verification Environment
Frozen target:
4.1.6-hotfix@9937f1b74a7a7a01f8e0dcb6e7d3ff447e0ce29e, [4.1.6-hotfix] fix(compile): preserve remote receiver ownership (#32591). Remote fetched at test start; the service binary was rebuilt for this exact commit using matching native inputs and confirmed by actualgit_version()at all endpoints. Local macOS arm64 topology:2 CN / 1 TN / 1 Log service / Proxy. Original and extended SQL actually ran via Proxy6101, CN116101, CN216102on loopback, using PyMySQL text protocol and Java/JDBC BVT. Endpoints were exercised, not merely health-checked.Go
1.26.4was used. Isolated SQL ports were chosen for this branch; nomainresult is substituted for hotfix verification.What Was Covered
pkg/sql/plan/functionandpkg/sql/plannormal test packages passed, including overload proofs, outer-join NULL extension, scalar-subquery boundaries and safe constraints.1,281successful,3failed,30pre-existing ignored per endpoint; the three failures are stale numeric-UNION protocol-type expectations, not hidden as a green standard run.Findings
Associated repair: PR #32519, [4.1.6-hotfix] fix(plan): infer result nullability from explicit proofs, merge
bf18d1090466825da1d1c67742491af5c1da2605. It shares sound result proofs across consumers, preserves audited safe constraints, and applies outer-join/scalar NULL extension before nullability-dependent optimization.The three remaining standard BVT mismatches are
union_null,null_union, andunion_cte: expected VARCHAR metadata versus actual BIGINT metadata, with identical rows. This is the intended shared numeric-UNION correction from #32461 / #32326, independently verified earlier, while this broad fixture retains the old headers. No source golden or product assertion was changed here. The Proxy values-only diagnostic passed1,284/1,284active statements with the same30existing ignores; this is not standard metadata-comparison success.Initial runner failures were setup-related: the fixture creates
testitself and some sessions intentionally require no selected database. The final standard run used an empty initial database and removed pre-created fixture residue; it had no abnormal statements. The hotfix Proxy address also had to be configured explicitly in the temporary launcher. Failed setup attempts are excluded from product conclusions.Expression/DOUBLE membership acceleration remains the separately accepted hotfix performance limitation; sound nullability is not weakened to recover an unsound ANTI plan.
Large-data regression required: No for this result-proof contract. Empty/zero/division, boundary window rows, scalar/outer-join and NULL insertion cases discriminate it without additional volume. This acceptance does not replace #32263's completed membership scale verification.
MOTR / BVT Coverage
Reused the existing CTAS fixture, live semantic/constraint probes and complete owning-package tests. No duplicate MOTR commit/PR was created. Shared catalog/session cases ran serially. The three legacy UNION header maintenance items remain explicit; no full standard-BVT/CI-green claim is made.
Final Conclusion
Fixed for the tested
4.1.6-hotfixfunction/aggregate/window nullability scope, preserving both legal NULL outputs and safe constraints. The broad fixture's stale UNION metadata expectations are separately documented above.fix(plan): preserve grouping-extension CTAS semantics on 4.1.6-hotfix (…