peter-toth commented on code in PR #60458:
URL: https://github.com/apache/spark/pull/60458#discussion_r4568206582


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -260,15 +260,18 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with 
PredicateHelper with J
       REGEXP_EXTRACT_FAMILY, REGEXP_REPLACE)
   }
 
-  private def isProbablyShuffleJoin(left: LogicalPlan,
-      right: LogicalPlan, hint: JoinHint): Boolean = {
-    !hintToBroadcastLeft(hint) && !hintToBroadcastRight(hint) &&
-      !canBroadcastBySize(left, conf) && !canBroadcastBySize(right, conf)
+  // A broadcast hash join can build only a side that its join type allows, 
and a hint can rule it
+  // out. A join without equi-join keys is not a hash join, so its join type 
does not matter here.
+  private def isProbablyShuffleJoin(join: Join): Boolean = join match {
+    case ExtractEquiJoinKeys(_, _, _, _, _, _, _, _) => 
!canPlanAsBroadcastHashJoin(join, conf)

Review Comment:
   **Finding 1.** With a hint, `JoinSelection` tries a merge hint between a 
hinted broadcast and the size-based one (`SparkStrategies.scala:342-346`). 
`canPlanAsBroadcastHashJoin` lets only a `SHUFFLE_HASH` hint veto the sizes 
(`getBroadcastHashJoinBuildSide`, `joins.scala:516-521`). So a merge hint on 
the small side still counts as a broadcast here, while the planner picks a sort 
merge join and shuffles both sides.
   
   With the new test's confs, `select /*+ merge(a) */ * from bf2 join (select 
c1 from bf1 where a1 = 5) a on a.c1 = bf2.c2` plans a `SortMergeJoin` with no 
bloom filter, on the base and on `60ac8a6`. 
`PushDownJoinThroughUnion.broadcastsRightForEveryBranch` handles the same gap 
(`PushDownJoinThroughUnion.scala:125-137`). Doing the same here:
   
   ```suggestion
       case ExtractEquiJoinKeys(_, _, _, _, _, _, _, _) =>
         // A hinted broadcast outranks a merge hint, which outranks a 
size-based broadcast.
         getBroadcastBuildSide(join, hintOnly = true, conf).isEmpty &&
           (hintToSortMergeJoin(join.hint) || !canPlanAsBroadcastHashJoin(join, 
conf))
   ```
   
   With it, the merge-hinted query gets a bloom filter on `c2`, and 
`InjectRuntimeFilterSuite` passes. A `merge(a)` line in the new test, next to 
the `shuffle_hash(a)` one, would cover it. A `SHUFFLE_REPLICATE_NL` hint plans 
a cartesian product, which does not shuffle, so it can stay as it is.
   



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