Skip to content

fix: narrow pessimistic insert table lock window - #24201

Merged
mergify[bot] merged 4 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix-insert-lock-window-3dev
Apr 25, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix-insert-lock-window-3dev

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24200

What this PR does / why we need it:

This PR narrows the lock hold window for pessimistic INSERT ... SELECT ... statements that were escalated to table locks. Before this change, Compile.prePipelineInitializer() acquired the target table lock before the source side of the pipeline started running, which let large source scans hold the target table lock for too long and block later writers.

The change keeps table-lock semantics intact but skips pre-pipeline table locking for Query_INSERT, allowing the existing LockOp in the execution pipeline to acquire the table lock closer to the actual write path. A focused compile test is added to lock the intended timing behavior.

Copilot AI review requested due to automatic review settings April 25, 2026 12:52
@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Apr 25, 2026
@mergify
mergify Bot requested a review from XuPeng-SH April 25, 2026 12:53
@mergify mergify Bot added the kind/bug Something isn't working label Apr 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR narrows the pessimistic table-lock hold window for INSERT ... SELECT ... by preventing Compile.prePipelineInitializer() from pre-acquiring table locks for Query_INSERT, deferring acquisition to the runtime LockOp instead.

Changes:

  • Add Compile.shouldPrePipelineLockTable() to decide whether a table lock should be acquired pre-pipeline.
  • Update compileLock() to use shouldPrePipelineLockTable() (skipping pre-pipeline table locks for INSERT).
  • Add a unit test covering shouldPrePipelineLockTable() behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/sql/compile/compile.go Introduces conditional pre-pipeline table locking and applies it to lock-target handling in compileLock().
pkg/sql/compile/compile_test.go Adds a focused unit test for the new pre-pipeline lock decision helper.

Comment thread pkg/sql/compile/compile.go Resolved
Comment thread pkg/sql/compile/compile.go Resolved
@mergify

mergify Bot commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-04-25 15:46 UTC · Rule: release-3.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-04-25 15:46 UTC · at e391a90baf42e24cca5cf6a911e6405797a7d1e5 · squash

This pull request spent 11 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

@mergify
mergify Bot merged commit b79773d into matrixorigin:3.0-dev Apr 25, 2026
43 of 45 checks passed
@mergify mergify Bot removed the queued label Apr 25, 2026
jiangxinmeng1 pushed a commit to jiangxinmeng1/matrixone that referenced this pull request Apr 27, 2026
This PR narrows the lock hold window for pessimistic `INSERT ... SELECT ...` statements that were escalated to table locks. Before this change, `Compile.prePipelineInitializer()` acquired the target table lock before the source side of the pipeline started running, which let large source scans hold the target table lock for too long and block later writers.

The change keeps table-lock semantics intact but skips pre-pipeline table locking for `Query_INSERT`, allowing the existing `LockOp` in the execution pipeline to acquire the table lock closer to the actual write path. A focused compile test is added to lock the intended timing behavior.

Approved by: @ouyuanning, @aunjgr, @XuPeng-SH
@LeftHandCold LeftHandCold mentioned this pull request Apr 27, 2026
1 of 7 tasks
mergify Bot pushed a commit that referenced this pull request Apr 27, 2026
PR #24201 moved 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 TPCH 1T load started taking that path too and the nightly load phase regressed noticeably after b79773d.

This patch keeps the #24201 behavior for regular INSERT statements, but restores the pre-pipeline table lock for LOAD DATA only. That keeps the fix scope narrow and avoids changing unrelated INSERT paths again.

A compile test was added to lock the routing behavior between regular INSERT and LOAD DATA.

Approved by: @ouyuanning, @XuPeng-SH
LeftHandCold added a commit to LeftHandCold/matrixone that referenced this pull request Apr 29, 2026
mergify Bot pushed a commit that referenced this pull request Apr 29, 2026
This backports #24201 to `main`.

For pessimistic `INSERT ... SELECT ...` statements that escalate to table locks, `Compile.compileLock` was 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 `LockOp` acquire 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:
- a compile unit test for the pre-pipeline lock routing
- a lockop unit test for the zero-row EOF table-lock path

Approved by: @aunjgr, @ouyuanning, @iamlinjunhong
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
This backports matrixorigin#24201 to `main`.

For pessimistic `INSERT ... SELECT ...` statements that escalate to table locks, `Compile.compileLock` was 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 `LockOp` acquire 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:
- a compile unit test for the pre-pipeline lock routing
- a lockop unit test for the zero-row EOF table-lock path

Approved by: @aunjgr, @ouyuanning, @iamlinjunhong
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This backports matrixorigin#24201 to `main`.

For pessimistic `INSERT ... SELECT ...` statements that escalate to table locks, `Compile.compileLock` was 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 `LockOp` acquire 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:
- a compile unit test for the pre-pipeline lock routing
- a lockop unit test for the zero-row EOF table-lock path

Approved by: @aunjgr, @ouyuanning, @iamlinjunhong
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This backports matrixorigin#24201 to `main`.

For pessimistic `INSERT ... SELECT ...` statements that escalate to table locks, `Compile.compileLock` was 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 `LockOp` acquire 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:
- a compile unit test for the pre-pipeline lock routing
- a lockop unit test for the zero-row EOF table-lock path

Approved by: @aunjgr, @ouyuanning, @iamlinjunhong
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This backports matrixorigin#24201 to `main`.

For pessimistic `INSERT ... SELECT ...` statements that escalate to table locks, `Compile.compileLock` was 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 `LockOp` acquire 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:
- a compile unit test for the pre-pipeline lock routing
- a lockop unit test for the zero-row EOF table-lock path

Approved by: @aunjgr, @ouyuanning, @iamlinjunhong

This branch was previously deployed

1 inactive deployment
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 size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants