Repository navigation
fix: preserve view authorization across index joins and replacement - #30799
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
4eaa002 to
6f571b6
Compare
|
mo-bot review · Commit: "interrupted" |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 55 minutes 30 seconds in the queue, with no time running CI. ReasonPull request #30799 has been merged manually at 6495ce9 HintYou were too fast! Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
…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).
What type of PR is this?
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: