Skip to content

fix: preserve view authorization across index joins and replacement - #30799

Merged
XuPeng-SH merged 5 commits into
mainfrom
fix/view-authorization-30785-30786
Oct 22, 2026
Merged

XuPeng-SH merged 5 commits into
mainfrom
fix/view-authorization-30785-30786

Conversation

@aptend

@aptend aptend commented Oct 22, 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 #30785
Fixes #30786

What this PR does / why we need it:

A role with SELECT on a view can incorrectly receive error 20101 when a JOIN index rewrite adds an index scan without the original view's authorization path. Carry the source scan's complete view path, snapshot and binding context into that index access, so optimization preserves DEFINER/INVOKER authorization.

CREATE OR REPLACE VIEW also invalidates existing grants by running an ordinary DROP and allocating a new logical ID. Replace the physical view relation under the existing lifecycle and catalog locks while preserving its logical ID and grants, as ALTER VIEW does. Keep ordinary DROP privilege cleanup and reject replacement of a base table.

Extend the existing tenant view-grant and object-drop SQL cases with forced JOIN index access, nested DEFINER and INVOKER controls, replacement identity and grant-option checks, failed replacement, transaction rollback, and DROP/CREATE rejection. Add focused planner and DDL unit coverage, including legacy views without an explicit logical ID and lock/delete failures.

Source: @TrentShen.

Validation:

  • Reproduced both 20101 failures through SQL on clean main at a949c88; the same synthetic-data probe succeeds after the fixes.
  • Rebased onto main at 0f7616a. The build, complete pkg/sql/plan and pkg/sql/compile package tests, go vet and incremental golangci-lint passed.
  • drop_object_privileges.sql and grant_view_non_sys.sql passed twice in normal comparison mode (173/173 each), with account/database/role/grant teardown verified between runs. The object-drop case now asserts that replacement preserves the logical ID and existing grant; removing its redundant re-GRANT also checks that ALTER VIEW inherits that retained grant. Actual DROP cleanup checks remain covered.
  • TestIssue29399TableRestoreRetainsDatabaseOwnership passed with CI's -race -tags matrixone_test -short -parallel=2 mode. The preceding remote run failed in its account-cleanup deadline; no timeout or assertion was weakened.
  • Existing alter_view.sql and replace_view.test passed all 223 checks.

@aptend aptend added the kind/bug Something isn't working label Oct 22, 2026
@aptend aptend self-assigned this Oct 22, 2026
@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 →

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 6f571b67a3abbdbd5cc07b678941d79d2c37af41

"interrupted"

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: 6f571b67a3abbdbd5cc07b678941d79d2c37af41

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-xupeng · review

Commit: 6f571b67a3abbdbd5cc07b678941d79d2c37af41

Assessment: approve

Reviewed all eight changed files and surrounding authorization, catalog, locking, rollback and publication owners. Both fixes preserve existing ownership boundaries, with meaningful positive and negative coverage. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a15209-2c6d-71e2-b8f3-aa17387fa283 · slot 2 · generation 0

Validation:

  • Isolation preflight passed. Retained native artifacts matched 194 current native/module inputs and passed repository provenance verification.

  • Nine focused tests passed across pkg/sql/plan and pkg/sql/compile, including both new regression tests and existing index, identity and lifecycle controls.

  • Test execution matched receipt checks/1792652617986873835-3.json and focused-tests.log. Command, source fingerprint and exit status were independently reconciled.

  • Frozen head/base and patch content verified; source remained clean after testing. The initial patch comparison differed only by its terminal newline.

  • Evidence inventory and review map retained under /home/xupeng/.local/state/mo-bot/jobs/6845435f35ad2c7278f91104/attempt-1/validated-evidence.json and review-map.json.

  • Reviewed frozen successful CI statuses and SQL regression wiring, including tenant authorization, grant-option retention, rollback and ordinary DROP cleanup.

Limitations:

  • Did not independently rerun SQL BVT, distributed concurrency scenarios or performance benchmarks. Raw CI/author execution logs were not supplied; reported results were treated as supplemental evidence.

  • Linked issue bodies were absent from the frozen evidence; their behavioral contracts were assessed from the PR description.

@mergify mergify Bot added the queued label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-22 07:06 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-22 08:01 UTC · at f728bdf4861f3feb5a5108ffcf88c5bf68d6ef33

This pull request spent 55 minutes 30 seconds in the queue, with no time running CI.

Reason

Pull request #30799 has been merged manually at 6495ce9

Hint

You were too fast!

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 6495ce9 into main Oct 22, 2026
@XuPeng-SH
XuPeng-SH deleted the fix/view-authorization-30785-30786 branch October 22, 2026 08:01
@mergify mergify Bot removed the queued label Oct 22, 2026
XuPeng-SH pushed a commit that referenced this pull request Oct 22, 2026
…lacement (#30820)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #30785, #30786.
Backport of #30799 to `4.2-dev`.

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

View-only SELECT can fail with error 20101 when an index JOIN rewrite
loses the original scan's view authorization. CREATE OR REPLACE VIEW
also changes the view's logical identity and leaves existing grants
attached to the old object.

- Carry the original scan's complete `OriginViews`, `DirectView`,
snapshot and binding context into synthetic index JOIN scans, using the
authorization representation in `4.2-dev`.
- Replace the physical view inside the existing transaction and catalog
locks while preserving its logical ID and grants. Reject replacing a
base table; keep actual DROP/CREATE on a new identity.
- Initialize the engine relation's effective logical ID before
materializing its cached `TableDef`, matching the relevant prerequisite
already present in main (#29633). Repeated replacements in the same
transaction now retain the original identity through commit and
rollback; hidden index tables retain their own identities.
- Add planner/compiler regressions and extend the existing tenant
authorization case to cover nested DEFINER views, INVOKER/direct-table
denial, retained grant options, failed replacement, repeated replacement
with commit/rollback and DROP/CREATE isolation. The target branch lacks
main's orphan-grant cleanup; the last oracle checks that the newly
created view has no inherited grants.

Source: @TrentShen (MatrixOne Cloud production report).

Validation on `4.2-dev` with Go 1.26.4 and locally built native
dependencies:

- Before the metadata fix, the new engine regression observes cached
logical ID 0 and the extended SQL regression fails on lost
identity/access. Authenticated tenant probes reproduce error 20101 after
two replacements and commit with privilege cache both ON and OFF; after
the fix, both probes preserve logical identity and existing access, and
rollback restores the prior definition and identity.
- Complete `pkg/vm/engine/disttae`, `pkg/sql/compile` and `pkg/sql/plan`
suites pass. The new engine regression also passes with `-race -tags
matrixone_test -short -parallel=2`. Existing engine integration controls
`TestAlterTableBasic` and `TestRelationExists` pass.
- `make build`, changed-package `go vet`, and incremental golangci-lint
v2.6.2 pass (0 lint issues).
- `grant_view_non_sys.sql` passes twice on the same instance (65/65
each), with account cleanup and global privilege-cache restoration
checked after each run. Related `alter_view.sql` and `replace_view.test`
pass (113/113 total).

This branch was previously deployed

1 inactive deployment
ci — f728bdf4 Deployed Oct 22, 2026 by mergify[bot]
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CREATE OR REPLACE VIEW invalidates existing grants [Bug]: view SELECT grant fails after JOIN index scan rewrite

3 participants