Skip to content

Perform deduplication based on join_keys when building ht - #19097

Merged
Mytherin merged 1 commit into
duckdb:mainfrom
tianjq16:optimize_perform_deduplication_when_building_ht
Sep 26, 2025
Merged

Mytherin merged 1 commit into
duckdb:mainfrom
tianjq16:optimize_perform_deduplication_when_building_ht

Conversation

@tianjq16

@tianjq16 tianjq16 commented Sep 23, 2025

Copy link
Copy Markdown
Contributor

When building a hash table in the PhysicalHashJoin operator, in some cases, if the join_keys is duplicated, it is actually not necessary to insert it. For example, the join_type is SEMI and the join condition is a equality condition.

@Mytherin
Mytherin requested a review from lnkuiper September 23, 2025 07:05

@lnkuiper lnkuiper left a comment

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.

Hi, thanks for the PR! This makes a lot of sense. I just have one request regarding the name of the newly added variable: Can we rename it so the code becomes easier to understand?

//! Whether or not we error on multiple rows found per match in a SINGLE join
bool single_join_error_on_multiple_rows = true;
//! Whether or not to perform deduplication based on join_keys when building ht
bool deduplicate_keys = false;

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.

Can we rename this to insert_duplicate_keys, and default it to true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comment, I have renamed the newly added variable.

Comment thread src/execution/join_hashtable.cpp Outdated

if (conditions.size() == 1 &&
(join_type == JoinType::SEMI || join_type == JoinType::ANTI || join_type == JoinType::MARK)) {
deduplicate_keys = true;

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.

insert_duplicate_keys = false;

Comment thread src/execution/join_hashtable.cpp Outdated
for (idx_t i = 0; i < key_match_count; i++) {
const auto need_compare_idx = state.key_match_sel.get_index(i);
const auto entry_index = state.keys_to_compare_sel.get_index(need_compare_idx);
if (!ht.deduplicate_keys) {

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.

if (ht.insert_duplicate_keys) {

@tianjq16
tianjq16 force-pushed the optimize_perform_deduplication_when_building_ht branch from 1ec9b52 to 6abf1f1 Compare September 23, 2025 16:06
@tianjq16
tianjq16 requested a review from lnkuiper September 23, 2025 18:17
@duckdb-draftbot
duckdb-draftbot marked this pull request as draft September 24, 2025 06:56
@hannes
hannes marked this pull request as ready for review September 24, 2025 06:56

@lnkuiper lnkuiper left a comment

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.

Thanks for the changes! Looks good to me now, ready when CI passes (not sure why all the runs got cancelled)

@tianjq16

Copy link
Copy Markdown
Contributor Author

Thanks for your review! What do I need to do to make CI pass?

@lnkuiper

Copy link
Copy Markdown
Member

Hi @tianjq16, yesterday a bunch of CI runs got cancelled (also on my Fork), not sure what happened. I think we should just run CI again

@Mytherin
Mytherin merged commit 2259ad7 into duckdb:main Sep 26, 2025
107 of 123 checks passed
@Mytherin

Copy link
Copy Markdown
Collaborator

Thanks!

krlmlr added a commit to krlmlr/duckdb-r-old that referenced this pull request Oct 21, 2025
Perform deduplication based on join_keys when building ht (duckdb/duckdb#19097)
krlmlr added a commit to krlmlr/duckdb-r-old that referenced this pull request Nov 1, 2025
Perform deduplication based on join_keys when building ht (duckdb/duckdb#19097)
krlmlr added a commit to krlmlr/duckdb-r-old that referenced this pull request Nov 2, 2025
Perform deduplication based on join_keys when building ht (duckdb/duckdb#19097)
krlmlr added a commit to krlmlr/duckdb-r-old that referenced this pull request Nov 2, 2025
Perform deduplication based on join_keys when building ht (duckdb/duckdb#19097)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants