Skip to content

Fix role rule merging and case-equivalent replacement - #33164

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/8e8808928d71bd0964b10e78c825a8a656c4f507de139302abf4f78ab581befc
Nov 27, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/8e8808928d71bd0964b10e78c825a8a656c4f507de139302abf4f78ab581befc

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 24, 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:

What this PR does / why we need it:

  • Compatible rules from active roles now preserve string literals when their predicates are combined. Rules matching Alice and Bob return both rows and exclude rows matching neither rule.
  • In case-sensitive mode (lower_case_table_names=0), rules with differently cased source database or table names remain distinct. If the rules cannot be merged, the existing later-role precedence applies.
  • With lower_case_table_names=1, ADD RULE replaces a case-equivalent entry for the same role with one canonical catalog key in the same transaction. DROP RULE can remove a legacy spelling without affecting another role's entries.

The predicate merge uses the source-preserving implementation from #33132. It compares typed projections and table identities under the reader's name semantics and merges the original predicate text using the reader's SQL mode. The rule cache preserves existing prepared handles across equivalent mode changes and invalidates them when the effective rules change. The reporter can verify the three behaviors after merge.

ADD RULE validates definitions with the default parser before writing the original SQL. This rejects syntax supported only by the writer's SQL mode and preserves each reader's existing interpretation of the stored rule. Projection matching uses the parser's comparison spelling for function names and aliases. Case-only differences preserve the role union and the emitted SQL retains the original spelling.

Legacy catalog keys written with dots inside an identifier still block data access when the key cannot be interpreted. Existing transaction and session recovery statements can run. DROP RULE removes the exact legacy key for the specified role. See the compatibility finding.

Validation

  • The same SQL inputs reproduced all three failures on the pre-fix baseline. The final commit passed the corresponding SQL assertions, plus direct SQL checks for prepared-handle reuse and invalidation and for GET_FORMAT in merged predicates.

  • Frontend and parser package tests passed, including the parser tree package. The full frontend race run passed, and six focused race tests passed 100 iterations each. Incremental static checks passed.

  • The local single-CN zz_accesscontrol BVT run covered all 43 scripts. Of 3,204 checks, 3,187 passed and 17 had existing ignore markers. There were zero failures or errors. The original head's CI also passed Ubuntu x86 unit tests, static analysis, and multi-CN Compose BVT.

  • Rebased head 6a23c1df7419: the frontend and parser suites, planner TestShowRewriteMetadata, go vet, incremental golangci-lint, and the service build passed.

  • Single-CN mo-tester comparison passed all 488 assertions across role_rule, remap_role_rule, and role_rule_prepared. Direct SQL confirmed that rejecting an ANSI_QUOTES-only replacement preserves the installed policy and that ABS(id) and abs(id) preserve both role-filtered rows. Multi-CN Compose BVT and SCA passed on that head.

  • Compatibility fix cbacfd41d283: reproduced the ADD RULE failure in the Coverage UT job and locally. The unchanged TestCTASCarriesRoleRuleAcrossSQLModesAndRemap now passes with -tags matrixone_test -short -covermode=set -coverpkg=./pkg/frontend and emits a coverage profile. The frontend suite, go vet, incremental lint, and service build also passed. Coverage, required CI, and multi-CN Compose BVT subsequently passed for this commit in run 45439262654.

  • Projection-alias fix b13e8d60730b: the new regression test and the existing SQL fixture reproduced the dropped row on the previous head. After the fix, the frontend and parser suites (mo-cgo-test -tags matrixone_test), go vet, incremental lint, and the service build passed. Single-CN mo-tester passed all 487 assertions across role_rule, remap_role_rule, and role_rule_prepared, including both role-filtered rows in the alias case. GitHub CI will verify the new head across its full configuration.

  • Conflict rebase 0118de282db3 onto c90a2c4e5797: the frontend and parser suites passed with mo-cgo-test -tags matrixone_test -count=1. go vet -tags matrixone_test passed for frontend and SQL integration. The same wrapper passed TestCTASCarriesRoleRuleAcrossSQLModesAndRemap and TestNativePreparedRoleRuleSurvivesDisabledRemapHint in pkg/tests/sqlintegration. A fresh service build passed all 576 single-CN mo-tester assertions across role_rule, remap_role_rule, and role_rule_prepared, including the upstream and PR fixtures for legacy keys, reader modes, and projection aliases. The previous head's GitHub CI is historical evidence. Full GitHub CI remains pending for the rebase.

  • Legacy key recovery 81d49481c4fd: the new public SQL regression failed on dd0401022db7 at ROLLBACK and passed after the fix. The fixture seeds the catalog bytes produced by v4.2.8 and verifies rollback, blocked direct and prepared access, exact removal, preservation of another role’s entry, and restored reads. The frontend suite and two related SQL integration tests passed with -tags matrixone_test -short -count=1. Focused frontend tests passed with -race. go vet and incremental golangci-lint passed with matrixone_test. A full release-to-target cluster upgrade was not run. The preceding head’s CI passed.

  • Rebase onto a3aae79f39be at 0824f3b203b8 preserves both role-rule patches byte for byte. The frontend short suite and three focused SQL integration cases passed with mo-cgo-test -tags matrixone_test -short -count=1. The SQL cases cover legacy-key recovery, CTAS across SQL modes and remap, and prepared statements with remap disabled. go vet -tags matrixone_test passed for frontend and SQL integration. The prior Coverage UT attempt stopped at worker dispatch. The upstream rollout is included in the new base, and coverage and required CI passed on the second attempt.

  • Legacy spelling collision fix 663440753b1e addresses the recovery finding. A live SQL regression seeded the catalog keys and SQL accepted by the v4.2.9 writer. Before the fix, ROLLBACK failed while loading the discarded rule. On the candidate, ROLLBACK and the session's switch to IGNORE_SPACE work, default-mode reads stay blocked, stale prepared statements require re-prepare, and the canonical policy still filters rows. The frontend short suite and four SQL integration cases passed with mo-cgo-test -tags matrixone_test -short -count=1; seven focused frontend tests passed with the race detector. Scoped go vet and incremental golangci-lint passed. A full release-to-target upgrade was not run.

Performance and limitations

ADD and DROP scan the affected role's catalog keys inside the existing transaction. A parser-mode transition can reparse the cached rules to check for equivalent behavior. Ordinary cache hits avoid that work.

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

@mergify

mergify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: d83f0635872ad09b1b8720dce7a46d373e2536cf

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

Commit: d83f0635872ad09b1b8720dce7a46d373e2536cf

Assessment: request_changes

Canonical key replacement reuses the existing normalizer and transaction. Two regressions remain. ADD RULE can commit SQL that breaks queries for readers in another SQL mode, and case-only differences in function names can remove rows from a role union.

Model: gpt-6.2-sol / xhigh

Session: 01a20de6-4798-7d33-92a8-6fabbca9bb9d · slot 3 · generation 1

  • P1 pkg/frontend/rewrite_rule.go:1775: An administrator using ANSI_QUOTES adds a rule whose SELECT uses double-quoted table identifiers. A session with that role active uses the default SQL mode.
    Impact: ADD RULE commits successfully, but the reader gets a syntax error even on an unrelated SELECT because the hint reader parses every active rule before checking whether the statement uses its target.
    Evidence: The baseline validated ADD RULE with the default parser. The candidate validates in the writer’s mode at line 1775, stores the original SQL at line 1800, and reparses it in the reader’s mode at pkg/sql/parsers/sqlparse.go:755. TestRoleRuleDefinitionAcrossReaderModes confirmed the error on SELECT 1 and passed with backtick-quoted identifiers. Ensure committed rule definitions have consistent parsing semantics across writer and reader modes.

  • P2 pkg/frontend/rewrite_rule.go:1319: Two active roles use the same source and projection alias, with abs(id) AS id in one rule and ABS(id) AS id in the other, and different row filters.
    Impact: The merge falls back to the later role and omits rows allowed only by the earlier role. The baseline combined both filters.
    Evidence: TestRoleRuleProjectionFunctionSpelling showed that both calls bind as abs and produced equal baseline comparison keys. The candidate’s keys differ because pkg/sql/parsers/tree/expr.go:1001 prints the original function spelling. Compare function names using their parser comparison spelling while preserving literal values and case-sensitive source identifiers.

Validation:

  • Isolation preflight and git diff --check passed. See preflight.log, diff-check.log, and receipts checks/1795529705324837844-3.json and checks/1795530073441476218-2.json.

  • The parser, MySQL parser, and parser tree suites passed with Go 1.27.1 and matching native artifacts, including both diagnostic probes. See parser-tests-native.log and checks/1795530390536195116-2.json.

  • All 29 selected frontend tests passed, covering merge behavior, ADD/DROP and rollback, legacy keys, prepared handles, cache refresh, and session migration. See frontend-tests.log and checks/1795530627480965466-2.json.

  • The frozen CI snapshot reports successful Ubuntu x86 unit tests and multi-CN Compose BVT jobs for the reviewed head.

Limitations:

  • The diagnostic probes exercised the parser and hint reader. The catalog and query consequences follow from the reviewed frontend paths.

  • The supplied evidence contains CI job summaries and author-reported race and single-CN results. Per-case BVT logs and race logs were unavailable.

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · queue conditions no longer match

28 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 10:58 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 11:27 · dd04010

Reason

Pull request #33164 has been dequeued

Queue conditions are not satisfied:

  • #changes-requested-reviews-by<=0
  • approved-reviews-by=XuPeng-SH

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Requeue requested — the merge queue status continues in this comment ↓.

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH

XuPeng-SH commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dd0401022db7302fce18cfce928bbc1aa921c847

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

Commit: dd0401022db7302fce18cfce928bbc1aa921c847

Assessment: request_changes

The change reuses the existing rule normalization and cache owners and resolves the earlier case and SQL-mode concerns. A release-written legacy key can, however, block recovery after upgrade. This is new evidence not covered by the prior approval.

Model: gpt-6.1-terra / max

Session: 01a2172e-434d-7533-8bcf-86e4c749a300 · slot 1 · generation 20

  • P2 pkg/frontend/rewrite_rule.go:1277: A supported 4.2.8 deployment has a role rule whose quoted database or table identifier contains a dot, producing a persisted rule name with more than one separator.
    Impact: After upgrade, policy loading fails before affected sessions can reach the existing recovery handling for statements such as ROLLBACK. An administrator using another role also cannot remove the entry through the normal DROP RULE path. Ordinary rewriting of this key was already broken before this PR; the regression is the loss of the recovery and removal paths.
    Evidence: The 4.2.8 writer stores the concatenated identifier parts without validating the resulting key. The new cache load normalizes every stored key and returns an error before the recovery bypass. DROP RULE independently rejects the same identifier at line 2142. The exact-head mock-catalog probes confirm both failures with an ordinary-name control. Preserve a safe exact-key removal and recovery path for these legacy entries while continuing to fail closed for data access.

Validation:

  • The assigned-head parser-to-handler probe passed under the race detector, asserting the legacy failure and ordinary-name control. See legacy-parser-probe.log and checks/1795692282082604577-2.json.

  • Recovered the same-head focused frontend race run from attempt 1, including cache, merge, rollback, and legacy-key controls. See attempt-1/frontend-focus-race.log and attempt-1/checks/1795691701555785138-2.json.

  • Private runtime preflight passed. Release-writer, hotfix comparison, native provenance, and whitespace evidence are reconciled in validation-reconciliation.json.

Limitations:

  • The probes use a mock catalog; no live release-to-target upgrade was run.

  • The supplied local refs did not include the v4.2.9 writer. The finding relies on retained data written by the supported v4.2.8 release and its examined November 14 hotfix.

…saction

Keep upstream predicate and projection merging, collapse legacy target
spellings within each role, and preserve active-role order across them.
Track reader modes across policy cache refreshes and retain the role-rule
SQL and prepared-statement regressions.
@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 0824f3b203b8324ec5a2a5eeb50a14a53bb0a942

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

Commit: 0824f3b203b8324ec5a2a5eeb50a14a53bb0a942

Assessment: request_changes

The change reuses the existing rule cache, parser, and catalog transaction, but early validation leaves a released-data recovery regression. The earlier dotted-key case is addressed; a distinct collision between legacy key spellings can still block every statement in an affected session.

Model: gpt-6.1-terra / max

Session: 01a21d48-fe75-7291-ad0f-2597b59d3ead · slot 1 · generation 28

  • P2 pkg/frontend/rewrite_rule.go:1297: A supported v4.2.9 catalog has two rules for one role under the legacy spellings db. t and db.t, and the discarded rule contains select count (*) as id from db.t.
    Impact: After upgrade, loading the policy fails even for a reader using IGNORE_SPACE, where that rule is valid. Policy capture occurs before the recovery bypass, so statements including ROLLBACK and SQL-mode or secondary-role recovery also fail.
    Evidence: The v4.2.9 writer preserved the whitespace in the catalog key and accepted the spaced COUNT syntax; see the retained release429-rewrite.txt and release429-grammar.txt. The current parser test at pkg/sql/parsers/dialect/mysql/sql_mode_test.go:114 documents rejection in default mode and acceptance with IGNORE_SPACE. This new load-time check hardcodes the default mode and returns before pkg/frontend/rewrite_rule.go:547 can recognize a recovery statement. The merge-base loaded the distinct spellings separately and validated discarded rules in the reader's mode. Defer collision validation and merging until after recovery eligibility is known, using the reader's mode while retaining fail-closed behavior for ordinary statements.

Validation:

  • Reviewed the complete delta, linked issue, pinned repository policy, and all 14 indexed discussion items; dispositions are recorded in discussion-assessment.json.

  • Private runtime preflight passed (preflight.log; checks/1795787951800435946-3.json). The frozen-head diff check passed (diff-check-source.log; checks/1795788448300018699-3.json).

  • The frozen current-head CI snapshot reports successful x86 unit tests, coverage, proxy and pessimistic multi-CN BVT, and required CI.

  • Verified the v4.2.9 release commit and the latest listed v4.2.8 hotfix writer; retained release sources and check receipts in the diagnostic directory.

Limitations:

  • No local Go test ran: toolchain bootstrap timed out, and dependency discovery timed out after a Go 1.27.1 executable was made available. The finding is based on source analysis and the existing parser test, not a local executable reproduction.

  • No live release-to-target upgrade was run. Per-case CI logs and the author's local test logs were not supplied.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 663440753b1eacdbb8716ab59e1de8c136c8ada2

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

Commit: 663440753b1eacdbb8716ab59e1de8c136c8ada2

Assessment: approve

The role-rule changes reuse the existing catalog transaction, parser, and cache owners. The per-role key scan and cached mode-specific variants address legacy spellings and reader modes without adding work to ordinary cache hits. The earlier default-parser, projection-alias, dotted-key, and legacy-collision concerns are resolved in the current source and fixtures.

Model: gpt-6.1-terra / max

Session: 01a21d48-fe75-7291-ad0f-2597b59d3ead · slot 1 · generation 28

Validation:

  • Reviewed the complete delta, linked issue, affected callers, test oracles, and all 16 indexed discussion items. Dispositions are recorded in discussion-assessment.json.

  • Private runtime preflight passed (preflight.log; checks/1795798703412991339-2.json). The frozen-head diff check passed (diff-check.log; checks/1795798703396522274-2.json).

  • The frozen exact-head CI snapshot reports successful Ubuntu x86 unit, coverage, proxy and pessimistic multi-CN BVT, and required CI jobs.

  • The author reports current-head focused frontend, SQL integration, and race runs, including the legacy-collision recovery case.

Limitations:

  • The local focused frontend command did not reach the tests because the native CGo prerequisites were absent; frontend-focused.log and checks/1795799047385675219-2.json record the setup failure. No local Go test pass is claimed.

  • Per-case CI and author test logs were not supplied. No full release-to-target upgrade was reported; the compatibility assessment uses the recorded release-writer analysis and the release-compatible catalog-byte fixtures.

@mergify

mergify Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

1 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Fri 27 Nov, 17:07 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 17:07 · 6634407

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/entrypoint.yaml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

To get back in the queue

  • Update or rebase the branch yourself: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

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

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants