Skip to content

Improve role base rule rewrite (#24393) - #24415

Merged
mergify[bot] merged 7 commits into
matrixorigin:3.0-devfrom
ouyuanning:cp-24393-to-3.0-dev
May 17, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:3.0-devfrom
ouyuanning:cp-24393-to-3.0-dev

Conversation

@ouyuanning

@ouyuanning ouyuanning commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

1、修复多角色合并时改写规则不起效的问题
2、多角色起效时,不同角色对同一个库表都有改写规则的时候,如果列一致的情况下,那么做union distinct合并。否则保留最后一个规则

Approved by: @heni02, @XuPeng-SH

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23271

What this PR does / why we need it:

1、修复多角色合并时改写规则不起效的问题
2、多角色起效时,不同角色对同一个库表都有改写规则的时候,如果列一致的情况下,那么做union distinct合并。否则保留最后一个规则

1、修复多角色合并时改写规则不起效的问题
2、多角色起效时,不同角色对同一个库表都有改写规则的时候,如果列一致的情况下,那么做union distinct合并。否则保留最后一个规则

Approved by: @heni02, @XuPeng-SH
@ouyuanning
ouyuanning requested a review from XuPeng-SH as a code owner May 16, 2026 02:01
@ouyuanning
ouyuanning requested a review from a user May 16, 2026 02:01
@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 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.

Request changes:

  1. SET ROLE does not invalidate the rewrite cache, so the session can keep applying rules loaded for the previous role set after a role switch.
  2. Rewrite merge currently treats all non-aggregate/non-window scalar functions as safe, which still admits volatile functions like rand(), uuid(), and now() into union distinct merging.

@ouyuanning
ouyuanning requested a review from aunjgr as a code owner May 16, 2026 03:39
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label May 16, 2026

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

Request changes:

rewrite_rule mergeability currently treats set-operation rules unsafely: outputColumnsFromRewriteSelectStatement() handles *tree.UnionClause by returning only the LEFT branch and ignoring RIGHT branch + Type/All/Distinct (UNION/UNION ALL/INTERSECT/EXCEPT/MINUS).

As a result, rules like select a ... union all select now() ... can be misclassified as mergeable, and later merged via union distinct even though semantics differ. Please make set-operation rules non-mergeable (or validate both branches and set-op type strictly), and update tests that currently codify left-only behavior.

@ouyuanning

Copy link
Copy Markdown
Contributor Author

Request changes:

rewrite_rule mergeability currently treats set-operation rules unsafely: outputColumnsFromRewriteSelectStatement() handles *tree.UnionClause by returning only the LEFT branch and ignoring RIGHT branch + Type/All/Distinct (UNION/UNION ALL/INTERSECT/EXCEPT/MINUS).

As a result, rules like select a ... union all select now() ... can be misclassified as mergeable, and later merged via union distinct even though semantics differ. Please make set-operation rules non-mergeable (or validate both branches and set-op type strictly), and update tests that currently codify left-only behavior.

已处理

@ouyuanning

Copy link
Copy Markdown
Contributor Author

Request changes:

  1. SET ROLE does not invalidate the rewrite cache, so the session can keep applying rules loaded for the previous role set after a role switch.
  2. Rewrite merge currently treats all non-aggregate/non-window scalar functions as safe, which still admits volatile functions like rand(), uuid(), and now() into union distinct merging.

已处理

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

LGTM. 多角色规则合并逻辑正确,错误处理改进明显,测试覆盖充分。

Minor suggestions for future improvement:

  1. getSqlForRoleIDsOfUserForRuleCache / getSqlForInheritedRoleIDsForRuleCache select with_grant_option but never use it — can be removed.
  2. Consider adding a depth/count limit for BFS role traversal to guard against pathological inheritance graphs.

@mergify

mergify Bot commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-17 09:37 UTC · Rule: release-3.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-17 09:37 UTC · at 1f7bac5b0eca05d9684bdbc6d1471282db3b96a6 · squash

This pull request spent 25 seconds in the queue, including 5 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

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/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants