@@ -1468,13 +1468,12 @@ impl ExecutionPlan for HashJoinExec {
14681468 ) -> Result < Arc < Statistics > > {
14691469 let stats = match ( partition, self . mode ) {
14701470 // For CollectLeft mode, the left side is broadcast (collected into
1471- // a single partition), so it needs overall stats. The context has
1472- // partition-specific stats which would be incorrect.
1473- // Right side is partitioned, so the context stats are correct.
1471+ // a single partition), so it needs overall stats (child_stats).
1472+ // Right side is partitioned, so it needs per-partition stats.
14741473 ( Some ( _) , PartitionMode :: CollectLeft ) => {
1475- let left_stats =
1476- ctx . compute_child_statistics ( self . left . as_ref ( ) , None ) ? ;
1477- let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
1474+ let left_stats = Arc :: clone ( & ctx . child_stats ( ) [ 0 ] ) ;
1475+ let right_stats =
1476+ ctx. compute_child_statistics ( self . right . as_ref ( ) , partition ) ? ;
14781477
14791478 estimate_join_statistics (
14801479 Arc :: unwrap_or_clone ( left_stats) ,
@@ -1488,8 +1487,10 @@ impl ExecutionPlan for HashJoinExec {
14881487 // For Partitioned mode, both sides are hash-partitioned symmetrically,
14891488 // so each output partition uses the matching partition from both sides.
14901489 ( Some ( _) , PartitionMode :: Partitioned ) => {
1491- let left_stats = Arc :: clone ( & ctx. child_stats ( ) [ 0 ] ) ;
1492- let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
1490+ let left_stats =
1491+ ctx. compute_child_statistics ( self . left . as_ref ( ) , partition) ?;
1492+ let right_stats =
1493+ ctx. compute_child_statistics ( self . right . as_ref ( ) , partition) ?;
14931494
14941495 estimate_join_statistics (
14951496 Arc :: unwrap_or_clone ( left_stats) ,
@@ -1505,8 +1506,8 @@ impl ExecutionPlan for HashJoinExec {
15051506 let left_stats = Arc :: clone ( & ctx. child_stats ( ) [ 0 ] ) ;
15061507 let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
15071508 estimate_join_statistics (
1508- ( * left_stats) . clone ( ) ,
1509- ( * right_stats) . clone ( ) ,
1509+ Arc :: unwrap_or_clone ( left_stats) ,
1510+ Arc :: unwrap_or_clone ( right_stats) ,
15101511 & self . on ,
15111512 & self . join_type ,
15121513 & self . join_schema ,
@@ -1516,10 +1517,8 @@ impl ExecutionPlan for HashJoinExec {
15161517 // Auto mode hasn't decided partitioning yet, so it needs
15171518 // overall stats from both sides.
15181519 ( Some ( _) , PartitionMode :: Auto ) => {
1519- let left_stats =
1520- ctx. compute_child_statistics ( self . left . as_ref ( ) , None ) ?;
1521- let right_stats =
1522- ctx. compute_child_statistics ( self . right . as_ref ( ) , None ) ?;
1520+ let left_stats = Arc :: clone ( & ctx. child_stats ( ) [ 0 ] ) ;
1521+ let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
15231522 estimate_join_statistics (
15241523 Arc :: unwrap_or_clone ( left_stats) ,
15251524 Arc :: unwrap_or_clone ( right_stats) ,
0 commit comments