Skip to content

Randomize materialize_statistics_on_insert in clickhouse-test - #108511

Merged
vdimir merged 6 commits into
masterfrom
vdimir/randomize_materialize_statistics_on_insert
Jul 3, 2026
Merged

vdimir merged 6 commits into
masterfrom
vdimir/randomize_materialize_statistics_on_insert

Conversation

@vdimir

@vdimir vdimir commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Version info

  • Merged into: 26.7.1.495 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [10a0cbb]

Summary: ✅


AI Review

Summary

This PR adds materialize_statistics_on_insert to stateless random settings and then pins a set of plan- and layout-sensitive tests back to 0 or disables statistics usage where needed. Those targeted test fixes are reasonable, but the core generator change still inverts a production-default write setting for almost the entire suite, so I would not approve it as-is.

Findings

⚠️ Majors

  • [tests/clickhouse-test:1558] materialize_statistics_on_insert now becomes true in about 95% of randomized runs even though the production default is 0, and that default was flipped specifically to avoid eager statistics builds on ordinary INSERTs. The added per-test pins only repair a handful of deterministic tests; they do not address the broader contract change that stateless randomization now mostly stops exercising the default delayed-materialization path and makes insert-heavy tests pay extra write-time work and on-disk-layout churn for a non-default mode. Suggested fix: randomize this like other default-false toggles (random.random() < ...), or move the eager path behind an explicit opt-in bucket/tag instead of making it the suite-wide near-default.
Final Verdict

⚠️ Needs changes.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 25, 2026
Comment thread tests/clickhouse-test
"enable_optimize_predicate_expression_to_final_subquery": lambda: random.random() > 0.05,
"enable_software_prefetch_in_aggregation": lambda: random.random() > 0.05,
"allow_reorder_prewhere_conditions": lambda: random.random() > 0.05,
"materialize_statistics_on_insert": lambda: random.random() > 0.05,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

materialize_statistics_on_insert currently defaults to 0; it was changed that way so ordinary INSERT paths avoid eager statistics builds and rely on merges or explicit MATERIALIZE STATISTICS. This generator enables the setting about 95% of the time, so randomized stateless runs mostly stop exercising the production default and make insert-heavy tests pay the eager statistics build cost whenever auto_statistics_types or explicit STATISTICS columns are present. Please keep the probability aligned with the default, for example by flipping this to an occasional non-default path (random.random() < 0.05), or make it an explicitly documented balanced choice if 50/50 coverage is intended.

vdimir and others added 2 commits June 29, 2026 16:16
Randomizing `materialize_statistics_on_insert` (it becomes `true` 95% of
the time) makes freshly-inserted parts carry materialized auto-statistics
(`auto_statistics_types` defaults to `minmax, uniq`), which the optimizer
reads. With the production default (`false`) those statistics are only
built during merges, so test parts had none.

This shifts plan/EXPLAIN output and on-disk layout in several tests:
- a `Statistics` step appears in `EXPLAIN indexes = 1` / JSON explain;
- statistics-informed estimates change join order, prewhere condition
  ordering, and projection-use decisions;
- a `statistics.packed` file appears in the part;
- hypothetical-index `source` flips because real statistics already prune.

No query results change - only plans and metadata.

Pin `materialize_statistics_on_insert = 0` in the affected plan/layout
tests, and disable auto-statistics (`auto_statistics_types = ''`) on the
no-statistics table in `04222_hypothetical_index_statistical`, which
intentionally enables the setting elsewhere.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vdimir
vdimir force-pushed the vdimir/randomize_materialize_statistics_on_insert branch from 36796ab to 2ece445 Compare June 29, 2026 17:09
@vdimir

vdimir commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

@groeneai failure for 03360_bool_remote look interesting, read logs and investigate what have happened and suggest fix so it won't make PRs CI flaky

@groeneai

Copy link
Copy Markdown
Collaborator

@vdimir That 03360_bool_remote failure is a pre-existing trunk flake, not caused by your materialize_statistics_on_insert randomization.

What happened (Stateless tests (arm_binary, parallel), CI report):

Code: 102. DB::Exception: Unexpected packet from server 127.0.0.2:9000
(expected TablesStatusResponse, got ProfileInfo): While executing Remote.
(UNEXPECTED_PACKET_FROM_SERVER)
in query: SELECT materialize(true) AS x FROM remote('127.0.0.{1,2}', system.one) LIMIT 1;

This is the known connection-pool desync: a pooled connection is returned out of sync, so the next query on it reads a leftover ProfileInfo packet where it expects TablesStatusResponse. It is a recurrence of #93018 / #93029 (the cancelled-query early-return in RemoteQueryExecutor::finish), and the whole Code 102 family across distributed tests converges on it.

Why your PR is not to blame:

  • 03360_bool_remote does no INSERT and creates no table with STATISTICS columns, so materialize_statistics_on_insert has no effect on it. The three queries are pure SELECT ... FROM remote('127.0.0.{1,2}', system.one).
  • The check's own randomized-settings diagnosis: 214 reruns with the same randomized settings, 0 failed ("not reproducible, likely transient") which points at a connection-layer race, not a settings or test-logic bug.

Fix is already in flight: #108854 (Fix flaky distributed query "Unexpected packet from server ...") makes ConnectionEstablisher::run retry packet-type-agnostically. Once it merges, 03360 stops failing. So no 03360-specific change is needed in this PR.

@KochetovNicolai
KochetovNicolai added this pull request to the merge queue Jul 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jul 3, 2026
@vdimir
vdimir enabled auto-merge July 3, 2026 13:02
@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.91% 85.93% +0.01%
Functions 91.53% 91.53% +0.00%
Branches 78.46% 78.50% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 96 line(s), 36 function(s) across 37 file(s) · Details

Top files
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesLinearRegression.h: 14 line(s), 32 function(s)
  • src/Processors/Transforms/BufferedShardByHashTransform.cpp: 8 line(s)
  • src/AggregateFunctions/AggregateFunctionSumMap.cpp: 6 line(s), 1 function(s)
  • src/Functions/dynamicElement.cpp: 6 line(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 5 line(s)

Full report

@vdimir
vdimir added this pull request to the merge queue Jul 3, 2026
Merged via the queue into master with commit c64875d Jul 3, 2026
174 checks passed
@vdimir
vdimir deleted the vdimir/randomize_materialize_statistics_on_insert branch July 3, 2026 17:14
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 3, 2026
pull Bot pushed a commit to stnxo2023/ClickHouse that referenced this pull request Jul 15, 2026
A PR's green CI describes the master of its last run, not of its merge.
PR ClickHouse#108548 merged on 2026-07-13 with CI last run on 07-01; on 07-03
master merged ClickHouse#108511, which added materialize_statistics_on_insert to
the settings randomizer in tests/clickhouse-test. The PR's new test
02346_text_index_bug108519_qcc_skip_index then failed on master whenever
the randomized setting was drawn (~40% of runs) and kept master red for
~7 hours until ClickHouse#110260 pinned auto_statistics_types at the table level.

The merge queue already builds the exact merged state (Build
(amd_binary)) but ran no stateless tests on it. Add "Stateless tests
(amd_binary, flaky check)" to MergeQueueCI: it reruns the PR's
new/changed stateless tests on the merge group state (the PR merged with
the current master), so a semantic conflict with post-CI master changes
bounces the PR from the queue instead of breaking master. The job
self-skips when the PR changes no tests.

Merge-queue runs use a reduced budget (20 iterations / 20 min instead of
50 iterations / 45 min): the PR CI already ran the full flaky check, and
a randomized setting drawn with probability 0.4 per run escapes 20
iterations with probability 0.6^20 ~= 4e-5.

Changed-file detection in merge-queue runs now uses the linked PR's
paginated files list (PR_NUMBER is 0 there, and the commits API caps a
merge commit's file list at 300 entries), and the changed-files fetch
fails closed in merge-queue runs so a GitHub API failure cannot silently
skip the check.

Incident: ClickHouse#108548
Follow-up fix it required: ClickHouse#110260

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…_materialize_statistics_on_insert

Randomize materialize_statistics_on_insert in clickhouse-test
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
A PR's green CI describes the master of its last run, not of its merge.
PR ClickHouse#108548 merged on 2026-07-13 with CI last run on 07-01; on 07-03
master merged ClickHouse#108511, which added materialize_statistics_on_insert to
the settings randomizer in tests/clickhouse-test. The PR's new test
02346_text_index_bug108519_qcc_skip_index then failed on master whenever
the randomized setting was drawn (~40% of runs) and kept master red for
~7 hours until ClickHouse#110260 pinned auto_statistics_types at the table level.

The merge queue already builds the exact merged state (Build
(amd_binary)) but ran no stateless tests on it. Add "Stateless tests
(amd_binary, flaky check)" to MergeQueueCI: it reruns the PR's
new/changed stateless tests on the merge group state (the PR merged with
the current master), so a semantic conflict with post-CI master changes
bounces the PR from the queue instead of breaking master. The job
self-skips when the PR changes no tests.

Merge-queue runs use a reduced budget (20 iterations / 20 min instead of
50 iterations / 45 min): the PR CI already ran the full flaky check, and
a randomized setting drawn with probability 0.4 per run escapes 20
iterations with probability 0.6^20 ~= 4e-5.

Changed-file detection in merge-queue runs now uses the linked PR's
paginated files list (PR_NUMBER is 0 there, and the commits API caps a
merge commit's file list at 300 entries), and the changed-files fetch
fails closed in merge-queue runs so a GitHub API failure cannot silently
skip the check.

Incident: ClickHouse#108548
Follow-up fix it required: ClickHouse#110260

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

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants