Skip to content

Introduce PackedStringRef & PackedStringHashTable - #93271

Closed
amosbird wants to merge 35 commits into
ClickHouse:masterfrom
amosbird:new-string-hash-table
Closed

amosbird wants to merge 35 commits into
ClickHouse:masterfrom
amosbird:new-string-hash-table

Conversation

@amosbird

@amosbird amosbird commented Dec 31, 2025 •

Copy link
Copy Markdown
Collaborator

This PR introduces PackedStringRef and PackedStringHashTable, 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 integrate StringHashTable cleanly with them. Some optimizations, such as consecutive key handling, were already awkward with StringHashTable, and the situation has only become more complex as more logic has been added around hash tables.

Instead of pushing StringHashTable further, this change moves the optimization to the string representation itself. PackedStringRef encodes 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.

copied-2025-12-31-16_51_22_144

PackedStringHashTable is 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 StringHashTable are left unchanged. If this approach proves effective, it can be gradually extended to more places and may eventually replace StringHashTable.

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):

  • Performance Improvement

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

Introduces PackedStringRef, a compact 16-byte representation for single-String aggregation keys, to reduce hash-table cell size and improve string-heavy GROUP BY workloads. The change is limited to aggregate string keys; other StringHashTable users are unchanged.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Dec 31, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cd73b80]

Summary: ✅


AI Review

Summary

This PR replaces plain single-String aggregation keys with PackedStringRef / PackedStringHashTable. The correctness issues previously raised around empty keys, big-endian behavior, and mixed-version two-level aggregation look addressed in the current code, but I still would not approve the unconditional rollout because the latest cached performance shards continue to show large regressions on short-string, low-cardinality workloads that are exactly on the key_string path this PR replaces.

Findings
⚠️ Majors
  • [src/Interpreters/AggregatedDataVariants.h:67] The current cached performance artifacts for cd73b80e0c9 still show material regressions on affected workloads even after the later fixes: if_transform_strings_to_enum regresses from 0.541s to 1.493s on amd_release shard 5/6 (2.76x), and group_by_sundy_li regresses from 0.0208s to 0.0534s on arm_release shard 3/6 (2.57x). Because key_string is switched to AggregationMethodPackedString unconditionally here, short, low-cardinality single-String GROUP BY queries can still get materially slower on the exact path this PR replaces.
    Suggested fix: either add an adaptive fallback / gate that keeps the old StringHashTable path for these patterns, or narrow the rollout and attach fresh before/after evidence showing the unconditional switch no longer regresses them.
Final Verdict

❌ Request changes: the correctness and compatibility issues I checked are addressed, but the unconditional switch still has reproducible performance regressions on real affected workloads, so the PR does not yet justify a blanket Performance Improvement claim.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Dec 31, 2025
@amosbird
amosbird force-pushed the new-string-hash-table branch from 1461760 to 68acbaa Compare December 31, 2025 08:42
@amosbird
amosbird force-pushed the new-string-hash-table branch from 68acbaa to ed38fd5 Compare December 31, 2025 08:45
@amosbird
amosbird force-pushed the new-string-hash-table branch from ea6780e to a9154e6 Compare December 31, 2025 13:32
@amosbird
amosbird force-pushed the new-string-hash-table branch from a9154e6 to fa0ca45 Compare December 31, 2025 13:33
@nickitat nickitat self-assigned this Jan 1, 2026
@amosbird

amosbird commented Jan 2, 2026

Copy link
Copy Markdown
Collaborator Author

Benchmarks show that PackedStringHashTable suffers a 15-28% regression for strings under 24 bytes and remains slower for keys greater than 24 bytes in very low-cardinality distribution compared to the original StringHashTable; this is because, in low-cardinality scenarios, the benefit of a smaller Cell size is negligible, while the additional decoding overhead of the Packed representation becomes the primary bottleneck compared to the highly optimized specialized paths in StringHashTable. Moving to draft for further investigation to find more opportunities; the future direction will likely follow the StringHashTable approach by seeking different optimized solutions for low-cardinality and high-cardinality workloads respectively.

@amosbird
amosbird marked this pull request as draft January 2, 2026 07:30
@clickhouse-gh

clickhouse-gh Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

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]>
@rschu1ze

Copy link
Copy Markdown
Member

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
alexey-milovidov added a commit to amosbird/ClickHouse that referenced this pull request May 9, 2026
`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
alexey-milovidov added a commit to amosbird/ClickHouse that referenced this pull request May 9, 2026
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
Comment thread base/base/PackedStringRef.h Resolved
alexey-milovidov and others added 3 commits May 9, 2026 23:45
…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]>
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review May 17, 2026 20:19
@alexey-milovidov

alexey-milovidov commented May 17, 2026 •

Copy link
Copy Markdown
Member

Just as mentioned in the comment, #93271, the overall result is mixed:

if_transform_strings_to_enum and group_by_sundy_li degraded:

https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_amd_release_master_head_3_6/report.html
https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_amd_release_master_head_4_6/report.html
https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_arm_release_master_head_1_6/report.html
https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_arm_release_master_head_5_6/report.html

However, some ClickBench queries improved:

https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_amd_release_master_head_6_6/report.html
https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_arm_release_master_head_2_6/report.html
https://s3.amazonaws.com/clickhouse-test-reports/PRs/93271/241f393ffb3ac91c46875f2467a384d19f32a4d7/performance_comparison_arm_release_master_head_3_6/report.html

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_); }

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.

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 🙂 .

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.

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):

@harikrishnan94 harikrishnan94 Jun 17, 2026 •

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.

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.

@alexey-milovidov

Copy link
Copy Markdown
Member

Reviewed the current state (41331141bb4). No changes pushed this round — the PR is blocked on a design decision that is the author's to make, and nothing mechanical is broken.

Blocker (unchanged): adaptive vs. unconditional PackedString

The ⚠️ Request changes verdict and the AggregatedDataVariants.h:67 thread both ask for the same thing: either an adaptive fallback/gate for low-cardinality single-String keys, or fresh before/after evidence that they no longer regress. As noted earlier, this is a design/feature decision left to @amosbird (and relates to the separate automatic LowCardinality idea). The root-cause tiny-key regression on group_by_sundy_li / if_transform_strings_to_enum was already addressed in b317b8d4117 (single-CRC hashing for 1..7 byte keys); what remains here is the design question, not a code defect.

CI triage — all three reds are non-blocking

  • Stateless tests (arm_asan_ubsan, targeted) — the job aborted at the CI-DB query stage with QUOTA_EXCEEDED (user play read_rows quota); no functional test actually ran. Transient infra, clears on re-run.
  • BuzzHouse (amd_msan) — the known harness bug (FileNotFoundError: status.tsv, harness aborts before writing status), fixed in master by Fix fuzzer status.tsv write aborting on "server_died: unbound variable" #107900. server.log is clean of any sanitizer fault or PackedString/aggregation crash.
  • Performance Comparison — the flagged "slower" queries sit at or barely above their noise thresholds (group_by_sundy_li +167.9% vs threshold +166.2%; if_transform_strings_to_enum +162% at threshold +162%) = instability, not a clean regression. The controlled cloud benchmark on the same head reported improvement with no regressions (ClickBench Q22 −24%, Q23 −33%, Q33/Q34 −14/−15%; TPC-H Q7 −36%, Q20 −51%).

Open review threads

  • harikrishnan94's 06-17 nits are left for @amosbird: rename HASH_SIZE_BYTES → SMALL_PTR_DATA_OFFSET (PackedStringRef.h:216, :220), ExternalKey → external_key_type (HashMap.h:69), the endianness-comment wording softening (PackedStringRef.h:21), and the ALWAYS_INLINE question (HashTable.h:178) — the last needs an answer rather than a code change.
  • The three clickhouse-gh threads about include_from / GraphiteMergeTree / checkNoSettingNamesAtTopLevel are misattributed (path: null, not anchored to any file this PR touches — it changes no config-processing code) and are not actionable here.

Not self-approving or merging (shepherd, not author).

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.
@alexey-milovidov

Copy link
Copy Markdown
Member

Continued this PR: merged latest master, fixed a protocol-revision collision introduced by the merge, and addressed the review comment about the compatibility test not exercising the changed path. Changes pushed (cd73b80e0c9).

1. Merged origin/master

The branch was ~2532 commits / 8 days behind. Clean auto-merge, no conflicts (including the hot files both sides touch). master only modified Planner.cpp and StorageJoin.cpp among this PR's files in that window; the PackedString/hash-table/aggregation machinery was untouched.

2. Bumped the protocol revision to 54487 (52b20f6592e)

master independently advanced DBMS_TCP_PROTOCOL_VERSION to 54486 for DBMS_MIN_PROTOCOL_VERSION_WITH_INTERNAL_QUERY_FLAG (from log-internal-secondary-queries). This PR had used 54486 as its next-free revision for DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD, so after the merge the guard collided with an unrelated feature and the branch no longer advanced the wire protocol past master.

That is incorrect: a stock 54486 server has no PackedStringRef-based selection, yet revision < DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD would treat it as new and re-enable two-level aggregation across incompatible servers. Moved both DBMS_TCP_PROTOCOL_VERSION and the guard to the next free revision 54487.

3. Added a focused single-String-key cross-version test (cd73b80e0c9)

Addresses the review note that test_string_aggregation_compatibility groups by (id, s2) with s2 a LowCardinality(String), so it goes through the multi-key serialized path and never exercises the single-String key_string / key_string_two_level variants that PackedStringRef replaces.

test_single_string_key_aggregation_compatibility 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) and out-of-line keys (> 11 bytes) to cover both representations; correct cross-version aggregation must dedup the 1000 distinct keys to 1000, and the legacy in-memory serialization scenario is covered too.

Verification

-fsyntax-only of Aggregator.cpp (pulls in the modified AggregationMethod.h / ColumnsHashing / HashMethod.h / PackedStringRef.h), Planner.cpp, StorageJoin.cpp, and InterpreterSelectQuery.cpp against the merged sources — all clean. CI re-triggering.

Still open (author's call — not touched)

The design question raised in the ⚠️ Request changes verdict and the AggregatedDataVariants.h thread (adaptive fallback/gate for low-cardinality single-String keys vs. fresh before/after evidence), and @harikrishnan94's naming/comment nits.

@clickhouse-gh

clickhouse-gh Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 140/148 (94.59%) · Uncovered code

Full report · Diff report

@rschu1ze rschu1ze added the hold Skip for auto-updating. label Jul 14, 2026
@harikrishnan94 harikrishnan94 added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Jul 15, 2026
@harikrishnan94

Copy link
Copy Markdown
Contributor

Taking this over - superseded by #110573, thanks @amosbird for the original work

harikrishnan94 added a commit to harikrishnan94/ClickHouse that referenced this pull request Jul 15, 2026
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]>
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 26, 2026
`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
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 26, 2026
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]>
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 26, 2026
…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]>
alexey-milovidov added a commit to amosbird/ClickHouse that referenced this pull request Jul 27, 2026
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.
alexey-milovidov added a commit that referenced this pull request Jul 31, 2026
…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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hold Skip for auto-updating. pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants