wangyum commented on a change in pull request #28575:
URL: https://github.com/apache/spark/pull/28575#discussion_r434621793
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -1372,6 +1376,108 @@ object PushPredicateThroughJoin extends
Rule[LogicalPlan] with PredicateHelper {
}
}
+/**
+ * Rewriting join condition to conjunctive normal form expression so that we
can push
+ * more predicate.
+ */
+object PushPredicateThroughJoinByCNF extends Rule[LogicalPlan] with
PredicateHelper {
Review comment:
Yes, such as the step of scanning web_sales table for TPC-DS q85.
Before this pr:
```
+- *(8) Filter (((isnotnull(ws_item_sk#3) AND isnotnull(ws_order_number#17))
AND isnotnull(ws_web_page_sk#12)) AND isnotnull(ws_sold_date_sk#0))
+- *(8) ColumnarToRow
+- FileScan parquet
default.web_sales[ws_sold_date_sk#0,ws_item_sk#3,ws_web_page_sk#12,ws_order_number#17,ws_quantity#18,ws_sales_price#21,ws_net_profit#33]
Batched: true, DataFilters: [isnotnull(ws_item_sk#3),
isnotnull(ws_order_number#17), isnotnull(ws_web_page_sk#12),
isnotnull(ws_sold_date_sk#0)], Format: Parquet, Location:
InMemoryFileIndex[file:/Users/yumwang/spark/SPARK-28216/sql/core/spark-warehouse/org.apache.spark.sql.TPCDSQuerySuite/web_sales],
PartitionFilters: [], PushedFilters: [IsNotNull(ws_item_sk),
IsNotNull(ws_order_number), IsNotNull(ws_web_page_sk),
IsNotNull(ws_sold_date_sk)], ReadSchema:
struct<ws_sold_date_sk:int,ws_item_sk:int,ws_web_page_sk:int,ws_order_number:int,ws_quantity:int,ws_sales_price:decimal(7,2),ws_net_profit:decimal(7,2)>
```
After this pr:
```
+- *(8) Filter (((((isnotnull(ws_item_sk#3) AND
isnotnull(ws_order_number#17)) AND isnotnull(ws_web_page_sk#12)) AND
isnotnull(ws_sold_date_sk#0)) AND ((((ws_sales_price#21 >= 100.00) AND
(ws_sales_price#21 <= 150.00)) OR ((ws_sales_price#21 >= 50.00) AND
(ws_sales_price#21 <= 100.00))) OR ((ws_sales_price#21 >= 150.00) AND
(ws_sales_price#21 <= 200.00)))) AND ((((ws_net_profit#33 >= 100.00) AND
(ws_net_profit#33 <= 200.00)) OR ((ws_net_profit#33 >= 150.00) AND
(ws_net_profit#33 <= 300.00))) OR ((ws_net_profit#33 >= 50.00) AND
(ws_net_profit#33 <= 250.00))))
+- *(8) ColumnarToRow
+- FileScan parquet
default.web_sales[ws_sold_date_sk#0,ws_item_sk#3,ws_web_page_sk#12,ws_order_number#17,ws_quantity#18,ws_sales_price#21,ws_net_profit#33]
Batched: true, DataFilters: [isnotnull(ws_item_sk#3),
isnotnull(ws_order_number#17), isnotnull(ws_web_page_sk#12),
isnotnull(ws_sold_date_sk#0), ((((ws_sales_price#21 >= 100.00) AND
(ws_sales_price#21 <= 150.00)) OR ((ws_sales_price#21 >= 50.00) AND
(ws_sales_price#21 <= 100.00))) OR ((ws_sales_price#21 >= 150.00) AND
(ws_sales_price#21 <= 200.00))), ((((ws_net_profit#33 >= 100.00) AND
(ws_net_profit#33 <= 200.00)) OR ((ws_net_profit#33 >= 150.00) AND
(ws_net_profit#33 <= 300.00))) OR ((ws_net_profit#33 >= 50.00) AND
(ws_net_profit#33 <= 250.00)))], Format: Parquet, Location:
InMemoryFileIndex[file:/Users/yumwang/spark/SPARK-28216/sql/core/spark-warehouse/org.apache.spark.sql.TPCDSQuerySuite/web_sales],
PartitionFilters: [], PushedFilters: [IsNotNull(ws_item_sk),
IsNotNull(ws_order_number), IsNotNull(ws_web_page_sk),
IsNotNull(ws_sold_date_sk),
Or(Or(And(GreaterThanOrEqual(ws_sales_price,100.00),LessThanOrEqual(ws_sales_price,150.00)),And(GreaterThanOrEqual(ws_sales_price,50.00),LessThanOrEqual(ws_sales_price,100.00))),And(GreaterThanOrEqual(ws_sales_price,150.00),LessThanOrEqual(ws_sales_price,200.00))),
Or(Or(And(GreaterThanOrEqual(ws_net_profit,100.00),LessThanOrEqual(ws_net_profit,200.00)),And(GreaterThanOrEqual(ws_net_profit,150.00),LessThanOrEqual(ws_net_profit,300.00))),And(GreaterThanOrEqual(ws_net_profit,50.00),LessThanOrEqual(ws_net_profit,250.00)))],
ReadSchema:
struct<ws_sold_date_sk:int,ws_item_sk:int,ws_web_page_sk:int,ws_order_number:int,ws_quantity:int,ws_sales_price:decimal(7,2),ws_net_profit:decimal(7,2)>
```
----------------------------------------------------------------
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]