You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Preserve Partitioning::Range across stage boundaries so downstream consumer operations (joins, aggregations, window functions) can remain co-partitioned without triggering unnecessary hash repartitions.
Background
The original description proposed unioning matching partition indices across tasks in NetworkCoalesceExec (output_partition[i] = Union(task[*].partition[i])). Topologically, that multi-producer exchange is a shuffle rather than a coalesce.
With datafusion-contrib/datafusion-distributed#730 adding range support to NetworkShuffleExec and apache/datafusion#25483 introducing range layout relationships upstream, the problem separates into two distinct boundaries:
NetworkShuffleExec (Sparse Exchange): When multiple producer tasks output the same range buckets, we need sparse connections so consumer i only reads bucket i across producers without per-row repartitioning.
NetworkCoalesceExec (Disjoint Gather): When producer tasks already hold disjoint, contiguous ranges (e.g. leaf file groups), coalescing them into fewer consumer tasks should yield a coarser SourceFinerRangePartitioning. Currently, it degrades to UnknownPartitioning:
Queries that execute a co-partitioned operation, reduce rows, and feed into a downstream stage expecting the same range key:
1. Multi-way join with early row reduction
SELECT*FROM (
SELECTt1.id, t1.val, t2.extraFROM t1 JOIN t2 ONt1.id=t2.idWHEREt1.val>100
) sub
JOIN t3 ONsub.id=t3.idORDER BYsub.idLIMIT10;
Stage 1: Co-partitioned join of t1 and t2 on id followed by a selective filter.
Stage 2: Directly join reduced stream with t3 (also range-partitioned on id) without reshuffling.
Current issue: NetworkCoalesceExec drops range partitioning to UnknownPartitioning, while NetworkShuffleExec cannot prove co-partitioning if split points or partition counts differ from t3, forcing a full hash repartition.
2. Group-by aggregation or window function over co-partitioned join
SELECTt1.category_id, count(*), sum(t2.amount)
FROM t1 JOIN t2 ONt1.category_id=t2.category_idGROUP BYt1.category_id;
Workers execute a co-partitioned join and partial aggregate.
Losing range layout across the stage boundary forces an intermediate hash shuffle instead of letting the final aggregate/window run in place per partition.
Summary
Preserve
Partitioning::Rangeacross stage boundaries so downstream consumer operations (joins, aggregations, window functions) can remain co-partitioned without triggering unnecessary hash repartitions.Background
The original description proposed unioning matching partition indices across tasks in
NetworkCoalesceExec(output_partition[i] = Union(task[*].partition[i])). Topologically, that multi-producer exchange is a shuffle rather than a coalesce.With
datafusion-contrib/datafusion-distributed#730adding range support toNetworkShuffleExecandapache/datafusion#25483introducing range layout relationships upstream, the problem separates into two distinct boundaries:NetworkShuffleExec(Sparse Exchange): When multiple producer tasks output the same range buckets, we need sparse connections so consumerionly reads bucketiacross producers without per-row repartitioning.NetworkCoalesceExec(Disjoint Gather): When producer tasks already hold disjoint, contiguous ranges (e.g. leaf file groups), coalescing them into fewer consumer tasks should yield a coarserSourceFinerRangePartitioning. Currently, it degrades toUnknownPartitioning:datafusion-distributed/src/execution_plans/common.rs
Lines 30 to 38 in 497b5b3
Impacted Plan Shapes
Queries that execute a co-partitioned operation, reduce rows, and feed into a downstream stage expecting the same range key:
1. Multi-way join with early row reduction
t1andt2onidfollowed by a selective filter.t3(also range-partitioned onid) without reshuffling.NetworkCoalesceExecdrops range partitioning toUnknownPartitioning, whileNetworkShuffleExeccannot prove co-partitioning if split points or partition counts differ fromt3, forcing a full hash repartition.2. Group-by aggregation or window function over co-partitioned join
Action Items
NetworkShuffleExecconnections and whole-batch forwarding between matching range partitions.SourceFiner/TargetFinerrange layouts for joins and aggregations.NetworkCoalesceExecto merge split points when gathering contiguous, disjoint task ranges rather than degrading toUnknownPartitioning.