Skip to content

fix(data branch): skip generated columns during apply - #26580

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26040
Aug 2, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26040

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 2, 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 #26040

What this PR does / why we need it:

Root cause

DATA BRANCH used one column classification for both read-only output and destination writes. Generated columns are user-visible and participate in DIFF/row identity, but they are not writable. Including them in MERGE, PICK, and portable-SQL INSERT layouts caused error 20301; excluding them from the shared visible layout instead removed them from plain DIFF, COLUMNS(...), and OUTPUT AS.

Schema compatibility also treated generated expressions as endpoint-local protobuf values. Generated column references store local column ordinals, so reordered unrelated schemas could make different logical references protobuf-equal, or make equivalent references unequal. That could let MERGE succeed while the destination recomputed a different value and could also corrupt generated-primary-key row identity.

Changes

  • Separate user-visible and destination-writable column classifications: generated columns remain visible for DIFF, projections, OUTPUT AS, and row identity, while STORED and VIRTUAL generated columns are omitted from all apply/portable-SQL writes.
  • Build a common writable layout from the common visible layout for MERGE/PICK apply paths.
  • Canonicalize every generated-expression column reference through its endpoint table definition and the existing lineage resolver before comparing expressions.
  • Require matching generated-column kind, storage mode, and logical expression metadata before columns are considered schema-compatible, including generated primary keys.
  • Fail closed when generated expression metadata, a referenced logical column, or a GeneratedColBinder-unsupported expression kind cannot be resolved safely.
  • Preserve the existing rejection of base-only visible columns and ordinary/generated mismatches.
  • Extend focused unit tests and BVT coverage for read-only visibility, writable layouts, lineage renames, reordered schemas, matching/mismatched formulas, generated primary keys, MERGE, PICK, portable SQL, projections, and OUTPUT AS.

Tests

  • make build
  • CGo-configured go vet -mod=readonly ./pkg/frontend
  • CGo wrapper: go test -count=1 -timeout=600s -coverprofile=... ./pkg/frontend
  • CGo race wrapper: go test -race -count=1 -timeout=600s ./pkg/frontend
  • CGo race wrapper: each of TestCanonicalizeDataBranchGeneratedExpr, TestDataBranchGeneratedColumnsLogicallyEqualBoundaries, and TestCheckSchemaCompatibility_GeneratedDefinitionsUseLogicalColumnIdentity passed independently with -race -count=100 (T below timer resolution, B=30s, N=100).
  • MatrixOne CI's exact parse_coverage.py against the complete PR diff and local frontend profile: 57/72 changed lines covered, 79.17% (required >75%).
  • mo-tester -i merge_generated_column -r 100: 80/80 statements passed; the generated result was manually inspected against the SQL semantics.
  • Pre-fix reproduction: MERGE failed with error 20301 and left the destination unchanged.
  • Post-fix coverage verifies STORED MERGE and VIRTUAL PICK converge, portable SQL omits generated destinations, read-only outputs retain generated values, reordered matching formulas converge, and reordered mismatched ordinary/generated-PK formulas are rejected without changing the destination.

Residual risks

No known residual risk. Generated-definition comparison is deliberately fail-closed when usable expression metadata or logical reference identity is absent. The change is confined to DATA BRANCH schema classification/validation and tests; it adds no concurrency, resource-lifecycle, or storage-lifecycle behavior.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

All previous blockers are fixed: generated columns remain visible while apply paths use writable columns only; incompatible generated definitions are rejected; and column references are compared by logical identity. The new single non-merge commit preserves those fixes and makes unsupported generated-expression kinds fail closed. No blocker or non-blocking finding remains. Diff/format checks passed; focused frontend tests could not start because cgo/libmo.dylib is absent.

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

Re-reviewed the full PR and the single commit added after my previous approval. The increment only tightens generated-expression canonicalization: leaf oneof kinds without column references remain comparable, while endpoint-dependent kinds that GeneratedColBinder rejects now fail closed; the earlier logical ColRef mapping and all visible/writable apply semantics are unchanged. The new boundary tests are deterministic, cover nil/origin/storage/resolution failures and unsupported oneof kinds, and both new focused tests passed under -race -count=100. Latest CI is also green. No correctness, compatibility, hot-path, lifecycle, wait-for, or unbounded-growth blocker remains.

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]: DATA BRANCH apply paths write generated columns explicitly and fail

3 participants