Skip to content

Devirtualize emission of non-joined rows in RIGHT and FULL joins - #105679

Merged
m-selmi merged 3 commits into
ClickHouse:masterfrom
m-selmi:batch-non-joined-rows-before-emission
May 26, 2026
Merged

m-selmi merged 3 commits into
ClickHouse:masterfrom
m-selmi:batch-non-joined-rows-before-emission

Conversation

@m-selmi

@m-selmi m-selmi commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

This change de-virtualizes the emission of non-joined rows in RIGHT and FULL join following the same principle used in AddedColumns.cpp

Benchmarking results from right_full_hash_join.xml:

nr query new (ms) old (ms) Δ (ms) Δ%
0 RIGHT wide × 90% unmatched 584 659 −75 −11.4%
1 RIGHT wide × 50% unmatched 597 629 −32 −5.1%
2 RIGHT wide × 10% unmatched 596 592 +4 +0.7%
3 RIGHT narrow × 90% unmatched 249 269 −20 −7.4%
4 RIGHT narrow × 50% unmatched 255 271 −16 −5.9%
5 RIGHT narrow × 10% unmatched 255 253 +2 +0.8%
6 RIGHT nullable × 90% unmatched 674 792 −118 −14.9%
7 RIGHT nullable × 50% unmatched 689 761 −72 −9.5%
8 RIGHT nullable × 10% unmatched 695 693 +2 +0.3%
9 FULL wide × 90% unmatched 618 688 −70 −10.2%
10 FULL wide × 50% unmatched 641 699 −58 −8.3%
11 FULL wide × 10% unmatched 612 612 0 0.0%
12 FULL narrow × 90% unmatched 252 271 −19 −7.0%
13 FULL narrow × 50% unmatched 252 265 −13 −4.9%
14 FULL narrow × 10% unmatched 248 250 −2 −0.8%
15 FULL nullable × 90% unmatched 738 837 −99 −11.8%
16 FULL nullable × 50% unmatched 735 819 −84 −10.3%
17 FULL nullable × 10% unmatched 701 699 +2 +0.3%

Changelog category (leave one):

  • Performance Improvement

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

De-virtualize the emission of non-joined rows in RIGHT and FULL join by batching them.


Note

Medium Risk
Touches RIGHT/FULL join non-joined row emission paths and adds a new IColumn overload that changes how defaults/null entries are handled; mistakes could lead to incorrect join output rows or crashes in edge cases (replicated columns, nullmaps, parallel buckets).

Overview
Improves RIGHT/FULL hash join non-joined row emission by collecting (ColumnsInfo*, row_num) pairs and then batch-filling output columns via fillFromBlocksAndRowNumbers, replacing per-row/per-column insertFrom loops.

Extends IColumn/IColumnHelper with a second fillFromBlocksAndRowNumbers overload optimized for the non-null case, while keeping the existing API that interprets nullptr entries as defaults; adds a performance test (right_full_hash_join.xml) covering wide/narrow/nullable build tables and varying unmatched rates.

Reviewed by Cursor Bugbot for commit 50e1346. Bugbot is set up for automated code reviews on this repo. Configure here.

Version info

  • Merged into: 26.6.1.150

@clickhouse-gh

clickhouse-gh Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c32c878]

Summary: ✅


AI Review

Summary

This PR refactors RIGHT/FULL HashJoin non-joined-row emission to batch (ColumnsInfo, row_num) collection and then use fillFromBlocksAndRowNumbers for devirtualized insertion, plus adds a focused performance scenario file. The current implementation preserves the original emission contract for non-joined rows, keeps null/default behavior separated via the existing typed overload, and includes concrete performance evidence in the PR description and benchmark config.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label May 22, 2026
@george-larionov george-larionov self-assigned this May 23, 2026

@george-larionov george-larionov 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.

Nice optimization! LGTM.

Comment thread src/Columns/IColumn.cpp
type->insertDefaultInto(*col);
continue;
}
}

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.

consider adding

else
{
    chassert(columns[j] != nullptr);
}

to guard against future bugs

@clickhouse-gh

clickhouse-gh Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 93.33% (70/75) · Uncovered code

Full report · Diff report

@m-selmi
m-selmi added this pull request to the merge queue May 26, 2026
Merged via the queue into ClickHouse:master with commit b12263d May 26, 2026
326 of 328 checks passed
@m-selmi
m-selmi deleted the batch-non-joined-rows-before-emission branch May 26, 2026 08:59
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 26, 2026
@Algunenano

Copy link
Copy Markdown
Member

The perf tests introduced here are extremely noisy. Up to 100% noise in master (e.g. always say faster/slower when running with the same binary) (ref: #100759). Could you have a look please?

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.

4 participants