Repository navigation
Conversation
…states Moves the pin from 76edd74f (2024-05-16) to c8e42183, the upstream master tip as of 2026-08-22. The old pin is a strict ancestor, so this is a fast-forward. Requested in ClickHouse#116587 by UnamedRus, to get the Apache DataSketches HyperLogLog union fix (apache/datasketches-cpp#512, merged upstream 2026-08-15) into the tree before Apache DataSketches HyperLogLog support lands. No upstream release carries that fix; the latest, 5.2.0, is from 2025-01-15. That HyperLogLog fix changes nothing today: it touches hll/include, and contrib/datasketches-cpp-cmake/CMakeLists.txt exposes only common/include, count/include and theta/include, so ClickHouse does not compile it. The same bump does fix a live path. theta/include/bit_packing.hpp mis-decoded the compressed (serialization version 4) Theta sketch format in two places: * unpack_bits_33 did `values[7] |= *ptr++ << 24` on a uint8_t. Integer promotion makes that an int shift, so a byte >= 0x80 yields a negative int and OR-ing it into a uint64_t sign-extends into the delta's top 32 bits. This is not undefined behaviour, which is why UBSan never flagged it. * unpack_bits_35 masked a two-bit field with 2 instead of 3, dropping bit 33 of the third delta in each block of eight. ThetaSketchData::read calls compact_theta_sketch::deserialize, which dispatches on the serialized entry_bits and routes anything other than 64 through unpack_bits_block8 into those routines. Deltas are a prefix sum, so one bad delta corrupts every later entry. theta_union::update keeps only entries below theta and early-stops on the first one that is not, because a version-4 sketch is ordered. So the sign-extension case truncates the retained set and the dropped-bit case makes an entry collide with an earlier one and deduplicate. Either way uniqTheta returns a value that is too low, with no error. ClickHouse always serializes the uncompressed form itself, so a compressed state has to come from another Apache DataSketches implementation. The new test covers both routines: 16 and 16 with the bump, 7 and 14 without it. The bump also fixes two write-side bugs in the same format (pack_bits_13 and a missing final partial byte); no ClickHouse code path reaches those. Every uniqTheta* state and the persisted countmin statistics file are byte-identical across the bump, verified in both directions, so the drift under the three compiled directories moves no persisted format.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own
Severity: ❌ blocker / I re-derived the test's liveness independently, without a build, by reimplementing One measurement worth recording because anyone repeating the compatibility sweep will Session id: cron:clickhouse-review-slot-8:20260827-041400 |
|
Workflow [PR], commit [0d97fa8] Summary: ✅
AI ReviewSummaryThis PR fast-forwards Final Verdict✅ No findings. |
Pre-PR validation gate (click to expand)
Also run: the Session id: cron:clickhouse-impl-slot-6:20260827-032300 |
|
cc @thevar1able @rschu1ze, could you review this? It bumps |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units11 translation units recompiled, 43 s compile time in total, 11 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only bumps the datasketches-cpp submodule (uniqTheta compressed-state deserialization) and adds a stateless test for it; no server query-execution code changes. None of the five flagged ClickBench queries (Q18, Q28, Q32, Q33, Q34) use uniqTheta, and all show flat CPU time against a uniform +6-7% wall-clock rise, which is environmental variance rather than a real regression. All five correctly stay not_sure. The envelope-suppression and test-disagreement outcomes are consistent with the data given the off-path diff. clickbenchFlagged queries (5 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
|
Problem 1: This PR looks like it merges from upstream HEAD (bad practice from the old days) instead of making a Problem 2: HEAD is a moving target + development version. It will be nicer to upgrade to the newest current stable version + backport the fix requested here. |
|
Both problems are real and this PR had both. Three measurements for whoever picks it up, since they make the stable-tag route cheap:
One mechanical constraint: |
|
Redone as #117422, addressing both points. The fork The backport is not a no-op on Your two measurements hold, and the release pin also shrinks the review surface a lot: over the three compiled directories the drift is 5 headers rather than 13. |
A PR that is opened and then reopened seconds later delivers two pull_request events at one head commit, so GitHub dispatches two complete PR workflow runs in parallel. Both are run_attempt = 1, and TEMPLATE_PULL_REQUEST_0 emits no concurrency block, unlike TEMPLATE_SCHEDULE and TEMPLATE_DISPATCH_WORKFLOW, so neither run supersedes the other. Everything the two runs share is keyed by (PR, sha) and never by RUN_ID: the S3 artifact objects from _Environment.get_s3_prefix_static, and the result_<workflow>.json document merged by _ResultS3.update_workflow_results. Two consequences measured at one commit of ClickHouse#116641 and of ClickHouse#116642: - Nine legs of one run died in the praktika pre-run artifact download with PreconditionFailed, because the other run re-uploaded the key while the ranged GET was in flight, so its ETag precondition no longer held. All nine are success in the sibling run at the identical tree, and two of them are flaky check legs. praktika had already closed this same race for the submodule cache object alone, with an If-None-Match write-once create in native_jobs.py. - The losing run's Finish Workflow read the shared result document while the other run's per-arch jobs were still RUNNING, and published "No per-arch Bugfix Validation job validated the bug". The sibling run contradicts it with three success jobs. Emit a concurrency group of workflow, PR number and head sha, with cancel-in-progress, for pull_request workflows. The head sha is in the group so a push starts a new group and never cancels the run at the previous commit. When the second run appears the first has created exactly one job, Config Workflow, so a supersession cancels that job and nothing else. The group is populated per event rather than written into the template, because TEMPLATE_PULL_REQUEST_0 is shared with the push workflows, where github.event.pull_request is null. A literal in the template would give MasterCI a degenerate group and, with cancel-in-progress, cancel every in-flight run on every master commit. master.yml and release_branches.yml stay byte-identical. The close-and-reopen originates from an app outside this repository. This change neither depends on it nor alters it, and a genuinely reopened PR still gets a run. retry_infra_failures.yml partially masks this today: a pre-run S3 failure is classified as infrastructure by its rule for a Run step that failed in under two minutes, and the run is retried. Co-Authored-By: Claude Opus 5 <[email protected]>
Closes: #116587
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
uniqThetaand its variants silently returning a value that is too low when reading anAggregateFunction(uniqTheta, ...)state that another Apache DataSketches implementation had serialized in the compressed Theta sketch form. Two decoding bugs incontrib/datasketches-cppcorrupted or dropped retained values.Description
Reported by @ UnamedRus in #116587, who asked for the Apache DataSketches HyperLogLog union fix (apache/datasketches-cpp#512, merged upstream 2026-08-15) to be in the tree before Apache DataSketches HyperLogLog support lands. @ alexey-milovidov asked me to take it.
No upstream release carries that fix, so this pins a post-release commit:
c8e42183, the upstreammastertip as of 2026-08-22. The latest release5.2.0(2025-01-15) does carry the Theta decoding fixes below (upstream5c193334) but not the HyperLogLog one, so that tag would not answer the request. The old pin76edd74fis from 2024-05-16 and is a strict ancestor, so the move is a fast-forward.The HyperLogLog fix itself changes nothing today: it touches
hll/include, andcontrib/datasketches-cpp-cmake/CMakeLists.txtexposes onlycommon/include,count/includeandtheta/include, so ClickHouse does not compile it. It lands here so it is present when #95045 addshll/include.The bump does change one compiled path, and that is the user-visible part.
theta/include/bit_packing.hppmis-decoded the compressed (serialization version 4) Theta sketch format in two places:unpack_bits_33shifted auint8_tleft by 24 after promotion toint, so a byte above0x7fbecame negative and sign-extended into the value's top 32 bits, andunpack_bits_35masked a two-bit field with 2 instead of 3.ThetaSketchData::readreaches both throughcompact_theta_sketch::deserializewhenever the state's entry width is not 64 bits. A mis-decoded value either exceeds the sketch theta, so the union stops early, or collides with an earlier value, so it is deduplicated. Either way the estimate comes back too low, with no error. ClickHouse always writes the uncompressed form itself, so this needs a state produced elsewhere.New test
05046_uniq_theta_compressed_state_116587pins both routines: 16 and 16 with the bump, 7 and 14 without it. The same bump also fixes two write-side bugs in that format, which no ClickHouse code path reaches today.Compatibility measurements for the 209-commit drift (click to expand)
Only three directories of the library are on the include path, so the review surface is
git diff 76edd74f..c8e42183 -- common/include count/include theta/include= 13 headers, +293/-89. The compressed-read fix above is the only behaviour change reachable from ClickHouse; everything else is uncalled, not included, or value-preserving (MIN_LG_K 5 -> 4is read by the builder'scheck_lg_kand by an uncompiled Jaccard header, ClickHouse never setslg_k, and the two array-sizing sites moved to the newMIN_LG_ARR, whose value is the old 5; thecount/refactor keeps the same hash seeds, the same probe arithmetic and the same serialization layout).Both persisted carriers were measured for byte identity, in both directions:
uniqTheta*stateuniqThetaStateat n = 0, 1, 2, 7, 8, 100, 4095, 4096, 4097, 10000, 1000000;StringandFixedStringkeys;uniqThetaMergeState;uniqThetaUnion/Intersect/Notincl. an empty operand;max_threads1 and 8uniqTheta*state, cross-readcountminstatisticsMergeTreewithSTATISTICS(countmin)onInt64,Float64,String, 20000 rowsstatistics.packedidentical (md5dc93bc75, 62519 bytes); reading either build's data directory with the other gives identical resultsBoth comparisons were sensitivity-controlled: a single added element moves the state hex, and changing one row moves the
statistics.packedmd5.02751_ip_types_aggregate_functions_statesalready assertscityHash64(hex(uniqThetaState(ip)))against a checked-in reference and passes unchanged, as do theuniqThetaand02864_statistics_*families and theStatisticsunit tests.Workflow [PR]
Sync PR [sync-upstream/pr/116642]