You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/02/09 02:35:33 UTC

[GitHub] [spark] ulysses-you opened a new pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

ulysses-you opened a new pull request #35451:
URL: https://github.com/apache/spark/pull/35451


   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Add check in `PartitionPruning` if the partition has static filter. So we can skip add dynamic partition pruning if there already exists.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Dynamic partition pruning add a filter as long as the join condition contains partition columns. But if there exists other condition which contains the static partition pruning, it's unnecessary to add an extra dynamic partition pruning.
   
   For example:
   ```sql
   CREATE TABLE t1 (c1 int) USING PARQUET PARTITIONED BY (p1 string);
   CREATE TABLE t2 (c2 int) USING PARQUET PARTITIONED BY (p2 string);
   
   SELECT * FROM t1 JOIN t2 ON t1.p1 = t2.p2 and t1.p1 = 'a' AND t2.c2 > 0;
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   no, only change the plan
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Add test in `DynamicPartitionPruningSuiteBase`


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803634992



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {
+    p.find {

Review comment:
       looks good, and add rule `BooleanSimplification` behind `CleanupDynamicPruningFilters` to cleanup the true predicates.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #35451:
URL: https://github.com/apache/spark/pull/35451#issuecomment-1063893638


   thank you @cloud-fan !


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803701656



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>
+        // partitioned table at left side
+        val df1 = sql(
+          s"""
+             |SELECT /*+ broadcast(s) */ * FROM fact_sk f
+             |JOIN dim_store s ON f.store_id = s.store_id AND $condition
+            """.stripMargin)
+        checkPartitionPruningPredicate(df1, false, withBroadcast)

Review comment:
       the execution of dpp includes subquery or reuse broadcast. If withBroadcast is true that means dpp use broadcast to execute. If both withSubquery and withBroadcast are false that means the plan does not contain dpp.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan closed pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #35451:
URL: https://github.com/apache/spark/pull/35451


   


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] weixiuli commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
weixiuli commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802286270



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>

Review comment:
       should we add more cases like 'f.store_id  <> 1' or 'f.store_id  != 1' ?




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #35451:
URL: https://github.com/apache/spark/pull/35451#issuecomment-1033365868


   cc @cloud-fan @wangyum @maryannxue 


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #35451:
URL: https://github.com/apache/spark/pull/35451#issuecomment-1062629364


   cc @cloud-fan 


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803303319



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {
+    p.find {

Review comment:
       OK. How about a different approach: we add DPP filters anyway, and then remove unnecessary ones in `CleanupDynamicPruningFilters`.
   
   In that rule, the predicates are already pushed dow to the source, so we can simply look at the predicates above scan, and remove DPP filters that has a corresponding static partition filters.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] amaliujia commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
amaliujia commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802243525



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasNoStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {

Review comment:
       Nit: use `hasStaticPartitionEqualityCondition` and reverses return values. It might be more readable to use `has` than `not has`. When calling this function, it will be more natural to write `if(hasStaticPartitionEqualityCondition)` for containing the condition and `if(!hasStaticPartitionEqualityCondition)` for not containing it. 




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] amaliujia commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
amaliujia commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802243525



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasNoStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {

Review comment:
       Nit: use `hasStaticPartitionEqualityCondition` and reverses return values. It might be more readable to use `has` than `not had`. When calling this function, it will be more natural to write `if(hasStaticPartitionEqualityCondition)` and `if(!hasStaticPartitionEqualityCondition)`. 




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802794715



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {
+    p.find {

Review comment:
       Shall we simply look at `LogicalPlan.constraints`? It's a bit risky to find a `Filter` in an arbitrary position.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803303319



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {
+    p.find {

Review comment:
       OK. How about a different approach: we add DPP filters anyway, and then remove unnecessary ones in `CleanupDynamicPruningFilters`.
   
   In that rule, the predicates are already pushed down to the source, so we can simply look at the predicates above scan, and remove DPP filters that has a corresponding static partition filters.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35451:
URL: https://github.com/apache/spark/pull/35451#issuecomment-1063669513


   thanks, merging to master!


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r822445761



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>

Review comment:
       to make the test more readable, can we rename `withBroadcast` to `hasDPP`? then in the code below we can do `checkPartitionPruningPredicate(df1, false, withBroadcast = hasDPP)`.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802404064



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>

Review comment:
       They are negative cases, so I just check some of these.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #35451:
URL: https://github.com/apache/spark/pull/35451#issuecomment-1034422070


   > is it similar to https://github.com/apache/spark/pull/34062 ?
   
   @cloud-fan yes, looks like a same issue want to fix.


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35451:
URL: https://github.com/apache/spark/pull/35451#issuecomment-1033883330


   is it similar to https://github.com/apache/spark/pull/34062 ?


-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802279108



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasNoStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {

Review comment:
       thank you @amaliujia 




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803666470



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>
+        // partitioned table at left side
+        val df1 = sql(
+          s"""
+             |SELECT /*+ broadcast(s) */ * FROM fact_sk f
+             |JOIN dim_store s ON f.store_id = s.store_id AND $condition
+            """.stripMargin)
+        checkPartitionPruningPredicate(df1, false, withBroadcast)

Review comment:
       I haven't touches this test suite for a while. What does `withBroadcast` mean?

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>
+        // partitioned table at left side
+        val df1 = sql(
+          s"""
+             |SELECT /*+ broadcast(s) */ * FROM fact_sk f
+             |JOIN dim_store s ON f.store_id = s.store_id AND $condition
+            """.stripMargin)
+        checkPartitionPruningPredicate(df1, false, withBroadcast)

Review comment:
       I haven't touched this test suite for a while. What does `withBroadcast` mean?




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r804296254



##########
File path: sql/core/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q13.sf100/explain.txt
##########
@@ -81,15 +81,15 @@ Input [13]: [ss_cdemo_sk#1, ss_hdemo_sk#2, ss_addr_sk#3, ss_store_sk#4, ss_quant
 Output [2]: [hd_demo_sk#16, hd_dep_count#17]
 Batched: true
 Location [not included in comparison]/{warehouse_dir}/household_demographics]
-PushedFilters: [IsNotNull(hd_demo_sk), Or(Or(EqualTo(hd_dep_count,3),EqualTo(hd_dep_count,1)),EqualTo(hd_dep_count,1))]
+PushedFilters: [IsNotNull(hd_demo_sk), Or(EqualTo(hd_dep_count,3),EqualTo(hd_dep_count,1))]

Review comment:
       this change from the added `BooleanSimplification`




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] amaliujia commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
amaliujia commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r802243525



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasNoStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {

Review comment:
       Nit: use `hasStaticPartitionEqualityCondition` and reverses return values. It might be more readable to use `has` than `not has`. When calling this function, it will be more natural to write `if(hasStaticPartitionEqualityCondition)` and `if(!hasStaticPartitionEqualityCondition)`. 




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803246640



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala
##########
@@ -229,6 +229,24 @@ object PartitionPruning extends Rule[LogicalPlan] with PredicateHelper {
     !plan.isStreaming && hasSelectivePredicate(plan)
   }
 
+  /**
+   * Check the partition has static filter. So we can skip add dynamic partition pruning
+   * if there already exists.
+   */
+  private def hasStaticPartitionEqualityCondition(e: Expression, p: LogicalPlan): Boolean = {
+    p.find {

Review comment:
       but the one issue is that if people disable `constraintPropagation`, the `LogicalPlan.constraints` will not work.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r803664923



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/CleanupDynamicPruningFilters.scala
##########
@@ -34,6 +34,32 @@ import org.apache.spark.sql.execution.datasources.v2.DataSourceV2ScanRelation
  */
 object CleanupDynamicPruningFilters extends Rule[LogicalPlan] with PredicateHelper {
 
+  private def collectEqualityConditionExpressions(condition: Expression): Seq[Expression] = {
+    splitConjunctivePredicates(condition).flatMap(_.collect {
+      case EqualTo(l, r) if l.deterministic && r.foldable => l
+      case EqualTo(l, r) if r.deterministic && l.foldable => r
+      case EqualNullSafe(l, r) if l.deterministic && r.foldable => l
+      case EqualNullSafe(l, r) if r.deterministic && l.foldable => r
+    })
+  }
+
+  /**
+   * Remove DynamicPruningSubquery if the pruning key has equality condition

Review comment:
       let's add more comments to explain the rationale: If a partition key already has equality conditions, then its DPP filter is useless and can't prune anything.




-- 
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: reviews-unsubscribe@spark.apache.org

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



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


[GitHub] [spark] ulysses-you commented on a change in pull request #35451: [SPARK-38148][SQL] Do not add dynamic partition pruning if there exists static partition pruning

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #35451:
URL: https://github.com/apache/spark/pull/35451#discussion_r822460725



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DynamicPartitionPruningSuite.scala
##########
@@ -1482,6 +1482,51 @@ abstract class DynamicPartitionPruningSuiteBase
       checkAnswer(df, Row(1150, 1) :: Row(1130, 4) :: Row(1140, 4) :: Nil)
     }
   }
+
+  test("SPARK-38148: Do not add dynamic partition pruning if there exists static partition " +
+    "pruning") {
+    withSQLConf(SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key -> "true") {
+      Seq(
+        "f.store_id = 1" -> false,
+        "1 = f.store_id" -> false,
+        "f.store_id <=> 1" -> false,
+        "1 <=> f.store_id" -> false,
+        "f.store_id > 1" -> true,
+        "5 > f.store_id" -> true).foreach { case (condition, withBroadcast) =>

Review comment:
       looks good




-- 
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: reviews-unsubscribe@spark.apache.org

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



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