fix: Do not add redundant exchange over remote function#27170
Merged
feilong-liu merged 1 commit intoprestodb:masterfrom Feb 23, 2026
Merged
fix: Do not add redundant exchange over remote function#27170feilong-liu merged 1 commit intoprestodb:masterfrom
feilong-liu merged 1 commit intoprestodb:masterfrom
Conversation
Contributor
Reviewer's GuideUpdates AddExchanges so it only adds a trailing remote round‑robin exchange for remote fixed‑parallelism projections when the preferred global properties are distributed, and adjusts/extends planner tests to assert the new behavior for both distributed and undistributed cases. Sequence diagram for AddExchanges conditional trailing exchange on ProjectNodesequenceDiagram
participant Planner as Planner
participant AddExchanges as AddExchanges
participant PreferredProperties as PreferredProperties
participant GlobalProps as GlobalProperties
Planner->>AddExchanges: visitProject(projectNode, preferredProperties)
AddExchanges->>AddExchanges: create first remote roundRobinExchange
AddExchanges->>AddExchanges: replace ProjectNode child with first exchange
AddExchanges->>PreferredProperties: getGlobalProperties()
PreferredProperties-->>AddExchanges: Optional<GlobalProperties>
AddExchanges->>GlobalProps: isDistributed()
GlobalProps-->>AddExchanges: boolean
alt distributed or absent (default true)
AddExchanges->>AddExchanges: create trailing remote roundRobinExchange
AddExchanges-->>Planner: PlanWithProperties(ProjectNode + two exchanges)
else undistributed
AddExchanges-->>Planner: PlanWithProperties(ProjectNode + one exchange)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
AddExchanges.visitProject, the new condition usespreferredProperties.getGlobalProperties().map(PreferredProperties.Global::isDistributed).orElse(true); consider whetherorElse(true)is really desired (i.e., defaulting to adding the trailing exchange when distribution is unknown) or if defaulting tofalsewould better reflect the intended behavior. - The two new tests for skipping vs not skipping the trailing exchange build the same session configuration multiple times; consider extracting a small helper to construct that session to keep the tests more focused on the query shape and expected plan.
- The method name
testRemoteFunctionFixedParallelismNotSkipsTrailingExchangeWhenDistributedis a bit hard to parse; renaming to something liketestRemoteFunctionFixedParallelismKeepsTrailingExchangeWhenDistributedwould make the intent clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `AddExchanges.visitProject`, the new condition uses `preferredProperties.getGlobalProperties().map(PreferredProperties.Global::isDistributed).orElse(true)`; consider whether `orElse(true)` is really desired (i.e., defaulting to adding the trailing exchange when distribution is unknown) or if defaulting to `false` would better reflect the intended behavior.
- The two new tests for skipping vs not skipping the trailing exchange build the same session configuration multiple times; consider extracting a small helper to construct that session to keep the tests more focused on the query shape and expected plan.
- The method name `testRemoteFunctionFixedParallelismNotSkipsTrailingExchangeWhenDistributed` is a bit hard to parse; renaming to something like `testRemoteFunctionFixedParallelismKeepsTrailingExchangeWhenDistributed` would make the intent clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
Actually, it should never be needed because if the next stage needs exchange, it will be done automatically. |
Summary: As title Differential Revision: D93701641
554735a to
b6e9167
Compare
Contributor
Author
You are right, we do not need this additional exchange. Updated the code |
kaikalur
approved these changes
Feb 20, 2026
NikhilCollooru
approved these changes
Feb 23, 2026
This was referenced Mar 31, 2026
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
We added an option in #27044 to set the number of tasks for remote functions, however we observe that it will add an unnecessary exchange even when the remote function directly send data to output node. This PR will remove this unnecessary exchange node.
Motivation and Context
Simplify plans
Impact
Make the plan to streaming result out.
Test Plan
Unit tests
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.
Summary by Sourcery
Adjust exchange planning for remote function projections to avoid adding unnecessary trailing exchanges when the plan is not required to be distributed.
Bug Fixes:
Tests: