Repository navigation
Answer sum, avg and sumCount from per-part statistics - #123950
alexey-milovidov merged 29 commits into
Conversation
…m-lowlevel-pattern-audit-2026-09-19 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [7e2be7b] Summary: ❌
AI ReviewSummaryThe PR answers unfiltered Final VerdictStatus: ✅ Approve. No unresolved findings. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes162 object files changed (+1.09 MiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units644 translation units recompiled, 5610 s compile time in total, 644 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: No query changes in a way this PR can explain. The one flagged query, clickbench Q16, measured +12.8% (598 ms vs 530 ms), but that is inside master's own recent range of 519-669 ms, so it stays a non-directional not_sure. The suppression is consistent with the diff: the new path that answers sum/avg/sumCount and count(column) from per-part statistics only runs for aggregations with no GROUP BY and no filter, and Q16 has a GROUP BY, so it still goes through normal aggregation. Two of the PR's clickbench runs shared the same machine, which adds run-to-run variance and fits this small shift, and nothing here looks like a real effect of the change. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
# Conflicts: # tests/queries/0_stateless/05029_columns_cache_comment_keeps_cache.sql # tests/queries/0_stateless/05136_columns_cache_part_removal_invalidation.sh
…m-lowlevel-pattern-audit-2026-09-19 # Conflicts: # src/Processors/QueryPlan/Optimizations/optimizeUseAggregateProjection.cpp # src/Storages/MergeTree/IMergeTreeDataPart.cpp # src/Storages/MergeTree/IMergeTreeDataPart.h # src/Storages/Statistics/tests/gtest_stats.cpp # tests/queries/0_stateless/05029_columns_cache_comment_keeps_cache.sql # tests/queries/0_stateless/05136_columns_cache_part_removal_invalidation.sh
… of github.com:ClickHouse/ClickHouse into small-perf-wins-from-lowlevel-pattern-audit-2026-09-19 # Conflicts: # tests/queries/0_stateless/05136_columns_cache_part_removal_invalidation.sh
…it in tests that check reading
…m-lowlevel-pattern-audit-2026-09-19
|
Yes, it should be ignored. |
…emory check` `IMergeTreeDataPart` keeps an `Estimates` map with an `Estimate` per column per part. An inline `std::optional<Field>` grew `Estimate` from 208 to 272 bytes and moved every hash node from the 256-byte to the 320-byte jemalloc size class, even for columns without a sum: +640,000 bytes in `07_many_parts.sql` (1000 parts x 10 columns). `OptionalFieldPtr` takes 8 bytes inline (the node is 256 bytes again) and allocates the `Field` only for the columns that have a sum. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123950&sha=ff22f2472b232cb00b502e76eab576a73fe4a429&name_0=PR&name_1=Storage%20memory%20check #123950 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…torage memory check`" This reverts commit 9e032bc per review: accept the `Storage memory check` difference instead. #123950 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous run skipped the full CI suite because of an unresolved review thread. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Storage memory check` fails a pull request whose memory increase is intended, which blocks `Mergeable Check`: ClickHouse#123950 keeps a new statistic per part, so `07_many_parts.sql` grows by 640,056 bytes (5.5%). With the `ci-storage-memory-increase-ok` label, a scenario over the threshold is reported OK and the job passes; without it, the failing scenario says how to allow it. As for `ci-relocation-headroom-ok`, a success that only the label allowed is not cached, and a private sync pull request reads the label from `upstream_pr_labels`. The HTML report still shows the increase. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#123950 (merged with master in 21e71b8), `SELECT sum(id)` over the web disk table is answered from the per-part `basic` statistics. The statistics are loaded by the first query and kept in memory, so the query after `http_forbid_headers` forbids `Authorization` sent no HTTP request and `test_userinfo_with_forbidden_authorization` failed with "Client expected to be failed but succeeded". A filter disables that optimization, so every query reads `id` from the web server again. The query needs no new setting, so the test stays the same on release branches that do not have `use_statistics_for_sum_avg_aggregation`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_small_read_streams_columns_cache` After merging `master`, `sum(k)` is answered from per-part statistics (#123950), so `EXPLAIN PIPELINE` no longer contains `MergeTreeSelect` and the test failed in the Fast test: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123890&sha=9ac96b189b524ed4582f6520a99a25a157b973f0&name_0=PR&name_1=Fast%20test Related: #123890 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #123950 `SELECT sum(x)` is answered from the `basic` statistics of the part with `use_statistics_for_sum_avg_aggregation`, so the query did not read the column through the userspace page cache any more: `05569_ubsan_unsigned_overflow_review_cases_7` returned `4950` instead of `INVALID_SETTING_VALUE`, and `05508_ubsan_unsigned_overflow_review_cases_6` passed without exercising the huge `page_cache_lookahead_blocks`. Disable the setting in both, as #123950 did for the other page cache tests. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120906&sha=13dbf235e9be8f7884d7b189970551437ff17fb1&name_0=PR&name_1=Stateless%20tests%20(amd_debug%2C%20flaky%20check) #120906 Related: #123950 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #123950, `sum(k)` can come from `basic` statistics, so the queries read nothing.
…part files after the upgrade After the restart, the upgraded server executes a MERGE_PARTS or MUTATE_PART entry whose result the other replica already committed under the previous release. checkPartChecksumsAndCommit compares the new part with the ZooKeeper part header written by the old release. Releases change the byte format of uncompressed part files: statistics.packed is registered with file_hash only, so it lands in the "hash of uncompressed files" bucket, and its content changed in 26.7 (auto_statistics_types default) and in 26.11 (ClickHouse#123950 adds the sum to basic statistics). The task then logs CHECKSUM_DOESNT_MATCH at error level, removes the local part and fetches the replica's part. The upgrade guide (docs/guides/oss/update.mdx) documents this message as expected while replica versions differ, and the statistics author confirmed it on ClickHouse#130674, but the post-upgrade log scan treated it as a failure. Filter the line only when "hash of uncompressed files doesn't match" is the sole clause. Divergent column data ("uncompressed hash of compressed files"), both clauses together, a different number of files and the KILL MUTATION "different columns hash" case still fail the job. The Upgrade check is the only CI job that reports these lines (the stress tests scan only "<Error>.*Application"), so a broader filter on "is not byte-identical to data on another replicas" would remove the only CI detector of divergent column data after replicated merges and mutations. Validated by running the extracted scan on the Upgrade check log of ClickHouse#130547 (1 line -> 0) and on 7 control lines (7 -> 5, every other shape kept), with GNU grep 3.11 locally and inside clickhouse/stress-test. Changing "Code: 40" to "Code: 41" in the new pattern restores both results. Related: ClickHouse#103395 Related: ClickHouse#130674 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ections with parallel replicas The aggregate and normal projection optimizers decided whether a coordinated read is the initiator's own share (and so must return what a projection or a prepared source answers) from `QueryPlanOptimizationSettings::is_parallel_replicas_initiator_with_projection_support`, computed once from the context the whole plan is optimized with. The initiator's local plan is optimized with a copy of the OUTER settings, so when parallel replicas are enabled only in a subquery's SETTINGS the flag is false there: the initiator emitted a NullSource for the `_minmax_count_projection`, `_statistics_projection` and `_exact_count_projection` blocks and skipped the projection read beside parts without the projection, while the followers do the same by design. `min`/`max`/`count` came back as 0 (since ClickHouse#82807), `sum`/`avg` as 0/nan (since ClickHouse#123950), and projection-answered rows were dropped. Use `ReadFromMergeTree::isParallelReplicasLocalPlanForInitiator()`, which reads the read's own context and is already used by the same code for the empty-ranges announcement (and its follower twin for the follower failpoints), and remove the plan-wide field. For a query whose outer and subquery contexts agree the answer is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
basicstatistics now keep exact sums of integer/Decimalcolumns, sosum,avg,sumCountwithoutGROUP BY/filters read only parts lacking them. ClickBenchcreate.sqlminusauto_statistics_types = '', loaded with this PR: Q2, Q3 are instant (1 ms vs 16-22 ms), Q29 2x faster.Setting
use_statistics_for_sum_avg_aggregation(off withcompatibility< 26.11); needsbasicstatistics.Design: sum is a trailing
basicfield (old readers skip it) insum's accumulator type and wraparound; states viadeserialize; merges backfill old parts.Downsides: not stored for
Nullable/LowCardinality; pseudo-projection renamed_statistics_projection; mixed-version replicas fetch merged parts.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
sum,avgandsumCountof integer andDecimalcolumns withoutGROUP BYand filters are now answered frombasiccolumn statistics without reading the data, and so iscount(column)in such queries. Controlled by the new settinguse_statistics_for_sum_avg_aggregation(enabled by default). Parts written by older versions get the sum on their next merge.Workflow [PR]
Sync PR [sync-upstream/pr/123950]
Version info
26.11.1.1791-master(included in26.11and later)