Skip to content

[GLUTEN-7548][VL] Optimize BHJ in velox backend#8931

Merged
JkSelf merged 26 commits intoapache:mainfrom
JkSelf:bhj-optimization-1
Mar 9, 2026
Merged

[GLUTEN-7548][VL] Optimize BHJ in velox backend#8931
JkSelf merged 26 commits intoapache:mainfrom
JkSelf:bhj-optimization-1

Conversation

@JkSelf
Copy link
Contributor

@JkSelf JkSelf commented Mar 7, 2025

What changes were proposed in this pull request?

This PR implements the optimization from the CK backend in the BHJ to the Velox backend, ensuring that the hash table is built only once per executor. The detailed design document can be found here.

This PR enhances performance by 1.29x in 3TB TPC-DS Q23a when compared to using broadcast thresholds of 100MB and 10MB. Additionally, it addresses the out-of-memory (OOM) issue encountered in Q24a and Q24b with a 100MB threshold.
However, there is still potential for further optimization by implementing concurrent hash table building to mitigate the performance degradation observed in Q67. We will continue to pursue further optimizations in subsequent PRs.

Note: This PR eliminates the need for #5563

How was this patch tested?

Existing tests

@github-actions github-actions bot added CORE works for Gluten Core BUILD VELOX labels Mar 7, 2025
@github-actions
Copy link

github-actions bot commented Mar 7, 2025

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?

[GLUTEN-${ISSUES_ID}][COMPONENT]feat/fix: ${detailed message}

See also:

@github-actions
Copy link

github-actions bot commented Mar 7, 2025

Run Gluten Clickhouse CI on x86

@JkSelf JkSelf changed the title [VL][test] test bhj optimization [GLUTEN-7548][VL][test] test bhj optimization Mar 7, 2025
@github-actions
Copy link

github-actions bot commented Mar 7, 2025

#7548

@JkSelf JkSelf force-pushed the bhj-optimization-1 branch from a6e8905 to 2b90118 Compare March 7, 2025 09:58
@github-actions
Copy link

github-actions bot commented Mar 7, 2025

Run Gluten Clickhouse CI on x86

@JkSelf JkSelf changed the title [GLUTEN-7548][VL][test] test bhj optimization [GLUTEN-7548][VL][test] Optimize BHJ in velox backend Mar 7, 2025
@FelixYBW
Copy link
Contributor

FelixYBW commented Mar 8, 2025

In long term, we need to implement the Spark way. Broadcast hashtable instead of raw table data.

@JkSelf
Copy link
Contributor Author

JkSelf commented Mar 10, 2025

In long term, we need to implement the Spark way. Broadcast hashtable instead of raw table data.

@FelixYBW Yes, we will support broadcasting the hash table approach after adding serialization/deserialization support to Velox's HashTable.

@JkSelf JkSelf force-pushed the bhj-optimization-1 branch from 2b90118 to 8e677fa Compare March 10, 2025 02:11
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

@JkSelf JkSelf force-pushed the bhj-optimization-1 branch from 8e677fa to 8fed157 Compare March 10, 2025 02:30
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

@FelixYBW
Copy link
Contributor

@zhztheplayer Is there memory management issue in this solution? Is the memory allocated in storage memory?

@JkSelf will this solution helpful to the final solution?

@JkSelf
Copy link
Contributor Author

JkSelf commented Mar 11, 2025

@JkSelf will this solution helpful to the final solution?

@FelixYBW Yes, the primary difference between Design 1 and Design 2 is the need for serialization and deserialization of Velox's hash table. Most of the remaining code can be shared between the two designs. We will evaluate the TPCH performance after addressing the result mismatch issue. If the performance does not meet expectations, we will proceed with implementing Design 2.

@JkSelf JkSelf marked this pull request as draft March 11, 2025 01:41
@JkSelf JkSelf force-pushed the bhj-optimization-1 branch from e7100cf to 7606ed3 Compare March 12, 2025 10:56
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

@JkSelf JkSelf force-pushed the bhj-optimization-1 branch from 880ef19 to d2b9c03 Compare March 13, 2025 03:27
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

@JkSelf JkSelf force-pushed the bhj-optimization-1 branch from d2b9c03 to fd92027 Compare March 18, 2025 11:57
@github-actions
Copy link

Run Gluten Clickhouse CI on x86

@zhztheplayer
Copy link
Member

Any test code to cover all of our changes to broadcast code? Given the tests are mostly based on Spark local mode where no broadcasting will actually happen.

cc @zjuwangg

@JkSelf
Copy link
Contributor Author

JkSelf commented Mar 19, 2025

@zhztheplayer Thank you for your review. It appears that the existing tests cover the broadcast changes introduced in this PR. I have added logging to the native broadcast hash table build code, and these logs will be printed during the CI process.

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Run Gluten Clickhouse CI on x86

@JkSelf
Copy link
Contributor Author

JkSelf commented Mar 9, 2026

@jinchengchenghh @liujiayi771 @zhztheplayer I'm merging this PR now to unblock our internal tests. I'll follow up with another PR to resolve your remaining comments. Thanks for the comments!

Copy link
Member

@zhztheplayer zhztheplayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some non-blocking comments.

isNullAwareAntiJoin,
bloomFilterPushdownSize,
threadBatches,
defaultLeafVeloxMemoryPool());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultLeafVeloxMemoryPool should already be counted into off-heap memory pool, but I suggest to verify it if you'd like to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core DOCS VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.