gengliangwang opened a new pull request #28733: URL: https://github.com/apache/spark/pull/28733
### 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 CNF(conjunctive normal form). The following example is the steps of this rule: 1. Prepare Table: ```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); EXPLAIN SELECT x.* FROM x JOIN y ON ((x.a > 1 AND x.a < 3 AND y.b = 1) OR (x.a > 3 AND x.a < 5 AND y.b = 2)); ``` 2. Convert the join condition to CNF: Step | Current condition --- | --- init | (x.a > 1 AND x.a < 3 AND y.b = 1) OR (x.a > 3 AND x.a < 5 AND y.b = 2) step 1 | ((x.a > 1 AND x.a < 3) OR (x.a > 3 AND x.a < 5 AND y.b = 2)) AND ((y.b = 1) OR (x.a > 3 AND x.a < 5 AND y.b = 2)) step 2 | ((x.a > 1 AND x.a < 3) OR (x.a > 3 AND x.a < 5)) AND ((x.a > 1 AND x.a < 3) OR (y.b = 2)) AND ((y.b = 1) OR (x.a > 3 AND x.a < 5 AND y.b = 2)) step 3 | ((x.a > 1 AND x.a < 3) OR (x.a > 3 AND x.a < 5)) AND ((x.a > 1 AND x.a < 3) OR (y.b = 2)) AND ((y.b = 1) OR (x.a > 3 AND x.a < 5)) AND ((y.b = 1) OR (y.b = 2)) 3. Split conjunctive predicates Predicates ---| ((x.a > 1 AND x.a < 3) OR (x.a > 3 AND x.a < 5)) ((x.a > 1 AND x.a < 3) OR (y.b = 2)) ((y.b = 1) OR (x.a > 3 AND x.a < 5)) ((y.b = 1) OR (y.b = 2)) 4. Push predicate Table | Predicate --- | --- x | ((x.a > 1 AND x.a < 3) OR (x.a > 3 AND x.a < 5)) y | ((y.b = 1) OR (y.b = 2)) ### Why are the changes needed? Improve query performance. PostgreSQL, [Impala](https://issues.apache.org/jira/browse/IMPALA-9183) and Hive support this feature. ### 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 Q13 | 84s | 21s TPCDS 5T q85 | 66s | 34s TPCH 1T q19 | 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]
