Skip to content

Improve HashJoin main loop - #82308

Merged
qoega merged 13 commits into
masterfrom
improve_hj
Jul 2, 2025
Merged

qoega merged 13 commits into
masterfrom
improve_hj

Conversation

@nickitat

@nickitat nickitat commented Jun 20, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Performance of HashJoin optimised by removing the additional loop over hash maps in the typical case of only one key column, also null_map and join_mask checks are eliminated when they're always true/false.


Screenshot 2025-06-24 at 21 29 41 Screenshot 2025-06-24 at 21 30 32 Screenshot 2025-06-24 at 21 31 22

Part of: #78539

@clickhouse-gh

clickhouse-gh Bot commented Jun 20, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1c398f2]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jun 20, 2025
@nickitat nickitat changed the title Improve HashJoin main loop Improve HashJoin main loop Jun 24, 2025
{
constexpr JoinFeatures<KIND, STRICTNESS, MapsTemplate> join_features;

auto & mapped = find_result.getMapped();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this code moved as-is from l.462

JoinCommon::JoinMask::Kind join_mask_kind,
typename AddedColumns,
typename Selector>
size_t HashJoinMethods<KIND, STRICTNESS, MapsTemplate>::joinRightColumns(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It has the same code as the generic joinRightColumns, but specialised for the case of one condition (i.e. one map)

@nickitat

Copy link
Copy Markdown
Member Author

I have to move optimizations for the multi-map case into a separate PR, because I'm having some issues with the arm build, and I don't want to delay this PR because of another CI problem.

@nickitat
nickitat marked this pull request as ready for review June 30, 2025 10:14
@vdimir vdimir self-assigned this Jul 2, 2025

namespace DB
{
template class HashJoinMethods<JoinKind::Full, JoinStrictness::RightAny, HashJoin::MapsAll>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you split it because it became heavier and started to hit the limit again?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep. And one inaccurate move could push us over the limit again, even after this split )


explicit JoinMask(bool value, size_t size)
JoinMask(bool value, size_t size)
: column(ColumnUInt8::create(size, value))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we actually use column in such case? Can't we just check kind in isRowFiltered ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That would make a lot of sense. Let me fix that.

@qoega
qoega added this pull request to the merge queue Jul 2, 2025
Merged via the queue into master with commit 839cc2b Jul 2, 2025
@qoega
qoega deleted the improve_hj branch July 2, 2025 14:02
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2025
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @nickitat @qoega @KochetovNicolai @vdimir — while reviewing this PR I found the following:

Happy to discuss — close anything that's wrong or already addressed.

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

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants