Repository navigation
Conversation
|
Workflow [PR], commit [cd73b80] Summary: ✅ AI ReviewSummaryThis PR replaces plain single- Findings
|
1461760 to
68acbaa
Compare
68acbaa to
ed38fd5
Compare
ea6780e to
a9154e6
Compare
a9154e6 to
fa0ca45
Compare
|
Benchmarks show that |
|
Dear @amosbird, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
Resolve conflict in `StorageJoin.cpp`: take master's version for `rawData` and `rawSize` template functions (non-const refs, no `static` since they are already in anonymous namespace). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
German strings, nice. @m-selmi Since you were recently working on similar hash table optimizations, let me ping you so you can subscribe and watch this PR as it evolves (it isn't ready for review yet). |
`StringViewHash::operator()` returns `size_t`, but `WeakHash32::data` is a container of `UInt32`. The implicit conversion was caught by `-Wshorten-64-to-32` in the `Fast test`, `Build (arm_tidy)`, and `Build (llvm_coverage_build)` jobs. Add an explicit cast to `UInt32`. The lower 32 bits are equivalent since `CRC32Hash` fills both halves with the same value. Report: ClickHouse#93271
The PR's `HashMapCell::getKey` returns the key by value (so `PackedStringRef` can be returned as `std::string_view`), but the master merge restored the older `T &` signature for `rawData` and `rawSize`. A non-const lvalue reference cannot bind to the temporary returned by `getKey`, so `arm_tidy` rejected the call. Re-apply the `const T &` qualifier from the original PR commit so both the temporary and the lvalue overloads compile. Report: ClickHouse#93271
`StringViewHash::operator()` returns `size_t`, but `WeakHash32::data` is a container of `UInt32`. The implicit conversion was caught by `-Wshorten-64-to-32` in the `Fast test`, `Build (arm_tidy)`, and `Build (llvm_coverage_build)` jobs. Add an explicit cast to `UInt32`. The lower 32 bits are equivalent since `CRC32Hash` fills both halves with the same value. Report: ClickHouse#93271
The PR's `HashMapCell::getKey` returns the key by value (so `PackedStringRef` can be returned as `std::string_view`), but the master merge restored the older `T &` signature for `rawData` and `rawSize`. A non-const lvalue reference cannot bind to the temporary returned by `getKey`, so `arm_tidy` rejected the call. Re-apply the `const T &` qualifier from the original PR commit so both the temporary and the lvalue overloads compile. Report: ClickHouse#93271
…ision The test was added in ClickHouse#90880 to demonstrate a cross-version string serialization bug that only manifests when two-level aggregation is active across servers running incompatible serialization formats. This PR introduces `AggregationMethodPackedString` for the `key_string` slot, replacing `AggregationMethodString` (`StringHashTable`). Because the on-the-wire layout for single-string-key aggregation states is incompatible between the two methods, this PR raises `DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD` from 54448 to 54484. As a side effect, two-level aggregation is now disabled in distributed queries against any server older than 54484 (including 25.6, used by `node256` in the integration test), and the bug demonstrated by the test cannot be reproduced anymore — the deduplication succeeds and the query returns 10000 instead of 20000. Update the assertion to 10000 and add a comment explaining the change. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=6bde8cea7bc1e97b3d8cd5c96e902042f1c7fd60&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%205%2F6%29 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The documented mode detection summary states that medium strings have `high != 0`, but `isMedium` was checking only `getSmallSize() == 0` and classified the empty representation (`high == 0`, `low == 0`) as medium. Add an explicit `isEmpty` helper, exclude it from `isMedium`, and handle the empty case explicitly in `operator std::string_view` so it returns a default-constructed (rather than null-data) view. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| bool keyEquals(const Key & key_, size_t /*hash_*/, const State & /*state*/) const { return bitEquals(key, key_); } | ||
| bool ALWAYS_INLINE keyEquals(const Key & key_) const { return bitEquals(key, key_); } | ||
| bool ALWAYS_INLINE keyEquals(const Key & key_, size_t /*hash_*/) const { return bitEquals(key, key_); } | ||
| bool ALWAYS_INLINE keyEquals(const Key & key_, size_t /*hash_*/, const State & /*state*/) const { return bitEquals(key, key_); } |
There was a problem hiding this comment.
Any specific reasons for changing this to ALWAYS_INLINE? Is this something we're leaning towards in new code or measured?
Motivation for this question: If this is what team leans toward, I need to change in my active PRs 🙂 .
There was a problem hiding this comment.
This looks local to the hot probe path, not like a repo-wide style change.
Here keyEquals / bitEquals sit directly on the aggregation and join hash-table lookup path, and for PackedStringRef the comparison now fans out into PackedStringRef::operator== with the small/medium/large dispatch. Marking these wrappers ALWAYS_INLINE keeps the whole compare visible to the caller and avoids paying extra wrapper-call overhead on every probe.
I would not treat this as a general convention for new code or something to retrofit into unrelated PRs. It only makes sense where profiling or codegen inspection shows the call boundary matters on a hot path like this one.
| /// yield identical `uint64_t` values regardless of endianness. | ||
| /// | ||
| /// ------------------------------------------------------------ | ||
| /// Byte layout (16 bytes total, identical on little-endian and big-endian): |
There was a problem hiding this comment.
Tiny doc nit, not blocking: the header says the byte layout is "identical on little-endian and big-endian," but I think that's only true for some fields.
hash32 and the medium length32 are written with a plain memcpy of the integer, so they end up in native byte order rather than being forced to LE. Only the packed pointer and the 64-bit length go through storeLE. So on a big-endian build, those two fields wouldn't have the same byte image as on little-endian.
This doesn't look like a correctness issue, since reads mirror writes on the same host and everything round-trips. But the comment seems to promise slightly more than the code guarantees.
Could we either soften the wording to something like "consistent within a process / host-stable" instead of endianness-stable, or run hash32 and length32 through storeLE too if cross-endian byte identity is actually the goal?
Mostly just want the comment to match the intent.
|
Reviewed the current state ( Blocker (unchanged): adaptive vs. unconditional
|
The latest `master` merge advanced `DBMS_TCP_PROTOCOL_VERSION` to `54486` for `DBMS_MIN_PROTOCOL_VERSION_WITH_INTERNAL_QUERY_FLAG` (from the `log-internal-secondary-queries` change). This PR previously used `54486` as the next-free revision for `DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`, so after the merge both the PR's guard and master's unrelated feature shared `54486`, and the branch no longer advanced the wire protocol past `master`. That is incorrect: a stock `54486` server does not have the `PackedStringRef`-based aggregation-variant selection, yet the guard `revision < DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD` would treat it as new, re-enabling two-level aggregation across incompatible servers. Move this PR to the next free revision `54487` for both `DBMS_TCP_PROTOCOL_VERSION` and `DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`, and update the reference in `test_string_aggregation_compatibility`.
Address review feedback: the existing cross-version cases group by `(id, s2)` where `s2` is `LowCardinality(String)`, so aggregation goes through the multi-key serialized path and never exercises the code this PR changes. `PackedStringRef` replaces the single-`String` `key_string` / `key_string_two_level` variants. Add `test_single_string_key_aggregation_compatibility`, which groups by a single plain `String` key under forced two-level aggregation (`group_by_two_level_threshold = 1`) across a new server and an old (25.6) server. The key column mixes inline keys (<= 11 bytes, fully packed into `PackedStringRef`) with non-inline keys (> 11 bytes, out-of-line), covering both representations. Correct cross-version aggregation must deduplicate the 1000 distinct keys to 1000; a bucketing mismatch between versions would inflate the count. The legacy in-memory serialization scenario (`serialize_string_in_memory_with_zero_byte = 0`) is covered too.
|
Continued this PR: merged latest 1. Merged
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 140/148 (94.59%) · Uncovered code |
Add self-documenting offset constants `SMALL_PAYLOAD_OFFSET` and `MEDIUM_LENGTH_OFFSET` instead of reusing `HASH_SIZE_BYTES` as a byte offset, rename `HashMapCell::ExternalKey` to `external_key_type` for consistency with the neighbouring type aliases, and correct the `PackedStringRef` header comment that claimed the byte image is identical across endianness (hash32 and length32 are stored in native byte order; the image is stable per host, which is sufficient since the value never crosses processes). Also replace a narrating comment in `ColumnsHashingImpl` with one that explains why the internal key getter is required for the cache, and inline a single-use variable in `keyHolderPersistKey` whose name suggested string length while it held the heap size. Co-authored-by: Cursor <[email protected]>
`StringViewHash::operator()` returns `size_t`, but `WeakHash32::data` is a container of `UInt32`. The implicit conversion was caught by `-Wshorten-64-to-32` in the `Fast test`, `Build (arm_tidy)`, and `Build (llvm_coverage_build)` jobs. Add an explicit cast to `UInt32`. The lower 32 bits are equivalent since `CRC32Hash` fills both halves with the same value. Report: ClickHouse#93271
The TSan stateless runs failed on `query_43` (`SELECT URL FROM test.hits WHERE URL LIKE '%yandex%' ORDER BY URL DESC`) because the runtime dataflow output-bytes estimate `RuntimeDataflowStatisticsOutputBytes` is sensitive to the block size. CI's randomization diagnosis isolated `--max_block_size 30152` as the sole culprit: the estimate dropped to ~25-29M against the expected `82404720`, exceeding the 2.5x tolerance, while runs without randomization passed 4/4. Pin `max_block_size` to its default (`65409`), mirroring the existing `max_threads` override, so the estimate stays stable against the randomized settings. CI report: ClickHouse#93271 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ytes_estimation` The aggregation-state size estimate checked by this test is recorded per bucket after the conversion to a two-level hash table. The test randomization can set `group_by_two_level_threshold` and `group_by_two_level_threshold_bytes` as low as 1, forcing the conversion from the very first block, which inflates the recorded estimate for `query_28` to ~59.4M against the expected 23722663 (ratio 2.50x, just over the 2.5x test threshold). Pin both thresholds to their defaults, continuing the test's established pinning pattern (`max_threads`, `max_block_size`). Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=89902268b9cfacc37dbfeb9871d0d4e18a2ecfb7&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 PR: ClickHouse#93271 Co-Authored-By: Claude Fable 5 <[email protected]>
Drop the `ABStringRef` string-key aggregation method: master merged ClickHouse#93271, which upstreams the same idea as `PackedStringRef` and makes `AggregationMethodPackedString` the default `key_string` / `key_string_two_level` method. The branch's `ABStringRef` machinery was never selected by default (its two-level bucketing did not reproduce `TwoLevelStringHashMap`'s), and keeping it alongside the upstreamed version would mean maintaining a duplicate hash method plus a `base/base/StringRef.h` compatibility shim that only existed to keep `ABStringRef` compiling after master replaced `StringRef` with `std::string_view`. Resolved every conflicting hunk in favour of master and removed the now-superseded files: - `base/base/ABStringRef.h`, `base/base/StringRef.h` (shim), `src/Common/HashTable/ABHashMap.h` - `HashMethodABString`, `HashMethodABSerialized`, `AggregationMethodABStringNoCache`, `AggregationMethodABSerialized`, `TwoLevelABHashMap`, `ArenaABStringHolder`, `SerializedABKeyHolder`, `DefaultHash<ABStringRef>` and the `key_ab_string` / `ab_serialized` variants. The remaining contents of the branch — `count_distinct_optimization` on by default and the opt-in `query_plan_rewrite_order_by_limit` rewrite — are unaffected.
…mment Measured with pre-built CI binaries against the `hits_v1` dataset under the test's pinned settings: master produced ~57..58 MB for `query_28` continuously since at least 2026-04-01 (2026-04-01: 57.3 MB, 2026-06-10: 57.8 MB, 2026-07-26 just before the merge of #110573: 57.0 MB, current master: 58.2 MB), so nothing regressed in the aggregation or statistics path around the failure. The recorded 23722663 was calibrated on 2025-12-31 on the branch of #93271 and carried unchanged into #110573, whose merge also overwrote the value master had been green with since February, 31064320 (ratio ~1.85 against the actual ~58 MB, which is why master stayed green until the merge). The final head of #93271 (before the `HashMethodPackedString` simplification) measures 58.4 MB as well, so the pull request itself does not change the estimate. With `group_by_two_level_threshold=1` the current estimate is 58170420 vs 58237072 at the pinned defaults, i.e. the threshold no longer affects this value. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=5baed0f5a10c333cd220b9646d6ef4647425079d&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 Co-Authored-By: Claude Fable 5 <[email protected]>
`StringViewHash::operator()` returns `size_t`, but `WeakHash32::data` is a container of `UInt32`. The implicit conversion was caught by `-Wshorten-64-to-32` in the `Fast test`, `Build (arm_tidy)`, and `Build (llvm_coverage_build)` jobs. Add an explicit cast to `UInt32`. The lower 32 bits are equivalent since `CRC32Hash` fills both halves with the same value. Report: ClickHouse#93271
The TSan stateless runs failed on `query_43` (`SELECT URL FROM test.hits WHERE URL LIKE '%yandex%' ORDER BY URL DESC`) because the runtime dataflow output-bytes estimate `RuntimeDataflowStatisticsOutputBytes` is sensitive to the block size. CI's randomization diagnosis isolated `--max_block_size 30152` as the sole culprit: the estimate dropped to ~25-29M against the expected `82404720`, exceeding the 2.5x tolerance, while runs without randomization passed 4/4. Pin `max_block_size` to its default (`65409`), mirroring the existing `max_threads` override, so the estimate stays stable against the randomized settings. CI report: ClickHouse#93271 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ytes_estimation` The aggregation-state size estimate checked by this test is recorded per bucket after the conversion to a two-level hash table. The test randomization can set `group_by_two_level_threshold` and `group_by_two_level_threshold_bytes` as low as 1, forcing the conversion from the very first block, which inflates the recorded estimate for `query_28` to ~59.4M against the expected 23722663 (ratio 2.50x, just over the 2.5x test threshold). Pin both thresholds to their defaults, continuing the test's established pinning pattern (`max_threads`, `max_block_size`). Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=93271&sha=89902268b9cfacc37dbfeb9871d0d4e18a2ecfb7&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 PR: ClickHouse#93271 Co-Authored-By: Claude Fable 5 <[email protected]>
Add self-documenting offset constants `SMALL_PAYLOAD_OFFSET` and `MEDIUM_LENGTH_OFFSET` instead of reusing `HASH_SIZE_BYTES` as a byte offset, rename `HashMapCell::ExternalKey` to `external_key_type` for consistency with the neighbouring type aliases, and correct the `PackedStringRef` header comment that claimed the byte image is identical across endianness (hash32 and length32 are stored in native byte order; the image is stable per host, which is sufficient since the value never crosses processes). Also replace a narrating comment in `ColumnsHashingImpl` with one that explains why the internal key getter is required for the cache, and inline a single-use variable in `keyHolderPersistKey` whose name suggested string length while it held the heap size. Co-authored-by: Cursor <[email protected]>
This PR introduces
PackedStringRefandPackedStringHashTable, a compact string key representation and a corresponding hash table implementation, primarily targeting string-heavy aggregation workloads. This is part of #81944.In the past we introduced
StringHashTable#5417 to optimize small string keys. Since then, ClickHouse has continued to evolve and gained more hash table–level optimizations, such as better capacity prediction, prefetching, and more specialized fast paths. These optimizations are generally designed around a single, uniform hash table layout and access pattern. As a result, it has become increasingly difficult to integrateStringHashTablecleanly with them. Some optimizations, such as consecutive key handling, were already awkward withStringHashTable, and the situation has only become more complex as more logic has been added around hash tables.Instead of pushing
StringHashTablefurther, this change moves the optimization to the string representation itself.PackedStringRefencodes small, medium, and large strings into a fixed 16-byte object, storing short strings inline while using tagged pointers for longer strings. Small strings of up to 11 bytes are fully inlined, which already covers a large portion of real-world string keys (such as tags, short identifiers, and common dimension values), making this optimization effective even with a relatively conservative inline threshold.PackedStringHashTableis built around this representation and fits naturally into the existing optimization framework, including prefetching and capacity prediction.At the moment this is only wired for aggregate string keys. Other usages of
StringHashTableare left unchanged. If this approach proves effective, it can be gradually extended to more places and may eventually replaceStringHashTable.No dedicated perf test is added in this PR. Any noticeable regression or improvement should already be covered by existing aggregation-related performance tests in CI.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Introduces
PackedStringRef, a compact 16-byte representation for single-Stringaggregation keys, to reduce hash-table cell size and improve string-heavyGROUP BYworkloads. The change is limited to aggregate string keys; otherStringHashTableusers are unchanged.Documentation entry for user-facing changes