Skip to content

[4.1.6-hotfix] fix(frontend): preserve string literals in merged role rules - #32890

Merged
XuPeng-SH merged 11 commits into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-22006-4.1.6-hotfix
Nov 19, 2026
Merged

XuPeng-SH merged 11 commits into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-22006-4.1.6-hotfix

Conversation

@ck89119

@ck89119 ck89119 commented Nov 18, 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 matrixorigin/matrixflow#22006

What this PR does / why we need it:

On 4.1.6-hotfix, merging two compatible role rules rebuilds their SELECT with an OR predicate. The default formatter emits decoded string values without SQL quotes. When the rewrite hint is read back, a value such as '0001' can become a number, and other values can make the rule fail to parse.

Use the existing single-quoted SQL literal formatter only when emitting the merged SELECT. Rule eligibility, fallback, cache invalidation and the source-row union from #24929 are unchanged.

The unit test compares reparsed trees for Unicode, zero-padded strings in a subquery, an embedded quote and a backslash. It failed at reparse before the fix and passes after it. The role-rule BVT now distinguishes '0001' from '1': one role sees one row; two roles see both matching rows even though their projections are equal. Re-saving the rule and querying from a new session produces the same result.

Local validation: full pkg/frontend unit tests, go vet, incremental golangci-lint, and zz_accesscontrol/role_rule.sql via mo-tester (335/335 passed).

@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 18, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

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

The literal and identifier handling fixes the reported examples, but the new merged-rule serialization still produces invalid SQL for supported predicates. I reproduced the user-visible failure with a real CN and two active roles; details and the requested regression coverage are in the inline comment.

This failure also exists on the base commit; it is not a regression introduced by this PR. I am requesting its closure because it affects the same multi-role rule round-trip that this change is intended to make reliable.

Validation: the frontend, MySQL parser and tree short tests and focused race tests passed; the existing role-rule BVT passed 355/355 on this head. An independent predicate round-trip matrix and a real multi-role SQL reproduction exposed the issue.

Comment thread pkg/frontend/rewrite_rule.go Resolved

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

The current head addresses the previously reported POSITION, EXTRACT and REGEXP round-trip failures. The merged formatter preserves string values and quoted identifiers, and the binary literal representation survives repeated merges. I found no additional blocking code issue in this review.

Validation on 60ae27bd1dfeaebf934bd56b41f735e9133ceb38:

  • Full pkg/frontend, pkg/sql/parsers/dialect/mysql, and pkg/sql/parsers/tree tests passed. Focused frontend race tests passed.
  • The isolated single-CN role_rule.sql BVT passed 355/355 twice. A separate two-role probe combining POSITION, EXTRACT, and REGEXP returned row 1 with the primary role and rows 1 and 2 with both roles.
  • The generated parser matches the grammar source. Additional predicate and string-escape round-trip probes passed apart from the existing AST spelling difference for the INTERVAL keyword, which preserves its parsed meaning.

CI remains red on this head: the x86 UT and arm64 SCA jobs failed, and their job logs are unavailable. Their failure causes are unverified, so the CI results still need investigation or a successful rerun before merge.

This branch was previously deployed

1 inactive deployment
ci — 60ae27bd Deployed Nov 18, 2026 by ck89119
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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants