924060929 commented on code in PR #63366:
URL: https://github.com/apache/doris/pull/63366#discussion_r3413700850


##########
fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java:
##########
@@ -824,14 +828,97 @@ public void 
foreachDownInCurrentFragment(Consumer<PlanNode> visitor) {
         });
     }
 
-    // Operators need to be executed serially. (e.g. finalized agg without key)
-    public boolean isSerialOperator() {
+    /**
+     * Node-level "is this operator inherently serial" property — answers 
without looking
+     * at the fragment.  Default false; subclasses override (e.g. finalized 
agg without key,
+     * UNPARTITIONED ExchangeNode with merge sort).
+     *
+     * Use ONLY in framework-internal places where we are already iterating 
within a
+     * fragment whose serial-source mode is fixed: {@link 
#shouldResetSerialFlagForChild}
+     * inputs, {@link #createLocalExchange} heavy-op gate, and 
child.isSerialNode() checks
+     * embedded inside an enforceRequire path.  Do NOT use it when computing a
+     * {@link LocalExchangeNode.LocalExchangeTypeRequire} on a child — call
+     * {@link #isSerialOperatorOnBe} instead.
+     */
+    public boolean isSerialNode() {

Review Comment:
   > @morrySnow just curious, why don't you impl it before translation and 
after post process in Nereids?
   
   (Answering the review-summary question here, anchored to where it actually 
runs.)
   
   It needs two inputs that only exist **after translation + distribute**, not 
on the Nereids physical plan:
   
   1. **PlanNode-level info** — `AddLocalExchange` walks the translated 
`PlanNode` / `PlanFragment` tree via `PlanNode.enforceAndDeriveLocalExchange` 
(`isSerialNode()` / `isSerialOperatorOnBe()`, the distribute-expr lists 
serialized to BE thrift, the fragment sink type, …). Those are the legacy 
`PlanNode`s the translator produces — they don't exist on the Nereids physical 
operators.
   
   2. **Instance counts** — whether to insert an LE (and the fan-out width) 
depends on the per-BE instance count: `addLocalExchange` skips fragments where 
`maxPerBeInstances <= 1` (mirroring BE's `_num_instances <= 1` no-op), and the 
PASSTHROUGH fan-out targets `_num_instances`. Instance assignment is done by 
`DistributePlanner`, which runs **after** translation.
   
   So it runs right here — after `splitFragments()` + `doDistribute()` — the 
first point where both the BE-facing PlanNode tree and the instance assignment 
exist. Doing it pre-translation in Nereids would mean re-deriving fragment 
structure + instance counts that haven't been computed yet.
   



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java:
##########
@@ -740,6 +742,19 @@ protected void distribute(PhysicalPlan physicalPlan, 
ExplainLevel explainLevel)
 
         splitFragments(physicalPlan);
         doDistribute(canUseNereidsDistributePlanner, explainLevel);
+
+        addLocalExchangeAfterDistribute();

Review Comment:
   > @morrySnow just curious, why don't you impl it before translation and 
after post process in Nereids?
   
   (Answering the review-summary question here, anchored to where it actually 
runs.)
   
   It needs two inputs that only exist **after translation + distribute**, not 
on the Nereids physical plan:
   
   1. **PlanNode-level info** — `AddLocalExchange` walks the translated 
`PlanNode` / `PlanFragment` tree via `PlanNode.enforceAndDeriveLocalExchange` 
(`isSerialNode()` / `isSerialOperatorOnBe()`, the distribute-expr lists 
serialized to BE thrift, the fragment sink type, …). Those are the legacy 
`PlanNode`s the translator produces — they don't exist on the Nereids physical 
operators.
   
   2. **Instance counts** — whether to insert an LE (and the fan-out width) 
depends on the per-BE instance count: `addLocalExchange` skips fragments where 
`maxPerBeInstances <= 1` (mirroring BE's `_num_instances <= 1` no-op), and the 
PASSTHROUGH fan-out targets `_num_instances`. Instance assignment is done by 
`DistributePlanner`, which runs **after** translation.
   
   So it runs right here — after `splitFragments()` + `doDistribute()` — the 
first point where both the BE-facing PlanNode tree and the instance assignment 
exist. Doing it pre-translation in Nereids would mean re-deriving fragment 
structure + instance counts that haven't been computed yet.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to