Skip to content

Store String columns of unknown average width in the hash join row store - #131917

Draft
murphy-4o wants to merge 2 commits into
ClickHouse:masterfrom
murphy-4o:join-row-store-unknown-string-width
Draft

murphy-4o wants to merge 2 commits into
ClickHouse:masterfrom
murphy-4o:join-row-store-unknown-string-width

Conversation

@murphy-4o

@murphy-4o murphy-4o commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Related: #125979
Depends: #132249

The hash join row store takes a String column only if statistics give its average size. Iceberg tables have no such statistics, so their joins never used the row store. Now an unknown average is treated as the inline size (15 bytes); longer values go to the overflow buffer and still gain.

TPC-DS SF100 on Iceberg: q11 0.86x, q74 0.91x, q87 0.94x, q38 0.96x; no query more than 5% slower.

Changelog category (leave one):

  • Performance Improvement

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

The hash join row store now also stores String columns without statistics (for example from Iceberg tables), which speeds up such joins.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131917]

The row store admitted a build-side String column only when statistics gave
its average size. Sources without statistics (Iceberg, Memory, MergeTree
without basic statistics) kept every string columnar, so a build side of a key
plus strings got no row store. An unknown average is now taken as the inline
size (15 bytes plus the offset); the min_string_column_bytes_for_hash_join_row_store
check still decides. A longer value goes to the overflow buffer and still saves
the cache miss of the columnar gather.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f36102f]


AI Review

Summary

PR #131917, head f36102f9a53fae8dea78bc471274356bf66c7cea, admits build-side String and Nullable(String) columns to the hash join row store when their average width is unknown, using 23 bytes for the existing size threshold. The regression test checks both result equivalence and actual row-store admission. The requested long-string performance cases are already present through merged PR #132249. No actionable correctness, lifetime, accounting, or compatibility findings remain after tracing packing, output gathering, unmatched rows, and spill reconstruction. No new inline comments were posted.

Missing context / blind spots
  • ⚠️ No local tests were run because this checkout has no ClickHouse binary or configured build. Current-head CI is still running. The PR supplies before/after Iceberg measurements; the published performance run predates the added 100–1000-byte string cases. Completion of the existing functional and performance jobs will provide current-head runtime confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 16, 2026
@murphy-4o
murphy-4o marked this pull request as ready for review November 16, 2026 07:23

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@clickhouse-gh clickhouse-gh Bot added the comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... label Nov 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f36102f9a with master 59e76b2ee (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.85 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 7.2 s 16.2 s +10.1 s (+165%)
Compile time of recompiled translation units

8 translation units recompiled, 23 s compile time in total, 8 of them have a recent master baseline.

Job report

@SmitaRKulkarni SmitaRKulkarni self-assigned this Nov 16, 2026
@SmitaRKulkarni

Copy link
Copy Markdown
Member

@murphy-4o : Could you add a case to tests/performance/hash_join_with_row_store_strings.xml with long String payload columns (100 to 1000 bytes) on a table without statistics (auto_statistics_types = ''), so we can see that unknown-width columns with long values don't regress in time or memory?

@rschu1ze

Copy link
Copy Markdown
Member

CC: @m-selmi

@m-selmi m-selmi self-assigned this Nov 17, 2026
@rschu1ze

Copy link
Copy Markdown
Member

Tbh, just assuming an average size and hoping for the best isn't a great strategy.

About the average string size: Do Parquet files not somehow store the uncompressed size per column that could be divided by the row count?

@murphy-4o

Copy link
Copy Markdown
Member Author

Tbh, just assuming an average size and hoping for the best isn't a great strategy.

About the average string size: Do Parquet files not somehow store the uncompressed size per column that could be divided by the row count?

  1. Baseline measurements for rowstore with long strings, conducted in a separate PR, showed no performance regression. We may consider removing the string length limitation of rowstore in the future.
  2. While Parquet files include uncompressed size data, the Iceberg planner should retrieve metadata from manifest files instead of reading individual Parquet files. But until Iceberg V4, the per-column row width statistic doesn't exist in manifest

@m-selmi

m-selmi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

I ran some experiments on my local machine (AMD EPYC 9R14, 32 cores, 1 MiB L2 per core, 128 MiB L3):

  • 3×, 10×: join output rows per build row. Cells: columnar → row store, in ms.
  • random: the build rows are shuffled, and consecutive probe rows hit random build rows.
  • sorted: both sides are stored in key order, so consecutive probe rows hit neighbouring build rows.
width order build rows 2 cols, 3× 2 cols, 10× 6 cols, 3× 6 cols, 10×
100 B random 10M 413 → 397 (1.04×) 959 → 839 (1.14×) 1039 → 957 (1.09×) 2531 → 2112 (1.20×)
100 B random 25M 1009 → 945 (1.07×) 2471 → 2087 (1.18×) 2579 → 2360 (1.09×) 6633 → 5278 (1.26×)
100 B sorted 10M 259 → 300 (0.86×) 433 → 501 (0.86×) 604 → 740 (0.82×) 1084 → 1319 (0.82×)
100 B sorted 25M 581 → 690 (0.84×) 1001 → 1166 (0.86×) 1414 → 1778 (0.80×) 2588 → 3178 (0.81×)
1 KiB random 1M 331 → 368 (0.90×) 586 → 610 (0.96×) 687 → 747 (0.92×) 1466 → 1450 (1.01×)
1 KiB random 2.5M 609 → 641 (0.95×) 1288 → 1244 (1.04×) 1557 → 1629 (0.96×) 3586 → 3397 (1.06×)
1 KiB sorted 1M 277 → 323 (0.86×) 430 → 465 (0.92×) 547 → 646 (0.85×) 958 → 1068 (0.90×)
1 KiB sorted 2.5M 484 → 562 (0.86×) 840 → 923 (0.91×) 1164 → 1387 (0.84×) 2255 → 2451 (0.92×)
4 KiB random 250K 295 → 362 (0.81×) 534 → 573 (0.93×) 714 → 797 (0.90×) 1368 → 1403 (0.98×)
4 KiB random 600K 524 → 599 (0.87×) 1108 → 1148 (0.97×) 1396 → 1541 (0.91×) 3174 → 3177 (1.00×)
4 KiB sorted 250K 265 → 323 (0.82×) 411 → 462 (0.89×) 615 → 721 (0.85×) 967 → 1048 (0.92×)
4 KiB sorted 600K 455 → 533 (0.85×) 793 → 854 (0.93×) 1158 → 1345 (0.86×) 2164 → 2324 (0.93×)

Looks like the picture is split, at 100 byte we can even get better performance in some cases.
But as strings get longer, there are regressions in both random and sorted input cases (the sorted cases are generally a weak point of the row layout transformation).

So IMO we should not jump to enabling this, at least not without a different strategy.
Some ideas:

  • collecting at runtime the average string sizes for the next query occurence.
  • building the row store in a post build phase while we collect average string sizes during the build. Checking if this could be done without much build time regression

@murphy-4o
murphy-4o marked this pull request as draft November 24, 2026 02:50
@murphy-4o

Copy link
Copy Markdown
Member Author

@m-selmi
Thanks for the comprehensive perf.
While there are other solutions available, they seem like overkill for this Iceberg-specific problem.
I’ll put this PR on hold for now to reconsider the approach.

This branch has not been deployed

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

Labels

comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants