NoahKusaba commented on code in PR #2914:
URL: 
https://github.com/apache/datafusion-ballista/pull/2914#discussion_r4684803509


##########
ballista/scheduler/src/state/aqe/optimizer_rule/distributed_exchange.rs:
##########
@@ -183,11 +186,54 @@ impl DistributedExchangeRule {
                             execution_plan.name()
                         );
                     }
+                    if execution_plan.is::<UnionExec>() {
+                        return 
self.stage_unsplittable_branches(execution_plan);
+                    }
                 }
             }
         }
         Ok(Transformed::no(execution_plan))
     }
+
+    /// Give each branch of `union` that a task can't run its share of a stage
+    /// of its own, as the static planner does (`can_stay_inline`).
+    ///
+    /// A task running some of the union's partitions restricts every other
+    /// branch to none. A branch that keeps a partition anyway, such as one
+    /// that merges its input through a `SortExec` or a global aggregate, would
+    /// run whole in every task, and restriction refuses such a task. Behind
+    /// an exchange the branch is a shuffle reader, which restricts cleanly, 
and
+    /// the merge runs once.
+    ///
+    /// A branch is judged as the stage's tasks would run it, its exchanges
+    /// replaced by readers, so one over an exchange that hasn't run is left
+    /// for a later pass: the union's stage can't start before then.
+    fn stage_unsplittable_branches(

Review Comment:
   Ran `main` (7faef66, this PR's base) against this branch: the 19 `UNION` 
queries at SF1, adaptive, `max_partitions_per_task=1`, local cluster with one 
executor, best of iterations 2–3.
   
   Only q49 changes plan, from 13 to 16 stages. Each of its three branches 
ranks over its whole input (`rank() over (order by …)`), so each now gets a 
stage of its own. On `main` its union stage ran as one task. The other 18 
queries have the same stage counts on both builds, so their differences are 
noise, up to ±20% at these sub-second times. Total: 12.98 s on `main`, 13.07 s 
on this branch.
   
   q49 again, alternating builds, 10 iterations each (median): `main` 0.490 s / 
0.467 s, this branch 0.479 s / 0.485 s. No measurable difference.



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