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


   ### What changes were proposed in this pull request?
   
   This PR add a new rule to support push predicate through join by rewriting 
join condition to conjunctive normal form. For example:
   ```sql
   create table x as select * from (values (1, 2, 3, 4)) as x(a, b, c, d);
   create table y as select * from (values (1, 2, 3, 4)) as x(a, b, c, d);
   ```
   
   ```sql
   postgres=# explain select x.* from x, y where x.b = y.b and ((x.a > 3 and 
y.a > 13) or (x.a > 1));
                               QUERY PLAN
   ------------------------------------------------------------------
    Merge Join  (cost=218.07..437.16 rows=6973 width=16)
      Merge Cond: (x.b = y.b)
      Join Filter: (((x.a > 3) AND (y.a > 13)) OR (x.a > 1))
      ->  Sort  (cost=89.18..91.75 rows=1028 width=16)
            Sort Key: x.b
            ->  Seq Scan on x  (cost=0.00..37.75 rows=1028 width=16)
                  Filter: ((a > 3) OR (a > 1))
      ->  Sort  (cost=128.89..133.52 rows=1850 width=8)
            Sort Key: y.b
            ->  Seq Scan on y  (cost=0.00..28.50 rows=1850 width=8)
   (10 rows)
   ```
   `x.b = y.b and ((x.a > 3 and y.a > 13) or (x.a > 1))` can be rewritten to 
`x.b = y.b and (((x.a > 3) or (x.a > 1)) and ((y.a > 13) or (x.a > 1))))`,  and 
then we can push down `((x.a > 3) or (x.a > 1))`.
   
   
   
   
   ### Why are the changes needed?
   Improve query performance.
   
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   
   ### How was this patch tested?
   Unit test and benchmark test.
   
   
   SQL | Before this PR | After this PR
   --- | --- | ---
   TPCDS 5T q85 | 66s | 34s
   TPCH 1T q7 | 37s | 32s
   
   


----------------------------------------------------------------
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:
[email protected]



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

Reply via email to