-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CORE] Use the smaller table to build hashmap in shuffled hash join #5750
Conversation
Thanks for opening a pull request! Could you open an issue for this pull request on Github Issues? https://github.com/apache/incubator-gluten/issues Then could you also rename commit message and pull request title in the following format?
See also: |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
4 similar comments
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
Test failure is unrelated. cc @rui-mo @zhztheplayer |
/Benchmark Velox |
/Benchmark Velox TPCDS |
fe60af1
to
8182c17
Compare
Run Gluten Clickhouse CI |
Then how does this PR work with lower Spark version? |
If there is no fallback, all versions of velox bakcend support using small table to build hashmap. If there is a fallback, it will remain consistent with vanilla spark, it is supported after 3.5 and not supported before 3.5. @zhztheplayer |
Does that mean we don't actually need strategy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/Benchmark Velox |
/Benchmark Velox TPCDS |
Do we still need In fact, I'm quite confused this logic here. In fact, if we can choose the right build side, why prefer new build side based on pattern there? |
@WangGuangxin The reasoning behind this is that, in cases where the child is an aggregation or filter, we discovered that Spark's smaller table selection was inconsistent with reality. If we follow Spark's recommendation in this case, we will actually be using the larger table as the build table, which will result in performance regression. But with this new modification, perhaps we can test the performance and see if we still need this hint. |
First of all, the judgment of JoinSelectionOverrides and Spark Join Selection are not the same. I am not sure why JoinSelectionOverrides does not have the judgment of size. Secondly, clickhouse backend has special processing. |
@rui-mo Do you have some contexts on this difference? If Velox backend doesn't require for the strategy then we may be able to move it to CH module. |
IIUC,
Both of them can be ( and should be ?) moved to In fact, if we reuse the |
@WangGuangxin A deeper issue might be the size estimation could be inaccurate if there is an aggregate or filter, e.g. in some case, the aggregated data has much less rows than its input and becomes the smaller table, but Spark still treats it as the larger table. |
8182c17
to
5671203
Compare
Run Gluten Clickhouse CI |
Of course, done. |
/Benchmark Velox |
/Benchmark Velox TPCDS |
===== Performance report for TPCH SF2000 with Velox backend, for reference only ====
|
We notice large regression for q14a/q14b on TPC-DS benchmark. We may need to double-check. Thanks.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We found performance regression for q14a/q14b. Would you take a look?
I will take a look later. |
Run Gluten Clickhouse CI |
/Benchmark Velox TPCDS |
Run Gluten Clickhouse CI |
===== Performance report for TPCDS SF2000 with Velox backend, for reference only ====
|
===== Performance report for TPCH SF2000 with Velox backend, for reference only ====
|
// condition. | ||
// case LeftOuter | LeftSemi => true | ||
// LeftOuter. | ||
case LeftOuter => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build left is supported by LeftSemi on Velox backend. For a left semi join, I assume we need to build left is the left table is smaller, so shall we add it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous regression of b14a/b14b was due to left semi join build left side. Although build left is supported by LeftSemi on Velox backend, but the performance is not as good as build right, vanilla spark also choose build right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function returns if building left is supported, which I assume indicates the backend's capability and shouldn't be mixed up with the build side selection.
vanilla spark also choose build right.
It is due to some special logic, e.g. preferredBuildSide, Gluten chooses to build left? If so, I think we need to fix there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning to remove preferredBuildSide
in the next PR because it is unnecessary and not as accurate as AQE. Like vanilla spark, its performance improvement is compared to sort merge join, for left outer and join outer, if both are shuffle hash joins, choosing a small table will not improve performance.
I don’t know the logic of velox’s support for small table build. Shuffle hash join is forced to be used here,
what I'm worried about is that for shuffle hash join of LeftSemi, build left is much slower than build right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/apache/spark/blob/branch-3.2/sql/core/src/test/resources/tpcds-plan-stability/approved-plans-v1_4/q14a/explain.txt
Both left and right of LeftSemi contain filter, so isPreferred(left)
and isPreferred(right)
both are true, so I think it is not caused by preferredBuildSide
, but because build left is much slower than build right in LeftSemi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a TODO here to describe why we don't add LeftSemi? Maybe also include the issue link.
facebookincubator/velox#9980
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
Run Gluten Clickhouse CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Thanks all for review. |
===== Performance report for TPCH SF2000 with Velox backend, for reference only ====
|
I looked it up and it seems like can't move custom strategy to ColumnarOverrides. Custom strategy is used to transform a LogicalPlan into a SparkPlan. Columnar rule implements Spark plan into Gluten plan. Custom strategy runs before Columnar rule. @zhztheplayer |
I think SHJ and SMJ in Spark share the same In the simplest case the topic could be very similar to the one about hash/sort agg, see this code |
This is a good way for me, thank you, I'll do it later. |
What changes were proposed in this pull request?
Background history: SPARK-36612 support left outer join build left or right outer join build right in shuffled hash join, it first took effect in spark 3.5.
#408 support use the smaller table to build hashmap in shuffled hash join in velox backend, and it overwrite
HashJoin
, so when fallback to vanilla spark all versions support, not just spark 3.5. But since the class loading order is not always predictable in Java 8 & HotSpot JVM, Support has been temporarily removed in #674.This PR finally select build side when
genShuffledHashJoinExecTransformer
to support use the smaller table to build hashmap in shuffled hash join in velox backend.JoinSelectionOverrides
will no longer generate illegal build side, causingEnsureRequirements
verification to fail.How was this patch tested?