mingmwang commented on code in PR #4219: URL: https://github.com/apache/arrow-datafusion/pull/4219#discussion_r1028797376
########## datafusion/core/src/physical_optimizer/join_selection.rs: ########## @@ -0,0 +1,972 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Utilizing exact statistics from sources to avoid scanning data +use std::sync::Arc; + +use arrow::datatypes::Schema; + +use crate::execution::context::SessionConfig; +use crate::logical_expr::JoinType; +use crate::physical_plan::expressions::Column; +use crate::physical_plan::joins::{ + utils::{ColumnIndex, JoinFilter, JoinSide}, + CrossJoinExec, HashJoinExec, PartitionMode, +}; +use crate::physical_plan::projection::ProjectionExec; +use crate::physical_plan::{ExecutionPlan, PhysicalExpr}; + +use super::optimizer::PhysicalOptimizerRule; +use crate::error::Result; +use crate::physical_plan::rewrite::TreeNodeRewritable; + +/// For hash join with the partition mode [PartitionMode::Auto], JoinSelection rule will make +/// a cost based decision to select which PartitionMode mode(Partitioned/CollectLeft) is optimal +/// based on the available statistics that the inputs have. +/// If the statistics information is not available, the partition mode will fall back to [PartitionMode::Partitioned]. +/// +/// JoinSelection rule will also reorder the build and probe phase of the hash joins +/// based on the avaliable statistics that the inputs have. +/// The rule optimizes the order such that the left (build) side of the join is the smallest. +/// If the statistics information is not available, the order stays the same as the original query. +/// JoinSelection rule will also swap the left and right sides for cross join to keep the left side +/// is the smallest. +#[derive(Default)] +pub struct JoinSelection {} + +impl JoinSelection { + #[allow(missing_docs)] + pub fn new() -> Self { + Self {} + } +} + +// TODO we need some performance test for Right Semi/Right Join swap to Left Semi/Left Join in case that the right side is smaller but not much smaller. +// TODO In PrestoSQL, the optimizer flips join sides only if one side is much smaller than the other by more than SIZE_DIFFERENCE_THRESHOLD times, by default is is 8 times. Review Comment: Actually I am not very sure about this, because our HashJoin implementation is quite different from PrestoSQL's. I think we need to do more benchmark on this. -- 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]
