andygrove commented on code in PR #2914:
URL:
https://github.com/apache/datafusion-ballista/pull/2914#discussion_r4682350017
##########
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:
Since each unsplittable branch now adds a stage and a shuffle, could you
share before/after timings against `main` for the 19 TPC-DS `UNION` queries at
SF1 with the adaptive planner? The stage count per query would be useful too.
I'd expect most TPC-DS union branches to be hash aggregates that stay inline,
so the impact is probably small. It would just be good to confirm. TPC-H has no
`UNION`, so it won't show anything here.
##########
ballista/scheduler/src/state/aqe/adapter.rs:
##########
@@ -248,6 +248,15 @@ impl BallistaAdapter {
Ok(Transformed::no(plan))
}
+ /// `plan` as its stage's tasks would see it: each `ExchangeExec`, which
+ /// must already be resolved, replaced by the reader the stage would get.
+ pub(crate) fn with_readers(
Review Comment:
Nit: this runs only the reader-building pass, and leaves out
`resolve_range_filter_cuts` and `attach_reader_bounds` from
`adapt_to_ballista`. So the plan `branch_splits` judges isn't exactly what the
tasks get. I think that's moot today, since a union with a range-repartitioned
child is rejected earlier in the `many` arm. Maybe worth a line in the doc
comment so nobody leans on it for more later?
##########
docs/source/upgrading/56.0.0.md:
##########
@@ -243,25 +243,22 @@ each task emitted its own copy of the build rows. These
joins now run as a
single task, so queries that use them may be slower. Other nested-loop joins
are unchanged.
-#### A split `UNION ALL` with a branch that merges its input runs as one task
+#### A `UNION ALL` branch that merges its input gets a stage of its own
When a stage is split between tasks, each task restricts the `UnionExec`
-branches other tasks own to no partitions. The adaptive planner can leave a
-branch that merges its input into one partition in the union's stage: in a
+branches other tasks own to no partitions. The adaptive planner used to leave
+a branch that merges its input into one partition in the union's stage: in a
`UNION ALL ... ORDER BY`, a branch with a `LIMIT` or an `ORDER BY ... LIMIT`,
or
a `UNION ALL` of aggregates without `GROUP BY`. Such a branch reads its input
whole and keeps its one partition, so every task of the stage ran it, and the
query returned wrong rows, over any source including Parquet.
-The scheduler now runs such a stage as one task, as it does a stage that
-collapses its input, so each branch runs once. The same goes for a branch that
-reads a broadcast, holds a node that sets its own partition count, or reads a
-leaf of several partitions that nothing can restrict. The task
-ignores `ballista.scheduler.max_partitions_per_task` and takes one vcore for
-each of the stage's partitions, up to what its executor has free, so the stage
-runs with less parallelism than before. The scheduler logs each such stage at
-`info` level, naming the branch. The static planner gives such a branch a stage
-of its own and is unaffected.
+The adaptive planner now gives such a branch a stage of its own, as the static
+planner does, so the union's stage reads the branch through a shuffle reader
and
+still splits between tasks. The same goes for a branch that reads a broadcast,
+holds a node that sets its own partition count, or reads a leaf of several
+partitions that nothing but a resolver can restrict. Each such branch adds a
Review Comment:
The PR body explains nicely that an embedder's `replan_rules` run after
`DistributedExchangeRule`. So a rule that puts a partition-keeping node into a
union branch now hits the "cannot restrict a `UnionExec` branch" error instead
of running as one task. Could that go into this upgrade note too? Library users
will read the guide rather than the PR, and it's the one case here that goes
from working to an error.
##########
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(
+ &self,
+ union: Arc<dyn ExecutionPlan>,
+ ) -> datafusion::error::Result<Transformed<Arc<dyn ExecutionPlan>>> {
+ let mut branches: Vec<_> =
union.children().into_iter().cloned().collect();
+ let mut staged = false;
+ for branch in &mut branches {
+ if matches!(nearest_exchange_status(branch),
ExchangeStatus::Unresolved)
+ ||
branch_splits(&BallistaAdapter::with_readers(Arc::clone(branch))?)
Review Comment:
Question: since no resolver is passed here, a custom node that a
`PartitionSliceableResolver` can restrict now gets a stage of its own, where in
55.0.0 it stayed inline. Results are right, it just costs a stage. Would you
mind opening the follow-up issue for passing the scheduler's resolver to
`DistributedExchangeRule` now, so it doesn't get lost? The resolver is already
on `SchedulerConfig`, so the plumbing looks small.
--
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]