Repository navigation
Apply role rewrite policies to EXPLAIN statements - #33160
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 388292584568a6c6b575944633ceb442397af063
Assessment: request_changes
The parser reuses the existing role-policy path for EXPLAIN ANALYZE. EXPLAIN PHYPLAN still needs to pass its wrapped statement through the database-remap visitor.
Model: gpt-6.2-sol / xhigh
Session: 01a20d4a-e012-78c2-a9c3-fb5e273c4075 · slot 1 · generation 4
- P1
pkg/sql/parsers/sqlparse.go:784: EXPLAIN PHYPLAN reads an unqualified table when the session remaps its default database and the role rule is keyed to the source database.
Impact: PHYPLAN can execute against the destination table without its effective role filter. Its statistics can include rows filtered out by the equivalent SELECT.
Evidence: The new branch attaches the source-keyed rule, but pkg/frontend/remap_db.go:322 visits only plain EXPLAIN and EXPLAIN ANALYZE. pkg/frontend/compiler_context.go:287 still supplies the remapped default database, so the rewrite lookup at pkg/sql/plan/query_builder.go:13963 misses the source-keyed rule. The existing contract is covered by test/distributed/cases/zz_accesscontrol/remap_role_rule.sql:37. Route PHYPLAN through the same remap visitor and add regression coverage for role-rule parity under remapping.
Validation:
-
Isolation preflight and git diff --check passed on the frozen head. Receipts are checks/1795519547080181007-2.json and checks/1795519779601145828-2.json.
-
The frozen CI snapshot records successful Ubuntu/x86 UT and multi-CN BVT jobs. The PHYPLAN finding was verified by tracing the parser, remapper, and planner.
Limitations:
-
Local product tests did not run. The parser check timed out during dependency downloads. The initial integration run was interrupted before its receipt was written, and the cache-only retry stopped at missing dependencies. See checks/1795519931691727350-2.json, parser.stderr, checks/1795519967776809699-2.json, and sqlintegration-cache.jsonl.
-
The frozen CI snapshot contains job results only, so individual regression-test execution could not be confirmed from CI.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 67461fa640435848bea5a970b72873967e7676e3
Assessment: request_changes
The PR reuses the ordinary SELECT rewrite path and resolves the prior PHYPLAN database-remap finding. Issue #31675 remains open at the EXPLAIN output boundary because scan input counts can still include rows denied by the role rule.
Model: gpt-6.2-sol / xhigh
Session: 01a20d4a-e012-78c2-a9c3-fb5e273c4075 · slot 1 · generation 4
- P2
pkg/sql/parsers/sqlparse.go:783: A restricted session runs EXPLAIN ANALYZE on a table whose effective role rule filters that same table, and a scanned batch contains both allowed and denied rows.
Impact: The query output honors the role filter, but the plan exposes a scan input count that includes denied rows. The count can change when only denied rows change, disclosing cardinality outside the role's authorized result.
Evidence: The binder reaches the base table for a self-table rewrite at pkg/sql/plan/query_builder.go:13988. The scan counts input rows before evaluating its filter at pkg/sql/colexec/table_scan/table_scan.go:205. The compiler propagates that count at pkg/sql/compile/analyze_module.go:331, and the public formatter prints it at pkg/sql/plan/explain/explain_node.go:1584. The new regression scans a replacement table and checks root output rows, so it does not cover this case. Protect pre-policy row counts at the public EXPLAIN boundary and add a regression using a filter on the original table.
Validation:
-
Reused the matching frozen-head scope and whitespace check from attempt 1. Receipt 1795528541451518114-2.json exited 0 and matches scope-verified.stdout.
-
Current private /tmp and loopback preflight and native prerequisite verification passed. Receipts 1795529693789563217-2.json and 1795529718729167339-2.json match the retained logs and frozen source.
-
The frozen CI snapshot records success for Ubuntu/x86 unit tests, SCA, two multi-CN BVT jobs, and CI Required. The author reported two passing runs of the single-CN MySQL regression on this head.
-
Saved review-plan.md and discussion-assessment.json and verified coverage of all five discussion entries.
Limitations:
-
The local parser retry timed out before emitting test events. Receipt 1795529899447525105-2.json exited 124 and matches parser.stderr and the empty parser.jsonl.
-
The denied-row count finding is based on the source trace. The supplied execution evidence does not cover a same-table role filter or establish that the new regression ran in multi-CN CI.
67461fa to
68a3852
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: b1d8fb3ef0883e0daec8ced8f198f6fff95e9cf1
Assessment: request_changes
The implementation addresses the earlier remapping, protected-statistics, and correlated-result-count concerns using the existing policy and EXPLAIN components. The prior approval did not address the repository’s required mo-tester BVT coverage for this public SQL and privilege behavior.
Model: gpt-6.1-terra / max
Session: 01a22087-cef5-7962-9206-10e0932e0fda · slot 1 · generation 34
- P2
pkg/tests/sqlintegration/explain_analyze_role_rule_test.go:29: The repository’s BVT suite runs against changes to role-governed EXPLAIN ANALYZE behavior.
Impact: The new Go integration test provides useful public-path coverage, but the required mo-tester suite has no maintained case for this behavior. A regression can therefore escape the BVT coverage required for SQL-visible and privilege changes.
Evidence: The pinned testing contract requires BVT public-path proof for SQL-visible and privilege behavior at review-policy/.agents/skills/mo-dev/references/testing-contract.md:25 and defines BVT as mo-tester cases under test/distributed/cases at line 141. The existing role-rule BVT exercises ordinary EXPLAIN UPDATE at test/distributed/cases/zz_accesscontrol/role_rule_dml_index.sql:28, not role-governed EXPLAIN ANALYZE. Extend a suitable role-rule BVT fixture with an authorized-result and protected analyzed-output check. This is a required coverage gap, not an observed runtime defect.
Validation:
-
The assigned-head parser, frontend policy and prepared-statement tests, and SQL integration regression passed with the isolated test executor; receipt checks/1795898461295425330-2.json and focused-tests.log.
-
Isolation preflight, native-input provenance verification, and git diff --check passed; receipts checks/1795898244208664990-3.json, checks/1795898244311969881-3.json, and checks/1795898420786619962-3.json.
-
The frozen CI snapshot reports successful x86 unit tests and multi-CN BVT jobs. Earlier same-PR one- and two-CN probes passed on head 223c2ae.
Limitations:
-
No local mo-tester case was run for the changed behavior because the required case is absent; the CI snapshot does not identify individual BVT case selection.
-
The earlier two-CN probe covered cross-CN policy visibility on an older head; it does not establish distributed physical execution on the assigned head.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 31af97bcc2e0779119d779395d4ed47a271a1a48
Assessment: request_changes
The change appropriately reuses the existing rewrite and remapping paths. The earlier remapping, statistics-redaction, correlated-count, and BVT-coverage concerns are addressed. A focused probe reproduced the previously identified row-count error for prepared EXPLAIN statements under a session limit.
Model: gpt-6.1-terra / max
Session: 01a22868-9f3f-7b70-a9d3-bd33c34f8163 · slot 1 · generation 37
- P2
pkg/sql/plan/explain/explain_query.go:199: A role-governed session prepares a parameterless EXPLAIN ANALYZE or EXPLAIN PHYPLAN ANALYZE, then sets sql_select_limit to 1 and executes it against two authorized rows.
Impact: Both prepared EXPLAIN variants can report Result: outputRows=2 even though the corresponding SELECT returns one row.
Evidence: ResultRowsLine reads the logical root's output count. The cached prepared pipeline marks that root as the last operator before adding the dynamic session-limit operator at pkg/sql/compile/compile.go:1700 and :1730, so the count can describe the batch before truncation. A same-head public MySQL probe reproduced 2 for both prepared variants; the limited SELECT and direct EXPLAIN controls returned 1, and unlimited controls returned 2. See model-switch-1795975917629824352/prepared-limit-probe.log and checks/1795976223878303178-3.json. Use a post-limit result count and add a regression for both prepared EXPLAIN variants.
Validation:
-
Isolation preflight passed: model-switch-1795975917629824352/checks/1795975943484499234-3.json.
-
The committed parser and SQL integration regressions passed on the assigned head: focused-tests.log and checks/1795976297555579979-3.json in model-switch-1795975917629824352.
-
The prepared-limit probe failed on both affected variants with passing direct and unlimited controls: prepared-limit-probe.log and checks/1795976223878303178-3.json in model-switch-1795975917629824352.
-
git diff --check passed: model-switch-1795975917629824352/checks/1795976333014667183-3.json.
-
The updated review plan and complete discussion assessment are retained in model-switch-1795975917629824352; discussion key coverage passed.
Limitations:
-
The focused public-path probe used one CN. The frozen CI snapshot reports successful unit and multi-CN BVT jobs but does not identify individual selected cases.
-
The author reports two successful exact-head BVT case runs; their raw logs were not supplied.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: ed993e4cd2ece78920cef8c8bef6dbf3b77762d1
Assessment: approve
The change reuses the existing role-policy and database-remapping paths, suppresses pre-policy execution statistics, and derives the reported SELECT count from the coordinator output. The earlier remapping, statistics, correlated-count, BVT-coverage, and prepared-limit concerns are addressed in the current scope.
Model: gpt-6.1-terra / max
Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45
Validation:
-
The private /tmp and loopback preflight passed, and native provenance matched 195 tracked inputs and seven outputs: preflight.log, native-audit.log, and receipts checks/1796020833387009781-3.json and checks/1796020900862660752-6.json.
-
The committed single-CN SQL integration regression passed. An extended probe also passed for aggregates, UNION, recursive CTEs, SQL PREPARE, and hidden-row changes: candidate-integration.log and review-probe.log; receipts checks/1796021110669054461-3.json and checks/1796021191742643003-3.json.
-
A two-CN probe used a restricted client on CN1, forced a remote scan, observed a remote scope, and passed the role-policy and output checks: multicn-probe.log and checks/1796021362363426731-3.json.
-
Focused parser and frontend tests passed. A policy-transition probe confirmed that prepared handles were rejected for re-preparation after a mandatory rule was added: parser-focused.log, frontend-focused.log, and policy-transition-json.log; receipts checks/1796021749615961449-3.json, checks/1796021902827676928-3.json, and checks/1796021731754873882-3.json.
-
Discussion coverage and retained command receipts were checked in evidence-audit.log and checks/1796022043021452072-5.json.
Limitations:
-
The author reports two exact-head mo-tester runs of the changed BVT case with cleanup verified; raw BVT logs were not supplied and the case was not independently rerun.
-
An initial policy-transition run timed out before producing test output; preflight and a subsequent bounded retry passed. An exploratory probe also used an unsupported physical EXPLAIN syntax; the supported prepared-EXECUTE variant passed on retry.
🚫 Left the queue · pull request branch update failed1 min in the queue, with no time running CI. So far
Reason The pull request can't be updated
To get back in the queue
Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
What this PR does / why we need it:
Apply the session's effective role rewrite policy to the statement inside EXPLAIN, EXPLAIN ANALYZE, and EXPLAIN PHYPLAN. The parser passes the validated policy to the enclosed query's read sources through the existing rewrite path. EXPLAIN ANALYZE displays the authorized plan. With mandatory role rules active, EXPLAIN ANALYZE and EXPLAIN PHYPLAN keep pre-policy operator statistics out of the client response and report the final SELECT row count. Policy loading errors still terminate the request before planning or execution. EXPLAIN PHYPLAN also visits the wrapped statement during database remapping, keeping the role-rule lookup aligned with the destination database.
Local validation on macOS/arm64 covered the parser's EXPLAIN variants, adjacent prepared-statement paths, and frontend policy-error handling. A single-CN MySQL text-protocol test used a synthetic role rule to assert the ordinary SELECT result, the authorized scan in EXPLAIN ANALYZE, and the root node's actual output count. The test also passed twice on the same fixture. Incremental go vet and lint passed.
The rewrite and output rules operate at statement scope. Local integration coverage was single-CN. The previous head passed the required CI run.
Validation for
67461fa640435848bea5a970b72873967e7676e3on macOS/arm64mo-cgo-test -count=2 -run '^TestExplainAnalyzeCarriesRoleRule$' ./pkg/tests/sqlintegrationpassed twice using the same single-CN fixture. The remapped PHYPLAN ANALYZE scanned the authorized source and reported the same output row count as SELECT.mo-cgo-testchecks passed inpkg/sql/parsersandpkg/frontendfor rewrite hints, database remapping, prepared EXPLAIN, and policy-loading errors. Incrementalgo vet,golangci-lint, and the PR artifact check passed.Validation for
68a38525ffa6758020d8fb240ccdd7883ef87ee1, rebased ontomain@b6f4ca00abd9f8cb9aa5e72d1be830238df22264mo-cgo-test -count=2 -run '^TestExplainAnalyzeCarriesRoleRule$' ./pkg/tests/sqlintegrationpassed twice on a single CN. The same-table regression checks authorized and zero-row results, adds denied rows, verifies text and native prepared EXPLAIN, and confirms that unrestricted execution still reports operator stats.mo-cgo-testchecks inpkg/sql/parsers,pkg/frontend, andpkg/sql/plan/explainpassed, including upstream SHOW rewrite attachment and the EXPLAIN rewrite cases. Incrementalgo vet,golangci-lint, and the PR artifact check passed. That head passed required CI, including both multi-CN BVT jobs. CI runValidation for
a56a88322c3c864165805d67b89dcc61c493a2de, rebased ontomain@56989d8ecd07544231bbbde6d1d87552f5a91f20mo-cgo-test.mo-cgo-test -run '^(TestExplainAnalyzeCarriesRoleRule|TestRoleRuleDMLAndIndexVisibility)$' ./pkg/tests/sqlintegrationpassed on one CN. This checks the EXPLAIN regression, including remapping and native prepared execution, alongside the upstream DML and index-metadata behavior.go vet,golangci-lint, and the PR artifact check passed. That head passed required CI, including both multi-CN BVT jobs. CI runValidation for
223c2ae4b2a5b5a3cf951ee6f3ceb1e7804ce4c3mo-cgo-test -count=2 -run '^TestExplainAnalyzeCarriesRoleRule$' ./pkg/tests/sqlintegrationpassed twice on one CN.pkg/sql/plan/explainandpkg/pb/planpackage tests, incrementalgo vet,golangci-lint, and the PR artifact check passed. Hosted CI for this commit is pending.BVT validation for
31af97bcc2e0779119d779395d4ed47a271a1a48test/distributed/cases/zz_accesscontrol/remap_role_rule.sqlto compare authorized SELECT results with protected logical and physical EXPLAIN ANALYZE output after database remapping.309a0ca650e0c55e90292767fd61e4976818d66dpassed 59/59 statements twice in normal comparison mode withnometaandignore, on the same single-CN instance. Verified teardown after both runs. The PR artifact check passed.Validation for
ed993e4cd2ece78920cef8c8bef6dbf3b77762d1on macOS/arm64outputRows=2when SELECT returned one row. After the fix, both protected ANALYZE variants match SELECT as the session row limit changes on the same prepared handle (2, 1, 0, 2), and the output remains redacted.mo-cgo-test -count=2 -run '^TestExplainAnalyzeCarriesRoleRule$' ./pkg/tests/sqlintegrationpassed on one CN.pkg/frontend,pkg/sql/plan/explain, andpkg/sql/compile. Incrementalgo vet,golangci-lint, and the PR artifact check passed.309a0ca650e0c55e90292767fd61e4976818d66din normal comparison mode withnometaandignore. Both runs passed 59/59 on the same single-CN instance, with cleanup verified after each run. Hosted CI passed on the previous head.Validation for
52b7f34a8d0ebbddb61fcb9f1c9e41aee10bd5fa, rebased ontomainatf1d7f1e4e8b3d0a66ac8516cf571a0a19d64cc08git range-diffmatched all six patches, and the workflow files match main.d73dae9ae5e8ec00c42dd5dcd29ee42b558e4371used macOS/arm64.mo-cgo-test -count=2 -run '^TestExplainAnalyzeCarriesRoleRule$' ./pkg/tests/sqlintegrationpassed on one CN. Focused EXPLAIN, role rewrite, remap, and session-limit checks passed in frontend, parser, EXPLAIN formatter, and compiler packages. The upstream native prepared SHOW integration test passed with-tags integration.nometaandignore. Verified fixture cleanup after both runs. Incrementalgo vet,golangci-lint, and the PR artifact guard passed.