Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
v4.2.1
Commit ID
Other Environment Information
- Environment: MatrixOne Cloud (MOC) serverless tenant
- Server: 8.0.30-MatrixOne-v4.2.1
- Client: PyMySQL over TLS
- Source: @TrentShen (feedback dated 2026-10-21)
Actual Behavior
A role granted SELECT only on a view can receive error 20101 when querying it. The GRANT succeeds and the role is active. Granting SELECT on the underlying app.vals table makes the same query succeed; revoking that table grant makes it fail again.
The failure is plan-dependent. It reproduces when the view's JOIN is planned with an index lookup on app.vals.idx_attr_id. This was reproduced with synthetic data on the reported v4.2.1 image and on MatrixOne main (baseline commit 838cc78aa1efe46693876a48c05c202979047b7b).
Expected Behavior
SELECT on a view should be authorized by the view grant when the query accesses its base tables through that view. The caller should not need direct SELECT on those base tables.
Steps to Reproduce
Run as a tenant administrator:
CREATE DATABASE app;
CREATE TABLE app.defs (
attr_id INT PRIMARY KEY,
attr_key VARCHAR(64) NOT NULL,
status VARCHAR(16) NOT NULL,
UNIQUE KEY uk_attr_key (attr_key),
KEY idx_status (status)
);
CREATE TABLE app.vals (
id BIGINT PRIMARY KEY,
employee_id VARCHAR(32) NOT NULL,
attr_id INT NOT NULL,
value_text VARCHAR(32),
UNIQUE KEY uk_emp_attr (employee_id, attr_id),
KEY idx_attr_id (attr_id)
);
INSERT INTO app.defs VALUES (1, 'team_member', 'ACTIVE'), (2, 'account_type', 'ACTIVE');
INSERT INTO app.vals VALUES (1, 'synthetic', 1, 'yes'), (2, 'synthetic', 2, 'virtual');
CREATE VIEW app.v AS
SELECT av.employee_id
FROM app.vals AS av
JOIN app.defs AS ad ON ad.attr_id = av.attr_id
WHERE ad.attr_key = 'team_member'
AND ad.status = 'ACTIVE'
AND av.value_text = 'yes';
CREATE ROLE reader;
GRANT CONNECT ON ACCOUNT * TO reader;
CREATE USER observer IDENTIFIED BY 'test-password' DEFAULT ROLE reader;
GRANT reader TO observer;
GRANT SELECT ON VIEW app.v TO reader;Connect as observer with role reader, then run:
SET enable_privilege_cache = off;
SELECT COUNT(*) FROM app.v;The initial query can succeed. Back as administrator, add enough non-matching rows to make the optimizer choose the index lookup, then flush/analyze the tables:
INSERT INTO app.vals VALUES
(3, 'other_1', 1, 'no'), (4, 'other_2', 1, 'no'),
(5, 'other_3', 1, 'no'), (6, 'other_4', 1, 'no'),
(7, 'other_5', 1, 'no'), (8, 'other_6', 1, 'no'),
(9, 'other_7', 1, 'no'), (10, 'other_8', 1, 'no'),
(11, 'other_9', 1, 'no'), (12, 'other_10', 1, 'no'),
(13, 'other_11', 1, 'no'), (14, 'other_12', 1, 'no'),
(15, 'other_13', 1, 'no'), (16, 'other_14', 1, 'no'),
(17, 'other_15', 1, 'no'), (18, 'other_16', 1, 'no'),
(19, 'other_17', 1, 'no'), (20, 'other_18', 1, 'no'),
(21, 'other_19', 1, 'no'), (22, 'other_20', 1, 'no');
ANALYZE TABLE app.vals, app.defs;In a fresh observer session (with privilege cache disabled), repeat SELECT COUNT(*) FROM app.v. It fails with error 20101. Then verify the base-table grant changes the result:
-- As administrator:
GRANT SELECT ON TABLE app.vals TO reader;
-- As observer: the view query succeeds.
-- As administrator:
REVOKE SELECT ON TABLE app.vals FROM reader;
-- As observer: the view query fails again with error 20101.Additional information
The likely failure path is the JOIN index rewrite: it creates a synthetic table scan for the index lookup without carrying the original view authorization lineage. The frontend then checks the scan as direct access to the base table. The synthetic scan should retain the view authorization context of the source scan.
Production details and customer data are omitted; the reproduction uses synthetic rows.
Activity
fix: preserve view authorization across index joins and replacement (#…
XuPeng-SH commentedon Oct 22, 2026
QA follow-up for PR #30820, current head
551de35250d6f52eff054db874c7567f70ba0c1c: the planner change now carries the original scan's view chain/direct-view context into the synthetic index scan and index join, with a planner regression and expanded tenant authorization BVT. The author reports related BVT/SQL and package tests passing on this head; I have not independently rerun them. The current head has no commit status checks; the visible connector workflows are unrelated. Issue remains open and assigned toslyunnn, which I left unchanged. Independent exact-head verification/formal re-review is still pending.[4.2-dev] fix: preserve view authorization across index joins and rep…
slyunnn commentedon Oct 23, 2026
Regression and extended verification for #30785 (2026-10-23)
Verification Environment
origin/main:91639500503a301742e0c84c8aa6c524f1e70792—docs(skills): add flexible defect-hunt workflow (#30946). Source and running binary identity matched. Runtime: Go1.27.1, Linux/arm64,TYPECHECK=1.551de35250d6f52eff054db874c7567f70ba0c1c—[4.2-dev] fix: initialize logical identity before caching table definitions. Runtime: Go1.26.4, Linux/arm64,TYPECHECK=1. Binary version and SQLgit_version()through all endpoints matched551de35250; a separate fresh data directory was used. This was exact-head verification, not a claim of testing the later4.2-devtip.2 CN / 1 TN / 1 Log service / Proxy. LOG/TN/CN1 and the actual Proxy module ran in one container; CN2 ran independently. Proxy127.0.0.1:6001, CN1127.0.0.1:16001, and CN2127.0.0.1:16002were reachable and actually exercised by the full regression matrix on both versions.COM_QUERY, with separate tenant administrator and fresh observer sessions explicitly using rolereader; existing BVT executed through the JDBC mo-tester runner.What Was Covered
2rows, addition of20nonmatching rows, statistics refresh, and the underlying-table grant/revoke sequence. View-onlySELECT COUNT(*)returned1, and the row was exactlysynthetic; removing the direct base-table grant did not break view access.INDEX JOINandIndex Table Scan on vals.idx_attr_id. Main selected this naturally with the22-row fixture. On the fixed backport, flushing only the fixture's two base tables and re-runningANALYZEenabled the natural target path with the same22rows. AFORCE INDEX FOR JOIN(idx_attr_id)control independently exercised that path on both versions.SELECTon each base table and directINSERTremained denied with20101. Granting and revoking base-table access produced the expected direct-access controls without changing the granted DEFINER view's result.0.132/132assertions on main and132/132on the exact backport head. Endpoint jobs used separate tenants and ran concurrently within each cache phase. Global-cache changes and BVT runs were serialized, and the previous cache setting was restored.TestIndexJoinPreservesScanAuthorizationpassed independently with-count=1on both versions. Its typed checks cover direct scans not borrowing an enclosing JOIN's view authority, a DEFINER view without JOIN context, and nested authorization/snapshot context.grant_view_non_sys.sqlwith its unchanged expected results twice on the same instance: main55/55in each run; exact backport65/65in each run. These cases also cover related view grant preservation, replacement and rollback controls. Tenant teardown was checked between runs; there were no skipped, abnormal or failed statements in the accepted runs.v4.2.1image was not independently rerun in this task; its reproduction is documented in the issue. Production MOC/serverless deployment, TLS transport, binary prepared statements, long-lived-session privilege invalidation, later4.2-devcommits, and performance/soak testing were not exercised.Findings
The relevant main fix is PR #30799, fix: preserve view authorization across index joins and replacement, merged as
6495ce997486c2445994081c1d85c39802f7049band included in the tested main commit.The backport is PR #30820, [4.2-dev] fix: preserve view authorization across index joins and replacement, merged as
4b11cd642008a0fd86ee3087d788f9c057b8a11a. Its requested head551de35250d6f52eff054db874c7567f70ba0c1cwas independently built and verified here.The synthetic index scan and index JOIN now retain the source scan's view authorization context. Both natural and forced target-index execution preserve view-only access, while direct-table and INVOKER rejection controls remain intact.
The backport initially chose a base scan for the in-memory fixture even when its cardinality was increased. Completing the report's FLUSH/statistics prerequisite produced the target index path using the original small fixture; those earlier non-target plans were not counted as target-index verification. No product failure remained in the completed acceptance cases.
MOTR / BVT Coverage
Persistent planner and tenant authorization regressions are already included in the fixes. They were executed directly, with additional real three-endpoint tenant/role/cache verification. No duplicate MOTR case, new regression commit, push or weekly PR update was needed. No MatrixOne production or test source was modified; build artifacts and temporary verification files were not committed.
Final Conclusion
Fixed for #30785 on latest fetched main and the exact
4.2-devbackport head requested by the QA comment. Independent regression verification is complete; this is not a formal GitHub PR review or a claim that production has been upgraded.Large-data regression is not required. The defect depends on authorization lineage across a particular index rewrite. The final
22-row fixture, fixture-only FLUSH/ANALYZE on the backport, explicit target-path assertions and a forced-index control cover that boundary; a single added NULL row covers the result boundary. Increasing volume would add cost without proving another authorization contract.The issue is left open for maintainer acceptance; no issue-state change was performed.