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 2023/01/14 13:28:05 UTC

[GitHub] [spark] wangyum opened a new pull request, #39571: [SPARK-42064][SQL] Implement bloom filter join hint

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

   ### What changes were proposed in this pull request?
   
   This PR implements the bloom filter join hint. Usage:
   ```sql
   SELECT /*+ BLOOM_FILTER_JOIN(bf1) */ * FROM bf1 JOIN bf2 ON bf1.c1 = bf2.c2
   ```
   
   ### Why are the changes needed?
   
   To improve the following cases:
   <img src="https://user-images.githubusercontent.com/5399861/212473884-9585f3b6-e103-4781-af10-7178ccd10f2b.png" width="200" height="730">
   
   ### 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.

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] dongjoon-hyun commented on a diff in pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39571:
URL: https://github.com/apache/spark/pull/39571#discussion_r1096104624


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -287,21 +299,24 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with PredicateHelper with J
         var newRight = right
         (leftKeys, rightKeys).zipped.foreach((l, r) => {
           // Check if:
-          // 1. There is already a DPP filter on the key
-          // 2. There is already a runtime filter (Bloom filter or IN subquery) on the key
-          // 3. The keys are simple cheap expressions
-          if (filterCounter < numFilterThreshold &&
-            !hasDynamicPruningSubquery(left, right, l, r) &&
-            !hasRuntimeFilter(newLeft, newRight, l, r) &&
-            isSimpleExpression(l) && isSimpleExpression(r)) {
+          // 1. hint to build bloom filter
+          // 2. There is already a DPP filter on the key
+          // 3. There is already a runtime filter (Bloom filter or IN subquery) on the key
+          // 4. The keys are simple cheap expressions
+          if (hintToBuildBloomFilter(hint) ||
+            (filterCounter < numFilterThreshold &&
+              !hasDynamicPruningSubquery(left, right, l, r) &&
+              !hasRuntimeFilter(newLeft, newRight, l, r) &&
+              isSimpleExpression(l) && isSimpleExpression(r))) {
             val oldLeft = newLeft
             val oldRight = newRight
-            if (canPruneLeft(joinType) && filteringHasBenefit(left, right, l, hint)) {
+            if (canPruneLeft(joinType) &&
+              (hintToBuildBloomFilterRight(hint) || filteringHasBenefit(left, right, l, hint))) {
               newLeft = injectFilter(l, newLeft, r, right)
             }
             // Did we actually inject on the left? If not, try on the right
             if (newLeft.fastEquals(oldLeft) && canPruneRight(joinType) &&
-              filteringHasBenefit(right, left, r, hint)) {
+              (hintToBuildBloomFilterLeft(hint) || filteringHasBenefit(right, left, r, hint))) {

Review Comment:
   The original indentation was wrong~



-- 
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] dongjoon-hyun commented on a diff in pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39571:
URL: https://github.com/apache/spark/pull/39571#discussion_r1096103776


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -287,21 +299,24 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with PredicateHelper with J
         var newRight = right
         (leftKeys, rightKeys).zipped.foreach((l, r) => {
           // Check if:
-          // 1. There is already a DPP filter on the key
-          // 2. There is already a runtime filter (Bloom filter or IN subquery) on the key
-          // 3. The keys are simple cheap expressions
-          if (filterCounter < numFilterThreshold &&
-            !hasDynamicPruningSubquery(left, right, l, r) &&
-            !hasRuntimeFilter(newLeft, newRight, l, r) &&
-            isSimpleExpression(l) && isSimpleExpression(r)) {
+          // 1. hint to build bloom filter
+          // 2. There is already a DPP filter on the key
+          // 3. There is already a runtime filter (Bloom filter or IN subquery) on the key
+          // 4. The keys are simple cheap expressions
+          if (hintToBuildBloomFilter(hint) ||
+            (filterCounter < numFilterThreshold &&

Review Comment:
   indentation?



-- 
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] dongjoon-hyun commented on a diff in pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #39571:
URL: https://github.com/apache/spark/pull/39571#discussion_r1096104058


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -287,21 +299,24 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with PredicateHelper with J
         var newRight = right
         (leftKeys, rightKeys).zipped.foreach((l, r) => {
           // Check if:
-          // 1. There is already a DPP filter on the key
-          // 2. There is already a runtime filter (Bloom filter or IN subquery) on the key
-          // 3. The keys are simple cheap expressions
-          if (filterCounter < numFilterThreshold &&
-            !hasDynamicPruningSubquery(left, right, l, r) &&
-            !hasRuntimeFilter(newLeft, newRight, l, r) &&
-            isSimpleExpression(l) && isSimpleExpression(r)) {
+          // 1. hint to build bloom filter
+          // 2. There is already a DPP filter on the key
+          // 3. There is already a runtime filter (Bloom filter or IN subquery) on the key
+          // 4. The keys are simple cheap expressions
+          if (hintToBuildBloomFilter(hint) ||
+            (filterCounter < numFilterThreshold &&
+              !hasDynamicPruningSubquery(left, right, l, r) &&
+              !hasRuntimeFilter(newLeft, newRight, l, r) &&
+              isSimpleExpression(l) && isSimpleExpression(r))) {
             val oldLeft = newLeft
             val oldRight = newRight
-            if (canPruneLeft(joinType) && filteringHasBenefit(left, right, l, hint)) {
+            if (canPruneLeft(joinType) &&
+              (hintToBuildBloomFilterRight(hint) || filteringHasBenefit(left, right, l, hint))) {

Review Comment:
   indentation.



-- 
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] rkkorlapati-db commented on a diff in pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "rkkorlapati-db (via GitHub)" <gi...@apache.org>.
rkkorlapati-db commented on code in PR #39571:
URL: https://github.com/apache/spark/pull/39571#discussion_r1106535935


##########
sql/core/src/test/scala/org/apache/spark/sql/InjectRuntimeFilterSuite.scala:
##########
@@ -607,4 +607,13 @@ class InjectRuntimeFilterSuite extends QueryTest with SQLTestUtils with SharedSp
         "Missing or unexpected reused ReusedSubqueryExec in the plan")
     }
   }
+
+  test("SPARK-42064: bloom filter join hint") {
+    assertDidNotRewriteWithBloomFilter(
+      "SELECT * FROM bf1 JOIN bf2 ON bf1.c1 = bf2.c2")
+    assertRewroteWithBloomFilter(
+      "SELECT /*+ BLOOM_FILTER_JOIN(bf1) */ * FROM bf1 JOIN bf2 ON bf1.c1 = bf2.c2")

Review Comment:
   I suppose we build multiple bloom filters if there are composite join predicates. Can we add some tests to verify?



-- 
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] github-actions[bot] commented on pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39571:
URL: https://github.com/apache/spark/pull/39571#issuecomment-1565099017

   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


-- 
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] sigmod commented on pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "sigmod (via GitHub)" <gi...@apache.org>.
sigmod commented on PR #39571:
URL: https://github.com/apache/spark/pull/39571#issuecomment-1416369868

   @andylam-db @rkkorlapati-db


-- 
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] andylam-db commented on pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "andylam-db (via GitHub)" <gi...@apache.org>.
andylam-db commented on PR #39571:
URL: https://github.com/apache/spark/pull/39571#issuecomment-1416386966

   1. How is this join hint resolved if it has >1 parameters? E.g.
   ```SELECT /*+ BLOOM_FILTER_JOIN(r, s) */ * FROM records r JOIN src s ON r.key = s.key```
   2. +1 for @ulysses-you comments: `filteringHasBenefit` can still prevent the runtime filter from being built even with the hint. I think we should either bypass `filteringHasBenefit` with the hint, or show warn logs if the hint does 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] github-actions[bot] closed pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint
URL: https://github.com/apache/spark/pull/39571


-- 
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 #39571: [SPARK-42064][SQL] Implement bloom filter join hint

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

   I mean something like https://github.com/apache/spark/pull/32355, e.g. we can not prune left for left outer join so it should show logs if the bloom_filter_join point to left. There are a lots of limits to prevent injecting runtime filter even we have bloom_filter_hint.


-- 
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] wangyum commented on pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by GitBox <gi...@apache.org>.
wangyum commented on PR #39571:
URL: https://github.com/apache/spark/pull/39571#issuecomment-1383309269

    @sigmod @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 pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

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

   Make sense to me. Shall we show some warn logs if the hint can not work ? We do the similar things for other join hints.


-- 
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] wangyum commented on pull request #39571: [SPARK-42064][SQL] Implement bloom filter join hint

Posted by GitBox <gi...@apache.org>.
wangyum commented on PR #39571:
URL: https://github.com/apache/spark/pull/39571#issuecomment-1383418899

   > Make sense to me. Shall we show some warn logs if the hint can not work ? We do the similar things for other join hints.
   
   Please see `ResolveJoinStrategyHints`.


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