Skip to content

[pull] master from ClickHouse:master - #7

Merged
pull[bot] merged 13 commits into
admariner:masterfrom
ClickHouse:master
May 5, 2021
Merged

pull[bot] merged 13 commits into
admariner:masterfrom
ClickHouse:master

Conversation

@pull

@pull pull Bot commented May 5, 2021 •

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot]

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

@pull pull Bot added the ⤵️ pull label May 5, 2021
@pull
pull Bot merged commit 7ae8938 into admariner:master May 5, 2021
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 18, 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 22, 2025
Docs: move aggregate functions docs to source code (#7)
pull Bot pushed a commit that referenced this pull request May 13, 2026
…tion` regressions

`generate_table_function #1` (8 integer column types, 1B rows) regresses ~18% and `#5`
(Date/DateTime, 1B rows) regresses ~16% on AMD release.

`fillColumnWithRandomData` is a big switch over `TypeIndex` that constructs a fresh
column for every block.  At `-march=x86-64-v3` the SLP vectorizer lowers the implicit
~32-byte zero-init of each newly-allocated `ColumnVector`/`ColumnString` to a
`vpxor xmm0; vmovdqu ymm0` pair (29 occurrences in PR vs 0 in master).  Each YMM
store dirties the upper YMM state, so clang inserts a `vzeroupper` (30 inserted)
before every external call from the dispatcher (`operator new`,
`PODArrayBase::reallocPowerOfTwoElements`, etc.) - the per-block dispatch ends up
bracketed by ~30 SSE/AVX transitions for no benefit (the inner PCG generation loop
is byte-equivalent to master's).

The inlined PCG inner loop is the dominant per-row cost, but at v3 the broader
function bloats from 16654 to 18241 bytes (+10%) and the cumulative `vzeroupper`
overhead in the per-block dispatch is what surfaces as the +15-18% regression.
The integer/Date paths are uniformly affected; Decimal/Float paths (#7/#8/#9)
do not regress because they go through a different per-element loop with no YMM
zero-init.

Compiling at v2 keeps the XMM-only zero-init that does not require `vzeroupper`.
The hot PCG inner loop's quality is not affected (master is already at v2 and
generates the same scalar code).

Local Sapphire Rapids LTO (max_threads=12, 10 iter):
  - `#1`:                      master 0.521s, PR 0.521s  (was 0.614s, +18%)
  - `#5`:                      master 0.177s, PR 0.178s  (was 0.208s, +16%)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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 Jul 18, 2026
Addresses AI review (blocker #7, `play.html:7955`): `stale_blank_reload`
recognized a dropped blank tab by its persisted title only. Because title
edits are flushed by the debounced `scheduleSave` rather than synchronously,
a plain reload right after renaming a blank tab leaves `history.state.tabName`
and `?tab=` at the new title while `IndexedDB` still holds the old one. The
title match then missed the pruned record, so startup recreated and re-persisted
the blank tab instead of pruning it.

Collect the stable ids of the pruned blank records (`pruned_blank_ids`) and key
`stale_blank_reload` on the reloaded `history.state.tabId` against that set. The
id survives an unsaved rename, so the stale echo is recognized regardless of a
pending title change; a genuine external shared bare link still begins a fresh
navigation with `history.state === null` and stays authoritative.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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 Aug 7, 2026
`_impl::divide` laid out and trimmed the limb arrays its two algorithms need before
either could start. That setup is a fixed cost, and when both operands occupy a
single limb it exceeds the division itself: 15 ns against the 10 ns the previous
shift-and-subtract loop took, which exited after two iterations because the quotient
had one significant bit. Wide types routinely hold values far smaller than their
width, so the narrow cases now short-circuit ahead of the setup - one limb each goes
to a 64-bit division, two limbs each to `unsigned __int128` - and the limb counts
they need are computed from the operands rather than from the copies, which the
general paths reuse. Both stay usable in constant evaluation.

Per division, averaged over 2^20 operations on a Zen 3:

| case | before this change | after |
| --- | --- | --- |
| both operands one limb | 15.2 ns | 8.6 ns |
| full width / `10^18` | 24.4 ns | 24.4 ns |
| both operands full width | 15.6 ns | 15.7 ns |

The first row was 10.4 ns before the limb-by-limb division, so this also removes the
regression the perf report showed on `bigint_arithm #7`
(`intDiv(toInt256(number + 1), number + 1)`, both operands one limb): +74% on amd
and +23% on arm, on a query stable on master over 946 runs.

Reports:
https://s3.amazonaws.com/clickhouse-test-reports/PRs/112477/df093502267a55bb79cba63b1f9f67bc4b50338a/performance_comparison_amd_release_master_head_3_6/report.html
ClickHouse#112477
pull Bot pushed a commit that referenced this pull request Aug 26, 2026
`AggregatingTransform::initGenerate` used `many_data->variants.size()` as the
number of producers to wait for on the finish barrier. That vector is sized at
construction and used to be immutable afterwards, but the adaptive aggregation
made the last finisher append the early-drain routing table to it, so the
vector grows while the producers that are still arriving read its size:

    Write of size 8 ... by thread T1033:
      #7 DB::AggregatingTransform::initGenerate() src/Processors/Transforms/AggregatingTransform.cpp:1375
    Previous read of size 8 ... by thread T1187:
      #1 DB::AggregatingTransform::initGenerate() src/Processors/Transforms/AggregatingTransform.cpp:1319

Count the producers with `ManyAggregatedData::num_producers`, fixed at
construction time, so the barrier never reads the vector that the last
finisher grows. The barrier's outcome is unchanged: only the finisher whose
`fetch_add` returns `num_producers - 1` proceeds, and it is the only thread
that touches `variants` afterwards.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ed4df189fc08473dd6cee5c84b4fce89d49ca640&name_0=MasterCI&name_1=Stress%20test%20%28arm_tsan%29

Caused by: ClickHouse#111459
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 21, 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 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 28, 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]>
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.

4 participants