Skip to content

Use Roaring64Map and_cardinality and intersect for 64-bit bitmaps - #120615

Merged
alexey-milovidov merged 9 commits into
ClickHouse:masterfrom
aschoube:bitmap-cardinality-roaring64
Oct 1, 2026
Merged

alexey-milovidov merged 9 commits into
ClickHouse:masterfrom
aschoube:bitmap-cardinality-roaring64

Conversation

@aschoube

@aschoube aschoube commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

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

Improved performance of bitmapAndCardinality, bitmapOrCardinality, bitmapXorCardinality, bitmapAndnotCardinality and bitmapHasAny for UInt64 and Int64 bitmaps, which previously had to materialize the intersection to compute the result.


Problem

#117478 made rb_and_cardinality and rb_intersect compute their result directly instead of building the intersection first, but only for element types narrower than 8 bytes:

else if constexpr (sizeof(T) < 8)
{
    ret = roaring_bitmap->and_cardinality(*r1.roaring_bitmap);
}
else
{
    /// Roaring64Map exposes no and_cardinality, so the intersection must be materialized.
    ret = (*roaring_bitmap & *r1.roaring_bitmap).cardinality();
}

RoaringBitmapWithSmallSet selects roaring::Roaring64Map when sizeof(T) >= 8, and that class had neither routine, so UInt64 and Int64 kept allocating and populating a whole intersection only to read one number off it and discard it. For bitmapHasAny this is worse than it looks: the early exit is not merely slower, it is absent. The entire intersection is built before the first element is examined, even when the two operands share their very first element.

UInt64 is the common width for the identifier sets these functions are usually pointed at, so this left the slow path on the case that matters most.

Change

CRoaring 5.2.0 added and_cardinality, intersect, or_cardinality, xor_cardinality and andnot_cardinality to Roaring64Map (RoaringBitmap/CRoaring#875). Both are implemented as a merge over the shared high-32 keys, delegating to the 32-bit routines, and intersect stops at the first shared element.

  • Bump contrib/croaring from v5.1.1 to v5.2.1.
  • Drop the sizeof(T) < 8 restriction in rb_and_cardinality and rb_intersect; both calls are now unconditional and the materializing branches are gone.
  • Name the representation choice once as use_roaring64 and use it for both the RoaringBitmap and Value aliases, so the condition that selects Roaring64Map and the condition that guarded these calls can no longer drift apart.

Five SQL functions are affected for 64-bit element types: bitmapAndCardinality and bitmapHasAny directly, and bitmapOrCardinality, bitmapXorCardinality and bitmapAndnotCardinality transitively, since all three derive their result from rb_and_cardinality by inclusion-exclusion.

Both routines are read-only, so results and the serialization format are unchanged.

What the submodule bump contains

An earlier revision of this description claimed the bump moves no C sources. That was wrong, and the scope deserves to be stated precisely rather than waved through, since croaring also backs the text index, the MergeTree delete bitmaps, the Iceberg and Delta Lake deletion vectors and the Puffin format, not just groupBitmap.

The full tree diff v5.1.1..v5.2.1 (342463b..44498eb) is 38 files, +766/-138, and it is four upstream commits: armv7 FreeBSD fixes (#879), Add a Fil-C CI job (#881), Add manually triggered release workflow, and the 5.2.1 version bump. Outside tests/, tools/ and .github/, every change is one of these:

file change
cpp/roaring/roaring64map.hh +154/-0: the new and_cardinality, intersect, or_cardinality, xor_cardinality and andnot_cardinality methods this PR uses. Pure addition, nothing existing is touched.
include/roaring/bitset_util.h, src/containers/bitset.c, src/containers/run.c _mm256_lddqu_si256 replaced by _mm256_loadu_si256 at 102 call sites, and nothing else: filtering the diff of these three files for those two names leaves zero lines. The two intrinsics load the same 32 unaligned bytes; vlddqu has been an alias of vmovdqu since Nehalem.
src/isadetection.c the <cpuid.h> include is now also guarded by CROARING_IS_X64, so non-x86 builds stop pulling an x86 header.
include/roaring/containers/array.h a 32-bit-ARM (#ifdef __arm__) fallback for vmaxvq_u16, which is AArch64-only. Not compiled on any architecture ClickHouse builds.
include/roaring/portability.h <sys/endian.h> is included on FreeBSD, and a new croaring_refcount_is_unique is added next to the existing refcount helpers.
src/containers/containers.c shared_container_extract_copy uses that helper: it now tests for uniqueness instead of decrementing, and releases the shared container on the copying branch. This is an upstream refcount fix, in a function ClickHouse reaches only through roaring_bitmap_overwrite and copy-on-write of shared containers.
CMakeLists.txt, doxygen, include/roaring/roaring_version.h the version number.

So contrib/croaring-cmake/CMakeLists.txt still needs no change: no source file is added or removed.

Validation of the upgrade

Built at v5.2.1 and run locally against the upgraded library, beyond the groupBitmap coverage described below:

  • all 20 stateless tests matching bitmap: 17 pass, 3 fail only for environmental reasons on a bare local server (test_cluster_two_shards and 127.0.0.{2,3} are not defined, and /etc/clickhouse-server/config.xml is unreadable);
  • all 223 stateless tests matching text_index, the heaviest in-tree user of the library: 218 pass, and the 5 failures are the same kind of environmental gap (three missing test clusters, process_query_plan_packet not enabled, and the hits dataset not loaded).

Measurements

The two paths were measured directly against Roaring64Map, which isolates the change from per-row overhead in the function layer. Median of 5 runs, each the mean over 500-2000 iterations; g++ 13.3.0 -O3 -DNDEBUG, CRoaring v5.2.1, pinned to one core of an i5-1135G7. old is (a & b).cardinality(), new is the direct routine. Both results are asserted equal before timing.

and_cardinality:

operands old ns/op new ns/op speedup
dense 2M, 50% overlap, 1 key 54677 1637 33.4x
sparse 300K stride-100, 50% overlap 261388 25992 10.1x
64 high-32 keys x 20K, 50% overlap 322962 8824 36.6x
evens vs odds 1.5M, no shared element 105904 5766 18.4x
identical 2M 128574 3328 38.6x

intersect, the path behind bitmapHasAny:

operands old ns/op new ns/op speedup
dense 2M, 50% overlap, 1 key 55652 91 610x
sparse 300K stride-100, 50% overlap 261489 185 1414x
64 high-32 keys x 20K, 50% overlap 344089 58 5936x
evens vs odds 1.5M, no shared element 113148 16017 7.1x
identical 2M, shares first element 133575 6 23420x

The last row of each table is the best case for the early exit and the fourth row is the worst case, where the operands occupy the same keys but share no element so every pair has to be examined. Even there, not writing a result structure is worth 7x.

These are library-level figures; the end-to-end gain per SQL call is smaller because it also carries the function layer's own per-row work. tests/performance/bitmap_cardinality.xml measures that part, and the CI perf comparison on this PR is the number to read for it.

Testing

tests/queries/0_stateless/05055_bitmap_cardinality_intersect_paths.sql already covered every combination of small-set and Roaring representation. The comment claiming UInt64 exercises a fallback is now wrong and has been corrected, and five cases were added:

  • Int32 and Int64 with negative values, both Large x Large and Large x Small. Negative values are stored as static_cast<Value>(x), so they land in the top half of the unsigned key space, and the Large x Small path applies that same cast on lookup. The existing signed cases only used range(40), so every value was non-negative and this half of the cast was never pinned.
  • UInt64 operands spread over many high-32 keys, with and without a shared element, which is the shape the new per-key merge walks. The second of these asserts exact cardinalities rather than only agreeing with the reference path.

The assertions remain differential: each function is checked against bitmapAnd combined with bitmapCardinality, which reaches the same answer through rb_and followed by size() and shares no code with the paths changed here. Every assertion prints 1 when the two agree.

tests/performance/bitmap_cardinality.xml measured UInt32 only, since UInt64 used to take a different code path. It now builds a parallel AggregateFunction(groupBitmap, UInt64) fixture and adds five queries over it: dense bitmapAndCardinality, operands spread over 64 high-32 keys, bitmapOrCardinality reaching rb_and_cardinality indirectly, and the two bitmapHasAny shapes, one exiting immediately and one with no early exit available.


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

Version info

  • Merged into: 26.10.1.1196-master (included in 26.10 and later)

bitmapAndCardinality and bitmapHasAny compute their result directly for
32-bit element types, but UInt64 and Int64 fell back to materializing the
whole intersection:

    ret = (*roaring_bitmap & *r1.roaring_bitmap).cardinality();

That fallback existed because Roaring64Map had neither routine. CRoaring
5.2.0 added and_cardinality, intersect, or_cardinality, xor_cardinality
and andnot_cardinality to Roaring64Map, so it is no longer needed.

Bump contrib/croaring from v5.1.1 to v5.2.1 and drop the sizeof(T) < 8
restriction, which also removes the duplicated representation condition:
the choice is now named once as use_roaring64 and reused by both the
RoaringBitmap and Value aliases.

Five SQL functions are affected for 64-bit element types:
bitmapAndCardinality and bitmapHasAny directly, and bitmapOrCardinality,
bitmapXorCardinality and bitmapAndnotCardinality transitively, since all
three derive their result from rb_and_cardinality.
@CLAassistant

CLAassistant commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh clickhouse-gh Bot added comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). external Author is not a member of the ClickHouse organization labels Sep 17, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 19, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [98d47b6]

Summary: ✅


AI Review

Summary

This PR switches the 64-bit bitmap cardinality / intersection helpers from the old materializing fallback to the direct Roaring64Map APIs now available on master, and it extends the stateless and performance coverage to the UInt64 / Int64 carrier cases that matter for the changed path. In the current merged diff, I do not see a remaining correctness, compatibility, or test-coverage issue that warrants a new review thread; the earlier concerns about the broad CRoaring bump and the missing negative Int64 Large x Small case are both addressed.

Final Verdict

✅ No new blockers or majors in the current diff.

LLVM Coverage Report

Measured on commit 98d47b6.

Metric Baseline Current Δ
Lines 88.30% 88.20% -0.10%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.60% -0.10%

Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements submodule changed At least one submodule changed in this PR. labels Sep 19, 2026
Comment thread contrib/croaring Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 36 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 16a56cb5-5e44-44cd-b6bb-6bc4c7c8ecbe
  • MIRAI run: d2aadb91-52ac-49af-b599-96641063638c
  • PR check IDs:
    • clickbench_2629225_1790823185
    • clickbench_2629231_1790823185
    • clickbench_2629247_1790823185
    • tpch_adapted_1_official_2629255_1790823185
    • tpch_adapted_1_official_2629281_1790823185
    • tpch_adapted_1_official_2629295_1790823185

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 20, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, the Integration tests (amd_msan, 1/8) red on this PR is unrelated to the change: test_max_bytes_ratio_before_external_order_group_by_for_server/test.py::test_max_bytes_ratio_before_external_distinct[user] fails in test setup, while is_built_with_thread_sanitizer queries system.build_options, with (total) memory limit exceeded: would use 10.64 MiB ..., current RSS: 10.81 GiB, maximum: 10.80 GiB — the MSan server is already at its memory limit before the test body runs, and the case is even labelled retry_ok. This PR only touches Roaring64Map intersection routines behind bitmap*Cardinality/bitmapHasAny and bumps contrib/croaring, neither of which is on that path. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120615&sha=864fde04c75f7cf71f486679b2d97f4dd5248acd&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%201%2F8%29 — could you investigate and fix it in a separate PR, or link the fix if one is already in flight? The other red, Build profile diff, is the fleet-wide No connection to LogCluster infrastructure failure already tracked in #120462.

@groeneai

Copy link
Copy Markdown
Collaborator

That signature is the setup-time sanitizer probe, and the fix is already on master: #120751, merged 2026-09-18 15:08 UTC. It reads is_built_with_thread_sanitizer() / is_built_with_memory_sanitizer() once in the module-scoped start_cluster fixture and has the per-test guards read the cached values, so on MSan test_max_bytes_ratio_before_external_distinct now skips without querying a server that the preceding test_max_bytes_ratio_before_external_sort case (which has no MSan skip) has already driven to max_server_memory_usage.

The run in your report predates it, and the traceback proves that rather than merely suggesting it: the frame is test.py:101, if node.is_built_with_thread_sanitizer(): inside the test body, whereas on current master line 101 is a parametrize entry and that call no longer exists in any test body of the file. 864fde04c75f is based on 398661cdf4e9 of 2026-09-17 10:13 UTC, 658 commits behind the merge. In the CI database the signature has 15 rows over 14 pull requests in 30 days, and the three recorded after the merge timestamp were all on trees still behind it (864fde04c75f 658 behind, 91cbe566183b 22, cd503815bc5d 592); zero are on a tree that contains it. The master merge pushed to this branch at 08:15 UTC, f5b20176b075, does contain it, so that job should be clean on a re-run.

One caveat on the test name: the same test also reds in a different signature, the 600 second client timeout at node.query on Integration tests (amd_asan_ubsan, db disk, 1/8), which #120751 does not address. That one is #121096, still open; on its head ff2c7527bc0a the target job is green with the DISTINCT cases at 61s against a 572s median over the previous 30 days.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thank you, that resolves it. I confirmed the ancestry locally: b20177693aeb (the merge of #120751) is an ancestor of this branch's head f5b20176b075, so the setup-time is_built_with_thread_sanitizer probe is gone from the test bodies on the tree that will be tested next. The red in my report was indeed on 864fde04c75f, which predates the merge, so I am treating the Integration tests (amd_msan, 1/8) failure as cleared by the master merge and not re-reporting it.

Noted on the second signature, the 600 second client timeout at node.query on Integration tests (amd_asan_ubsan, db disk, 1/8) tracked in #121096 — if it shows up on a re-run here I will link it there rather than open anything new.

The remaining red, Build profile diff, is the fleet-wide No connection to LogCluster infrastructure failure in #120462, which is still open.

@anandheritage

Copy link
Copy Markdown
Contributor

Thanks @aschoube for incorporating my Croaring bitmap changes : RoaringBitmap/CRoaring#875
And extending the improvement of : #117478

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @anandheritage, thank you — the Roaring64Map::and_cardinality and Roaring64Map::intersect methods this PR uses come from your RoaringBitmap/CRoaring#875, and the contrib/croaring bump to v5.2.1 here is what brings them in. Credit is noted in the PR description.

Status update: this PR is approved and has 0 unresolved review threads, but its CI had never actually run — the workflow runs for the fork branch were sitting in action_required, which is why the head commit showed no checks for two days despite the pushes. I have approved the run for 43dfc8e140ca and it is now in_progress, so a real report should appear shortly.

@aschoube

Copy link
Copy Markdown
Contributor Author

Both remaining red checks on 43dfc8e140ca look unrelated to this change, so this is a request to re-run one job rather than a new revision.

Performance Comparison (amd_release, master_head, 3/6) — the only blocking failure. The single query over threshold is not one this PR touches:

+1.333x  +33.5%   15.3ms -> 20.4ms   order_by_read_in_order #1 [amd/3]
         threshold: +28.9%
SELECT * FROM hits_100m_single ORDER BY CounterID DESC, toStartOfWeek(EventDate)...

Both numbers sit inside the query's normal range on master. Over the last 30 days of master_head runs on that same shard, order_by_read_in_order #1 spans 10–22 ms with a median of 17 ms and a coefficient of variation of 15.4% (158 samples); on amd_release, master_head, 1/6 it spans 11–25 ms. On unrelated PRs from 2026-09-21, the two binaries within a single run of this shard disagree by as much in both directions — 15 vs 19, 19 vs 16, 21 vs 19. A +33.5% move against a +28.9% threshold is inside that noise.

The diff is 20 lines in AggregateFunctionGroupBitmapData.h plus the contrib/croaring bump — nothing on the path of an ORDER BY over hits_100m_single. The other 11 perf shards are green, and all 10 queries classified as faster are bitmap_cardinality on the new UInt64 fixture (−48% to −96.6%; #9, the bitmapHasAny early-exit shape, is 117.6ms → 4.7ms on amd and 96.0ms → 3.2ms on arm).

Build profile diff — RuntimeError: CI logs cluster query failed raised from compare_compile_times in ci/jobs/build_profile_diff_job.py, i.e. the fleet-wide No connection to LogCluster failure in #120462, which is still open. A re-run will not clear this one.

@alexey-milovidov, could you re-run Performance Comparison (amd_release, master_head, 3/6)? Everything else on this run passed.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @aschoube, agreed on both counts, and I have re-run Performance Comparison (amd_release, master_head, 3/6) on the same head 43dfc8e140ca (run attempt 3, queued now) rather than pushing a new revision.

order_by_read_in_order #1 is a known noise source: it is tracked in #121456 and the CI-side fix is #121090 (still open). Build profile diff is the fleet-wide #120462 and will stay red until that lands, so I did not re-run it. The other 11 perf shards report only the bitmap_cardinality speedups this PR is meant to bring.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The re-run of Performance Comparison (amd_release, master_head, 3/6) on 43dfc8e140ca (run attempt 3) passed, so order_by_read_in_order #1 was noise as expected. The only remaining red is Build profile diff, which is the fleet-wide #120462 and does not depend on this branch. No new revision is needed; the PR is ready for merge from my side.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The CI-side fix for the only remaining red, Build profile diff (#120462), has landed on master via #121048 and #121393, so I merged origin/master into this branch to pull it in (clean, no conflicts) and pushed 6892d64cc48c. The diff against master is still exactly the PR's own 5 files (contrib/croaring pointer, AggregateFunctionGroupBitmapData.h, bitmap_cardinality.xml, and the 05055_bitmap_cardinality_intersect_paths test); _roaring and AggregateFunctionGroupBitmap.cpp build cleanly on the merged tree.

Since this is a fork branch, the new workflow run needed maintainer approval again. I approved it and it is in_progress now.

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 98d47b6eb with master 253f06071 (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.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -28.7 s (-6%) in total before that adjustment.

Job report

@aschoube

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, the workflow run for 69a20f99 is at action_required and hasn't started — could you approve it? That head is your own master merge from 2026-09-23 00:25, so the branch content is unchanged from the revision you said was ready to merge. Nothing else is outstanding.

`Int64` bitmaps go through `Roaring64Map`, so the lookup-side
`contains(static_cast<UInt64>(x))` on the small-set operand is a separate
carrier from the 32-bit `Int32` case. Add that shape (with an absolute
expected cardinality) next to the existing `Int32` one.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @aschoube The 69a20f99 run was superseded: I pushed 834303c, which adds the Int64 negative Large x Small case the last bot review asked for (thread resolved). The new PR workflow run (35809884052) is approved and running now.

@aschoube

Copy link
Copy Markdown
Contributor Author

The only red on 834303c2 is Performance Comparison (arm_release, master_head, 2/6), and it looks like the same noise as before rather than anything this branch does.

It flagged three timeseries_to_grid_aggregation_functions queries:

#6    89.7ms -> 115.2ms  (+28.5%)  confirmed_regression
#11  137.3ms -> 165.6ms  (+20.6%)  confirmed_regression
#12  139.1ms -> 165.1ms  (+18.7%)  confirmed_regression

On the previous head 6892d64c the same test failed on a different shard with a different set of queries — Performance Comparison (arm_release, master_head, 1/6), queries #2, #7, #16, #21. On this run 1/6 passed. A regression from the change here would have to land on the same queries each time; this one moves.

The queries are flagged on unrelated work too. Over the last 7 days, slower rows: #6 on 19 distinct pull requests, #12 on 8, #11 on 7, and the previous run's #7 on 24 and #2 on 15. #6 and #12 also appear on master's own runs (pull_request_number = 0), where this branch's code is absent.

The two graders disagree on this run as well: by the compare.sh thresholds on client_time, the only query over its threshold anywhere in the 12 shards is index_bulk_filtering #2 on arm/2 — none of the three above — and the overall verdict is no significant change. Both failing jobs also carried the under-utilized CPU and disk-almost-full labels.

timeseries_to_grid_aggregation_functions benchmarks timeSeries*ToGrid over Float64, and touches neither groupBitmap nor contrib/croaring.

The 11 queries classified as faster are all bitmap_cardinality on the UInt64 fixture, and they reproduce across all three runs so far — #9 at 93.1ms -> 3.1ms on arm and 111.0ms -> 4.7ms on amd.

@alexey-milovidov, could you re-run Performance Comparison (arm_release, master_head, 2/6)?

Separately: I could not find an open issue for this test. Given it is producing slower rows on roughly 100 distinct pull requests a week and on master itself, it may be worth tracking alongside #121456 — happy to open one if that would help.

@aschoube

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, run 35954415504 for 5be3ae5e has been at action_required since 2026-09-24 04:09 UTC and hasn't started — could you approve it?

That supersedes my earlier request to re-run Performance Comparison (arm_release, master_head, 2/6) on 834303c2, so no need to do both: a full run on the new head covers it.

@aschoube

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, the run on 5be3ae5e is 158 green, 14 skipped and one red shard again — but the red has now moved three times with no overlap:

head failing shard flagged queries
6892d64c arm_release, master_head, 1/6 timeseries_to_grid_aggregation_functions #2, #7, #16, #21
834303c2 arm_release, master_head, 2/6 timeseries_to_grid_aggregation_functions #6, #11, #12
5be3ae5e amd_release, master_head, 2/6 read_in_reverse_order_final #1

Different architecture, different shard, and this time a different test — the timeseries_to_grid_aggregation_functions queries that failed on both previous heads passed here.

This run's flag is read_in_reverse_order_final #1 at 7.1ms -> 8.3ms (+16.4%, confirmed_regression). That is a 1.2 ms difference, and on master's own runs of that same shard the query spans 6-15 ms with a median of 8 over 117 samples in the last 30 days — so both sides of the comparison sit mid-range and the reported value is master's median.

The threshold-based grader disagrees with the dashboard one here as well: by compare.sh thresholds on client_time, nothing on amd_release 2/6 is over its threshold, and the only queries that are anywhere in the 12 shards are rand #0 and rand #1 on arm_release 1/6 (+43.6%, +46.2%) — a shard this run passed. Those are SELECT count() FROM (SELECT rand64() FROM zeros(1000000000)). All three failing jobs so far carried the under-utilized CPU and disk-almost-full labels.

Meanwhile the intended result is stable across all four runs: 16 queries classified as faster, all bitmap_cardinality on the UInt64 fixture, with #9 at 94.4ms -> 3.2ms on arm and 94.0ms -> 3.2ms on amd.

Given that, I don't think this shard is telling us anything about the branch. Happy to ask for a re-run of amd_release, master_head, 2/6 if you would rather have a green report, though on the pattern above it seems as likely to move to a fourth shard as to clear. Whichever you prefer.

I also could not find an open issue for these single-shard confirmed_regression flags. If it would help, I can open one with the per-query slower counts from the last 30 days.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @aschoube Agreed, the read_in_reverse_order_final #1 red on 5be3ae5e is noise. It's the harness flake tracked in #122500: --stop-merges froze mid-merge part layouts, so the two servers compared different numbers of parts. The fix, #122073, merged 2026-09-25, after that head was cut. I merged master (clean, and the diff is still only this PR's 5 files), pushed 3ddf2318534a, and approved the new PR run 36407771285. It's running now.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status of run 36407771285 on 3ddf2318534a (still in progress): the two perf reds are expected. Performance Comparison (arm_release, master_head, 5/6) failed only on improvements: bitmap_cardinality #6/#8/#10 are 2.4x to 4.7x faster, which is what this PR is for. Performance Comparison (amd_release, master_head, 2/6) shows the same bitmap_cardinality gains (up to 8.2x), plus one slowdown, math_exp #2 at +22%. That query evaluates exp over numbers and never touches CRoaring or groupBitmap, so this PR cannot have caused it. The MIRAI AI verdict for the perf run is no_change on regressions. 0 unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Run 36407771285 on 3ddf2318534a has finished. Everything is green except three Performance Comparison shards. Each one is a single confirmed_regression flag on a query that never touches CRoaring or groupBitmap:

shard flagged query client_time
arm_release, master_head, 1/6 group_uniq_array #7 70.6 ms -> 84.7 ms (+19.9%)
arm_release, master_head, 5/6 codecs_int_select #0 44.8 ms -> 55.1 ms (+22.8%)
amd_release, master_head, 2/6 math_exp #2 393.9 ms -> 481.7 ms (+22.2%)

Correction to my previous comment: arm 5/6 did not fail only on the bitmap_cardinality improvements. Its failing entry is the codecs_int_select #0 flag above. By compare.sh thresholds the only change is the intended bitmap_cardinality speed-up (up to 27.7x). The flagged shard has been different on every head of this PR (see the table in @aschoube's comment of 2026-09-27), and the job carries the under-utilized CPU / disk-almost-full labels.

@groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120615&sha=3ddf2318534a1e4ec1bf232f2621d8e39d06c885&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F6%29 , https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120615&sha=3ddf2318534a1e4ec1bf232f2621d8e39d06c885&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%205%2F6%29 and https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120615&sha=3ddf2318534a1e4ec1bf232f2621d8e39d06c885&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%202%2F6%29 (dashboard-grader confirmed_regression false positives on unrelated short queries), and provide a fix in a separate PR. If the fix is already in progress, link it here.

The branch is current (merged master today), 0 unresolved review threads, nothing to push.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. None of the three comes from this PR:

shard query what moved
arm 1/6 group_uniq_array #7 user time +19%, all of it self time in AggregateFunctionGroupUniqArrayGeneric<true, false>::add (154 -> 230 of 289 -> 362 CPU samples): the per-binary slow mode on ARM I measured on #100330
arm 5/6 codecs_int_select #0 kernel time only: user 25.9 -> 23.8 ms, system 17.9 -> 30.1 ms, the same 160 MB read from the page cache on both sides. All 29 runs of this query that were >15% slower in the last 14 days (23 PR, 6 master) were system-time driven
amd 2/6 math_exp #2 user time +22% on a query that reads no table: the per-build offset I wrote up on #96844

Since earlier today the dashboard scores these rows with master history (C3 supports, 30 points). They still confirm because master-vs-master pairs rarely show these modes (C3 noise 2.1% / 4.4% / 6.5%), while the dashboard's own flakyLately on the same rows reads 65 / 33 / 67 PR flags vs 4 / 12 / 2 master flags in 14 days, in both directions. A live re-score of the last 160 PR runs (147 PRs) has 69 confirmed_regression rows on 45 runs; 48 of those rows flip direction like these three, and not confirming them would clear 34 of the 45 runs. Only 3 of the 69 still lack master history, so the C3 fallback I proposed on #119556 no longer helps, and I withdraw it.

Per #121847, noisy confirmed_regression rows are handled in the dashboard's scoring (ClickHouse/performance-comparison#5), which I cannot send a PR to. @egor-click, will the dashboard stop confirming rows whose flakyLately flips direction (keeping them as likely_regression), or should I send that rule in-tree in perf_dashboard_gate?

@egor-click

Copy link
Copy Markdown
Contributor

@groeneai i have updated the rule to limit by likely regression max if test-query is in top 150 flaky ones.
I have also added a rule that if test is flaky on the particular PR and flips direction on the single PR

I don't think that general rule of flip is a good idea, yes, we do not want to fail CI on flaky test, but we also don't want to miss a real regression if test was moving both direction on diffferent PRs where it actually can move both directions for a reason

@groeneai

Copy link
Copy Markdown
Collaborator

Thanks, understood. I won't send a flip rule in-tree.

A live re-score of run 36407771285 now gives group_uniq_array #7 and codecs_int_select #0 likely_regression (capped at Flaky lately #92 and #129) and math_exp #2 noise (multimodal history), so none of the three blocks any more. The gate takes the tier when the job runs, so the three shards need a re-run to pick this up. No in-tree PR from me for these.

On the 160 PR runs from my previous comment, the cap demotes 37 of the 69 confirmed_regression rows, and the runs with one drop from 45 to 23.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai and @egor-click. The updated scoring now rates group_uniq_array #7 and codecs_int_select #0 as likely_regression and math_exp #2 as noise, so I re-ran the three failed Performance Comparison shards of run 36407771285 (attempt 3) on the same head 3ddf2318534a. I didn't push a new head, because that would need another approval. There are 0 unresolved review threads.

@aschoube

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, thanks for re-running the perf shards. All checks on 3ddf2318 are green now.

The PR now conflicts with master, though. #119464 bumped contrib/croaring to v5.2.2 (6ef0aaad) after that run started, and this branch pins v5.2.1 (44498eba). v5.2.2 contains everything in v5.2.1, so the fix is to merge master and take master's pointer. No code changes are needed.

That means a new head, which needs another approval. Would you like me to push the merge, or would you rather do it yourself?

pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Sep 29, 2026
Rerun dashboard-selected queries with the dashboard's practical threshold
and fresh statistical evidence before blocking master-head comparisons.
Keep missing or failed confirmation blocking and retain cleared rows in
Check Results with their rerun evidence.

Related: ClickHouse#119556 (comment)
Related: ClickHouse#120615 (comment)
Related: ClickHouse/performance-comparison#6
@alexey-milovidov

Copy link
Copy Markdown
Member

@aschoube, please push.

@aschoube

aschoube commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, pushed 98d47b6e: master merged in, with contrib/croaring taken from master (v5.2.2, 6ef0aaad). That was the only conflict, and the PR's own diff against master is unchanged. Could you approve the CI run?

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Thanks, all good!

Merged via the queue into ClickHouse:master with commit 8de7a5f Oct 1, 2026
149 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants