fix(sql): support shared locking reads - #26598
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed at 0845cc4.
[P1] Preserve the shared lock mode across SELECT unwrapping and rewrites
selectLockMode is derived only from the current stmt before the ParenSelect stripping loop and is then passed as a local argument. Accepted query shapes that replace/rebind the SELECT therefore lose the requested mode:
((select n_nationkey from nation for share))builds successfully but produces noLOCK_OPat all.select n_regionkey, row_number() over (order by n_regionkey) from nation group by n_regionkey with rollup for sharegoes throughrewriteRollupWindowSelect; the generated SELECT has no lock info, so rebinding defaults to Exclusive and produces two Exclusive lock targets.
The first query silently provides no locking protection; the second unnecessarily conflicts with other shared readers. I reproduced both by inspecting every LOCK_OP.LockTargets[].Mode after runOneStmt: expected Shared, observed nil and [Exclusive, Exclusive], respectively. Please carry the query-block lock type through unwrapping/generated SELECTs (or make it explicit scoped builder state) and add regressions for these paths.
The added focused parser/planner tests pass 5x under race, full parser and plan package tests pass, vet passes, and CI is green; those tests currently cover only the direct binding path.
Support SELECT ... FOR SHARE and LOCK IN SHARE MODE with shared lock targets.
fixed |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed at d560c75. No blocking findings.
The previous P1 is closed: the binder now derives the effective query-block lock info after parenthesis unwrapping, carries it into the synthesized ROLLUP/window SELECT, and applies the selected mode to every collected target. The two original counterexamples now produce Shared targets only.
I also checked the same state-propagation shape across DISTINCT, ORDER/LIMIT, joins, derived tables, scalar/EXISTS subqueries, UNION branches, and mixed Shared/Exclusive UNION branches. Modes remain scoped to the owning query block. A real embedded-cluster test confirmed that FOR SHARE and LOCK IN SHARE MODE readers are mutually compatible, while an UPDATE on the same row times out until both readers commit.
Validation on the exact head:
- forced mysql_sql.go regeneration is clean;
- focused parser test: count=20;
- focused planner test: count=20;
- focused planner race test: count=5;
- full MySQL parser and plan packages pass;
- go vet passes for both owning packages;
- CI is green.
Merge Queue Status
This pull request spent 1 hour 52 minutes 29 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
Support SELECT ... FOR SHARE and LOCK IN SHARE MODE with shared lock targets.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24733
What this PR does / why we need it:
fix(sql): support shared locking reads