Repository navigation
Add string column support in hash join row store - #125979
Conversation
|
Workflow [PR], commit [f7c2dca] Summary: ✅
AI ReviewSummaryReviewed PR #125979 at Consumers checked for the new representation:
The new Missing context / blind spots
Final Verdict✅ Approve. No new inline findings or thread changes are required. Normal CI completion remains pending. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes481 object files changed (+288.81 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units2689 translation units recompiled, 16682 s compile time in total, 2689 of them have a recent master baseline. |
harikrishnan94
left a comment
There was a problem hiding this comment.
Can this be one template <size_t HASH_BYTES> struct PackedStringRefT? no base, no protected. PackedStringRef / UnhashedPackedStringRef become aliases for <4> / <0>, and the hash and medium members get requires. also add a copyTo for <0>, the same copy loop sits in ColumnString.cpp and gatherColumnStringChars.
|
Thanks for the PR, @m-selmi! few comments inline.
|
|
@harikrishnan94 thanks for the comments! Please check the Memory behavior sections added to the description for a breakdown of the increase in memory usage when strings are transformed. |
harikrishnan94
left a comment
There was a problem hiding this comment.
Thanks Hechem for the changes, LGTM
`PackedStringRef` becomes `PackedStringRefT<4>`, and the new `UnhashedPackedStringRef` is `PackedStringRefT<0>`. The unhashed value has no hash and no medium encoding. A string of up to 15 bytes is stored in the value itself, and a longer string as its length and its address. `buildShort` builds the value of a string of up to 15 bytes with one 16-byte load and a mask, without a branch on the length. `buildLong` builds the value of a longer string. `build(ptr, len)` calls one of them by the length. `size` and `copyTo` read a string back. `operator==` compares two values as strings: small values by their 16 bytes, and large values by their bytes when their addresses differ. `heapSize`, `getHeapPtr` and `setHeapPointer` read and rebind the address of a large string, as a key holder needs when it moves a key into an arena. The conversion to `std::string_view` views a small string in the value and a large string where it is. The unhashed value is 4-byte aligned, so that a row can hold it at any multiple of 4 bytes. `PackedStringRef` keeps the 8-byte alignment of its hash table cells. The unit tests check the layout, the alignment and the access of the new type: the empty string, zero bytes in a string, the longest small string, the large encoding, equality and the heap pointer. The type and the code of `buildShort` come from #125979, where the hash join row store uses them. Co-Authored-By: Hechem Selmi <[email protected]> Co-Authored-By: Nihal Z. Miaji <[email protected]> Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…lysis The row store for `String` keys (#125979), merged from master, estimates the right input of a hash join for the average bytes of its columns with `estimateReadRowsCount`, without `find_single_node_read`. In the probe plan of automatic parallel replicas that analyzed the read again, which `05508_throwing_limit_swap` caught after the merge: 6 index analysis rounds against 5 without automatic parallel replicas. Pass `find_single_node_read` there as well, like the other join estimates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #104884
Related: #121981
Store
StringandNullable(String)columns of the right table in the hash join row store.UnhashedPackedStringRef: up to 15 bytes inline, longer values copied to a per-store overflow buffer.basicstatistics is at most 23 bytes (15 chars + offset). Without statistics, it stays columnar.min_string_column_bytes_for_hash_join_row_store = 0keepsStringcolumns out of the row store.Benchmark results:
from
hash_join_with_row_store_strings.xmlBreakdown by column count, build size, and string length distribution:
The row layout is not worth it at small string columns because the columns already fit in cache and no cache misses can be saved compared to the columnar format. In contrast, row store has the overhead of extracting the packed string refs during output column gather.
Memory behavior:
Nullable) instead of the columnarn + 8bytes (chars + offset), a value longer than 15 bytes is also copied to the store's overflow buffer.Per value, that is
8 − nbytes more forn ≤ 8, n - 8 bytes less forn > 8and 8 bytes more for longer values.max_bytes_in_joinand spilling see it.max_joined_block_size_rowsand the number of probing streams. Like the output block, it is tracked by the memory tracker but not counted in the join size.Measured peak memory in above experiment: +1% to +18% at 10M and 50M build rows

The worst case from the perspective of memory occurs when all string values are 1 byte long. For 6 columns of 10M rows: memory usage increased by +57% (1,102 → 1,728 MiB), and runtime improved by 1.89x (637 -> 337 ms).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Hash joins now store
StringandNullable(String)columns of the right table in the row store when their average value size (frombasiccolumn statistics) is at most 15 bytes. Joins that output several such columns from a large right table can achieve speedups of 1.4x to 2.4x or higher with more columns, with about 9% to 15% more memory for the right table. Controlled bymin_string_column_bytes_for_hash_join_row_store(default 8 MiB,0disables).Workflow [PR]
Sync PR [sync-upstream/pr/125979]
Version info
26.11.1.1770-master(included in26.11and later)