Skip to content

fix(plan): preserve CTAS and division nullability on 4.2-dev - #32153

Merged
XuPeng-SH merged 7 commits into
matrixorigin:4.2-devfrom
ck89119:issue-20285-4.2-dev
Nov 5, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:4.2-devfrom
ck89119:issue-20285-4.2-dev

Conversation

@ck89119

@ck89119 ck89119 commented Nov 4, 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:

Related to https://github.com/matrixorigin/matrixflow/issues/20285#issuecomment-6594984801

Addresses the kernel nullability failures, not the application-level retry and result-loading behavior tracked by that issue.

What this PR does / why we need it:

Two nullability defects on 4.2-dev reject valid materialization or silently discard NULL groups:

  • CTAS reads bind-time constraints before outer joins and scalar subqueries have propagated null extension. Derive constraints from the final optimized output while preserving source defaults, ENUM types, prepared-query handling and CTAS-specific DATETIME nullability.
  • /, DIV and MOD can return NULL for a zero divisor even with NOT NULL operands. Mark this operator family nullable at the shared function-inference owner so COALESCE/IFNULL cannot turn their results into false non-null guarantees for GROUP BY, DISTINCT or CTAS.

Preserve the complete bound query before CTAS optimization for PREPARE parameter/schema collection, including an independent root-ID slice; continue deriving target constraints from the optimized output. Regression tests cover unused placeholders and leading/middle/trailing pruning, CTEs, repeated EXECUTE, wrong arity and outer-join null extension.

Also fix a pre-existing positional bug on the same consumer path: the CTAS follow-up INSERT used to compact surviving parameter ordinals and could bind the first supplied value where the second was required. Internal prepared query plans now use the existing gap-preserving normalization on initial and retry builds. DDL/DCL retain their previous handling.

Existing UNION nullability merging and MARK-join execution are unchanged. Correct the old CTAS MIN/MAX NOT NULL expectations: empty-input aggregates can produce NULL, while COUNT remains non-null.

Validation against exact baseline 88e5fb5417, with Go 1.26.4 and native artifacts built in the isolated worktree:

  • Baseline real SQL reproduces outer-join and empty-aggregate CTAS error 3819, plus NULL-row loss and CTAS failures for division-family COALESCE/IFNULL fallbacks. The fixed binary preserves the complete NULL/0 row sets and materializes successfully; UNION NULL controls pass on both revisions.
  • 26 original planner nullability cases, eight prepared-CTAS pruning cases, ordinal-gap/alias tests, internal consumer Query/DDL/DCL controls, source-metadata/temporal controls and division-family inference tests across all registered overloads pass.
  • New pruning UT fails 7/8 cases on the original PR. Three-version real SQL confirms the reported EXECUTE error, separately reproduces the baseline's wrong leading/middle bindings, and verifies the fix writes 1, 22, (11,33) and the complete outer-join NULL row set as appropriate.
  • Full planner/function tests passed for the initial fix; full pkg/sql/plan and pkg/sql/compile tests, gofmt, vet and incremental golangci-lint v2.6.2 pass after the parameter fix. Whole-PR changed-block Go UT statement coverage: 19/24 (79.17%), distinct from whole-package coverage.
  • Full CTAS BVT passes twice on the same isolated instance: each run has 1,090 successes, zero failures and 30 existing skips. New cases are not skipped, and teardown is independently verified.
  • Expression BVT group: 633 successes, zero failures and one existing skip.
  • Existing prepared BVT: prepare_all 364 successes/one existing skip; prepared_projection_cardinality 26 successes; prepare_ddl_schema_change 293 successes. Zero failures in all three.

No production changes or production-query replay were performed. This does not claim a comprehensive audit of every function's nullability.

@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Nov 4, 2026
@ck89119
ck89119 marked this pull request as ready for review November 4, 2026 10:28
@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 8f63e5ca63836f1dac75863fb1e3d0cb7e21a27d

Review discussion changed before publication; a fresh contextual review is queued.

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

Reviewed 8f63e5c against 4.2-dev. No blocking finding. CTAS derives output nullability after optimization while retaining source defaults/ENUM metadata and the complete pre-optimization parameter graph for PREPARE. The independent Steps slice prevents root-ID remapping from corrupting that graph. Internal query parameter normalization preserves pruned ordinal gaps on both initial and retry builds; DDL/DCL retain their existing owner. Division-family functions correctly decline a non-NULL proof for zero divisors. Reviewed the NULL-group, outer-join, empty-aggregate, prepared pruning/arity/repeated-EXECUTE and explicit NOT NULL controls. Ordinary bug-fix exemption applies. Reused current-head green CI and the reported scoped SQL/BVT red-green evidence; no full local suite rerun.

@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 8f63e5ca63836f1dac75863fb1e3d0cb7e21a27d

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: 8f63e5ca63836f1dac75863fb1e3d0cb7e21a27d

Assessment: approve

No blocking findings. The fix reuses existing optimization and parameter-normalization owners. The prepare-only query copy preserves original arity while CTAS constraints follow optimized output semantics.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete nine-file delta, all four discussion entries and linked issue context; recorded source reasoning and complete discussion dispositions.

  • Parsing/formatting of seven Go files, SQL/result command alignment and frozen-input integrity passed. Receipt: checks/1793795447322047909-2.json; retained logs and validation-receipt-audit.json reconcile both audit attempts.

  • Reused successful current-head build, UT, SCA, coverage and multi-CN BVT statuses. Verified that the author's reported baseline matches six relevant merge-base source files.

Limitations:

  • No local product tests or SQL execution were repeated. Author SQL/BVT results remain reported evidence; raw execution logs were unavailable.

  • Application retries, result loading and deployment latency in matrixflow #20285 remain outside this fix.

@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 6b972d4e1ab30073c1aee02acc9a754c6f53015d

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: 6b972d4e1ab30073c1aee02acc9a754c6f53015d

Assessment: approve

No actionable defects remain. CTAS reuses optimized output nullability while preserving source metadata; the prepare-only snapshot retains arity, and existing normalization preserves parameter positions on initial build and retry.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all nine changed files, affected owners and consumers, all six discussion entries, and linked issue context. Saved review-plan.md and discussion-assessment.json.

  • Local receipt 1793852550214859083-2 exited 0: frozen-source checks, seven-file gofmt check, 93 SQL/result statement alignments, and 35 independent expected-output checks including 24 metadata rows. Retained review-audit.log and review-audit-report.json.

  • Reused supplied current-head successful shared build, Ubuntu UT, arm64 static analysis, coverage, complementary PROXY/PESSIMISTIC multi-CN BVT, and CI Required results.

  • Completion receipt 1793852712471165359-2 exited 0: verified receipt/log correlation, complete discussion coverage, retained artifact hashes, and unchanged clean source.

Limitations:

  • No local Go product tests or database workloads were executed. Author-reported baseline/fixed SQL and dedicated BVT results lacked supplied raw logs.

  • Application retry/result-loading behavior and deployment-related latency are outside this kernel nullability fix.

This branch was successfully deployed

No deployments
ci — 372e2c91 Deployed Nov 5, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants