Repository navigation
Use Roaring64Map and_cardinality and intersect for 64-bit bitmaps - #120615
Conversation
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.
|
Workflow [PR], commit [98d47b6] Summary: ✅
AI ReviewSummaryThis PR switches the 64-bit bitmap cardinality / intersection helpers from the old materializing fallback to the direct Final Verdict✅ No new blockers or majors in the current diff. LLVM Coverage ReportMeasured on commit 98d47b6.
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: 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
|
|
🕵 @groeneai, the |
|
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 The run in your report predates it, and the traceback proves that rather than merely suggesting it: the frame is One caveat on the test name: the same test also reds in a different signature, the 600 second client timeout at |
|
🕵 Thank you, that resolves it. I confirmed the ancestry locally: Noted on the second signature, the 600 second client timeout at The remaining red, |
|
Thanks @aschoube for incorporating my Croaring bitmap changes : RoaringBitmap/CRoaring#875 |
|
🕵 @anandheritage, thank you — the 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 |
|
Both remaining red checks on
Both numbers sit inside the query's normal range on master. Over the last 30 days of The diff is 20 lines in
@alexey-milovidov, could you re-run |
|
🕵 @aschoube, agreed on both counts, and I have re-run
|
|
🕵 The re-run of |
|
🕵 The CI-side fix for the only remaining red, Since this is a fork branch, the new workflow run needed maintainer approval again. I approved it and it is |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units43 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. |
|
@alexey-milovidov, the workflow run for |
`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]>
|
The only red on It flagged three On the previous head The queries are flagged on unrelated work too. Over the last 7 days, The two graders disagree on this run as well: by the
The 11 queries classified as faster are all @alexey-milovidov, could you re-run Separately: I could not find an open issue for this test. Given it is producing |
|
@alexey-milovidov, run 35954415504 for That supersedes my earlier request to re-run |
|
@alexey-milovidov, the run on
Different architecture, different shard, and this time a different test — the This run's flag is The threshold-based grader disagrees with the dashboard one here as well: by Meanwhile the intended result is stable across all four runs: 16 queries classified as faster, all Given that, I don't think this shard is telling us anything about the branch. Happy to ask for a re-run of I also could not find an open issue for these single-shard |
|
🕵 @aschoube Agreed, the |
|
🕵 Status of run 36407771285 on |
|
🕵 Run 36407771285 on
Correction to my previous comment: @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 The branch is current (merged master today), 0 unresolved review threads, nothing to push. |
|
Investigated. None of the three comes from this PR:
Since earlier today the dashboard scores these rows with master history (C3 Per #121847, noisy |
|
@groeneai i have updated the rule to limit by likely regression max if test-query is in top 150 flaky ones. 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 |
|
Thanks, understood. I won't send a flip rule in-tree. A live re-score of run 36407771285 now gives On the 160 PR runs from my previous comment, the cap demotes 37 of the 69 |
|
🕵 Thanks @groeneai and @egor-click. The updated scoring now rates |
|
@alexey-milovidov, thanks for re-running the perf shards. All checks on The PR now conflicts with master, though. #119464 bumped That means a new head, which needs another approval. Would you like me to push the merge, or would you rather do it yourself? |
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
|
@aschoube, please push. |
…roaring64 # Conflicts: # contrib/croaring
|
@alexey-milovidov, pushed |
|
Thanks, all good! |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improved performance of
bitmapAndCardinality,bitmapOrCardinality,bitmapXorCardinality,bitmapAndnotCardinalityandbitmapHasAnyforUInt64andInt64bitmaps, which previously had to materialize the intersection to compute the result.Problem
#117478 made
rb_and_cardinalityandrb_intersectcompute their result directly instead of building the intersection first, but only for element types narrower than 8 bytes:RoaringBitmapWithSmallSetselectsroaring::Roaring64Mapwhensizeof(T) >= 8, and that class had neither routine, soUInt64andInt64kept allocating and populating a whole intersection only to read one number off it and discard it. ForbitmapHasAnythis 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.UInt64is 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_cardinalityandandnot_cardinalitytoRoaring64Map(RoaringBitmap/CRoaring#875). Both are implemented as a merge over the shared high-32 keys, delegating to the 32-bit routines, andintersectstops at the first shared element.contrib/croaringfrom v5.1.1 to v5.2.1.sizeof(T) < 8restriction inrb_and_cardinalityandrb_intersect; both calls are now unconditional and the materializing branches are gone.use_roaring64and use it for both theRoaringBitmapandValuealiases, so the condition that selectsRoaring64Mapand the condition that guarded these calls can no longer drift apart.Five SQL functions are affected for 64-bit element types:
bitmapAndCardinalityandbitmapHasAnydirectly, andbitmapOrCardinality,bitmapXorCardinalityandbitmapAndnotCardinalitytransitively, since all three derive their result fromrb_and_cardinalityby 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
croaringalso backs the text index, theMergeTreedelete bitmaps, the Iceberg and Delta Lake deletion vectors and the Puffin format, not justgroupBitmap.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 the5.2.1version bump. Outsidetests/,tools/and.github/, every change is one of these:cpp/roaring/roaring64map.hhand_cardinality,intersect,or_cardinality,xor_cardinalityandandnot_cardinalitymethods this PR uses. Pure addition, nothing existing is touched.include/roaring/bitset_util.h,src/containers/bitset.c,src/containers/run.c_mm256_lddqu_si256replaced by_mm256_loadu_si256at 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;vlddquhas been an alias ofvmovdqusince Nehalem.src/isadetection.c<cpuid.h>include is now also guarded byCROARING_IS_X64, so non-x86 builds stop pulling an x86 header.include/roaring/containers/array.h#ifdef __arm__) fallback forvmaxvq_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 newcroaring_refcount_is_uniqueis added next to the existing refcount helpers.src/containers/containers.cshared_container_extract_copyuses 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 throughroaring_bitmap_overwriteand copy-on-write of shared containers.CMakeLists.txt,doxygen,include/roaring/roaring_version.hSo
contrib/croaring-cmake/CMakeLists.txtstill 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
groupBitmapcoverage described below:bitmap: 17 pass, 3 fail only for environmental reasons on a bare local server (test_cluster_two_shardsand127.0.0.{2,3}are not defined, and/etc/clickhouse-server/config.xmlis unreadable);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_packetnot enabled, and thehitsdataset 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.oldis(a & b).cardinality(),newis the direct routine. Both results are asserted equal before timing.and_cardinality:intersect, the path behindbitmapHasAny: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.xmlmeasures 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.sqlalready covered every combination of small-set and Roaring representation. The comment claimingUInt64exercises a fallback is now wrong and has been corrected, and five cases were added:Int32andInt64with negative values, bothLarge x LargeandLarge x Small. Negative values are stored asstatic_cast<Value>(x), so they land in the top half of the unsigned key space, and theLarge x Smallpath applies that same cast on lookup. The existing signed cases only usedrange(40), so every value was non-negative and this half of the cast was never pinned.UInt64operands 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
bitmapAndcombined withbitmapCardinality, which reaches the same answer throughrb_andfollowed bysize()and shares no code with the paths changed here. Every assertion prints1when the two agree.tests/performance/bitmap_cardinality.xmlmeasuredUInt32only, sinceUInt64used to take a different code path. It now builds a parallelAggregateFunction(groupBitmap, UInt64)fixture and adds five queries over it: densebitmapAndCardinality, operands spread over 64 high-32 keys,bitmapOrCardinalityreachingrb_and_cardinalityindirectly, and the twobitmapHasAnyshapes, one exiting immediately and one with no early exit available.Workflow [PR]
Sync PR [sync-upstream/pr/120615]
Version info
26.10.1.1196-master(included in26.10and later)