Skip to content

[Bug]: CREATE OR REPLACE VIEW invalidates existing grants #30786

Closed

Description

@aptend

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

v4.2.1

Commit ID

d239386

Other Environment Information

  • Environment: MatrixOne Cloud (MOC) serverless tenant
  • Server: 8.0.30-MatrixOne-v4.2.1
  • Client: PyMySQL over TLS
  • Source: @TrentShen (feedback dated 2026-10-21)

Actual Behavior

After a view has been granted to a role, CREATE OR REPLACE VIEW replaces its catalog object with a new logical object ID. Existing grants remain associated with the previous ID (on v4.2.1) and no longer authorize queries. A reader then gets error 20101. Granting SELECT on the replacement view again restores access.

This was observed in production and reproduced on the reported v4.2.1 image. MatrixOne main also loses the effective grant during replacement, although its DROP cleanup removes the old privilege row instead of leaving it orphaned.

Expected Behavior

Replacing the definition of an existing view with the same name should preserve that view's existing grants. If replacement is intended to have DROP-and-CREATE privilege semantics, the behavior should be explicitly documented and surfaced rather than silently invalidating access during an idempotent DDL replay.

Steps to Reproduce

Run as a tenant administrator:

CREATE DATABASE app;
CREATE TABLE app.t1 (id INT);
INSERT INTO app.t1 VALUES (42);
CREATE VIEW app.v1 AS SELECT id FROM app.t1;

CREATE ROLE reader;
GRANT CONNECT ON ACCOUNT * TO reader;
CREATE USER observer IDENTIFIED BY 'test-password' DEFAULT ROLE reader;
GRANT reader TO observer;
GRANT SELECT ON VIEW app.v1 TO reader;

Connect as observer with role reader and verify:

SELECT * FROM app.v1;
-- Returns 42.

As administrator, replace the view with the same definition:

CREATE OR REPLACE VIEW app.v1 AS SELECT id FROM app.t1;

In a fresh observer session, run SELECT * FROM app.v1 again. It fails with error 20101. As administrator, regrant and retry:

GRANT SELECT ON VIEW app.v1 TO reader;

The reader query succeeds after the new grant. Comparing the view's catalog logical ID before and after replacement shows that it changed, while the original grant referred to the old object ID.

Additional information

The behavior makes routine idempotent view deployment silently revoke access. Replacement should preserve the existing logical identity and grants, or migrate the grants to the replacement object as part of the same operation. A regression test should also check that an actual DROP followed by CREATE does not inherit the dropped view's grants.

Activity

  1. added
    kind/bug
    on Oct 22, 2026
  2. added a commit that references this issue on Oct 22, 2026
    6495ce9
  3. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    QA follow-up for PR #30820, updated head 551de35250d6f52eff054db874c7567f70ba0c1c:

    The new commit moves effective logical-ID resolution before the transaction relation's GetTableDef cache is materialized. It adds an engine regression and extends the tenant SQL case for repeated replacement with commit/rollback and grant retention. Static review indicates this directly addresses the stale cached LogicalId=0 path from the earlier P2.

    The author reports the engine/compile/plan suites, focused race test, build, vet/lint and related BVTs passing on this head; these are author-reported results, not an independent rerun. A re-review was requested, but the formal CHANGES_REQUESTED review still targets the prior head, and its inline thread remains unresolved. The current head has no combined status checks; MongoDB and Iceberg connector workflows are in progress and unrelated.

    I consider the reported root cause addressed by the new code and regression, pending exact-head independent verification/formal re-review. Issue remains open; existing assignees (aptend, Ariznawlll) are unchanged.

  4. slyunnn commented on Oct 23, 2026

    @slyunnn

    Regression and extended verification for #30786 (2026-10-23)

    Verification Environment

    • Latest fetched MatrixOne origin/main: e19f698de0fc52a60f60f2ff689d6d16a5100334 — fix(frontend): keep Decimal256 primary-key pairing in DATA BRANCH (#30837). Clean source HEAD matched this commit; the runtime was rebuilt with Go 1.27.1, Linux/arm64, TYPECHECK=1, and restarted. Binary version, SQL git_version() and current-start service readiness were verified.
    • Additional exact-head verification: 551de35250d6f52eff054db874c7567f70ba0c1c — [4.2-dev] fix: initialize logical identity before caching table definitions, the updated head requested in the preceding QA comment. Its matching Go 1.26.4, Linux/arm64 binary was restarted and checked. This is the specified backport head, not a claim about the latest 4.2-dev tip or production deployment.
    • Each version used a complete local 2 CN / 1 TN / 1 Log service / Proxy topology with separate version-owned storage. Actual Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001 and CN2 127.0.0.1:16002 were reachable, and each endpoint executed the original and extended SQL, not just health checks.
    • Clients: PyMySQL over MySQL text protocol (COM_QUERY), plus existing mo-tester BVTs through Connector/J. Administrative and fresh reader sessions explicitly set and verify enable_privilege_cache as both OFF and ON. Production MOC/TLS and binary prepared-statement execution were not tested.

    What Was Covered

    • OK — Original reproduction at all three endpoints: a reader with only SELECT ON VIEW reads 42, then continues reading 42 after identical-definition CREATE OR REPLACE VIEW, without regranting. Direct base-table access remains denied with 20101.
    • OK — Replacement changes the physical ID while preserving the logical ID and existing grant records. Changed definitions return the new result. Retained WITH GRANT OPTION is checked both in metadata and by successfully delegating access to another role/user.
    • OK — Two replacements within one transaction retain the original logical identity before and after COMMIT; both readers observe the final definition. Two further replacements followed by ROLLBACK restore the committed physical ID, logical ID, definition and grants. This independently exercises the cached logical-ID path highlighted in the preceding comment.
    • OK — Missing-source replacement returns 1146; replacing a base table returns 1050. Failed replacements preserve the existing view, source data, identity, grants and reader access.
    • OK — Authorized empty and NULL results remain accessible. Actual DROP VIEW followed by CREATE VIEW gets a new identity and inherits neither the original reader's nor the delegated role's object grants; both are denied with 20101. Explicit regrant restores access, and revoke denies it again.
    • OK — The endpoint/cache matrix passed 282/282 checks on main and 282/282 on the exact backport head. Endpoint jobs ran concurrently with isolated tenants; lifecycle operations within each tenant ran in order. No engine-parallel execution claim is made.
    • OK — Main focused compiler regressions passed, including existing-view/legacy-ID handling, absent view, IF NOT EXISTS, base-table rejection and lock/delete failures. On the exact backport head, the compiler regression and engine TestCreateTablePublishesLogicalIdentity passed, including the hidden-index identity control.
    • OK — Existing BVTs passed twice on the same instance per version: main 396/396 each run; backport 178/178 each run. All runs had 0 failed, abnormal or ignored checks. Created accounts, roles, users, tables/views and snapshots were checked for cleanup; global settings were restored. Main topology was restored afterward.
    • Not covered — Production MOC upgrade/TLS replay, fresh execution on the originally affected v4.2.1 image, concurrent competing DDL, long-lived reader-session invalidation, TKE, performance/soak testing and a new race/full-package run. Author-reported broader validation is not represented as independently rerun here.

    Findings

    Main fix: PR #30799, merge 6495ce997486c2445994081c1d85c39802f7049b — fix: preserve view authorization across index joins and replacement.

    Backport: PR #30820, merge 4b11cd642008a0fd86ee3087d788f9c057b8a11a — [4.2-dev] fix: preserve view authorization across index joins and replacement. Its tested head includes 551de35250, which initializes effective logical identity before GetTableDef caches it.

    Replacement now retains the view's logical identity rather than applying ordinary drop-and-create grant semantics. Repeated replacement, commit/rollback and independent reader checks passed on both tested versions. This supplies independent functional evidence for the prior QA follow-up; it is not a formal PR review submission or confirmation that production has been upgraded.

    MOTR / BVT Coverage

    Reused committed regressions: TestCreateOrReplaceViewPreservesIdentity, main TestAlterViewPreservesLogicalID, backport TestCreateTablePublishesLogicalIdentity, and grant_view_non_sys.sql. Main additionally ran drop_object_privileges.sql; both versions ran their existing alter_view.sql and replace_view.test cases. The backport tenant case directly covers repeated transactional replacement with commit/rollback.

    No duplicate MOTR case was needed, so no new recording, regression commit, branch push or weekly PR update was made. Existing expected results were compared unchanged. BVTs ran serially/exclusively because they use fixed object names and global cache/case-sensitivity settings; the separate tenant-isolated endpoint matrix ran concurrently. No MatrixOne service or test source was modified.

    Final Conclusion

    Fixed on the tested latest-main commit and specified 4.2-dev backport head: CREATE OR REPLACE VIEW preserves existing effective grants, including repeated replacements within a transaction; true DROP/CREATE remains privilege-isolated.

    Large-data regression is not required: the defect concerns catalog identity, transaction-local metadata caching and grant binding, not row counts, batch/block boundaries or resource scale. One source row distinguishes the outcomes; additional volume would not improve this acceptance evidence.

    The issue remains open for maintainer acceptance. No issue state, labels or assignees were changed.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions