Skip to content

fix(plan): preserve source defaults in view metadata - #26729

Merged
XuPeng-SH merged 22 commits into
matrixorigin:mainfrom
ck89119:issue-26232-main
Aug 8, 2026
Merged

XuPeng-SH merged 22 commits into
matrixorigin:mainfrom
ck89119:issue-26232-main

Conversation

@ck89119

@ck89119 ck89119 commented Aug 5, 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:

Fixes #26232

What this PR does / why we need it:

genViewTableDef already receives the authoritative OutputColumnProvenance introduced for #26226, but it only consumed that provenance for ENUM/SET types and discarded source column defaults. As a result, a direct source column such as qty INT NOT NULL DEFAULT 7 lost its persisted default in View metadata.

This change:

  • snapshots the complete explicit source plan.Default, including its typed Expr, in the existing planner-local provenance;
  • persists that default only for outputs with unique source-column provenance, while preserving final output nullability;
  • keeps aliases, explicit View column names, transparent derived tables, non-recursive CTEs, View-of-View, and precisely bound join columns eligible;
  • continues to clear default provenance for constants, semantic expressions, aggregates, set operations, recursive CTEs, and non-unique outputs;
  • separates View metadata inheritance from CTAS default policy, so CTAS from a View does not copy the View/source default 7 and instead uses an executable integer target default 0 where the MySQL behavior is independently covered;
  • preserves [Bug]: View projection loses ENUM/SET ordering and CTAS type metadata #26226 ENUM/SET type, ordering, CTAS, and raw-value transport behavior.

Validation:

  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/sql/plan
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m -run 'TestIssue262(26|32)' ./pkg/tests/issues
  • focused planner tests under -race
  • go build and go vet for the affected packages with the repository CGo include contract

The embedded SQL regression independently checks View DESC, information_schema.columns, and SHOW CREATE VIEW, then checks CTAS DESC, information_schema.columns, SHOW CREATE TABLE, and an INSERT that omits the NOT NULL target column.

@ck89119
ck89119 requested a review from a user August 6, 2026 09:25
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Aug 6, 2026
# Conflicts:
#	pkg/sql/plan/build_ddl_test.go

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

Reviewed at head dad9696 against main@629cbbe2fe51d6d457a31f450c7e5c1bc4628213. No actionable correctness, compatibility, lifecycle, or performance issues found. GitHub CI is green; focused planner and frontend YEAR tests passed.

This branch was previously deployed

1 inactive deployment
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: View metadata drops source defaults and breaks View CTAS inserts

3 participants