Skip to content

fix(plan): preserve row rewrite rules through views - #29695

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/issue-29093-main
Oct 9, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/issue-29093-main

Conversation

@iamlinjunhong

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:

issue #29093

What this PR does / why we need it:

An ordinary view expansion created an isolated planner bind context without carrying the effective row rewrite policy from the outer query. Role row access rules therefore applied to direct base-table scans but were skipped when the same table was reached through a view.

This change propagates only the rewrite option into the view context while preserving the view's independent name and CTE scope. Nested view expansion and existing stacked rewrite-chain handling continue to apply the policy to the underlying base table. The access-control regression covers direct and ordinary-view queries with enable_remap_hint enabled and disabled.

Validation:

  • GOWORK=off go list -mod=readonly ./pkg/sql/plan
  • GOWORK=off go build -mod=readonly ./pkg/sql/plan
  • GOWORK=off go vet -mod=readonly ./pkg/sql/plan
  • GOWORK=off go test -mod=readonly -v -count=1 -timeout 120s ./pkg/sql/plan
  • Added role_rule distributed regression for ordinary views.

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

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Oct 8, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Oct 8, 2026
@iamlinjunhong
iamlinjunhong force-pushed the codex/issue-29093-main branch from 0fd5ab9 to d8e3eb8 Compare October 8, 2026 11:48
@iamlinjunhong
iamlinjunhong force-pushed the codex/issue-29093-main branch from d8e3eb8 to be97ba2 Compare October 8, 2026 15:15

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

Deep review: APPROVE on 6e55734cd3c5b53ff03087ad2fc31905317cfbd5. Reviewed directly, without subagents. No blocking findings.

The previous saved-view binding-mode finding is resolved in code and verified through the public MySQL path: a mode-0 view queried by a mode-1 caller now binds the replacement qualifier correctly. Policy-key normalization remains separate from the stored view's name-resolution mode.

Design and scope: all four changed files/hunks reviewed. bindView retains its independent name/CTE scope and carries the existing rewrite policy into the existing stacked-rewrite mechanism. The short qualifier inside a view agrees with ordinary table binding and persisted star expansion. No duplicate policy owner, state machine, storage, cache, or execution path was introduced. This is a focused bug fix; a separate feature design is unnecessary. Production +17/-3; tests +86/-0; documentation unchanged. The BVT extends the existing role/data fixture and teardown.

Validation:

  • Reused exact-head CI run 37887975994: owning planner race shards and Linux SCA passed. The compose BVT log confirms zz_accesscontrol/role_rule.sql actually ran, with 206/206 checks passing (2.022s).
  • Ran TestBindViewPropagatesOuterRewriteOption through the controlled CGo wrapper: PASS.
  • Ran an independent, review-only public SQL probe twice against the same isolated instance: PASS. It checked exact visible IDs through direct/ordinary/nested/CTE views, aliases and qualification, self/left joins, outer-CTE scope isolation, native prepared reuse with the optional hint both off and on, stacked role/session rules, invalid-policy rejection and same-session recovery, and the saved/caller case-mode boundary. Database/user/role teardown postconditions were checked after each round. The two-round probe completed in 9.01s (10.523s package total).
  • A challenged mode-1 rewrite source naming an inaccessible case-sensitive physical table returned the same 1146 through direct SQL and the view; the corresponding valid current-mode source passed. That input is not evidence of a view-specific regression.

Performance: the added propagation/qualifier work is in planning. View queries now perform the required policy rewrite and filtering that they previously bypassed. There is no new executor path, synchronization, or background resource. This is a code-path assessment, not a measured TP-throughput claim; no throughput benchmark was run.

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

mergify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-09 07:40 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-09 08:30 UTC · at 012d4ea54c1e185e0a4ac19bb1c517e5596d1b18

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

Reason

Pull request #29695 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

This branch was previously deployed

1 inactive deployment
ci — 012d4ea5 Deployed Oct 9, 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.

3 participants