Skip to content

refactor(schedule): introduce staged query placement - #25537

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:refactor_schedule_phase5_0708
Jul 8, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:refactor_schedule_phase5_0708

Conversation

@XuPeng-SH

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 #25451

What this PR does / why we need it:

This PR introduces the next scheduler refactor step after the current-CN placement policy work:

  • separates query worker decisions from scan/stage materialization
  • adds explicit stage placement decisions for single-worker and query-worker stages
  • keeps scan placement decisions in the schedule package with focused unhappy-path coverage
  • preserves local sentinel semantics while materializing executable engine nodes only at compile boundaries
  • updates compile tests for stage placement, scan placement, current-CN route handling, and execution-node identity matching

@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

Copy link
Copy Markdown
Contributor Author

Correction to my earlier LGTM: the delayed runtime pass found a real blocker.

MINUS / INTERSECT can now be moved onto the lone scheduled query worker via newScopeListOnSingleWorkerStage(), but the feeder paths still assume the result stage is coordinator-local.

Concretely:

  • compileTpMinusAndIntersect() still wires inputs with plain local connector regs.
  • newScopeListForMinusAndIntersect() still builds leftMerge/rightMerge with c.newMergeScope(...) on the current CN.

That means a single-remote-worker MINUS/INTERSECT can now receive coordinator-local feeders through local-only connectors, and the multi-scope path can also break when the current-CN side still carries an id-only sentinel with empty FromAddr.

I would treat this as a blocker. The safe fix is to keep MINUS/INTERSECT on the coordinator unless all feeder scopes are already on the chosen worker, or add a stage-aware feeder/merge path that materializes the inputs on the same worker and uses a real cross-CN dispatch when needed.

XuPeng-SH added a commit that referenced this pull request Jul 9, 2026
…tch source address (#25556)

## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue #25554

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

PR #25537 replaced `isSameCN` with `sameExecutionNode` in
`constructDispatchLocalAndRemote`. The new function correctly treats
empty-vs-non-empty addresses as different execution nodes, but
`compileExternScanParallelWrite` still hardcoded an empty address for
the source scope, causing:

1. dispatch Prepare sees RemoteRegs + FuncId=`SendToAnyLocalFunc` →
raises `"SendToAnyLocalFunc should not send to remote"`
2. Runtime tries to connect to empty address via morpc → `"dial tcp4:
missing address"` infinite retry
3. Query hangs forever until workflow timeout

**Fix**: Pass the current CN address (`c.addr`) to
`constructScopeForExternal` in `compileExternScanParallelWrite`, so
`sameExecutionNode` correctly identifies source and target as the same
local node.

**Affected**: All LOAD DATA with compressed files (flate/bz2/gzip/lz4)
where `mcpu > 1`. Not specific to any compression type.

## Verification

- `go vet ./pkg/sql/compile/` ✅
- `go test ./pkg/sql/compile/` ✅
- Added `TestSameExecutionNodeMatchesByAddressForLocalScope` regression
test ✅

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25451

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

This PR introduces the next scheduler refactor step after the current-CN
placement policy work:

- separates query worker decisions from scan/stage materialization
- adds explicit stage placement decisions for single-worker and
query-worker stages
- keeps scan placement decisions in the schedule package with focused
unhappy-path coverage
- preserves local sentinel semantics while materializing executable
engine nodes only at compile boundaries
- updates compile tests for stage placement, scan placement, current-CN
route handling, and execution-node identity matching
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…tch source address (matrixorigin#25556)

## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue matrixorigin#25554

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

PR matrixorigin#25537 replaced `isSameCN` with `sameExecutionNode` in
`constructDispatchLocalAndRemote`. The new function correctly treats
empty-vs-non-empty addresses as different execution nodes, but
`compileExternScanParallelWrite` still hardcoded an empty address for
the source scope, causing:

1. dispatch Prepare sees RemoteRegs + FuncId=`SendToAnyLocalFunc` →
raises `"SendToAnyLocalFunc should not send to remote"`
2. Runtime tries to connect to empty address via morpc → `"dial tcp4:
missing address"` infinite retry
3. Query hangs forever until workflow timeout

**Fix**: Pass the current CN address (`c.addr`) to
`constructScopeForExternal` in `compileExternScanParallelWrite`, so
`sameExecutionNode` correctly identifies source and target as the same
local node.

**Affected**: All LOAD DATA with compressed files (flate/bz2/gzip/lz4)
where `mcpu > 1`. Not specific to any compression type.

## Verification

- `go vet ./pkg/sql/compile/` ✅
- `go test ./pkg/sql/compile/` ✅
- Added `TestSameExecutionNodeMatchesByAddressForLocalScope` regression
test ✅

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25451

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

This PR introduces the next scheduler refactor step after the current-CN
placement policy work:

- separates query worker decisions from scan/stage materialization
- adds explicit stage placement decisions for single-worker and
query-worker stages
- keeps scan placement decisions in the schedule package with focused
unhappy-path coverage
- preserves local sentinel semantics while materializing executable
engine nodes only at compile boundaries
- updates compile tests for stage placement, scan placement, current-CN
route handling, and execution-node identity matching
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…tch source address (matrixorigin#25556)

## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue matrixorigin#25554

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

PR matrixorigin#25537 replaced `isSameCN` with `sameExecutionNode` in
`constructDispatchLocalAndRemote`. The new function correctly treats
empty-vs-non-empty addresses as different execution nodes, but
`compileExternScanParallelWrite` still hardcoded an empty address for
the source scope, causing:

1. dispatch Prepare sees RemoteRegs + FuncId=`SendToAnyLocalFunc` →
raises `"SendToAnyLocalFunc should not send to remote"`
2. Runtime tries to connect to empty address via morpc → `"dial tcp4:
missing address"` infinite retry
3. Query hangs forever until workflow timeout

**Fix**: Pass the current CN address (`c.addr`) to
`constructScopeForExternal` in `compileExternScanParallelWrite`, so
`sameExecutionNode` correctly identifies source and target as the same
local node.

**Affected**: All LOAD DATA with compressed files (flate/bz2/gzip/lz4)
where `mcpu > 1`. Not specific to any compression type.

## Verification

- `go vet ./pkg/sql/compile/` ✅
- `go test ./pkg/sql/compile/` ✅
- Added `TestSameExecutionNodeMatchesByAddressForLocalScope` regression
test ✅

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#25451

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

This PR introduces the next scheduler refactor step after the current-CN
placement policy work:

- separates query worker decisions from scan/stage materialization
- adds explicit stage placement decisions for single-worker and
query-worker stages
- keeps scan placement decisions in the schedule package with focused
unhappy-path coverage
- preserves local sentinel semantics while materializing executable
engine nodes only at compile boundaries
- updates compile tests for stage placement, scan placement, current-CN
route handling, and execution-node identity matching
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…tch source address (matrixorigin#25556)

## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

issue matrixorigin#25554

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

PR matrixorigin#25537 replaced `isSameCN` with `sameExecutionNode` in
`constructDispatchLocalAndRemote`. The new function correctly treats
empty-vs-non-empty addresses as different execution nodes, but
`compileExternScanParallelWrite` still hardcoded an empty address for
the source scope, causing:

1. dispatch Prepare sees RemoteRegs + FuncId=`SendToAnyLocalFunc` →
raises `"SendToAnyLocalFunc should not send to remote"`
2. Runtime tries to connect to empty address via morpc → `"dial tcp4:
missing address"` infinite retry
3. Query hangs forever until workflow timeout

**Fix**: Pass the current CN address (`c.addr`) to
`constructScopeForExternal` in `compileExternScanParallelWrite`, so
`sameExecutionNode` correctly identifies source and target as the same
local node.

**Affected**: All LOAD DATA with compressed files (flate/bz2/gzip/lz4)
where `mcpu > 1`. Not specific to any compression type.

## Verification

- `go vet ./pkg/sql/compile/` ✅
- `go test ./pkg/sql/compile/` ✅
- Added `TestSameExecutionNodeMatchesByAddressForLocalScope` regression
test ✅

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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/refactor Code refactor kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants