2010YOUY01 commented on code in PR #22370:
URL: https://github.com/apache/datafusion/pull/22370#discussion_r3280959380


##########
datafusion/optimizer/src/expand_join_or_predicate.rs:
##########
@@ -0,0 +1,174 @@
+// 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.
+
+//! [`ExpandJoinOrPredicate`] rewrites inner joins with OR filters into a 
UNION ALL
+//! of mutually exclusive hashjoin-capable inner joins.
+
+use crate::optimizer::ApplyOrder;
+use crate::{OptimizerConfig, OptimizerRule};
+use std::sync::Arc;
+
+use datafusion_common::tree_node::Transformed;
+use datafusion_common::Result;
+use datafusion_expr::logical_plan::{Join, LogicalPlan, Projection, Union};
+use datafusion_expr::utils::{can_hash, find_valid_equijoin_key_pair, 
split_binary_owned, split_conjunction_owned};
+use datafusion_expr::{Expr, ExprSchemable, JoinType, Operator};
+
+#[derive(Default, Debug)]
+pub struct ExpandJoinOrPredicate;
+
+impl ExpandJoinOrPredicate {

Review Comment:
   I think approach 1 means adding a new specialized hash join operator for 
ORed equality conditions:
   
   ```sql
   SELECT *
   FROM t1
   JOIN t2
   ON (t1.v1 = t2.v1) OR (t1.v2 = t2.v2)
   ```
   
   We could add a specialized `DisjointHashJoinExec` operator. The core logic 
would look like:
   
   1. Buffer the build side and build hash tables for `t1.v1` and `t1.v2`.
   2. Probe the other side. For each probe row, probe both hash tables, union 
and deduplicate the matched build-side row indices, and then materialize the 
joined rows.
   
   The benefits are:
   
   * No repeated scans, which can be expensive for Parquet.
   * Simpler planning.
   
   I think this approach would be relatively straightforward to implement after:
   
   * https://github.com/apache/datafusion/pull/21983
   
   I'm looking for help reviewing this feature 🎣 , would also be happy to help 
with follow-up work, such as extending this idea into a disjoint equi-join 
implementation.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to