Skip to content

[pull] master from ClickHouse:master - #6

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

pull[bot] merged 39 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 : )

fm4v and others added 9 commits December 9, 2024 17:05
…memory_eng_2

Resubmit More insistent compression in StorageMemory
…umns

Bring back optimization for reading subcolumns of single column in Compact parts
Add inferred format name to create query in File/S3/URL/HDFS/Azure engines
Add integration tests for Refreshable Materialized Views (mv4)
Revert "Enable JIT compilation for more expressions"
Fix flakiness of 01319_query_formatting_in_server_log.sql
@pull pull Bot added the ⤵️ pull label Dec 10, 2024
@pull
pull Bot merged commit 20ccb63 into erickirt:master Dec 10, 2024
pull Bot pushed a commit that referenced this pull request Jul 16, 2025
…ary bridge cleanup

<details>

<summary>stacktrace</summary>

    #5  DB::ContextSharedMutex::lockSharedImpl (this=this@entry=0x7ffff5b96040) at /src/ch/clickhouse/src/Interpreters/Context.cpp:1036
            watch = {start_ns = 98678735300141, stop_ns = 0, clock_type = 4, is_running = true}
            increment = {what = <optimized out>, amount = 1}
    #6  0x00005555699352d6 in DB::SharedMutexHelper<DB::ContextSharedMutex, DB::SharedMutex>::lock_shared (this=0x7ffff5b96040) at /src/ch/clickhouse/src/Common/SharedMutexHelper.h:70
    #7  DB::SharedLockGuard<DB::ContextSharedMutex>::SharedLockGuard (mutex_=..., this=<optimized out>) at /src/ch/clickhouse/src/Common/SharedLockGuard.h:19
    #8  DB::ContextSharedPart::getConfigRef (this=0x7ffff5b96000) at /src/ch/clickhouse/src/Interpreters/Context.cpp:760
    #9  DB::Context::getConfigRef (this=<optimized out>) at /src/ch/clickhouse/src/Interpreters/Context.cpp:1590
    #10 0x000055556450941c in DB::ProxyConfigurationResolverProvider::get (request_protocol=DB::ProxyConfiguration::Protocol::HTTP) at /src/ch/clickhouse/src/Common/ProxyConfigurationResolverProvider.cpp:161
    #11 0x00005555669ea75f in DB::BuilderRWBufferFromHTTP::create (this=0x7fffffffa848, credentials_=...) at /src/ch/clickhouse/src/IO/ReadWriteBufferFromHTTP.cpp:814
    #12 0x000055556cea0035 in DB::ExternalDictionaryLibraryBridgeHelper::bridgeHandShake (this=0x7ffd60c4ca18) at /src/ch/clickhouse/src/BridgeHelper/ExternalDictionaryLibraryBridgeHelper.cpp:79
    #13 0x000055556cea1f34 in DB::ExternalDictionaryLibraryBridgeHelper::removeLibrary (this=0x7ffff5b96044) at /src/ch/clickhouse/src/BridgeHelper/ExternalDictionaryLibraryBridgeHelper.cpp:186
    #14 0x0000555566cb0248 in DB::LibraryDictionarySource::~LibraryDictionarySource (this=0x7ffd60c78318) at /src/ch/clickhouse/src/Dictionaries/LibraryDictionarySource.cpp:70
    #15 0x000055556708d775 in std::__1::__shared_count::__release_shared[abi:ne190107]() (this=0x7ffd60c78300) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:156
    #16 std::__1::__shared_weak_count::__release_shared[abi:ne190107]() (this=0x7ffd60c78300) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:185
    #17 std::__1::shared_ptr<DB::IDictionarySource>::~shared_ptr[abi:ne190107]() (this=0x7ffd60c605b0) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:668
    #18 DB::HashedDictionary<(DB::DictionaryKeyType)0, false, false>::~HashedDictionary (this=0x7ffd60c60398) at /src/ch/clickhouse/src/Dictionaries/HashedDictionary.h:378
    #19 0x0000555569a9c477 in std::__1::__shared_count::__release_shared[abi:ne190107]() (this=0x7ffd60c60380) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:156
    #20 std::__1::__shared_weak_count::__release_shared[abi:ne190107]() (this=0x7ffd60c60380) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:185
    #21 std::__1::shared_ptr<DB::IExternalLoadable>::~shared_ptr[abi:ne190107]() (this=0x7ffff4832560) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:668
    #22 DB::ExternalLoader::LoadingDispatcher::Info::~Info (this=0x7ffff4832548) at /src/ch/clickhouse/src/Interpreters/ExternalLoader.cpp:719
    #23 std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, DB::ExternalLoader::LoadingDispatcher::Info>::~pair (this=0x7ffff4832530, this@entry=0x7ffd60c60390) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__utility/pair.h:65
    #24 __destroy_at<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, DB::ExternalLoader::LoadingDispatcher::Info>, 0> (__loc=__loc@entry=0x7ffff4832530) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/construct_at.h:67
    #25 0x0000555569a9c628 in destroy<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, DB::ExternalLoader::LoadingDispatcher::Info>, void, 0> (__p=0x7ffff5b96044, __p@entry=0x7ffff4832530) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/allocator_traits.h:339
    #28 std::__1::unique_ptr<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::ExternalLoader::LoadingDispatcher::Info>, void*>, std::__1::__hash_node_destructor<std::__1::allocator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::ExternalLoader::LoadingDispatcher::Info>, void*> > > >::~unique_ptr[abi:ne190107]() (this=<optimized out>) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:261
    #31 DB::ExternalLoader::LoadingDispatcher::setConfiguration (this=this@entry=0x7ffecad4c300, new_configs=...) at /src/ch/clickhouse/src/Interpreters/ExternalLoader.cpp:495
    #32 0x0000555569a9116d in DB::ExternalLoader::reloadConfig (this=0x7ffecb3fd740, repository_name=...) at /src/ch/clickhouse/src/Interpreters/ExternalLoader.cpp:1533
    #33 DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0::operator()() const (this=<optimized out>) at /src/ch/clickhouse/src/Interpreters/ExternalLoader.cpp:1334
    #34 std::__1::__invoke[abi:ne190107]<DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0&>(DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0&) (__f=...) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__type_traits/invoke.h:149
    #35 std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ne190107]<DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0&>(DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0&) (__args=...) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__type_traits/invoke.h:224
    #36 std::__1::__function::__default_alloc_func<DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0, void ()>::operator()[abi:ne190107]() (this=<optimized out>) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__functional/function.h:210
    #37 std::__1::__function::__policy_invoker<void ()>::__call_impl[abi:ne190107]<std::__1::__function::__default_alloc_func<DB::ExternalLoader::addConfigRepository(std::__1::unique_ptr<DB::IExternalLoaderConfigRepository, std::__1::default_delete<DB::IExternalLoaderConfigRepository> >) const::$_0, void ()> #38 0x0000555569966aaa in std::__1::__function::__policy_func<void ()>::operator()[abi:ne190107]() const (this=0x7ffff5b96044) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__functional/function.h:716
    #39 std::__1::function<void()>::operator() (this=0x7ffff5b96044) at /src/ch/clickhouse/contrib/llvm-project/libcxx/include/__functional/function.h:989
    #40 BasicScopeGuard<std::__1::function<void()> >::invoke (this=0x7ffff5b96044) at /src/ch/clickhouse/base/base/../base/scope_guard.h:101
    #41 BasicScopeGuard<std::__1::function<void()> >::reset (this=0x7ffff5b96044) at /src/ch/clickhouse/base/base/../base/scope_guard.h:63
    #42 DB::ContextSharedPart::shutdown (this=0x7ffff5b96000) at /src/ch/clickhouse/src/Interpreters/Context.cpp:909
    #43 0x00005555644cf5cb in DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&)::$_3::operator()() const (this=this@entry=0x7fffffffc870) at /src/ch/clickhouse/programs/server/Server.cpp:1257
    #44 0x00005555644b4439 in BasicScopeGuard<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&)::$_3>::invoke (this=0x7fffffffc870) at /src/ch/clickhouse/base/base/../base/scope_guard.h:101
    #45 BasicScopeGuard<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&)::$_3>::~BasicScopeGuard (this=0x7fffffffc870) at /src/ch/clickhouse/base/base/../base/scope_guard.h:50
    #46 DB::Server::main (this=0x7fffffffe4c8) at /src/ch/clickhouse/programs/server/Server.cpp:2788
    #47 0x0000555572cbbee9 in Poco::Util::Application::run (this=0x7fffffffe4c8) at /src/ch/clickhouse/base/poco/Util/src/Application.cpp:315
    #48 0x000055556449c390 in DB::Server::run (this=0x7fffffffe4c8) at /src/ch/clickhouse/programs/server/Server.cpp:610
    #49 0x0000555564499aec in mainEntryClickHouseServer (argc=6, argv=0x7ffff67ecdc0) at /src/ch/clickhouse/programs/server/Server.cpp:397
    #50 0x000055555dc994c2 in main (argc_=<optimized out>, argv_=<optimized out>) at /src/ch/clickhouse/programs/main.cpp:340

</details>
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
pull Bot pushed a commit that referenced this pull request Jun 26, 2026
The CI-report-link fallback in `new_tests_check.py` short-circuited the
per-arch Bugfix Validation contract for PRs that add new functional or
integration regression tests: if all per-arch jobs reported `validated=false`
but the PR body contained a link to a CI report, the hook still passed.

Restructure `check` to be mutually exclusive on the FT/IT-vs-rest axis so
neither shortcut can bypass per-arch validation:

  if has_ft or has_it:
      # must validate on at least one arch — no link / no unit fallback
      return any_bugfix_validation_passed()
  if has_unit:
      # unit-only PR — per-arch FT/IT machinery doesn't apply
      return True
  # no new tests — operator-supplied CI report link is acceptable
  return has_ci_report_link(pr_body)

Truth-table verified against all 32 (has_unit, has_ft, has_it,
validation_passed, ci_report_link) combinations: 32/32 match the expected
contract; both bypass concerns (#5 `has_unit`, #6 CI-report-link) closed.

Addresses bot review concern #6 on PR ClickHouse#103541.
pull Bot pushed a commit that referenced this pull request Jul 18, 2026
Address review (blocker #9): a whitespace-only scratch tab is pruned on
reload because `(r.query || '').trim() === ''`, but `writeHistoryEntry`
had encoded that whitespace into the URL hash, so `has_url_query` is
`true`. The two "authoritative URL" branches in `reconcileStartup`
(`play.html`) then fired on `has_url_query` and recreated the blank tab,
and the trailing `scheduleSave` wrote it straight back to `IndexedDB` —
so whitespace-only scratch tabs still survived a plain reload, defeating
the pruning.

Add `stale_blank_reload_bare` (a `stale_blank_reload` whose URL query is
itself blank by the same `trim` rule) and treat it exactly like a bare
`?tab=`: non-authoritative in the saved-tabs "open new tab" branch, the
no-saved-tabs "adopt bootstrap" branch, the URL parameter rebuild, and
the deferred auto-run. A NON-blank hash on a stale reload is instead a
genuine unsaved edit that never reached `IndexedDB` before the reload,
so it stays authoritative and the tab is recreated with that real query,
preserving the edit.

Validated with node --check on the extracted script and a 13-scenario
branch-logic simulation covering the reviewer's exact repro (both
saved-survivor and no-survivor cases), the unsaved-edit preservation
case, and regressions for the earlier blockers (#6 external bare link,
#7 rename-before-reload, #8 duplicate-title survivor), plain load,
external shared links, and run-backed empty editors.
pull Bot pushed a commit that referenced this pull request Sep 21, 2026
`ThreadPoolImpl::scheduleImpl` handed its `wait_microseconds` parameter
straight to `std::condition_variable::wait_for`, which evaluates the wait
as `steady_clock::now() + duration` in nanoseconds, multiplying a
microsecond duration by 1'000. The parameter is a `uint64_t`, while the
settings that feed it are `Int64` microsecond timespans, so a negative
timeout arrives as a huge unsigned count and that multiplication
overflows `Int64`. UBSan aborts the server; a release build wraps to a
deadline in the past, so the schedule fails at once with
`Cannot schedule a task: no free thread` instead of waiting.

The setting that reaches it is `lock_acquire_timeout`:
`MergeTreeDataSelectExecutor::filterPartsByPrimaryKeyAndSkipIndexes`
passes `lock_acquire_timeout.totalMicroseconds()` to `scheduleOrThrow`
when it analyses the primary key of several parts in parallel.

Found on master in the stress test:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=a54f19b0b7169af771a26d449065c368684b07a3&name_0=MasterCI&name_1=Stress%20test%20%28amd_asan_ubsan%29

    /ClickHouse/contrib/llvm-project/libcxx/include/__chrono/duration.h:93:79: runtime error:
    signed integer overflow: -100000000000000000 * 1000 cannot be represented in type '_Ct'
    #5  std::condition_variable::wait_for<...>(...)      condition_variable.h:193
    #6  ThreadPoolImpl<...>::scheduleImpl<void>(...)     src/Common/ThreadPool.cpp:470
    #7  ThreadPoolImpl<...>::scheduleOrThrow(...)        src/Common/ThreadPool.cpp:655
    #8  DB::MergeTreeDataSelectExecutor::filterPartsByPrimaryKeyAndSkipIndexes(...)
                                    src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:1286

Clamp the count with a new `saturatedMicroseconds`, the microsecond-typed
sibling of the `saturatedMilliseconds` and `saturatedSeconds` helpers,
which covered every millisecond- and second-typed `wait_for` but not this
microsecond one. The pool cannot reuse the millisecond clamp because
`wait_microseconds` must keep sub-millisecond resolution. A count above
the one-year cap keeps meaning "wait until a thread frees up", the same
thing the existing clamp already does for a huge positive timeout.
pull Bot pushed a commit that referenced this pull request Sep 27, 2026
A condition that may throw is put into its own read step even when it reads the same storage columns as the step before it. Each such step then deserialized the storage column again, so a `Map` was read once per key, which made `startsWith` and `LIKE` conjunctions over `Map` subcolumns about 2.4x slower in the performance check (`map_subcolumns_prewhere` #6 and #7). Now the columns of such a run of steps are read by its first step, and the later steps only evaluate their condition on the filtered rows. Reading is safe, only the evaluation has to wait for the filter.

`RowsReadByPrewhereReaders` counts the rows a step passes even when it reads no columns, so `04631` asserts the single read through `ReadCompressedBytes` instead.
pull Bot pushed a commit that referenced this pull request Sep 29, 2026
Query #7 of tests/performance/array_first_last.xml (arrayLast over
Array(Array(UInt64))) takes a different time in each server process of
the same build. In 14 days of Performance Comparison runs on amd it moved
by more than 15% between the two servers in 50 of 633 runs, 36 of them
master against master, while #6 (arrayFirst over the same column) moved
in 0 of 641 and the tuple queries #4/#5 in 2 and 3; arm is quiet. Per
run, #6 and #7 move in opposite directions (r = -0.53 over 524 amd runs;
in 33 of the 37 runs where #7 moved by more than 15%, #6 moved the other
way), while #4/#5 move together (r = +0.42).

Each nested_values row holds 32 inner arrays of 2 UInt64, so rows are 256
bytes apart in the inner offsets and 512 bytes apart in the data. #6 and
#7 read one inner array per row, so for the whole query every row is read
at the same position modulo 256/512 bytes, i.e. at the same few offsets
inside every memory page. Which offsets those are depends on where the
column is allocated: jemalloc is built with cache_oblivious, which puts
every large allocation at a random multiple of 64 bytes inside its first
page, and the table is filled once per server. So each server reads the
column at its own fixed page offsets.

Fill nested_values with 31 inner arrays per row. Rows are then 248/496
bytes apart and the read position walks through every offset of the page
within one query, so the timing no longer depends on the allocation. The
query texts and the per-row work (one copy of a 2-element array per row,
250000 rows) are unchanged.

Local check with the official master build 26.10.1.906 on a Xeon 6975P-C:
16 separately filled copies of the table per arm in one server, measured
round-robin for 20 rounds. This machine does not show the spread with
either layout (#7 across copies: 14.14-14.68 ms with 32 elements and
random allocation offsets, 13.93-14.27 ms page-aligned with
MALLOC_CONF=cache_oblivious:false, 13.95-14.32 ms with 31 elements), so
it cannot confirm the mechanism and the change rests on the CI data. The
level of #7 stays (31 vs 32 elements: 0.98x); #7/#6 goes from 1.11 to
1.03.

Related: ClickHouse#120510

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

5 participants