Skip to content

fix: authorize exclusive SELECT lock targets - #31978

Merged
XuPeng-SH merged 4 commits into
mainfrom
fix/31916-locking-select-privilege
Nov 2, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
fix/31916-locking-select-privilege

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 1, 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 #31916

What this PR does / why we need it:

A SELECT-only user could execute SELECT ... FOR UPDATE, acquire exclusive locks, and block writers. Require SELECT plus UPDATE or DELETE for each exclusive locking-read target; existing ALL/ownership grants also qualify. Ordinary SELECT and shared locking reads retain their SELECT-only requirements. MatrixOne does not currently support granting LOCK TABLES. See the MySQL 8.4 locking-read privilege contract.

Capture logical lock targets and view paths during binding, preserve them across rewrites and prepared execution, and reauthorize rebuilt plans before compilation, including CTAS retry sources. Preserve inherited roles and DEFINER account boundaries.

For eligible multi-target view checks, reuse the caller role closure and one last-definer closure within one authorization transaction at the statement's admitted catalog snapshot. Copy working roles for every target and still check each target's view grants, metadata, and base privileges. Revalidate identity, membership generation, and snapshot minimum between targets; resume independent checks when reuse eligibility changes. No new cross-request cache. Single-target, bare/mixed-target, cold-membership, cache-disabled, and unpinned cases retain independent checks.

Use one deferred transaction finalizer for authorization reads. Boundary and target errors roll back; logical denials commit the catalog read, and cold membership results are published only after a successful commit into the same cache generation. Cancellation is checked before taking an eligibility-loss fallback, and a failed prefix commit prevents the fallback. Existing typed errors and cleanup failures remain inspectable through the shared transaction error contract. In a dual operation/rollback failure, both identities survive through errors.Is; the existing rollback-first wire error selection remains unchanged.

Validation after rebase onto be8eb40ad8:

  • Frontend owning normal/race suites pass; native integration normal/race passes CTAS retry and actual admitted batching, including controlled generation invalidation, principal/minimum changes, cancellation, and injected begin/commit/rollback failures with cleanup/error-identity assertions, cold positive/negative membership publication, cancellation plus eligibility loss, and failed-prefix-commit assertions.
  • Planner normal/race suites were rerun after the dependency changes; the protobuf package compiles in both modes and has no package-local tests. Mixed bare-table/view fallback and distinct same-account definer closures are covered. Secondary-role SQL remains its existing no-op; the internal compatibility flag is tested separately. Scoped gofmt, vet, pinned molint, and configured golangci-lint 2.14 pass in default and integration modes, zero lint issues.
  • 108 public SQL controls plus four text PREPARE cases (12 allow/revoke/regrant execution assertions) pass, including multi-view binary prepared revoke/regrant, role-link revocation, cache on/off, INVOKER/DEFINER, CTAS, and rejection before locking. Removing the per-target role copy makes the new negative control return unauthorized success.
  • Same-base cleanup comparison: candidate and pre-cleanup secured code both rebased onto be8eb40ad8, identical standalone fixture, four interleaved blocks. Eight-table/nine-role locking views: INVOKER 78.16 → 77.86 ms and DEFINER 72.29 → 72.08 ms (mean block medians). No cleanup speedup is claimed. Initial short ordinary INVOKER samples looked slower; four ordinary-only follow-up blocks did not reproduce it (candidate 2.66/3.12 ms versus baseline 2.71/3.56 ms). These measurements do not establish universal latency neutrality or concurrent throughput.
  • Historical pre-rebase cost/profile evidence: exact secured 794b55a source executes 72 caller inheritance reads for eight targets and nine roles; the shared evaluator executes 9, retaining all target metadata/base checks. CPU profiles confirm the batch is selected and reduce sampled role-expansion CPU from 1.57 s to 0.26 s.
  • Historical pre-rebase paired C/B/B/C SQL measurements against secured 794b55a, with identical standalone settings, three warmups and twelve samples per block: eight-table/nine-role locking views improve 100.12 → 72.65 ms for DEFINER (27.4%) and 103.18 → 77.32 ms for INVOKER (25.1%), using mean block medians. One-role improvement is smaller (about 4–8%). Eight-table ordinary controls stay within 1.5%; single-target locking remains unchanged.

These are small one-row standalone fixtures, not production throughput measurements. Short ordinary-query samples were noisy; a bounded ordinary-only follow-up showed substantial variation on the same binary, so no universal zero-overhead claim is made. Per-target catalog checks and lock execution costs remain.

The CTAS regression drives the actual retry callback across view retargeting; it does not force the concurrent CREATE-name admission schedule or replay a complete prepared CTAS protocol execution. Public fixtures use an independent SQL client; the full mo-tester suite was not run locally. CI results for the newly published revision remain separate from these local checks.

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

@XuPeng-SH

XuPeng-SH commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 794b55a1f824b1b3fb7031212f4a77c60e460fd3

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 794b55a1f824b1b3fb7031212f4a77c60e460fd3

Assessment: approve

No actionable findings. Exclusive locking reads retain logical authorization targets through planning, view resolution and compile retries, while preserving shared-read behavior.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Reviewed the complete delta, affected owners and consumers, all discussion entries and linked issue #31916. Saved review-plan.md and discussion-assessment.json.

  • Focused frontend, planner and protobuf tests passed: focused-native-tests.log; receipt checks/1793528463932254733-3.json.

  • TestSelectLockCTASRetry passed ordinary and prepared-with-changed-USE cases: ctas-retry-integration.log; receipt checks/1793528599407848547-3.json.

  • Descriptor comparison, formatting, whitespace, discussion coverage and native-input provenance checks passed. Final source remained unchanged at the assigned head.

  • Commands, source fingerprints, exits and retained logs are reconciled in validation-evidence.json. The initial missing-native-library setup failure was recovered.

  • Shared-read behavior agrees with the cited MySQL locking-read contract.

Limitations:

  • Full mo-tester and race suites were not run locally. Broader author-reported checks lack retained local_validation artifacts; owning CI checks were pending or queued in the supplied snapshot.

@XuPeng-SH

XuPeng-SH commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: e2759125424459af109d9e55ac7f2afd46dd08e4

Review linked issue or PR description changed before publication; a fresh contextual review is queued.

@XuPeng-SH

XuPeng-SH commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: e2759125424459af109d9e55ac7f2afd46dd08e4

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: e2759125424459af109d9e55ac7f2afd46dd08e4

Assessment: approve

No actionable findings. The complete source review and matching validation remain applicable; the expanded PR description introduces no new contract conflict.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Confirmed identical frozen source and patch, reviewed the expanded description, and assessed all five discussion entries.

  • Reconciled 13 same-head receipts with commands, exits, source fingerprints and retained logs. Reused focused tests, full planner/protobuf suites, frontend race coverage and go vet.

  • Reused three batch tests with 100 race repetitions each, plus CTAS retry integration in normal and race modes, including three additional race repetitions.

  • Verified native and descriptor provenance and unchanged source. Review records and the current evidence audit are saved in the diagnostic directory.

Limitations:

  • The full frontend normal suite had one environment failure: unchanged Test_openNewFile_nilCtx writes into the read-only checkout. Frontend race coverage excludes that test.

  • Newly reported public SQL controls, mutation results, CPU profiles and latency improvements lack retained local_validation artifacts and remain author-reported.

  • Full mo-tester and golangci-lint were not independently run; frozen CI remained pending. Prepared CTAS retry coverage uses the production rebuild helper rather than the complete prepared protocol.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 3af7499989249eb0e556e511b2cfcbb0a1bf12e9

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 3af7499989249eb0e556e511b2cfcbb0a1bf12e9

Assessment: approve

No actionable findings. Exclusive-lock authorization, view-principal isolation, batch fallback and retry handling satisfy the scoped contract.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Reviewed all 16 changed files and affected consumers. Saved review-plan.md and discussion-assessment.json covering all seven discussion keys.

  • Focused frontend/planner tests passed: 14 top-level tests and 56 subtests. Receipt 1793584906199301055-3.json; focused-tests.log. Protobuf package compiled with no selected tests.

  • CTAS and batch integration tests passed, including cancellation, boundary changes and transaction failures. Receipt 1793584987892677075-3.json; ctas-batch-integration.log.

  • Isolation preflight, native build, descriptor comparison, formatting and whitespace checks passed. validation-manifest.json and evidence-audit.log reconcile receipts, logs and source fingerprints. Source remains unchanged.

  • SELECT-only shared reads agree with the MySQL 8.4 locking-read contract, resolving the linked issue's broader shared-read claim.

Limitations:

  • Full mo-tester, full race suites and standalone lint were not rerun; relevant frozen CI checks remained pending.

  • Author performance and broader public-SQL claims lack retained local_validation artifacts and were not independently reproduced.

  • CTAS coverage exercises the actual retry callback, not the full prepared CTAS protocol or a forced concurrent create-name schedule.

@XuPeng-SH
XuPeng-SH merged commit ea184ad into main Nov 2, 2026
@XuPeng-SH
XuPeng-SH deleted the fix/31916-locking-select-privilege branch November 2, 2026 03:41
gouhongshen added a commit to gouhongshen/matrixone that referenced this pull request Nov 2, 2026
…e to txnTable refactor

Upstream main advanced 41 commits past the previous merge base
4183159; its matrixorigin#31978 (exclusive SELECT lock authorization) added
Query.select_lock_references (field 21) and message SelectLockReference
to proto/plan.proto and regenerated pkg/pb/plan/plan.pb.go, colliding
with this branch's regenerated bindings (Node.scan_read_role = 97, enum
ScanReadRole, IndexScanInfo.parent_table_id = 7, LockTarget additions).

Resolution:
- plan.pb.go: take the auto-merged plan.proto (additive on both sides,
  no field-number collision: this branch's fields are 97/7/20, main's
  are 21 and the new SelectLockReference message) and regenerate the
  bindings with the repository's verified protoc/gogofast toolchain plus
  the plan_string_literal_form and plan_collation_admission
  postprocessors. The regenerated bindings equal main's HEAD plus
  exactly this PR's additive identifiers; verified by bidirectional
  diff with no deletions of either side's code.
- disttae: upstream matrixorigin#31488 removed the write-only txnTable field
  clusterByIdx from the struct while this branch's
  cloneForExecutionRead literal and the execution_read_test constructor
  still referenced it. Follow upstream's structure: drop the two dead
  references. All remaining clone fields exist in the merged struct,
  and deepcopy/base_binder/query_builder deltas of both sides survive
  verbatim.

Validation: full-tree go build ./pkg/... and the 9-arm focused ladder
(green-{compile,lockop,disttae,plan,txnclient,moerr,issue30955,
enginetest,frontend-combined}) plus go vet green on the merged tree.

This branch was successfully deployed

No deployments
ci — e902f841 Deployed Nov 2, 2026 by XuPeng-SH
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 kind/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SELECT ... FOR UPDATE is allowed with only SELECT privilege and can block writers

2 participants