Skip to content

[Bug]: [4.1.6-hotfix] close function, aggregate and window nullability gaps without dropping safe constraints #32264

Closed

Description

@ck89119

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/y returns 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

  1. added
    kind/bug
    on Nov 5, 2026
  2. added
    severity/s0
    and removed on Nov 5, 2026
  3. assigned and unassigned on Nov 12, 2026
  4. slyunnn commented on Nov 13, 2026

    @slyunnn

    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 actual git_version() at all endpoints. Local macOS arm64 topology: 2 CN / 1 TN / 1 Log service / Proxy. Original and extended SQL actually ran via Proxy 6101, CN1 16101, CN2 16102 on loopback, using PyMySQL text protocol and Java/JDBC BVT. Endpoints were exercised, not merely health-checked.

    Go 1.26.4 was used. Isolated SQL ports were chosen for this branch; no main result is substituted for hotfix verification.

    What Was Covered

    • OK — Original division over zero: SELECT, GROUP BY and DISTINCT preserve the complete NULL group; equivalent CTAS materializes the valid NULL result.
    • OK — Empty MAX and LAG boundary CTAS retain nullable outputs. Actual INSERT NULL succeeds on the nullable outputs.
    • OK — COUNT, REPLACE, MD5 and COALESCE with a proven non-NULL fallback retain NOT NULL constraints; explicit INSERT NULL remains rejected.
    • OK — Missing-path JSON_EXTRACT, invalid UNHEX and no-match REGEXP_SUBSTR materialize legal NULL results. Thirty independently asserted live scenario records passed across all three endpoints.
    • OK — Complete owning pkg/sql/plan/function and pkg/sql/plan normal test packages passed, including overload proofs, outer-join NULL extension, scalar-subquery boundaries and safe constraints.
    • Failed — Standard full CTAS BVT: 1,281 successful, 3 failed, 30 pre-existing ignored per endpoint; the three failures are stale numeric-UNION protocol-type expectations, not hidden as a green standard run.
    • Not covered — Complete MySQL compatibility, production scale/concurrency, fresh race runs, and other maintenance branches.

    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, and union_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 passed 1,284/1,284 active statements with the same 30 existing ignores; this is not standard metadata-comparison success.

    Initial runner failures were setup-related: the fixture creates test itself 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-hotfix function/aggregate/window nullability scope, preserving both legal NULL outputs and safe constraints. The broad fixture's stale UNION metadata expectations are separately documented above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions