Skip to content

refactor: unify shuffle implementations - #25814

Merged
mergify[bot] merged 11 commits into
matrixorigin:mainfrom
aunjgr:refactor/unify-shuffle
Jul 20, 2026
Merged

mergify[bot] merged 11 commits into
matrixorigin:mainfrom
aunjgr:refactor/unify-shuffle

Conversation

@aunjgr

@aunjgr aunjgr commented Jul 16, 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 #24097

What this PR does / why we need it:

Unifies the Shuffle and ShuffleV2 implementations, retaining the former V2 local shared-pool execution model in Shuffle while adding explicit drain-all-buckets behavior for distributed execution.

The shared pool is generation-scoped, bounds ready and recycled batches, resumes blocked writes without losing the input batch, tracks off-heap batch memory once, and tears down safely on normal and failed pipelines. The change also removes the obsolete ShuffleV2 opcode and implementation, preserves protobuf compatibility, and regenerates protobuf bindings with make pb.

Validation:

  • Focused batch, shuffle, and compile package tests
  • Shuffle race test
  • Targeted build and vet
  • Added executable-line coverage: 79.22% (694/876)
  • Relevant group and full-outer-join BVTs executed; query values matched, while the current goldens contain stale result metadata and fixed-core EXPLAIN ANALYZE output

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

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 refactors MatrixOne’s execution pipeline to unify the former ShuffleV2 behavior into Shuffle, removing the ShuffleV2 opcode/implementation while preserving protobuf compatibility and adding an explicit “drain all buckets” mode for distributed execution.

Changes:

  • Adds drain_all_buckets to the pipeline.Shuffle protobuf and wires it through pipeline (de)serialization.
  • Removes ShuffleV2 (opcode, debug name, code, tests, CODEOWNERS entry) and updates planning/compile logic to use a single Shuffle operator with either local shared-pool or distributed drain-all behavior.
  • Reworks shuffle shared-pool lifecycle/backpressure and updates operator duplication to share generation-scoped pools without mutating reusable templates; adds targeted unit tests for pool behavior and serialization.

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
proto/pipeline.proto Adds drain_all_buckets field to Shuffle instruction for distributed drain-all behavior.
pkg/vm/types.go Reserves former ShuffleV2 opcode slot to keep later wire values stable.
pkg/sql/plan/ap_multi_cn_shuffle_merge_guide.md Updates documentation to reference only shuffle (removes shuffleV2).
pkg/sql/compile/scope.go Uses a shared duplication context when cloning operators for parallel scopes.
pkg/sql/compile/scope_test.go Verifies duplicated shuffles share a pool per generation and do not mutate the template.
pkg/sql/compile/remoterun.go Serializes/deserializes DrainAllBuckets in pipeline Shuffle instructions.
pkg/sql/compile/remoterun_test.go Adds Shuffle serialization roundtrip coverage including DrainAllBuckets.
pkg/sql/compile/operator.go Removes ShuffleV2 duplication path; adds duplication context to share ShufflePool across workers; updates shuffle construction helpers.
pkg/sql/compile/operator_test.go Updates duplication tests to cover shared pool behavior, consumer index assignment, and join-shuffle expr/col handling.
pkg/sql/compile/debugTools.go Removes shuffleV2 from debug instruction name mapping.
pkg/sql/compile/compile.go Unifies join/group shuffle compilation paths; introduces local vs distributed shuffle join/group selection; sets DrainAllBuckets for distributed cases.
pkg/sql/compile/compile_test.go Updates shuffle-group compilation tests for the unified local/distributed behavior.
pkg/sql/colexec/shuffleV2/types.go Deleted: removes ShuffleV2 operator implementation.
pkg/sql/colexec/shuffleV2/shufflepool.go Deleted: removes ShuffleV2 pool implementation.
pkg/sql/colexec/shuffleV2/shuffle.go Deleted: removes ShuffleV2 execution implementation.
pkg/sql/colexec/shuffleV2/shuffle_test.go Deleted: removes ShuffleV2 unit tests.
pkg/sql/colexec/shuffle/types.go Adds fields needed for unified shuffle behavior (e.g., CurrentShuffleIdx, DrainAllBuckets) and updates container state/lifecycle.
pkg/sql/colexec/shuffle/shufflepool.go Reworks ShufflePool into a bounded, generation-scoped shared pool with backpressure and drain-all support.
pkg/sql/colexec/shuffle/shufflepool_test.go New: adds focused tests for pool stopping semantics, fairness, abort/cleanup, backpressure/resume, and memory reporting.
pkg/sql/colexec/shuffle/shuffle.go Unifies Shuffle execution with resumable writes + drain-all mode and updated runtime-filter handling.
pkg/sql/colexec/shuffle/shuffle_test.go Updates Shuffle tests for new drain-all semantics and adds shared-pool fixed-bucket worker coverage.
pkg/container/batch/batch_set.go Adds readiness helpers (ReadyCount/ReadyDelta) and adjusts Union ownership timing for error paths.
pkg/container/batch/batch_set_test.go Adds readiness/off-heap growth test coverage.
CODEOWNERS Removes obsolete ShuffleV2 ownership entry.
Files not reviewed (2)
  • pkg/pb/logservice/logservice.pb.go: Generated file
  • pkg/pb/pipeline/pipeline.pb.go: Generated file

Comment thread pkg/sql/colexec/shuffle/shuffle.go Resolved
@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 →

@aunjgr

aunjgr commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@gouhongshen Fixed in 5e2ba1000 and updated onto the latest main via cdb8935ae.

Shuffle.Call now normalizes a successful child result to ExecNext, so a non-empty ExecStop from Limit cannot terminate the pipeline while shuffle-pool batches remain. Shuffle emits its own terminal status only after all writers stop and the ready/tail batches are drained.

Added TestShuffleDrainsBufferedRowsAfterChildExecStop using a real Limit and the expression-shuffle single-bucket fast path. Without the fix it returns 2 of 6 rows and leaves 4 rows pooled; with the fix all 6 rows are returned and mpool usage returns to zero.

Validation on the current head:

  • focused regression under -race -count=100
  • full shuffle package under -race
  • shuffle and dependent compile package tests
  • package build and vet

@aunjgr
aunjgr requested a review from gouhongshen July 20, 2026 03:04

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex automated review

No blocking regressions found. Focused CGo tests could not run because the checkout lacks cgo/libmo.dylib.

@mergify mergify Bot added the queued label Jul 20, 2026
@mergify

mergify Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-20 08:38 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-07-20 12:20 UTC · at b20638ce1b3ea7443db8167a77cbd232416b83f5 · squash

This pull request spent 3 hours 42 minutes 13 seconds in the queue, including 1 hour 1 minute 16 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed current head cdb8935 in depth. No blocking correctness or regression issues remain. I checked local/shared and distributed/drain-all routing, ready-token and batch ownership, bounded backpressure/resume, child ExecStop draining, abort/reset cleanup, wait-for exits, generation-scoped pool duplication, remote serialization, and opcode compatibility. The previously raised token-claim and premature-stop issues are fixed in this head. Focused tests passed for batch, shuffle, and compile packages; shuffle pool concurrency tests also passed under -race.

@mergify
mergify Bot merged commit a898fef into matrixorigin:main Jul 20, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label Jul 20, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Unifies the Shuffle and ShuffleV2 implementations, retaining the former V2 local shared-pool execution model in Shuffle while adding explicit drain-all-buckets behavior for distributed execution.

The shared pool is generation-scoped, bounds ready and recycled batches, resumes blocked writes without losing the input batch, tracks off-heap batch memory once, and tears down safely on normal and failed pipelines. The change also removes the obsolete ShuffleV2 opcode and implementation, preserves protobuf compatibility, and regenerates protobuf bindings with `make pb`.

Validation:

- Focused batch, shuffle, and compile package tests
- Shuffle race test
- Targeted build and vet
- Added executable-line coverage: 79.22% (694/876)
- Relevant group and full-outer-join BVTs executed; query values matched, while the current goldens contain stale result metadata and fixed-core EXPLAIN ANALYZE output

Approved by: @XuPeng-SH, @fengttt, @gouhongshen, @volgariver6, @LeftHandCold
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Unifies the Shuffle and ShuffleV2 implementations, retaining the former V2 local shared-pool execution model in Shuffle while adding explicit drain-all-buckets behavior for distributed execution.

The shared pool is generation-scoped, bounds ready and recycled batches, resumes blocked writes without losing the input batch, tracks off-heap batch memory once, and tears down safely on normal and failed pipelines. The change also removes the obsolete ShuffleV2 opcode and implementation, preserves protobuf compatibility, and regenerates protobuf bindings with `make pb`.

Validation:

- Focused batch, shuffle, and compile package tests
- Shuffle race test
- Targeted build and vet
- Added executable-line coverage: 79.22% (694/876)
- Relevant group and full-outer-join BVTs executed; query values matched, while the current goldens contain stale result metadata and fixed-core EXPLAIN ANALYZE output

Approved by: @XuPeng-SH, @fengttt, @gouhongshen, @volgariver6, @LeftHandCold
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Unifies the Shuffle and ShuffleV2 implementations, retaining the former V2 local shared-pool execution model in Shuffle while adding explicit drain-all-buckets behavior for distributed execution.

The shared pool is generation-scoped, bounds ready and recycled batches, resumes blocked writes without losing the input batch, tracks off-heap batch memory once, and tears down safely on normal and failed pipelines. The change also removes the obsolete ShuffleV2 opcode and implementation, preserves protobuf compatibility, and regenerates protobuf bindings with `make pb`.

Validation:

- Focused batch, shuffle, and compile package tests
- Shuffle race test
- Targeted build and vet
- Added executable-line coverage: 79.22% (694/876)
- Relevant group and full-outer-join BVTs executed; query values matched, while the current goldens contain stale result metadata and fixed-core EXPLAIN ANALYZE output

Approved by: @XuPeng-SH, @fengttt, @gouhongshen, @volgariver6, @LeftHandCold

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/refactor Code refactor size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: query execution performance improvements

8 participants