gene-bordegaray commented on code in PR #23239:
URL: https://github.com/apache/datafusion/pull/23239#discussion_r3498768534
##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1245,15 +1180,58 @@ pub fn ensure_distribution(
child = add_merge_on_top(child, removed_fetch);
}
Distribution::HashPartitioned(exprs) => {
+ let child_partitions =
+ child.plan.output_partitioning().partition_count();
+ let hash_satisfied = child
+ .plan
+ .output_partitioning()
+ .satisfaction(
+ &requirement,
+ child.plan.equivalence_properties(),
+ allow_subset_satisfy_partitioning,
+ )
+ .is_satisfied();
+ let range_satisfied_for_aggregate =
+ aggregate_can_reuse_range_partitioning(&plan)
+ && allow_subset_satisfy_partitioning
+ && range_partitioning_satisfies_key_partitioning(
+ child.plan.output_partitioning(),
+ exprs,
+ child.plan.equivalence_properties(),
+ allow_subset_satisfy_partitioning,
+ );
+
+ // When subset satisfaction is enabled, preserve an
+ // already-satisfying partitioning. Otherwise, hash
+ // repartition may also increase parallelism.
+ let needs_hash_repartition = if
allow_subset_satisfy_partitioning {
+ !hash_satisfied
+ } else {
+ !hash_satisfied || target_partitions > child_partitions
+ };
+ let should_add_hash_repartition = hash_necessary
+ && needs_hash_repartition
+ && !range_satisfied_for_aggregate;
+
Review Comment:
I know... this rule was the first optimizer rule I spent time in and man,
its a hard one to digest. It is on my bucket list to clean this guy up more too
--
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]