Repository navigation
fix: narrow pessimistic insert table lock window - #24231
Merged
mergify[bot] merged 4 commits intoApr 29, 2026
Merged
Conversation
1 of 7 tasks
There was a problem hiding this comment.
Pull request overview
This PR backports a fix to reduce how long pessimistic INSERT ... SELECT ... can hold an escalated table lock by avoiding pre-pipeline table locking for Query_INSERT, deferring acquisition to LockOp while preserving the “lock even on zero rows” semantics via EOF-time table locking.
Changes:
- Add
Compile.shouldPrePipelineLockTable()and routecompileLockto skip pre-pipeline table locks for INSERT, settingLockTableAtTheEndinstead. - Add a compile unit test covering the pre-pipeline lock routing behavior.
- Add a
lockopunit test covering EOF-time table locking when no rows are produced.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/sql/compile/compile.go | Introduces INSERT-specific logic to defer table lock acquisition to runtime LockOp (plus EOF fallback) rather than pre-pipeline. |
| pkg/sql/compile/compile_test.go | Adds a focused unit test for shouldPrePipelineLockTable behavior across statement types. |
| pkg/sql/colexec/lockop/lock_op_test.go | Adds a unit test asserting EOF-time table locking when the child produces no rows. |
iamlinjunhong
approved these changes
Apr 29, 2026
mergify Bot
pushed a commit
that referenced
this pull request
Apr 29, 2026
This backports #24226 to `main` on top of #24231. `#24231` moves regular `Query_INSERT` table locking off the pre-pipeline path. `LOAD DATA` is also planned as `Query_INSERT` and always carries a table-locking `LockOp`, so it needs a narrow exception to stay on the pre-pipeline lock path and avoid retrying the same whole-table lock on every non-empty batch. This stacked backport keeps the `#24231` behavior for regular INSERT statements, but restores pre-pipeline table locking for `LOAD DATA` only. It also makes `Compile.lockTable()` lock all pre-pipeline targets instead of returning after the first one. Also included: - coverage that distinguishes regular INSERT from `LOAD DATA` - coverage that locks all pre-pipeline targets Stacking note: - GitHub cannot base an upstream PR on a fork branch, so this PR currently includes the `#24231` backport in its visible diff as well. After `#24231` lands, this branch should be rebased so reviewers only see the incremental `#24226` change. Approved by: @aunjgr, @ouyuanning
Backport matrixorigin#24201 to main. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Replace the flaky wall-clock assertion with a deterministic check that sender only invokes the underlying RPC client once when the backend retry budget is disabled. Co-authored-by: Copilot <[email protected]>
Contributor
Merge Queue Status
This pull request spent 24 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
fixes #24200
What this PR does / why we need it:
This backports #24201 to
main.For pessimistic
INSERT ... SELECT ...statements that escalate to table locks,Compile.compileLockwas still keeping the target table on the pre-pipeline lock path. That can make a large source scan hold the target-table lock before the write side starts running and block later writers for too long.This backport keeps the same table-lock semantics, but lets
LockOpacquire the table lock when the first batch reaches the target pipeline. It also preserves EOF-time table locking for the zero-row path so inserts that produce no rows still keep the intended table-lock behavior.Also included:
Validation
go test ./pkg/sql/compile ./pkg/sql/colexec/lockop -count=1(blocked in this Darwin environment because the repository's current CGO dependencies require missing headers such asusearch.h/xxhash.h; the backport was kept aligned with the merged 3.0-dev fix and will rely on CI for full package validation)