Skip to content

[pull] master from ClickHouse:master - #3

Merged
pull[bot] merged 4 commits into
erickirt:masterfrom
ClickHouse:master
Dec 10, 2024
Merged

pull[bot] merged 4 commits into
erickirt:masterfrom
ClickHouse:master

Conversation

@pull

@pull pull Bot commented Dec 10, 2024 •

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

nickitat and others added 4 commits December 9, 2024 14:44
@pull pull Bot added the ⤵️ pull label Dec 10, 2024
@pull
pull Bot merged commit d6b8576 into erickirt:master Dec 10, 2024
pull Bot pushed a commit that referenced this pull request Feb 11, 2025
CI: https://s3.amazonaws.com/clickhouse-test-reports/75848/479ca9b0a40fa32074501bea7d9eb7d369f3ddd4/integration_tests__tsan__2_6_.html

<details>

<summary>Race</summary>

```
E           Exception: Sanitizer assert found for instance ==================
E           WARNING: ThreadSanitizer: data race (pid=8)
E             Write of size 8 at 0x726000005c78 by thread T585 (mutexes: write M0, write M1):
E               #0 std::__1::enable_if<is_move_constructible<DB::SnapshotFileInfo*>::value && is_move_assignable<DB::SnapshotFileInfo*>::value, void>::type std::__1::swap[abi:ne180100]<DB::SnapshotFileInfo*>(DB::SnapshotFileInfo*&, DB::SnapshotFileInfo*&) build_docker/./contrib/llvm-project/libcxx/include/__utility/swap.h:44:7 (clickhouse+0x1dad0fb6) (BuildId: eb398fb9d76a60d418ba7222d10f730fae2208dc)
E               #1 std::__1::shared_ptr<DB::SnapshotFileInfo>::swap[abi:ne180100](std::__1::shared_ptr<DB::SnapshotFileInfo>&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:694:5 (clickhouse+0x1dad0fb6)
E               #2 std::__1::shared_ptr<DB::SnapshotFileInfo>::operator=[abi:ne180100](std::__1::shared_ptr<DB::SnapshotFileInfo>&&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:663:32 (clickhouse+0x1dad0fb6)
E               #3 DB::KeeperStateMachine<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>::save_logical_snp_obj(nuraft::snapshot&, unsigned long&, nuraft::buffer&, bool, bool) build_docker/./src/Coordination/KeeperStateMachine.cpp:846:30 (clickhouse+0x1dad0fb6)

E             Previous read of size 8 at 0x726000005c78 by thread T572:
E               #0 std::__1::shared_ptr<DB::SnapshotFileInfo>::shared_ptr[abi:ne180100](std::__1::shared_ptr<DB::SnapshotFileInfo> const&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:565:82 (clickhouse+0x1daea9b2) (BuildId: eb398fb9d76a60d418ba7222d10f730fae2208dc)
E               #1 DB::KeeperStateMachine<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>::create_snapshot(nuraft::snapshot&, std::__1::function<void (bool&, std::__1::shared_ptr<std::exception>&)>&)::'lambda'(std::__1::variant<std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>>, std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::RocksDBContainer<DB::KeeperRocksNode>>>>>&&, bool)::operator()(std::__1::variant<std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>>, std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::RocksDBContainer<DB::KeeperRocksNode>>>>>&&, bool) const build_docker/./src/Coordination/KeeperStateMachine.cpp:803:22 (clickhouse+0x1daea9b2)

```

</details>

v2: guard latest_snapshot_meta and latest_snapshot_buf as well (thanks to @davenger)
pull Bot pushed a commit that referenced this pull request Aug 20, 2025
pull Bot pushed a commit that referenced this pull request Sep 17, 2025
pull Bot pushed a commit that referenced this pull request Nov 19, 2025
…y names

When ClickHouse encounters a distributed table directory with a name that:
- starts with the pattern `shardN_all_replicas` (e.g., `shard3_all_replicas_bkp`)
- but doesn't end with exactly `_all_replicas`

It would crash with a segmentation fault due to out-of-bounds array access.

Trace example:
```
* thread #1, name = 'clickhouse-serv', stop reason = signal SIGSEGV
  * frame #0: 0x000000001194481b clickhouse-server`DB::Cluster::Address::Address(DB::Cluster::Address const&) + 27
    frame #1: 0x0000000011944550 clickhouse-server`void std::__1::vector<DB::Cluster::Address, std::__1::allocator<DB::Cluster::Address> >::__push_back_slow_path<DB::Cluster::Address const&>(DB::Cluster::Address const&&&) + 208
    frame #2: 0x00000000129a6c35 clickhouse-server`DB::StorageDistributed::parseAddresses(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const + 3349
    frame #3: 0x00000000129a589b clickhouse-server`DB::StorageDistributed::getDirectoryQueue(std::__1::shared_ptr<DB::IDisk> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 3675
    frame #4: 0x00000000129a3f22 clickhouse-server`DB::StorageDistributed::initializeDirectoryQueuesForDisk(std::__1::shared_ptr<DB::IDisk> const&) + 2082
    frame #5: 0x000000000f681c48 clickhouse-server`DB::ThreadPoolCallbackRunnerLocal<void, ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true> >, std::__1::function<void ()> >::operator()(std::__1::function<void ()>&&, Priority)::'lambda'()::operator()() + 136
    frame #6: 0x000000000f68286c clickhouse-server`std::__1::packaged_task<void ()>::operator()() + 44
    frame #7: 0x000000000d83335b clickhouse-server`ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true> >::ThreadFromThreadPool::worker() + 2395
    frame #8: 0x000000000d839e23 clickhouse-server`void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<false, true>::ThreadFromGlobalPoolImpl<void (ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true> >::ThreadFromThreadPool::*)(), ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true> >::ThreadFromThre
adPool*>(void (ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true> >::ThreadFromThreadPool::*&&)(), ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true> >::ThreadFromThreadPool*&&)::'lambda'(), void ()> >(std::__1::__function::__policy_storage const*) + 99
    frame #9: 0x000000000d830602 clickhouse-server`ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::worker() + 2242
    frame #10: 0x000000000d8379ba clickhouse-server`_ZNSt3__114__thread_proxyB6v15007INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN14ThreadPoolImplINS_6threadEE20ThreadFromThreadPoolEFvvEPSA_EEEEEPvSF_ + 90
```
pull Bot pushed a commit that referenced this pull request Dec 23, 2025
Docs: move aggregate functions docs to source (#3)
pull Bot pushed a commit that referenced this pull request Jan 18, 2026
pull Bot pushed a commit that referenced this pull request Mar 31, 2026
## #1: Cross-test ownership ratio (find_tests.py)

Replace plain `1/width` scoring with `1/(width × region_test_count)` where
`region_test_count = uniqExact(test_name)` for each region.  A region covered
by 1 test scores 1000× higher than one covered by 1000 tests, naturally
eliminating the hot-region problem without a hard cap.

## #2: Branch direction (LLVMCoverageMapping + coverage_log)

Parse `BranchRegion` (LLVM kind=4) in `readLLVMCoverageMapping`.  Format:
kind-marker → true_counter → false_counter → line/col, producing two
`CoverageRegion` entries with `is_branch=true` and `is_true_branch` set.
Added `branch_flags Array(UInt8)` to `system.coverage_log` (0=code, 1=true,
2=false).  Tests that covered both sides of a changed condition now carry that
information for smarter ranking.

## #3: Indirect call targets (coverage.h/cpp + CoverageCollection)

Read `LLVMProfileData::Values` (LLVM value profiling, kind IPVK_IndirectCallTarget)
to capture which concrete functions were called via virtual dispatch or function
pointers.  Each observation: `(caller_name_hash, caller_func_hash, callee_offset,
call_count)` where `callee_offset = callee_abs − binary_load_base` (from
`/proc/self/maps`), stable across ASLR restarts.  Flushed alongside coverage
counters into `system.coverage_indirect_calls`.  Fixes the fundamental gap where
a test covering `IStorage::read` cannot be distinguished from a test specifically
dispatching to `StorageMergeTree::read`.

## #4: XRay call-depth tracking (coverage.h/cpp + cmake/sanitize.cmake)

New CMake option `WITH_COVERAGE_XRAY=ON` enables `CLICKHOUSE_XRAY_INSTRUMENT_COVERAGE`.
At test start, activates XRay (`__xray_patch`) with a handler that maintains per-thread
relative call depth.  On first activation, builds a `(xray_function_id → profile_data_index)`
map by resolving each function via `__xray_function_address(id)` + `dladdr()` → symbol name
→ FNV64 hash → match against `LLVMProfileData::NameRef`.  This solves the PIE
`FunctionPointer=0` limitation: XRay provides real runtime text addresses where
`LLVMProfileData::FunctionPointer` is always null.  When enabled, `min_depth` in
`CovCounter` contains actual call depth; otherwise falls back to call-count proxy.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
pull Bot pushed a commit that referenced this pull request Apr 26, 2026
…079-3df0)

`LimitSeekableReadBuffer::seek` used the expression
`pos + position_change` inside its in-buffer fast-path check. When the
inner buffer has not materialized its memory yet — as is the case for
`EmptyReadBuffer`, `ParallelReadBuffer`, and `ReadWriteBufferFromHTTP`,
all of which start with `pos == nullptr` — and a non-zero seek is
requested before the first `next()`, this triggers undefined behavior
per [expr.add]: "applying non-zero offset N to null pointer". On master
BuzzHouse (arm_asan_ubsan) this surfaced from the BACKUP write path as
STID 3079-3df0:

```
src/IO/LimitSeekableReadBuffer.cpp:97:34: runtime error: applying non-zero offset 1178 to null pointer
  #0 DB::LimitSeekableReadBuffer::seek(long, int)
  #1 DB::BackupWriterDefault::copyDataToFile(...)
  #2 DB::BackupImpl::writeFile(...)
  #3 DB::BackupsWorker::writeBackupEntries(...)
```

Replace the pointer-arithmetic comparison with an equivalent check
expressed via pointer *differences* and integer arithmetic, which is
well-defined regardless of whether `pos` is null. The condition is
mathematically identical to the original for all legal inputs.

Add `gtest_limit_seekable_read_buffer.cpp` covering the null-`pos`
regression plus two sanity tests for the in-buffer and out-of-buffer
seek paths. Without the fix the first test reproduces the exact UBSan
error from CI; with the fix all three pass cleanly under
`-fsanitize=address,undefined`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=4b8132993ce0625e9c0ed0bf15ed16eb6df8262b&name_0=MasterCI&name_1=BuzzHouse+%28arm_asan_ubsan%29
pull Bot pushed a commit that referenced this pull request May 20, 2026
…ax indices

Address PR ClickHouse#101170 review feedback (CI #2):

- Drop the 5 add_minmax_index_for_* members from ProjectionDescription. They
  were stale ad-hoc fields duplicating MergeTreeSettings; with the new generic
  SettingsChanges flow the effective MergeTreeSettings is already the canonical
  representation.
- Thread the already-computed effective MergeTreeSettings (defaults from the
  projection index plus user WITH SETTINGS overrides) into fillProjectionDescription
  and fillProjectionDescriptionByQuery as a new parameter, instead of
  reconstructing it. fillProjectionDescriptionByQuery reads the implicit-minmax
  flags via strongly-typed MergeTreeSetting accessors.
- Add the 5 add_minmax_index_for_* names to ALLOWED_PROJECTION_SETTINGS so the
  feature added in ClickHouse#105137 (Enable Implicit Skip Indices for Projections) keeps
  working under the new settings flow.

The ATTACH validation gap raised by review item #3 is intentionally left as
`mode <= LoadingStrictnessLevel::CREATE` to match the project-wide convention
(InterpreterCreateQuery, registerStorageMergeTree, etc. all validate user input
on CREATE/SECONDARY_CREATE only). The previous loadSettings validated
unconditionally because it had no access to mode; now that we do, aligning with
the rest of the codebase is the consistent choice.
pull Bot pushed a commit that referenced this pull request May 24, 2026
The point-lookup queries (#4-#7) in apply_patch_parts_join produced
18-30% test noise because the four UPDATE statements that build the
patch parts ran with default parallelism. Parallel threads racing into
the patch builder produce different patch-part split boundaries on
every run, which changes how many patch granules a point lookup at
id=5000000 ends up reading. Per-server timing then depends on the
random split, not on the code being measured.

Force INSERT and UPDATE to use a single thread plus a block size large
enough to fit each whole patch, so the patch-part layout is the same
on every run. Locally verified deterministic over 20 cycles. Setup
time goes from ~4.2s to ~6.3s. Scan queries (#0-#3) still detect
patch-apply-path regressions as before.

Refs ClickHouse#100759.
pull Bot pushed a commit that referenced this pull request Jun 6, 2026
ClickHouse#106278 tried to remove the LIMIT-without-ORDER-BY non-determinism by
sampling with WHERE cityHash64(WatchID) % N = 0. Post-merge master data
showed it did not work: it made the measured queries scan the whole table on
every run, so instead of reducing the noise it regressed it badly:

  classification #0: 6.5% -> 76% noisy
  classification #1:  10% -> 90% noisy

(#2/#3/#4 were already clean.)

Materialize the deterministic subset once into its own single-part table
(single-threaded insert + OPTIMIZE FINAL) and measure over that, so the
determinism lives in the setup (like ClickHouse#106249 for reading_from_file) and the
measured queries read only the subset instead of rescanning the source.
pull Bot pushed a commit that referenced this pull request Aug 3, 2026
Fix build: store StorageMetadataHandle in a local before conversion
pull Bot pushed a commit that referenced this pull request Aug 20, 2026
A query flagged in `report.html` was dropped when `all-query-metrics.tsv` had
no `client_time` row for it, and a shard whose TSV could not be read dropped
all of its flagged queries. With every flagged query dropped the run ended with
"the comparison ran and was clean" - a non-empty CI report turned into an
all-clear. The cause is deliberate on CI's side: `compare.sh` retracts a query
from the TSV when its confirmation rerun demoted it, while the report still
lists it under both "Changes in Performance" and "Unconfirmed Changes". On
PR ClickHouse#115255 that is `round_down` #2 and #3 and `and_compare_chain_derived` #2.

Those rows carry their own numbers, so they are now read from `report.html` and
marked `*` in the report - CI's verdict on them was already in doubt, which
makes them the most interesting queries to rerun, not the ones to discard. A
flagged query readable from neither source is reported as unresolved, and if
that leaves nothing to rerun the run fails instead of reporting a clean
comparison.

The commit under test drove only the report and binary lookup; the XMLs,
`perf.py`, its `stat_threshold`, and the configs still came from the working
tree. Query indices are positional and substitutions expand them, so a tree
that differs from the measured commit silently reruns a different query - on a
checkout one commit behind master, `and_compare_chain_derived.xml` has no query
#2 at all while CI flagged exactly that, and a `refs/pull/<n>/merge` checkout
is never the commit CI measured. `tests/performance`, `programs/server` and
`tests/config/top_level_domains` are now extracted from that commit into the
work dir and everything runs from there, fetching the commit when the clone
lacks it. `--use-working-tree-tests` opts out for iterating on a local test.

Verified: all six flagged queries of PR ClickHouse#115255 are now kept, the three the TSV
retracts carrying the report's numbers and flagged as unconfirmed; a dry run of
PR ClickHouse#112688 recovers `date_time_64` #5, which had been dropped the same way, and
runs against the extracted tree.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115278&sha=baefff6dcc4dbb3201337a52b5ca54453fb34562&name_0=PR&name_1=Style%20check
Pull request: ClickHouse#115278

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GYYbBbrQpmi2zkYJ8LQw5Z
pull Bot pushed a commit that referenced this pull request Sep 22, 2026
The CIDB query that learns the per-query performance thresholds aggregated
GROUP BY test, query_index and returned any(query_display_name), while both
consumers of the resulting historical-thresholds.tsv join it on all three
columns: report_thresholds (compare.sh:1238-1243), which publishes
changed_threshold/unstable_threshold, and flagged_queries in confirm_changes
(compare.sh:921-926), which decides which queries enter the confirmation rerun.

query_display_name is the query text while query_index is positional, so
editing a test's substitution values changes the text at an unchanged index.
The historical window then holds two display names for one
(test, query_index), any() returns one of them per run, and the other text's
join misses. join_use_nulls is not in CHPC_REPORT_LOCAL_QUERY_SETTINGS
(compare.sh:46), so the miss yields 0 and ceil(greatest(0.15, 0, 0), 2)
silently collapses to the 0.15 floor. A noisy micro benchmark judged by that
floor is then reported slower on unrelated pull requests and on master, at a
different set of query indices each run.

This restores the producer's grain to the three columns the consumers already
join on. 36a3734 narrowed it from

    group by test, query_index, query_display_name

to

    GROUP BY test, query_index

in the same edit that shrank the window from three months to one; the
consumers were not touched, and the original grain still survives in the
commented-out calibration query 20 lines below.

double_check_perf.py carries a deliberate copy of the same query (its comment
says so, and its consumer already keys a dict on all three fields), so it gets
the same two-line fix.

Measured on play.clickhouse.com, 2026-09-21, window
today() - 1M - 1W .. today() - 1W:

  * 5596 (test, query_index) groups hold a bar and none loses it; rows emitted
    5596 to 5644, rows read identical at 15.02e9.
  * 50 groups across 12 tests currently carry two display names, 18 of them in
    timeseries_to_grid_aggregation_functions, whose window substitution changed
    in 46d27f5.
  * Over 8 interleaved pairs the median paired server time is -0.67 s (faster
    in 5 of 8) and median peak memory drops 1514 to 1289 MiB, so exposure to
    the 10 s fetch timeout is unchanged at 3 of 8 in both arms.
  * On master c67f0b1, whose fetch succeeded, all four carrier-test indices
    published at the bare floor are ambiguous and all five that kept a learned
    bar are single-name, 9 of 9.

Two pre-existing behaviours are unchanged: a brand-new query text gets the
floor until it has more than 100 rows in the window, and grace_hash_join #3
and #7 have a 14-row variant against 1977 that now gets the floor rather than
a bar pooled over two different query texts.

Related: ClickHouse#116234

Co-Authored-By: Claude Opus 5 <[email protected]>
pull Bot pushed a commit that referenced this pull request Sep 29, 2026
…ion over a `Nullable` argument

The `-If` null adapters merged the null map with the condition into a buffer
sized by the absolute end row of the call and filled only `[row_begin, row_end)`.
Aggregation in order calls `addBatchSinglePlace` once per key interval, and
window frames once per frame update, so with 8-row groups every call asked for
up to 64 KiB to use 8 bytes. The merges the nested functions do for themselves
(`SingleValueData`, `groupBit*`, the simple moments, `regr_*`,
`timeSeriesLastTwoSamples`) were sized the same way.

On x86_64 every such request above 32 KiB exceeds jemalloc's thread cache
limit (`opt_tcache_max`) and takes the arena large-extent path, whose cost
depends on the state of the process. On aarch64 (64 KiB pages) these sizes are
small size classes served from the thread cache. That is why queries #2 to #5
of `tests/performance/aggregation_in_order_if_null_map.xml` are unstable on
the amd runners only: in the last 14 days CIDB has 2008 of the test's 2174 amd
`unstable` verdicts on #2 to #5, and 8 on arm in total.

With a single `Nullable` argument no merged map is needed:
`addBatchSinglePlaceNotNull` takes the null map and the condition column
separately, and every implementation handles `if_argument_pos`
(`AggregateFunctionIf` already calls them all that way). So
`AggregateFunctionIfNullUnary` with a non-`Nullable` condition passes the
value's null map and the condition at position 1, and
`AggregateFunctionIfNullVariadic` with exactly one `Nullable` argument passes
that argument's null map to the nested `-If` function, which applies the
condition. The merges those calls reach allocate `row_end - row_begin` bytes
and call their kernels with pointers rebased by `row_begin`, as `sum` and
`avg` already do. The same rows are added in the same order, so the results
do not change. Two or more `Nullable` arguments (query #5, `corr(x, w)`), a
`Nullable` condition of a one-argument `-If` function and the TimeSeries
array merges keep their merged buffer.

Measured on a release build (x86_64, `max_threads` 8), base / this change,
per run of each query of the test:
- jemalloc large allocations above 32 KiB: #0 703 / 703, #1 714 / 714,
  #2 302182 / 703, #3 302142 / 663, #4 229046 / 1718, #5 115413 / 115413;
- CPU profiler samples in the jemalloc large-extent path: #2 33% / 0.9%,
  #3 31% / 0.5%;
- perf.py median of 13 runs, two alternating rounds (ms): #2 38.2, 39.8 /
  24.6, 21.7; #3 39.0, 40.2 / 21.3, 19.8; #4 44.3, 45.4 / 28.3, 25.9;
  #0, #1 and #5 unchanged;
- `minIf(x, cond) OVER (ORDER BY k ROWS BETWEEN 100 PRECEDING AND CURRENT
  ROW)` over 1M rows: 340 / 166 ms, and `sumIf(y, cn)` over a `Nullable`
  condition: 301 / 89 ms;
- aggregation without keys over the same table: 12.2 / 12.3 ms.

Query #0, flagged on ClickHouse#118490,
never had such a buffer and is not changed here.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118490&sha=8ded98e22889e53dd536b141b564e136c76482a9&name_0=PR&name_1=Performance%20Comparison%20(amd_release%2C%20master_head%2C%203%2F6)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pull Bot pushed a commit that referenced this pull request Sep 29, 2026
`Regexps::LocalCacheTable::getOrSet` incremented `RegexpLocalCacheHit` or
`RegexpLocalCacheMiss` on every lookup, and `MatchImpl::matchOneRow` does
one lookup per row whenever the pattern of `LIKE`/`match` is not a
constant. `ProfileEvents::increment` does an atomic add at every level of
the counter chain. The user and global levels are per-CPU since ClickHouse#105056,
but the thread group level is a single row, so every thread of the query
wrote the same cache line on every row. The query was bound by that line:
`re2_regex_caching` `#3` took 91 ms at both 8 and 32 threads, and its cost
differed between server processes, which made `#3`, `#5` and `#6` of that
test noisy on the amd performance shards.

The table now counts hits and misses in two members and adds them to
ProfileEvents once, in its destructor. A table is a local of
`vectorVector`/`vectorFixedVector`/`constantVector`, so it lives for one
block on one thread: the totals per query are unchanged (a miss is still
counted before `createRegexp`, so a failed compile still reports it), and
the shared counter is written twice per block instead of once per row.
Tables that did no lookup report nothing, as before. With
`trace_profile_events = 1` these two events now give one `trace_log` row
per block (with the block total) instead of one per row.

Release build, 8 threads pinned to 8 physical cores, 10 server processes
per binary: `#3` and `#5` 90 -> 18 ms, `#6` 94 -> 34 ms, the other queries
of the test unchanged; user CPU at 8 threads over 1 thread for `#3` goes
from 5.2 to 1.0. At 32 threads `#3` goes from 91 to 15 ms.

The new test checks the exact hit and miss totals for the three callers
(String, FixedString and constant haystacks).

Related: ClickHouse#121795, ClickHouse#100759

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pull Bot pushed a commit that referenced this pull request Sep 29, 2026
…columns performance test

`least_greatest_const_columns #2` returns the 256-byte constant `repeat('d', 256)` for every row, so
the result `ColumnString` grows its `chars` by power-of-two `realloc` up to 16 MiB per block. Whether
jemalloc grows that buffer in place or moves and copies it (`large_ralloc` -> `memcpy`) differs
between server processes, and in CI CPU profiles that copy is the only part of the query whose sample
count differs between the two servers. In 14 days the two servers differed by more than 15% in 94 of
775 amd and 23 of 1692 arm runs of this query, and in none for `#3`, which takes the same arguments
with `least` and returns the ~7-byte `toString(number)`.

Add a constant `'e'` that wins every row, so the result is one byte per row. The query still compares
`toString(number)` against the four 256-byte constants that are not materialized since ClickHouse#119108, and
still returns a constant argument.

Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/36432228454/job/109047348805
PR: ClickHouse#122184

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant