2010YOUY01 commented on code in PR #23239:
URL: https://github.com/apache/datafusion/pull/23239#discussion_r3504791451
##########
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 think it’s good to proceed if someone is confident they fully understand
the related implementation and can confirm this complexity is hard to avoid.
Otherwise, it feels a bit risky to rely only on tests here. The code may
become harder to evolve if we keep adding more logic without a clearer model.
--
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]