Skip to content

[pull] master from ClickHouse:master - #2

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

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

Conversation

@pull

@pull pull Bot commented May 3, 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 3, 2021
@pull
pull Bot merged commit b868cab into admariner:master May 3, 2021
pull Bot pushed a commit that referenced this pull request May 5, 2021
pull Bot pushed a commit that referenced this pull request May 19, 2021
* master: (694 commits)
  Fix integration test test_storage_kafka failed error
  Fix test 00163_column_oriented_formats failed error
  Read ORC file by stripe to reduce memory cost
  Function toDateTime decimal overflow ubsan fix
  Revert "[RFC] Fix memory tracking with min_bytes_to_use_mmap_io"
  Zlib use attribute constructor for functable initialization
  Translate to Russian (clickhouse-client documentation)
  Simple key dictionary primary key wrong order fix
  Disable hedged requests
  Added integration test
  Revert "Function `arrayFold` for folding over array with accumulator"
  Fix documentation for the GRANT command.
  Added system query reload model
  Make function `unhex` case insensitive for compatibility
  Improve documentation for CREATE ROW POLICY command #2.
  Add exception message
  Fix tidy
  Fix waiting for all connections closed on shutdown.
  Disable postgresql_port in perf tests
  Mark 01605_adaptive_granularity_block_borders as long
  ...
pull Bot pushed a commit that referenced this pull request Jun 15, 2021
ASTTableIdentifier part #2: Introduce ASTTableIdentifier
pull Bot pushed a commit that referenced this pull request Jul 6, 2021
pull Bot pushed a commit that referenced this pull request Jul 6, 2021
pull Bot pushed a commit that referenced this pull request Jul 14, 2021
* fix: DateTime64 on MaterializedPostgreSQL

* Update StoragePostgreSQL.cpp
pull Bot pushed a commit that referenced this pull request Aug 13, 2021
pull Bot pushed a commit that referenced this pull request Aug 13, 2021
pull Bot pushed a commit that referenced this pull request Aug 18, 2021
pull Bot pushed a commit that referenced this pull request Aug 19, 2021
pull Bot pushed a commit that referenced this pull request Aug 19, 2021
…_clock_gettime2

Revert "less sys calls #2: make vdso work again"
pull Bot pushed a commit that referenced this pull request Aug 25, 2021
pull Bot pushed a commit that referenced this pull request Aug 25, 2021
…rt-27492-less_clock_gettime2

Revert "Revert "less sys calls #2: make vdso work again""
pull Bot pushed a commit that referenced this pull request Sep 15, 2021
add compression key-word and some tests
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 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 24, 2025
Docs: move aggregate functions docs to source (#2)
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 13, 2026
`getReturnTypeImpl` already constrains the second argument of
`kostikConsistentHash` / `jumpConsistentHash` to an integer type, so the
constant bucket count can be read directly via `IColumn::getInt` /
`getUInt` instead of materialising an intermediate `Field`.

Apart from being a small simplification this fixes a `-march=x86-64-v3`
regression: `Field` is a 32-byte object, and `clang` lowered the
`Field buckets_field = (*arguments[1].column)[0]` copy to YMM
`vmovups`-pairs.  The dirtied AVX upper state then forced `vzeroupper`
before every per-row call to the (separately compiled, scalar-only)
`ConsistentHashing` helper, regressing
`consistent_hashes #0/#2/#4` ~10–13% on AMD release.

After the refactor the per-row hot path no longer touches YMM at all;
the remaining `vzeroupper` instructions left in the function body are in
cold exception-construction paths and execute as no-ops because the
upper YMM state is already clean.

On Sapphire Rapids LTO (100M rows):
  - master:                 0.211–0.215 s
  - PR (no fix):            0.227–0.242 s  (+11 %)
  - PR + this refactor:     0.211–0.214 s  (matches master)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pull Bot pushed a commit that referenced this pull request May 13, 2026
`convertNumericGeneral` runs a per-element `static_cast` loop. For
same-width integer conversions (e.g. `toInt64(UInt64)`, `toUInt32(Int32)`,
`toUInt8(Int8)`) `static_cast` is a pure bit-reinterpret, so the loop is
semantically a memcpy.  Calling `std::memcpy` directly is the natural way
to express that.

It also avoids a v3 codegen issue that caused the recurring CI regression
in `decimal_casts #2` (`SELECT toInt64(x) y, toDecimal32(y, 1),
toDecimal64(y, 5), toDecimal128(y, 6) FROM t` with `x UInt64`):

- At `-march=x86-64-v3` clang's SLP vectorizer widens the trivial copy
  loop to 4-way unrolled 256-bit `vmovdqu ymm` stores in
  `callOnIndexAndDataType<...NameToInt64...>` (232 YMM moves vs master's
  126 XMM `movdqu`).  The wider stores left the upper YMM state dirty,
  triggering an SSE/AVX state-save penalty on Intel cores that serialise
  the transition - reproducible in CI as ~+13.6% on this query, even
  though the YMM loop on its own is no faster (memory-bandwidth-bound).
- Routing same-width integer conversions to `std::memcpy` removes the
  YMM emission entirely and shrinks
  `callOnIndexAndDataType<DataTypeNumber<long>, ..., NameToInt64>` from
  30527 to 4084 bytes.  No XMM, no YMM in the function body.

Local Sapphire Rapids LTO (max_threads=12, 500 iter):
  - master:  0.064s median, 0.072s p90
  - PR:      0.063s median, 0.070s p90

Behaviour preserved: same-width integer reinterprets (e.g. `toInt8(255_u8)
== -1`, `toUInt8(-1_i8) == 255`, `toInt32(0xFFFFFFFF_u32) == -1`) match
the pre-change loop output.  The accurate / overflow-checking strategies
(`AccurateConvertStrategyAdditions`, `AccurateOrNullConvertStrategyAdditions`)
are excluded from the fast path because they need the per-element checks.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pull Bot pushed a commit that referenced this pull request May 13, 2026
At x86-64-v3 the loop and SLP vectorizers widen the per-row Int128
stores in convertToDecimalBatch into YMM/XMM packs (vmovq +
vpunpcklqdq + vmovdqu) wrapping the BMI2 mulxq, costing 4 vmovq
GPR->XMM moves and 2 vpunpcklqdq per 2 elements. The packing
overhead dominates the mulxq win, regressing sum #16 ~12% and
decimal_casts #2 ~7-12% on x86-64-v3 vs v2 master.

Disable the loop and interleave vectorizers for the scaled multiply
loop with a clang loop pragma gated on __AVX2__. Plain GPR stores
keep the mulxq v3 win and match v2 master's hot-loop perf.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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 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 Jun 30, 2026
The "Docker server image" job builds the distroless/alpine/ubuntu images with
`docker buildx build`. buildx resolves the SBOM scanner image
(docker/buildkit-syft-scanner, pulled because of --sbom=true) and base images
from docker.io. When docker.io has a transient outage, the build fails at:

  #2 resolve image config for docker-image://docker.io/docker/buildkit-syft-scanner:stable-1
  #2 ERROR: unexpected status from HEAD request to https://registry-1.docker.io/...

and the downstream "docker library image test" then reports "image does not
exist!" as a secondary victim.

praktika's Shell.run / Result.from_commands_run already support retries with
exponential backoff and an error allowlist, but the buildx build and the
imagetools merge commands ran with no retries. Wire retries=5 and an
allowlist of transient registry/network signatures into both. The allowlist
keeps fail-fast behavior for genuine Dockerfile/build errors. This mirrors the
existing retry hardening for the in-Dockerfile wget downloads (ClickHouse#105139) and the
keeper image S3 artifact fetch (ClickHouse#108675).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
pull Bot pushed a commit that referenced this pull request Jul 11, 2026
- Resolve setting query parameters on a copy of the changes instead of
  mutating the AST, so the placeholders are preserved for the old-server
  compatibility rewrite in ClientBase::processOrdinaryQuery (review major #1).
- Pass the changes to checkSettingsConstraints as const: the non-const
  overload rewrites the list and drops no-op changes, which lost the
  "changed" flag for a setting explicitly set to its current value
  (e.g. SET log_queries = 1) and broke 03595_set_query_no_eq_set_to_one.
- Teach QueryParameterVisitor / analyzeReceiveQueryParams to discover query
  parameters used as setting values (stored inside FieldFromAST), so
  predefined HTTP handlers accept param_<name> for them (review major #2).
- Renumber the stateless test to 04416 to satisfy the test-numbers style check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pull Bot pushed a commit that referenced this pull request Jul 27, 2026
pull Bot pushed a commit that referenced this pull request Jul 30, 2026
The fix in this PR makes three FilterTransform call sites compose their
applied filter into ChunkInfoRowNumbers. Only the two stripped-PREWHERE
fallback filters were covered by 04615; the Iceberg equality-delete
notIn filter was not, so the equality-delete half of the contract was
unproven.

Reverting only the equality-delete call site to the old behaviour makes
the new test fail, and pristine master fails it too: on a table that
carries equality delete files the _row_number column is built from a
stale mask, which either aborts with a column length mismatch
("Expected the argument #2 ('__table1._row_number' of type Int64) to
have 423 rows, but it has 470") or silently yields compacted post-filter
indices instead of physical row positions. Those indices are what the
mutation path writes into positional delete files, so a wrong value
deletes the wrong rows.

The test uses the existing committed fixtures: deletes_db/eq_deletes_table
(equality plus position deletes, also read under PREWHERE so the fallback
filter stacks on top of the notIn filter) and
deletes_db/eq_deletes_required_table (equality deletes only, where the
exact physical row numbers are asserted). The per-file offset assertion is
independent of the engine path: it is checked against the raw Parquet data
files read directly through s3().

Co-Authored-By: Claude Fable 5 <[email protected]>
pull Bot pushed a commit that referenced this pull request Aug 3, 2026
Populate skipping_indices_types for session temporary tables
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 7, 2026
Address review on 03480_year.sql and year.cpp:

- The query-result-cache section is gone; determinism is asserted from
  `system.functions` (`year 0 <empty alias_to>`), which is a direct read of the
  flag rather than an observation of one of its consumers.
- `no-parallel` goes with it. The tag was earned only by the query result cache
  being a global singleton; what is left creates one table in the test's own
  database and reads `system.functions`, so it is safe to run against itself.
- The `year(datetime, timezone)` case is removed from the test, and the
  timezone argument is removed from the documented signature, the arguments
  list and the examples. Only the one-argument form is documented now.

Dropping the timezone example renumbers the remaining ones, so the
`docs_examples` baseline entry for the current-year example moves from
`Function/year#2` to `Function/year#1`. Left at `#2` the runner reports it as a
known failure that no longer exists, which fails the job.

The index-analysis statement gains a `pruned` column. Comparing the two row
estimates for equality also holds when neither spelling prunes: on the same
fixture with `ORDER BY tuple()` both estimates are 40000, so `same_index_scan`
is 1 while `pruned` is 0.

Co-Authored-By: Claude Opus 5 <[email protected]>
pull Bot pushed a commit that referenced this pull request Sep 24, 2026
Review asked to keep the block sizes always a power of two, so the fill's
`max_block_size` moves from 65409 to 65536. It now matches the
`max_insert_block_size` beside it and
tests/performance/join_convert_full_to_left_or_right.xml, which pins the same
pair at 65536.

65409 was the current default of the setting (`DEFAULT_BLOCK_SIZE` in
src/Core/Defines.h, 65536 minus the SIMD padding), so the pinned value is now a
deliberate round number instead of a restatement of that default. The comment
dropped the sentence naming 65409 as the default, which the swap makes false,
and states the invariant the pin buys instead.

Nothing the test asserts or measures changes. Both tables still write 16 active
parts, so the `throwIf` oracles stand; the cut moves from 15 x 65409 rows +
18865 to 15 x 65536 + 16960. Measured with `EXPLAIN indexes = 1` on all three
queries, 65409 -> 65536:

  #0  parts 3/16 unchanged, index range 39246 -> 39321 granules, read 3 -> 3
  #1  parts 1/16 unchanged, read 1 -> 1
  #2  parts 12/16 unchanged, 156984 -> 157284 granules, read 133114 -> 133110

The +0.19% is the range the skip index walks, not the data read. With both
sides at one layout the worst arm spread measured on #0 is +9.6% over 5537
jobs, against the check's 15% floor, so the shift is far below either.
pull Bot pushed a commit that referenced this pull request Sep 27, 2026
These queries were flagged as slower/faster/unstable on master runs, or scored as confirmed regressions by the performance dashboard on unrelated PRs, because the two compared servers did not measure the same work:

- `and_compare_chain_derived`: both tables are created with `numbers_mt`, which writes a varying number of parts, and the measured runs stop merges, so the servers read different layouts (the join query took 34 ms over 17 parts and 82 ms over one part on the same binary). Merge each table to one part and check it. Query 2 now keeps 2M rows per side (`8000000 < l.v`) and runs at about 150 ms instead of 20 ms.
- `set_index`: the IN set was built from `rand`, so every run looked up a different set, selected different ranges and read a different number of rows before `read_overflow_mode = 'break'`. Use a fixed pseudo-random sample (`toUInt32(cityHash64(number))`) and merge the 500M-row table to one part.
- `formats_columns_nullable`: `SELECT * ... LIMIT 1000` read 6-10 ms, and parallel parsing parsed a varying amount ahead before the LIMIT cancelled it (`LIMIT 30000` of CSV took 197 ms with it and 38 ms without). Disable parallel parsing for that query and read 100000 rows, about 200 ms for text formats.
- `serialization_pool_lookup`: the fixed `max_threads = 16` oversubscribed the 8 pinned cores of the amd runners; query 0 was flagged in 9.3% of amd master runs against 0.4% on arm. Use the harness default of one thread per pinned CPU.

Master flag rates over 14 days (slower/faster/unstable share of master runs): `and_compare_chain_derived #2` 5-8%, `set_index #0` 14% (arm), `formats_columns_nullable #1` 19% (arm), `serialization_pool_lookup #0` 9% (amd).
pull Bot pushed a commit that referenced this pull request Sep 27, 2026
Query #0 groups 5M rows by a single-type Dynamic key. For every row the
aggregation looks up the variant's default serialization in
SerializationObjectPool: a shared lock on the key's shard mutex,
weak_ptr::lock, and the release of the returned SerializationPtr. These
are atomic read-modify-writes on two cache lines that every aggregation
thread writes for every row. One key means one shard, so the pool's
sharding cannot spread the load, and the query is bound by how fast those
lines move between cores. That speed is fixed per server process.

CI data (query_metric_runs_v1, arm, 1177 runs since 2026-09-17): the 5-7
samples of one server agree within 0.7% (p50), but the per-process medians
span 0.643-0.840 s (p05-p95). Fast and slow processes do the same work
(same arena bytes, memory, two-level hash tables and page faults) and
differ only in user CPU time (9.5 vs 12.1 s). The wall time does not
depend on the thread count: arm 0.754 s with 16 threads vs 0.775 s with
12, amd 0.669 s with 16 threads on 8 pinned cores vs 0.686 s with 8. So
each A/B run compares two random draws of that per-process speed. Runs
whose new/old median moved by more than 15% (raw samples):

                                 arm PR   arm master   amd PR   amd master
    serialization_pool_lookup #0  123/789     54/558    68/176     220/560
    serialization_pool_lookup #1   41/789     11/558     5/176      20/560
    serialization_pool_lookup #2    0/789      0/558     0/176       0/560
    group_by_dynamic_keys #0        0/782      0/559     0/173       0/559

group_by_dynamic_keys #0 runs the same per-row lookup path with
max_threads = 1. On PR ClickHouse#117533 the performance dashboard scored #0 as a
confirmed regression (arm 5/6, 0.670 -> 0.799 s) that the shard's own
report did not flag.

Run #0 in one thread, from numbers instead of numbers_mt, so it times the
pool's hit path itself, which does not depend on the process. Queries #1
(two keys, where sharding spreads the load) and #2 (the multi-threaded
MergeTree read) keep the contention coverage.

Local check on x86 with the official 26.10.1.820 master build, perf.py,
7 runs: old #0 1.76 s with 12 threads (15.4 s user CPU per run), new #0
0.57 s (0.56 s user CPU), same result. Ten fresh servers pinned to 8
cores with max_threads = 8: old #0 per-process medians 0.68-1.08 s; new
#0 0.56-0.58 s in 8 of them and 0.72-0.73 s in the two whose table
fills were also about 25% slower (9.2-10.0 s vs 7.4-8.6 s).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pull Bot pushed a commit that referenced this pull request Sep 27, 2026
Pointing `contrib/nlohmann-json` at the ClickHouse fork makes the copy of
`nlohmann::json` that `ai-sdk-cpp` vendors in
`third_party/nlohmann_json_patched` an ODR violation rather than a duplicate.
Both are version 3.12.0, so both define the same `nlohmann::json_abi_v3_12_0`
symbols, and the two definitions no longer match: the fork holds a
`number_buffer` member in `lexer` that the vendored copy has no field for, and
drops the `decimal_point_char` the vendored copy keeps, so the fork's `parser`
is the larger of the two. The linker resolves this by keeping one definition of
each symbol, so a `parser` laid out by the vendored header is handed to a
`parse` compiled from the fork header, which reads and destroys members past
the end of it.

In a sanitizer build this aborts on the first response of a model, which is how
it was found - every AI client test of
ClickHouse#114043 failed this way:

    ERROR: AddressSanitizer: stack-buffer-overflow
        #0 nlohmann::json_abi_v3_12_0::detail::parser<...>::parse(...)
             contrib/nlohmann-json/single_include/nlohmann/json.hpp:13073
        #1 nlohmann::json_abi_v3_12_0::basic_json<...>::parse<...>(...)
             contrib/ai-sdk-cpp/third_party/nlohmann_json_patched/include/nlohmann/json.hpp:4053
        #2 ai::providers::BaseProviderClient::generate_text_single_step(...)
      [32, 232) 'ref.tmp' (line 4053) <== Memory access at offset 240 overflows this variable

and the `MemorySanitizer` build reports the same defect from the other side,
the `lexer` destructor of that call destroying a `std::string` that was never
constructed. In a release build the same code reads and writes past the end of
a stack object without anything catching it, on the path of the `??` command of
the client and of the server-side `aiGenerate` function.

Nothing on this branch drives a model, which is why its own CI does not show
this, so the fix goes here rather than only in the pull request that found it:
this branch is the one that introduces the second definition.

Build `ai-sdk-cpp` against `contrib/nlohmann-json` instead, so there is one.
The vendored copy exists to keep the number parsing away from the locale, which
the fork does properly, so there is nothing left to keep it for.
`nlohmann-json` is now added unconditionally rather than only for
`google-cloud-cpp` - the two are enabled independently of each other - and its
include directory is marked as a system one, because it now reaches
ClickHouse's own translation units through `ai-sdk-cpp`.

Co-Authored-By: Claude Opus 5 (1M context) <[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
…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