Skip to content

fix: correct information schema views metadata - #28903

Closed
gouhongshen wants to merge 76 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27655-view-definition
Closed

gouhongshen wants to merge 76 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27655-view-definition

Conversation

@gouhongshen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Documentation
  • Test and CI

Which issue(s) this PR fixes

Fixes #27655

Supersedes #27716, whose author branch is read-only for this account and is behind current main. The replacement preserves the reviewed implementation while making the current-main protocol allocation explicit.

What this PR does / why we need it

Information-schema VIEWS previously exposed incomplete or non-replayable metadata for persisted views. This PR makes the contract structural and mixed-version safe.

  • Persist a parser-derived, star-stabilized SELECT definition and CHECK OPTION in ViewData for newly created, altered, regenerated, cloned, and restored views.
  • Register mo_view_definition and mo_view_check_option. Current rows read frozen metadata without parsing; legacy rows parse their persisted Stmt with the saved SQL mode and lower-case setting, matching normal view binding and releasing every parsed AST.
  • Add MORPC v73 and function IDs 579/580. Upgrade, tenant initialization, and remote expression handling retain the predecessor VIEWS definition below v73 and reject the new function on unsupported peers.
  • Upgrade information_schema.VIEWS without changing public result widths; preserve legacy row visibility and ensure the metadata definition follows the same expanded-star statement used for execution.
  • Add parser, function, protocol, upgrade, system-view, and BVT coverage, including legacy --, #, and // comments immediately before AS.
  • Document the protocol/rollback ordering constraint.

Validation

  • go test ./pkg/sql/plan/function -count=1
  • go test ./pkg/util/sysview -count=1
  • go test ./pkg/bootstrap/versions/v4_0_6 -count=1
  • go test ./pkg/sql/compile -run 'Test.*(View|Remote)' -count=1
  • git diff --check origin/main...HEAD

All passed locally.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Closing this replacement PR: #28272 does not semantically depend on #27716. The open v73 allocation is a merge-order condition, so #28272 can rebase directly onto current main and claim the next version if it lands first.

XuPeng-SH added a commit that referenced this pull request Sep 16, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #26068

## What this PR does / why we need it:

### Root cause

Database-branch identity was inferred only from active ordinary-table
rows in `mo_branch_metadata`. A successfully created branch database
therefore lost all recognizable identity when its source had no ordinary
tables, or after all cloned ordinary tables were dropped. `DATA BRANCH
DELETE DATABASE` could not distinguish that database from an ordinary
database and rejected the delete.

### Implementation

- Persists the categorical `data-branch` identity in the existing
`mo_database.dat_type` field as part of the same internal `CREATE
DATABASE` operation.
- Uses one cluster-wide `MORPCVersion75` gate for every producer and
consumer: create, delete, publication classification, logical snapshot
restore, PITR, and account/cluster restore.
- Rejects branch-database creation below v75 before DDL; at v75 it
writes the marker atomically.
- Keeps table-receipt validation for every ordinary table. The database
marker handles only the previously ambiguous empty, view-only,
sequence-only, and all-tables-dropped cases.
- Makes ALTER PUBLICATION classify the effective persisted database even
when the statement omits a DATABASE clause, including correct
cross-account owner resolution.
- Preserves statement-local clone context across reusable `ExecCtx`
instances.
- Serializes branch database deletion against concurrent object DDL
using the existing exclusive `mo_database` catalog-row lock.
- Restores the marker from authoritative `dat_type` data and preflights
snapshot and PITR source identities at their public restore entries
before target-account creation, account deletion, session kill,
view-metadata invalidation, foreign-key cleanup, table restore, or
database replacement.
- Adds focused unit, embedded lifecycle, concurrency, restore,
multi-statement, and BVT coverage.

### Compatibility

Current main owns protocol versions v64 through v74, with v74 assigned
to corrected numeric HEX overload identities. This rebased PR claims the
next continuous version, v75; it does not depend on #27716 or #28903.
Concurrent PR #28950 must merge afterward as v76; the allocation order
is recorded in both PRs.

Below v75, new branch-database creation and marked restore input fail
before mutation, while existing table-backed branches continue to use
table receipts. Downgrade does not erase markers. Re-enabling v75
restores marker-aware behavior without migration. No catalog schema
migration is required because `dat_type` already exists and is persisted
by backup/checkpoint/replay.

The exact design revision is
`data-branch-database-identity-2026-09-16-r20`. Revision r20 keeps the
v75-then-v76 allocation order and v74/v75 boundary coverage, and moves
cluster, account, database, and table snapshot/PITR admission ahead of
irreversible account, metadata, FK, and object side effects.

### Validation

- `go test ./pkg/frontend -run
'Test(DataBranchDatabaseIdentityCapability|DataBranchCreateDatabaseRejectsBeforeExecutorBelowCapability|PrepareLogicalRestoreDatabaseCapability|NewLogicalRestoreDatabaseDefinitionRequiresTypeColumn|PreflightLogicalRestoreDatabases|ValidateDataBranchDeleteDatabaseTargetUsesDatabaseIdentity|LoadBranchDatabaseTypeRejectsMissingDatabase|InstallDataBranchCloneContextRestoresRequestContext|IsUserDatabaseType|DoAlterPublicationDataBranchIdentityCapability|MarkedDatabaseRestoreRejectsBeforeDestructiveWorkBelowCapability|MarkedAccountRestorePreflightsBeforeDestructiveWorkBelowCapability|ClusterRestorePreflightsBeforeAccountSideEffects|MarkedTableSnapshotRestorePreflightsBeforeFkSideEffects|RestorePitrPreflightsBeforeAccountCreation|RestorePitrPreflightsBeforeExistingAccountSideEffects|MarkedDatabaseRestorePreservesIdentityAtCapability)$'
-count=1`
- `go test ./pkg/tests/issues -run
TestIssue26068DataBranchDatabaseIdentityLifecycle -count=1`
- `go test ./pkg/sql/compile -run
TestCreateDatabaseChecksExistingBeforeSerializingAbsence -count=1`
- `git diff --check origin/main...HEAD`

All commands above pass after syncing current main; `go test
./pkg/frontend -count=1` also passes on PR head
`a1d4fa4ad6ea2a93643c665c38ceec85ae2bb0b7`. Isolated
`TestScope_Database` fails with the same `missing lock service` panic on
both this branch and exact base
`2ea4ec2e6ef4b20321a235ef416228506813e39b`; the PR does not modify that
DropDatabase lineage-lock path.

CI run 34948994437 passed the shared build, arm64 SCA, UT coverage, and
both Compose BVT jobs. Ubuntu/x86 UT ended after 71m43s with the global
timeout (Error 124) while unrelated fileservice and vm/engine tests were
still active; no #28272-owned test reported a failure. The preceding
rebased head 55339dc completed Ubuntu/x86 UT and all required checks
successfully. On pre-rebase head
`2d2af51450241340058720fe786d55a64d1db784`, all build, SCA, and BVT
checks passed. The two unrelated failures were rerun after their logs
established infrastructure or shared-runner causes: Ubuntu/x86 UT passed
in about 49 minutes, and UT Coverage passed in about 30 minutes. On
preceding head `81d463a7922448f5713ce10f9463a396e6876ba7`, build, arm64
SCA, UT Coverage, both BVT jobs, and the authorized Ubuntu/x86 UT rerun
all passed. Rebased review-fix head
`822050e783141dc047260991d1b8c6d67e57c474` passed build, arm64 SCA, UT
Coverage, Ubuntu/x86 UT, and both Compose BVT jobs. Current
restore-entry review-fix head `a1d4fa4ad6ea2a93643c665c38ceec85ae2bb0b7`
is running CI. The diff is confined to data-branch database identity,
its producer/consumer/restore paths, design, and tests; no CI workflow
is changed.

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to matrixorigin#26068

## What this PR does / why we need it:

### Root cause

Database-branch identity was inferred only from active ordinary-table
rows in `mo_branch_metadata`. A successfully created branch database
therefore lost all recognizable identity when its source had no ordinary
tables, or after all cloned ordinary tables were dropped. `DATA BRANCH
DELETE DATABASE` could not distinguish that database from an ordinary
database and rejected the delete.

### Implementation

- Persists the categorical `data-branch` identity in the existing
`mo_database.dat_type` field as part of the same internal `CREATE
DATABASE` operation.
- Uses one cluster-wide `MORPCVersion75` gate for every producer and
consumer: create, delete, publication classification, logical snapshot
restore, PITR, and account/cluster restore.
- Rejects branch-database creation below v75 before DDL; at v75 it
writes the marker atomically.
- Keeps table-receipt validation for every ordinary table. The database
marker handles only the previously ambiguous empty, view-only,
sequence-only, and all-tables-dropped cases.
- Makes ALTER PUBLICATION classify the effective persisted database even
when the statement omits a DATABASE clause, including correct
cross-account owner resolution.
- Preserves statement-local clone context across reusable `ExecCtx`
instances.
- Serializes branch database deletion against concurrent object DDL
using the existing exclusive `mo_database` catalog-row lock.
- Restores the marker from authoritative `dat_type` data and preflights
snapshot and PITR source identities at their public restore entries
before target-account creation, account deletion, session kill,
view-metadata invalidation, foreign-key cleanup, table restore, or
database replacement.
- Adds focused unit, embedded lifecycle, concurrency, restore,
multi-statement, and BVT coverage.

### Compatibility

Current main owns protocol versions v64 through v74, with v74 assigned
to corrected numeric HEX overload identities. This rebased PR claims the
next continuous version, v75; it does not depend on matrixorigin#27716 or matrixorigin#28903.
Concurrent PR matrixorigin#28950 must merge afterward as v76; the allocation order
is recorded in both PRs.

Below v75, new branch-database creation and marked restore input fail
before mutation, while existing table-backed branches continue to use
table receipts. Downgrade does not erase markers. Re-enabling v75
restores marker-aware behavior without migration. No catalog schema
migration is required because `dat_type` already exists and is persisted
by backup/checkpoint/replay.

The exact design revision is
`data-branch-database-identity-2026-09-16-r20`. Revision r20 keeps the
v75-then-v76 allocation order and v74/v75 boundary coverage, and moves
cluster, account, database, and table snapshot/PITR admission ahead of
irreversible account, metadata, FK, and object side effects.

### Validation

- `go test ./pkg/frontend -run
'Test(DataBranchDatabaseIdentityCapability|DataBranchCreateDatabaseRejectsBeforeExecutorBelowCapability|PrepareLogicalRestoreDatabaseCapability|NewLogicalRestoreDatabaseDefinitionRequiresTypeColumn|PreflightLogicalRestoreDatabases|ValidateDataBranchDeleteDatabaseTargetUsesDatabaseIdentity|LoadBranchDatabaseTypeRejectsMissingDatabase|InstallDataBranchCloneContextRestoresRequestContext|IsUserDatabaseType|DoAlterPublicationDataBranchIdentityCapability|MarkedDatabaseRestoreRejectsBeforeDestructiveWorkBelowCapability|MarkedAccountRestorePreflightsBeforeDestructiveWorkBelowCapability|ClusterRestorePreflightsBeforeAccountSideEffects|MarkedTableSnapshotRestorePreflightsBeforeFkSideEffects|RestorePitrPreflightsBeforeAccountCreation|RestorePitrPreflightsBeforeExistingAccountSideEffects|MarkedDatabaseRestorePreservesIdentityAtCapability)$'
-count=1`
- `go test ./pkg/tests/issues -run
TestIssue26068DataBranchDatabaseIdentityLifecycle -count=1`
- `go test ./pkg/sql/compile -run
TestCreateDatabaseChecksExistingBeforeSerializingAbsence -count=1`
- `git diff --check origin/main...HEAD`

All commands above pass after syncing current main; `go test
./pkg/frontend -count=1` also passes on PR head
`a1d4fa4ad6ea2a93643c665c38ceec85ae2bb0b7`. Isolated
`TestScope_Database` fails with the same `missing lock service` panic on
both this branch and exact base
`2ea4ec2e6ef4b20321a235ef416228506813e39b`; the PR does not modify that
DropDatabase lineage-lock path.

CI run 34948994437 passed the shared build, arm64 SCA, UT coverage, and
both Compose BVT jobs. Ubuntu/x86 UT ended after 71m43s with the global
timeout (Error 124) while unrelated fileservice and vm/engine tests were
still active; no matrixorigin#28272-owned test reported a failure. The preceding
rebased head 55339dc completed Ubuntu/x86 UT and all required checks
successfully. On pre-rebase head
`2d2af51450241340058720fe786d55a64d1db784`, all build, SCA, and BVT
checks passed. The two unrelated failures were rerun after their logs
established infrastructure or shared-runner causes: Ubuntu/x86 UT passed
in about 49 minutes, and UT Coverage passed in about 30 minutes. On
preceding head `81d463a7922448f5713ce10f9463a396e6876ba7`, build, arm64
SCA, UT Coverage, both BVT jobs, and the authorized Ubuntu/x86 UT rerun
all passed. Rebased review-fix head
`822050e783141dc047260991d1b8c6d67e57c474` passed build, arm64 SCA, UT
Coverage, Ubuntu/x86 UT, and both Compose BVT jobs. Current
restore-entry review-fix head `a1d4fa4ad6ea2a93643c665c38ceec85ae2bb0b7`
is running CI. The diff is confined to data-branch database identity,
its producer/consumer/restore paths, design, and tests; no CI workflow
is changed.

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to matrixorigin#26068

## What this PR does / why we need it:

### Root cause

Database-branch identity was inferred only from active ordinary-table
rows in `mo_branch_metadata`. A successfully created branch database
therefore lost all recognizable identity when its source had no ordinary
tables, or after all cloned ordinary tables were dropped. `DATA BRANCH
DELETE DATABASE` could not distinguish that database from an ordinary
database and rejected the delete.

### Implementation

- Persists the categorical `data-branch` identity in the existing
`mo_database.dat_type` field as part of the same internal `CREATE
DATABASE` operation.
- Uses one cluster-wide `MORPCVersion75` gate for every producer and
consumer: create, delete, publication classification, logical snapshot
restore, PITR, and account/cluster restore.
- Rejects branch-database creation below v75 before DDL; at v75 it
writes the marker atomically.
- Keeps table-receipt validation for every ordinary table. The database
marker handles only the previously ambiguous empty, view-only,
sequence-only, and all-tables-dropped cases.
- Makes ALTER PUBLICATION classify the effective persisted database even
when the statement omits a DATABASE clause, including correct
cross-account owner resolution.
- Preserves statement-local clone context across reusable `ExecCtx`
instances.
- Serializes branch database deletion against concurrent object DDL
using the existing exclusive `mo_database` catalog-row lock.
- Restores the marker from authoritative `dat_type` data and preflights
snapshot and PITR source identities at their public restore entries
before target-account creation, account deletion, session kill,
view-metadata invalidation, foreign-key cleanup, table restore, or
database replacement.
- Adds focused unit, embedded lifecycle, concurrency, restore,
multi-statement, and BVT coverage.

### Compatibility

Current main owns protocol versions v64 through v74, with v74 assigned
to corrected numeric HEX overload identities. This rebased PR claims the
next continuous version, v75; it does not depend on matrixorigin#27716 or matrixorigin#28903.
Concurrent PR matrixorigin#28950 must merge afterward as v76; the allocation order
is recorded in both PRs.

Below v75, new branch-database creation and marked restore input fail
before mutation, while existing table-backed branches continue to use
table receipts. Downgrade does not erase markers. Re-enabling v75
restores marker-aware behavior without migration. No catalog schema
migration is required because `dat_type` already exists and is persisted
by backup/checkpoint/replay.

The exact design revision is
`data-branch-database-identity-2026-09-16-r20`. Revision r20 keeps the
v75-then-v76 allocation order and v74/v75 boundary coverage, and moves
cluster, account, database, and table snapshot/PITR admission ahead of
irreversible account, metadata, FK, and object side effects.

### Validation

- `go test ./pkg/frontend -run
'Test(DataBranchDatabaseIdentityCapability|DataBranchCreateDatabaseRejectsBeforeExecutorBelowCapability|PrepareLogicalRestoreDatabaseCapability|NewLogicalRestoreDatabaseDefinitionRequiresTypeColumn|PreflightLogicalRestoreDatabases|ValidateDataBranchDeleteDatabaseTargetUsesDatabaseIdentity|LoadBranchDatabaseTypeRejectsMissingDatabase|InstallDataBranchCloneContextRestoresRequestContext|IsUserDatabaseType|DoAlterPublicationDataBranchIdentityCapability|MarkedDatabaseRestoreRejectsBeforeDestructiveWorkBelowCapability|MarkedAccountRestorePreflightsBeforeDestructiveWorkBelowCapability|ClusterRestorePreflightsBeforeAccountSideEffects|MarkedTableSnapshotRestorePreflightsBeforeFkSideEffects|RestorePitrPreflightsBeforeAccountCreation|RestorePitrPreflightsBeforeExistingAccountSideEffects|MarkedDatabaseRestorePreservesIdentityAtCapability)$'
-count=1`
- `go test ./pkg/tests/issues -run
TestIssue26068DataBranchDatabaseIdentityLifecycle -count=1`
- `go test ./pkg/sql/compile -run
TestCreateDatabaseChecksExistingBeforeSerializingAbsence -count=1`
- `git diff --check origin/main...HEAD`

All commands above pass after syncing current main; `go test
./pkg/frontend -count=1` also passes on PR head
`a1d4fa4ad6ea2a93643c665c38ceec85ae2bb0b7`. Isolated
`TestScope_Database` fails with the same `missing lock service` panic on
both this branch and exact base
`2ea4ec2e6ef4b20321a235ef416228506813e39b`; the PR does not modify that
DropDatabase lineage-lock path.

CI run 34948994437 passed the shared build, arm64 SCA, UT coverage, and
both Compose BVT jobs. Ubuntu/x86 UT ended after 71m43s with the global
timeout (Error 124) while unrelated fileservice and vm/engine tests were
still active; no matrixorigin#28272-owned test reported a failure. The preceding
rebased head 55339dc completed Ubuntu/x86 UT and all required checks
successfully. On pre-rebase head
`2d2af51450241340058720fe786d55a64d1db784`, all build, SCA, and BVT
checks passed. The two unrelated failures were rerun after their logs
established infrastructure or shared-runner causes: Ubuntu/x86 UT passed
in about 49 minutes, and UT Coverage passed in about 30 minutes. On
preceding head `81d463a7922448f5713ce10f9463a396e6876ba7`, build, arm64
SCA, UT Coverage, both BVT jobs, and the authorized Ubuntu/x86 UT rerun
all passed. Rebased review-fix head
`822050e783141dc047260991d1b8c6d67e57c474` passed build, arm64 SCA, UT
Coverage, Ubuntu/x86 UT, and both Compose BVT jobs. Current
restore-entry review-fix head `a1d4fa4ad6ea2a93643c665c38ceec85ae2bb0b7`
is running CI. The diff is confined to data-branch database identity,
its producer/consumer/restore paths, design, and tests; no CI workflow
is changed.

---------

Co-authored-by: XuPeng-SH <[email protected]>

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 kind/documentation Improvements or additions to documentation kind/enhancement kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: information_schema.VIEWS reports aggregate views as updatable and returns CREATE VIEW as the definition

4 participants