Skip to content

fix(compile): validate distributed shuffle reuse topology - #25987

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aunjgr:fix/shuffle-reuse-topology-25930
Jul 21, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aunjgr:fix/shuffle-reuse-topology-25930

Conversation

@aunjgr

@aunjgr aunjgr commented Jul 21, 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:

issue #25930

What this PR does / why we need it:

A logical ShuffleMethod_Reuse decision does not by itself guarantee that the
compiled probe scopes have the physical layout required by a distributed
shuffle join. A packed local scope (Mcpu = DOP) represents all local buckets,
but the distributed reuse path treated that single scope as one bucket. The
build shuffle could therefore emit bucket N to a dispatch with only one
receiver, causing the reported shuffleToAllFunc index-out-of-range panic.

This change reuses distributed probe scopes only when there is exactly one
Mcpu=1 scope per global bucket in stage-node order. Otherwise it materializes
the normal distributed shuffle layout. Multi-CN DEDUP also falls back because
its scope normalization merges the per-bucket layout before dispatch wiring.

Regression coverage includes packed-scope fallback, valid materialized reuse,
misordered multi-CN scopes, multi-CN DEDUP normalization, and a focused BVT
using a shuffled DISTINCT probe with a merged UNION ALL build. The BVT
panics on unpatched main with index out of range [1] with length 1 and passes
18/18 statements with this fix.

Validation:

  • make build
  • go vet -mod=readonly ./pkg/sql/compile with repository CGo flags
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s ./pkg/sql/compile
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=240s -run '^TestDistributedShuffleJoin' ./pkg/sql/compile
  • mo-tester BVT: shuffle_reuse_topology.sql (18/18)

@aunjgr
aunjgr requested a review from XuPeng-SH as a code owner July 21, 2026 12:17
@aunjgr
aunjgr requested a review from a user July 21, 2026 12:17
@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 →

@XuPeng-SH XuPeng-SH 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.

Deep review completed on 2aee1d3. I traced logical shuffle reuse through physical scope materialization, stage-node/bucket ordering, local/remote dispatch index wiring, hash-build/join consumption, multi-CN DEDUP normalization, and cleanup/wait boundedness. No blocking findings.

Verified locally: focused topology regressions x20; focused race; full pkg/sql/compile and full race; pkg/sql/colexec/dispatch; go build and go vet. I also clean-merged latest main a327eaa and reran the full compile package plus focused race successfully.

Ubuntu UT and SCA are green. Compose/standalone/coverage jobs were still running at review time.

@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 actionable regressions found. The topology validation correctly prevents invalid distributed reuse and preserves valid reuse; existing review and CI evidence are consistent.

VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#25987)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#25930

## What this PR does / why we need it:

A logical `ShuffleMethod_Reuse` decision does not by itself guarantee
that the
compiled probe scopes have the physical layout required by a distributed
shuffle join. A packed local scope (`Mcpu = DOP`) represents all local
buckets,
but the distributed reuse path treated that single scope as one bucket.
The
build shuffle could therefore emit bucket N to a dispatch with only one
receiver, causing the reported `shuffleToAllFunc` index-out-of-range
panic.

This change reuses distributed probe scopes only when there is exactly
one
`Mcpu=1` scope per global bucket in stage-node order. Otherwise it
materializes
the normal distributed shuffle layout. Multi-CN DEDUP also falls back
because
its scope normalization merges the per-bucket layout before dispatch
wiring.

Regression coverage includes packed-scope fallback, valid materialized
reuse,
misordered multi-CN scopes, multi-CN DEDUP normalization, and a focused
BVT
using a shuffled `DISTINCT` probe with a merged `UNION ALL` build. The
BVT
panics on unpatched main with `index out of range [1] with length 1` and
passes
18/18 statements with this fix.

Validation:

- `make build`
- `go vet -mod=readonly ./pkg/sql/compile` with repository CGo flags
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s
./pkg/sql/compile`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1
-timeout=240s -run '^TestDistributedShuffleJoin' ./pkg/sql/compile`
- `mo-tester` BVT: `shuffle_reuse_topology.sql` (18/18)

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#25987)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#25930

## What this PR does / why we need it:

A logical `ShuffleMethod_Reuse` decision does not by itself guarantee
that the
compiled probe scopes have the physical layout required by a distributed
shuffle join. A packed local scope (`Mcpu = DOP`) represents all local
buckets,
but the distributed reuse path treated that single scope as one bucket.
The
build shuffle could therefore emit bucket N to a dispatch with only one
receiver, causing the reported `shuffleToAllFunc` index-out-of-range
panic.

This change reuses distributed probe scopes only when there is exactly
one
`Mcpu=1` scope per global bucket in stage-node order. Otherwise it
materializes
the normal distributed shuffle layout. Multi-CN DEDUP also falls back
because
its scope normalization merges the per-bucket layout before dispatch
wiring.

Regression coverage includes packed-scope fallback, valid materialized
reuse,
misordered multi-CN scopes, multi-CN DEDUP normalization, and a focused
BVT
using a shuffled `DISTINCT` probe with a merged `UNION ALL` build. The
BVT
panics on unpatched main with `index out of range [1] with length 1` and
passes
18/18 statements with this fix.

Validation:

- `make build`
- `go vet -mod=readonly ./pkg/sql/compile` with repository CGo flags
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s
./pkg/sql/compile`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1
-timeout=240s -run '^TestDistributedShuffleJoin' ./pkg/sql/compile`
- `mo-tester` BVT: `shuffle_reuse_topology.sql` (18/18)

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#25987)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#25930

## What this PR does / why we need it:

A logical `ShuffleMethod_Reuse` decision does not by itself guarantee
that the
compiled probe scopes have the physical layout required by a distributed
shuffle join. A packed local scope (`Mcpu = DOP`) represents all local
buckets,
but the distributed reuse path treated that single scope as one bucket.
The
build shuffle could therefore emit bucket N to a dispatch with only one
receiver, causing the reported `shuffleToAllFunc` index-out-of-range
panic.

This change reuses distributed probe scopes only when there is exactly
one
`Mcpu=1` scope per global bucket in stage-node order. Otherwise it
materializes
the normal distributed shuffle layout. Multi-CN DEDUP also falls back
because
its scope normalization merges the per-bucket layout before dispatch
wiring.

Regression coverage includes packed-scope fallback, valid materialized
reuse,
misordered multi-CN scopes, multi-CN DEDUP normalization, and a focused
BVT
using a shuffled `DISTINCT` probe with a merged `UNION ALL` build. The
BVT
panics on unpatched main with `index out of range [1] with length 1` and
passes
18/18 statements with this fix.

Validation:

- `make build`
- `go vet -mod=readonly ./pkg/sql/compile` with repository CGo flags
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s
./pkg/sql/compile`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1
-timeout=240s -run '^TestDistributedShuffleJoin' ./pkg/sql/compile`
- `mo-tester` BVT: `shuffle_reuse_topology.sql` (18/18)

Co-authored-by: XuPeng-SH <[email protected]>

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants