wangyum opened a new pull request #31857:
URL: https://github.com/apache/spark/pull/31857


   ### What changes were proposed in this pull request?
   
   It will push down the foldable predicate to left side if it is a RIGHT JOIN. 
But it will not push down the foldable predicate to right side if it is a LEFT 
JOIN. For example:
   
   ```scala
   spark.sql("CREATE TABLE t1 using parquet AS SELECT id AS a, id AS b FROM 
range(10)")
   spark.sql("CREATE TABLE t2 using parquet AS SELECT id AS x, id AS y FROM 
range(10)")
   ```
   Push down to left side:
   ```scala
   spark.sql("SELECT * FROM t1 RIGHT JOIN t2 ON false").explain
   == Physical Plan ==
   *(1) Project [cast(null as bigint) AS a#13L, cast(null as bigint) AS b#14L, 
x#18L, y#19L]
   +- *(1) ColumnarToRow
      +- FileScan parquet default.t2[x#18L,y#19L]
   ```
   Will not push down:
   ```scala
   spark.sql("SELECT * FROM t1 LEFT JOIN t2 ON false").explain
   == Physical Plan ==
   BroadcastNestedLoopJoin BuildRight, LeftOuter, false
   :- *(1) ColumnarToRow
   :  +- FileScan parquet default.t1[a#13L,b#14L]
   +- BroadcastExchange IdentityBroadcastMode, [id=#89]
      +- *(2) ColumnarToRow
         +- FileScan parquet default.t2[x#18L,y#19L]
   ```
   
   This pr to make it push down the foldable predicate to both sides of Join.
   
   
   ### Why are the changes needed?
   
   Avoid `BroadcastNestedLoopJoin` to improve query performance.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   
   ### How was this patch tested?
   
   Unit test.
   


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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to