@@ -1448,13 +1448,12 @@ impl ExecutionPlan for HashJoinExec {
14481448 ) -> Result < Arc < Statistics > > {
14491449 let stats = match ( partition, self . mode ) {
14501450 // For CollectLeft mode, the left side is broadcast (collected into
1451- // a single partition), so it needs overall stats. The context has
1452- // partition-specific stats which would be incorrect.
1453- // Right side is partitioned, so the context stats are correct.
1451+ // a single partition), so it needs overall stats (child_stats).
1452+ // Right side is partitioned, so it needs per-partition stats.
14541453 ( Some ( _) , PartitionMode :: CollectLeft ) => {
1455- let left_stats =
1456- ctx . compute_child_statistics ( self . left . as_ref ( ) , None ) ? ;
1457- let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
1454+ let left_stats = Arc :: clone ( & ctx . child_stats ( ) [ 0 ] ) ;
1455+ let right_stats =
1456+ ctx. compute_child_statistics ( self . right . as_ref ( ) , partition ) ? ;
14581457
14591458 estimate_join_statistics (
14601459 Arc :: unwrap_or_clone ( left_stats) ,
@@ -1468,8 +1467,10 @@ impl ExecutionPlan for HashJoinExec {
14681467 // For Partitioned mode, both sides are hash-partitioned symmetrically,
14691468 // so each output partition uses the matching partition from both sides.
14701469 ( Some ( _) , PartitionMode :: Partitioned ) => {
1471- let left_stats = Arc :: clone ( & ctx. child_stats ( ) [ 0 ] ) ;
1472- let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
1470+ let left_stats =
1471+ ctx. compute_child_statistics ( self . left . as_ref ( ) , partition) ?;
1472+ let right_stats =
1473+ ctx. compute_child_statistics ( self . right . as_ref ( ) , partition) ?;
14731474
14741475 estimate_join_statistics (
14751476 Arc :: unwrap_or_clone ( left_stats) ,
@@ -1485,8 +1486,8 @@ impl ExecutionPlan for HashJoinExec {
14851486 let left_stats = Arc :: clone ( & ctx. child_stats ( ) [ 0 ] ) ;
14861487 let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
14871488 estimate_join_statistics (
1488- ( * left_stats) . clone ( ) ,
1489- ( * right_stats) . clone ( ) ,
1489+ Arc :: unwrap_or_clone ( left_stats) ,
1490+ Arc :: unwrap_or_clone ( right_stats) ,
14901491 & self . on ,
14911492 & self . join_type ,
14921493 & self . join_schema ,
@@ -1496,10 +1497,8 @@ impl ExecutionPlan for HashJoinExec {
14961497 // Auto mode hasn't decided partitioning yet, so it needs
14971498 // overall stats from both sides.
14981499 ( Some ( _) , PartitionMode :: Auto ) => {
1499- let left_stats =
1500- ctx. compute_child_statistics ( self . left . as_ref ( ) , None ) ?;
1501- let right_stats =
1502- ctx. compute_child_statistics ( self . right . as_ref ( ) , None ) ?;
1500+ let left_stats = Arc :: clone ( & ctx. child_stats ( ) [ 0 ] ) ;
1501+ let right_stats = Arc :: clone ( & ctx. child_stats ( ) [ 1 ] ) ;
15031502 estimate_join_statistics (
15041503 Arc :: unwrap_or_clone ( left_stats) ,
15051504 Arc :: unwrap_or_clone ( right_stats) ,
0 commit comments