Apache DataFusion SQL Query Engine
Minor: Rewrite LogicalPlan::max_rows for Join and Union, made it easier to understand (#14012)
Eugene Marushchenkode6d5119d0de
diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rsindex cc922709c8..005bf4b984 100644--- a/datafusion/expr/src/logical_plan/plan.rs+++ b/datafusion/expr/src/logical_plan/plan.rs@@ -1317,18 +1317,13 @@ impl LogicalPlan {join_type,..}) => match join_type {- JoinType::Inner | JoinType::Left | JoinType::Right | JoinType::Full => {- match (left.max_rows(), right.max_rows()) {- (Some(left_max), Some(right_max)) => {- let min_rows = match join_type {- JoinType::Left => left_max,- JoinType::Right => right_max,- JoinType::Full => left_max + right_max,- _ => 0,- };- Some((left_max * right_max).max(min_rows))- }- _ => None,+ JoinType::Inner => Some(left.max_rows()? * right.max_rows()?),+ JoinType::Left | JoinType::Right | JoinType::Full => {+ match (left.max_rows()?, right.max_rows()?, join_type) {+ (0, 0, _) => Some(0),+ (max_rows, 0, JoinType::Left | JoinType::Full) => Some(max_rows),+ (0, max_rows, JoinType::Right | JoinType::Full) => Some(max_rows),+ (left_max, right_max, _) => Some(left_max * right_max),}}JoinType::LeftSemi | JoinType::LeftAnti | JoinType::LeftMark => {@@ -1337,17 +1332,12 @@ impl LogicalPlan {JoinType::RightSemi | JoinType::RightAnti => right.max_rows(),},LogicalPlan::Repartition(Repartition { input, .. }) => input.max_rows(),- LogicalPlan::Union(Union { inputs, .. }) => inputs- .iter()- .map(|plan| plan.max_rows())- .try_fold(0usize, |mut acc, input_max| {- if let Some(i_max) = input_max {- acc += i_max;- Some(acc)- } else {- None- }- }),+ LogicalPlan::Union(Union { inputs, .. }) => {+ inputs.iter().try_fold(0usize, |mut acc, plan| {+ acc += plan.max_rows()?;+ Some(acc)+ })+ }LogicalPlan::TableScan(TableScan { fetch, .. }) => *fetch,LogicalPlan::EmptyRelation(_) => Some(0),LogicalPlan::RecursiveQuery(_) => None,@@ -3433,15 +3423,15 @@ pub enum Partitioning {/// input output_name/// ┌─────────┐ ┌─────────┐/// │{{1,2}} │ │ 1 │-/// ├─────────┼─────►├─────────┤-/// │{{3}} │ │ 2 │-/// ├─────────┤ ├─────────┤-/// │{{4},{5}}│ │ 3 │-/// └─────────┘ ├─────────┤-/// │ 4 │-/// ├─────────┤-/// │ 5 │-/// └─────────┘+/// ├─────────┼─────►├─────────┤+/// │{{3}} │ │ 2 │+/// ├─────────┤ ├─────────┤+/// │{{4},{5}}│ │ 3 │+/// └─────────┘ ├─────────┤+/// │ 4 │+/// ├─────────┤+/// │ 5 │+/// └─────────┘/// ```#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd)]pub struct ColumnUnnestList {