Repository navigation
fix(compile): schedule union all branches lazily - #27009
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the complete diff at ba5d758. Lazy admission is gated by streaming demand and semantic barriers, preserves ordinary UNION ALL topology, activates receivers before producers, and closes startup/error/cancel/early-limit/reuse cleanup paths without waiting on unstarted branches. Focused unionall/compile tests pass locally; CI is green.
Merge Queue Status
This pull request spent 9 minutes 37 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
aptend
left a comment
There was a problem hiding this comment.
Reviewed the complete diff at eee7c0a. Lazy admission is limited to streaming LIMIT demand across non-blocking nodes; ordinary UNION ALL keeps the concurrent topology, while nested eligible chains preserve branch order and internal parallelism. The receiver-before-producer handoff and active-only wait accounting close early-stop, cancellation, submission-failure, terminal-signal, and prepared-reuse paths without waiting on unstarted branches. Full affected-package tests, focused race tests, and 100x lifecycle stress tests pass locally.
## 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#26066 ## What this PR does / why we need it: Compiles UNION ALL with sequential branch activation only when a streaming LIMIT can short-circuit it. The demand is propagated before physical scopes are built, so ordinary UNION ALL keeps its original concurrent topology and pays no extra connector, spool, merge, channel, or goroutine hop. An eligible UNION ALL starts only its first logical branch while retaining that branch's internal parallelism. Directly nested UNION ALL chains are absorbed into one scheduler; this prevents a buffered inner scheduler from starting a later leaf before the outer LIMIT can stop consumption. Semantic boundaries such as ORDER BY, window, assertion/barrier filters, and user-level lock side effects stop demand propagation, and an inner LIMIT remains intact. On early LIMIT stop or cancellation, unstarted branches have no goroutine, reader, remote notification, or terminal signal to wait for. Cleanup drains only active receivers. Startup and cancellation races still deliver a terminal signal for every activated receiver, and execution-generation callbacks are cleared before reuse. Coverage includes unchanged non-LIMIT topology, demand propagation and blocking boundaries, nested chain flattening and ANALYZE attribution, inner-LIMIT preservation, first-branch satisfaction, empty-branch advancement, full exhaustion, cancellation between receivers, startup failure, missing callbacks, active-only cleanup, and prepared-generation reuse. Tests: - `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/colexec/merge ./pkg/sql/compile -count=1 -timeout=10m` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestCompileUnionAll.*|TestStreamingUnionAll.*|TestCompilePlanScope.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=1 -timeout=5m` - `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=100 -timeout=2m` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## 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#26066 ## What this PR does / why we need it: Compiles UNION ALL with sequential branch activation only when a streaming LIMIT can short-circuit it. The demand is propagated before physical scopes are built, so ordinary UNION ALL keeps its original concurrent topology and pays no extra connector, spool, merge, channel, or goroutine hop. An eligible UNION ALL starts only its first logical branch while retaining that branch's internal parallelism. Directly nested UNION ALL chains are absorbed into one scheduler; this prevents a buffered inner scheduler from starting a later leaf before the outer LIMIT can stop consumption. Semantic boundaries such as ORDER BY, window, assertion/barrier filters, and user-level lock side effects stop demand propagation, and an inner LIMIT remains intact. On early LIMIT stop or cancellation, unstarted branches have no goroutine, reader, remote notification, or terminal signal to wait for. Cleanup drains only active receivers. Startup and cancellation races still deliver a terminal signal for every activated receiver, and execution-generation callbacks are cleared before reuse. Coverage includes unchanged non-LIMIT topology, demand propagation and blocking boundaries, nested chain flattening and ANALYZE attribution, inner-LIMIT preservation, first-branch satisfaction, empty-branch advancement, full exhaustion, cancellation between receivers, startup failure, missing callbacks, active-only cleanup, and prepared-generation reuse. Tests: - `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/colexec/merge ./pkg/sql/compile -count=1 -timeout=10m` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestCompileUnionAll.*|TestStreamingUnionAll.*|TestCompilePlanScope.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=1 -timeout=5m` - `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=100 -timeout=2m` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## 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#26066 ## What this PR does / why we need it: Compiles UNION ALL with sequential branch activation only when a streaming LIMIT can short-circuit it. The demand is propagated before physical scopes are built, so ordinary UNION ALL keeps its original concurrent topology and pays no extra connector, spool, merge, channel, or goroutine hop. An eligible UNION ALL starts only its first logical branch while retaining that branch's internal parallelism. Directly nested UNION ALL chains are absorbed into one scheduler; this prevents a buffered inner scheduler from starting a later leaf before the outer LIMIT can stop consumption. Semantic boundaries such as ORDER BY, window, assertion/barrier filters, and user-level lock side effects stop demand propagation, and an inner LIMIT remains intact. On early LIMIT stop or cancellation, unstarted branches have no goroutine, reader, remote notification, or terminal signal to wait for. Cleanup drains only active receivers. Startup and cancellation races still deliver a terminal signal for every activated receiver, and execution-generation callbacks are cleared before reuse. Coverage includes unchanged non-LIMIT topology, demand propagation and blocking boundaries, nested chain flattening and ANALYZE attribution, inner-LIMIT preservation, first-branch satisfaction, empty-branch advancement, full exhaustion, cancellation between receivers, startup failure, missing callbacks, active-only cleanup, and prepared-generation reuse. Tests: - `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/colexec/merge ./pkg/sql/compile -count=1 -timeout=10m` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestCompileUnionAll.*|TestStreamingUnionAll.*|TestCompilePlanScope.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=1 -timeout=5m` - `.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=100 -timeout=2m` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
issue #26066
What this PR does / why we need it:
Compiles UNION ALL with sequential branch activation only when a streaming LIMIT can short-circuit it. The demand is propagated before physical scopes are built, so ordinary UNION ALL keeps its original concurrent topology and pays no extra connector, spool, merge, channel, or goroutine hop.
An eligible UNION ALL starts only its first logical branch while retaining that branch's internal parallelism. Directly nested UNION ALL chains are absorbed into one scheduler; this prevents a buffered inner scheduler from starting a later leaf before the outer LIMIT can stop consumption. Semantic boundaries such as ORDER BY, window, assertion/barrier filters, and user-level lock side effects stop demand propagation, and an inner LIMIT remains intact.
On early LIMIT stop or cancellation, unstarted branches have no goroutine, reader, remote notification, or terminal signal to wait for. Cleanup drains only active receivers. Startup and cancellation races still deliver a terminal signal for every activated receiver, and execution-generation callbacks are cleared before reuse.
Coverage includes unchanged non-LIMIT topology, demand propagation and blocking boundaries, nested chain flattening and ANALYZE attribution, inner-LIMIT preservation, first-branch satisfaction, empty-branch advancement, full exhaustion, cancellation between receivers, startup failure, missing callbacks, active-only cleanup, and prepared-generation reuse.
Tests:
.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/colexec/merge ./pkg/sql/compile -count=1 -timeout=10m.agents/skills/mo-dev/scripts/mo-cgo-test -race ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestCompileUnionAll.*|TestStreamingUnionAll.*|TestCompilePlanScope.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=1 -timeout=5m.agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/unionall ./pkg/sql/compile -run '^(TestSequentialUnionAll.*|TestLazyUnionAll.*|TestLazyNestedUnionAll.*)$' -count=100 -timeout=2m