planner: make SELECT ... SKIP LOCKED fail loudly instead of silently not locking#69782
planner: make SELECT ... SKIP LOCKED fail loudly instead of silently not locking#69782takaidohigasi wants to merge 1 commit into
Conversation
…not locking Previously `SELECT ... FOR UPDATE SKIP LOCKED` was parsed but the lock type was unsupported everywhere downstream, so the statement silently degraded to a plain non-locking read (pingcap#69720), and on nonclustered-PK tables planning could fail with "Can't find column ..._tidb_rowid" because LogicalLock.PruneColumns did not preserve the handle columns for unsupported lock types (pingcap#61621, pingcap#67715). Now: - FOR UPDATE SKIP LOCKED returns ErrNotSupportedYet 'SKIP LOCKED' at preprocess (which also covers the PointGet fast path). - FOR SHARE SKIP LOCKED follows the FOR SHARE noop handling: rejected unless noop functions are enabled, noop-with-warning when they are, and ErrNotSupportedYet when shared lock promotion is enabled. - LogicalLock.PruneColumns keeps TblID2Handle/TblID2PhysTblIDCol columns from being pruned for unsupported (noop) lock types, since PhysicalLock is still built and resolves them against the child schema. close pingcap#69720, close pingcap#61621, close pingcap#67715, ref pingcap#18207 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @takaidohigasi. Thanks for your PR. I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughSKIP LOCKED validation now rejects unsupported lock modes, shared-lock noop handling includes SKIP LOCKED, and logical lock pruning preserves required handle and partition columns. Regression coverage exercises nonclustered primary-key queries and shared-lock promotion settings. ChangesSKIP LOCKED handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: context deadline exceeded" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What problem does this PR solve?
Issue Number: close #69720, close #61621, close #67715, ref #18207
Problem Summary:
SELECT ... FOR UPDATE SKIP LOCKEDis parsed, but the lock type is unsupported everywhere downstream:FOR UPDATEguarantee.Can't find column ..._tidb_rowid in schema(select for update skip locked failed with message Can't find column test.T._tidb_rowid in schema Column #61621, FOR UPDATE SKIP LOCKED on JOIN triggers _tidb_rowid resolution error in TiDB #67715):buildSelectLockstill builds aLogicalLockcarryingTblID2Handle, butLogicalLock.PruneColumnsdoes not preserve the handle columns for unsupported lock types, soPhysicalLock.ResolveIndicescannot resolve them against the pruned child schema.What changed and how does it work?
checkSelectLockInfovalidation to preprocess (which also covers the PointGet fast path):FOR UPDATE SKIP LOCKEDnow returnsErrNotSupportedYet(1235)This version of TiDB doesn't yet support 'SKIP LOCKED'instead of silently not locking.FOR SHARE SKIP LOCKEDfollows the existingFOR SHAREnoop handling: rejected unless noop functions are enabled, noop-with-warning when they are, andErrNotSupportedYetwhentidb_enable_shared_lock_promotionis enabled (promotion would execute it asFOR UPDATE).LogicalLock.PruneColumnsnow keeps theTblID2Handle/TblID2PhysTblIDColcolumns from being pruned for unsupported (noop) lock types as well, sincePhysicalLockis still built and resolves those columns against the child schema.This is a preparatory, independently cherry-pickable step for the real SKIP LOCKED support tracked in #18207 (design doc and implementation in follow-up PRs).
Check List
Tests
TestSelectLockSkipLockedinpkg/planner/core/preprocess_test.gocovers the exact repro of #61621 (which fails with the_tidb_rowiderror before this fix), the silent-no-op case of #69720, and the FOR SHARE noop/promotion matrix.Side effects
Statements using
FOR UPDATE SKIP LOCKEDthat previously (incorrectly) executed as plain reads now return error 1235. This behavior was a correctness bug; applications relying on it were not actually acquiring any locks.Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit
SKIP LOCKEDclauses, including clearer handling of unsupported lock modes.FOR SHARE SKIP LOCKEDbehavior with shared-lock promotion and noop-function settings.SKIP LOCKEDscenarios and related error handling.