Repository navigation
Description
Description
When a user enables compatible secondary roles, row rewrite rules must combine at the base-row level with OR semantics. On current main, SET SECONDARY ROLE ALL does not add rows made visible by granted secondary roles: the query still returns only the default role's rows.
This is broader than duplicate-projection handling. The original minimal case, where two independently visible base rows both project to a=1, returns one row/count instead of two. The current direct E2E also shows the non-overlapping base-row union itself is missing.
Environment
- MatrixOne:
main@480b91764a94cf9ab49d3f2b43a60cb63ce677c6 - Earlier minimal reproduction:
main@780ef933f2479aa1679faf13d08850ce6c8f7c2f - Deployment: macOS arm64, single-node local isolated MatrixOne service
- Required session setting:
enable_remap_hint = 1
Steps to reproduce
CREATE DATABASE rcac_secondary;
CREATE TABLE rcac_secondary.sales(order_id INT PRIMARY KEY, tenant_id INT);
INSERT INTO rcac_secondary.sales VALUES (1,1), (2,2), (3,3), (4,1);
CREATE ROLE rcac_r1, rcac_r2, rcac_r3;
ALTER ROLE rcac_r1 ADD RULE "select * from rcac_secondary.sales where tenant_id = 1" ON TABLE rcac_secondary.sales;
ALTER ROLE rcac_r2 ADD RULE "select * from rcac_secondary.sales where tenant_id = 2" ON TABLE rcac_secondary.sales;
ALTER ROLE rcac_r3 ADD RULE "select * from rcac_secondary.sales where tenant_id = 3" ON TABLE rcac_secondary.sales;
CREATE USER rcac_secondary_u IDENTIFIED BY '<test-password>' DEFAULT ROLE rcac_r1;
GRANT CONNECT ON ACCOUNT * TO rcac_r1;
GRANT SELECT ON TABLE rcac_secondary.sales TO rcac_r1, rcac_r2, rcac_r3;
GRANT rcac_r2, rcac_r3 TO rcac_secondary_u;Log in as rcac_secondary_u and execute:
SET enable_remap_hint = 1;
SELECT order_id FROM rcac_secondary.sales ORDER BY order_id;
SET SECONDARY ROLE ALL;
SELECT order_id FROM rcac_secondary.sales ORDER BY order_id;
SET ROLE rcac_r2;
SELECT order_id FROM rcac_secondary.sales ORDER BY order_id;
SET ROLE rcac_r3;
SELECT order_id FROM rcac_secondary.sales ORDER BY order_id;Actual behavior
default rcac_r1: 1, 4
SET SECONDARY ROLE ALL: 1, 4
SET ROLE rcac_r2: 2
SET ROLE rcac_r3: 3
The explicit-role controls show that the individual rules, grants, and row filters are valid. The failure is specific to the SET SECONDARY ROLE ALL combination path.
The original duplicate-projection reproducer has the same defect class: two roles respectively allow distinct base rows (a=1, marker=1) and (a=1, marker=2), but after SET SECONDARY ROLE ALL, SELECT a, COUNT(*) ... GROUP BY a returns 1 | 1 and SELECT COUNT(*) returns 1; both should be 2.
Expected behavior
SET SECONDARY ROLE ALL should make the visible base-row set equivalent to:
(tenant_id = 1) OR (tenant_id = 2) OR (tenant_id = 3)
The combined query must return 1, 2, 3, 4. Distinct base rows must remain distinct even if a later user projection gives them the same value; no UNION DISTINCT-style collapse may occur before the user's query semantics are applied.
Stability / impact
- Reproduced directly on current
mainin an isolated service. - Incorrectly omits data authorized by secondary roles, affecting ordinary queries, aggregates, pagination, and multi-role workflows.
- Existing
zz_accesscontrol/role_rule.sqlexpected output matches the default-role-only result afterSET SECONDARY ROLE ALL, so its passing result does not validate the required union semantics.
Evidence and initial scope
- Single-role filtering and explicit
SET ROLE rcac_r2/SET ROLE rcac_r3controls pass. - Evidence limits the fault to secondary-role rule loading, merging, or application in the runtime rewrite path; root cause is not yet confirmed.
- This issue is independent of [Bug]: ordinary view bypasses row rewrite rule and exposes hidden rows #29093, where a normal view bypasses a base-table row rule.
Regression coverage
After remediation, add or correct an end-to-end regression that verifies:
- two non-overlapping role rules return their base-row union;
- three compatible role rules return the full OR union;
- overlapping rows occur once by base-row identity; and
- two distinct authorized base rows with identical projected values remain two rows/count
2.
Activity
iamlinjunhong commentedon Oct 10, 2026
Investigated against
main@e5dd4724f782067e1c76c38c9d2f55cebceda4a9. Merged PR #26734 intentionally changedSET SECONDARY ROLE ALL/NONEto successful, state-preserving no-ops: the current active role stays unchanged, and separately granted roles are not automatically combined. ExplicitSET ROLE <role>remains supported.The current frontend handler and the
secondary_role_disabledregression encode this contract. Consequently, the default-role-only result afterSET SECONDARY ROLE ALLin this report is expected under the adopted design; the explicit-role controls are consistent with it.We are retaining that contract and stopping this fix without a code change or PR. Restoring secondary-role union would require a separate product decision covering authorization, row-rule merging, DDL ownership, and cache behavior. This investigation does not establish correctness of general duplicate-projection merging or address #29093.
slyunnn commentedon Oct 13, 2026
Regression and extended verification for #29081 (2026-10-13)
Verification Environment
origin/mainat175a645a85994f2c95992d3aa8d6dacb6d9e167f(fix(sql): preserve filtered UNION ALL right branch columns (#30015)). The testedmo-servicebinary was built from that exact commit and embedded the samemainbranch and commit ID.2 CN / 1 TN / 1 Log service / Proxydeployment.127.0.0.1:6731(mapped to Proxy listener6009), CN1127.0.0.1:16731(CN listener16001), and CN2127.0.0.1:16732(CN listener16002). All three accepted SQL connections and executed the scenario.09b361f6bdfb5407f51b6648cc964ac96f639839,#26734remove secondary role. It intentionally definesSET SECONDARY ROLE ALLandSET SECONDARY ROLE NONEas accepted, state-preserving compatibility no-ops.What Was Covered
issue29081_r1exposedorder_idvalues1,4;SET SECONDARY ROLE ALLretained roleissue29081_r1and exposed the same values on Proxy, CN1, and CN2.SET SECONDARY ROLE NONEalso retained the active role and the same filtered rows on all three endpoints.SET ROLE issue29081_r2returned2, andSET ROLE issue29081_r3returned3, proving individual role switching remains functional.ERROR 20101 (HY000); the same session then completed subsequent role operations successfully.(a = 1)row with distinct markers returned one row per active role. AfterSET SECONDARY ROLE ALL, roleissue29081_dup1remained active and still returned only marker1; explicitSET ROLE issue29081_dup2returned marker2.1,2,3,4was not asserted as correct because current MatrixOne deliberately does not implement secondary-role merging.Findings
The reported behavior is reproducible on current
main, but it is intentional rather than a remaining implementation defect:ALLandNONEpreserve the single active role. The source implementation returns immediately for a secondary-role request, and the existing regressiontest/distributed/cases/zz_accesscontrol/secondary_role_disabled.sqlencodes the same contract, including denied secondary privileges and explicitSET ROLEcontrols.No large-data regression is needed. The behavior depends on session role state and privilege/rule selection, not row count, block or batch boundaries, memory/spill, concurrency, skew, transport, or resource scale. The two-row duplicate-projection control is the minimum data shape that distinguishes the reported claim.
MOTR / BVT Coverage
No MOTR branch, recording, replay, commit, or push was needed because no new behavior is required. Existing MatrixOne BVT
zz_accesscontrol/secondary_role_disabledalready covers the supported no-op contract. The three endpoint sessions were launched in parallel because they used isolated client sessions and read-only verification after setup; SQL within each session remained ordered because role state is session-scoped.Final Conclusion
Out of scope. The expected secondary-role union and associated row-rule merge requested by this issue conflict with the deliberate compatibility contract introduced by merged PR
#26734. Restoring that behavior requires a new product decision covering authorization semantics, rule merging, and ownership/cache implications; it is not a regression to fix on currentmain.