Skip to content

Pin away the statistics randomization in 05182 - #120084

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-05182-auto-statistics
Sep 15, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-05182-auto-statistics

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

05182_join_order_conflict_detector_cast_null_propagation asserts a join plan shape, and it makes t1 look expensive through param__internal_join_table_stat_hints to get the reordering it wants to observe. A table that carries automatic statistics without basic gets the optimizer an estimate of its own, which costs the join the other way, so both reassociation arms - the non-vacuity controls of the test - stop reassociating. Every row arm and every exception arm still agrees, which is why only the plan half of the reference differs.

clickhouse-test randomizes auto_statistics_types to a random subset of uniq, uniq_v2, tdigest, countmin, basic, so a run reddens whenever the subset leaves basic out. Measured against master 7fe32951 with clickhouse local:

auto_statistics_types plan
'', basic, basic,uniq, basic,tdigest, basic,countmin, basic, uniq_v2 (the default), all five the one the reference records
uniq, uniq_v2, tdigest, countmin, uniq_v2,tdigest, countmin,uniq_v2,tdigest (the value CI reported) the reassociation arms flip to left-deep

Creating the tables with auto_statistics_types = '' pins it. With this change the whole test output matches its reference and the three CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN arms still raise; with the randomized value the same binary reproduces the CI failure exactly.

The test only became reachable this way when #119305 re-landed the OUTER-to-INNER conversion, which is what makes these joins reorderable at all. CIDB: 0 failures in 12428 runs over 1267 commits before a88f878d7, 26 failures in 506 runs over 120 commits after it. A report on master: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=a88f878d7c1350301bc015fc06e7d356ee90e487&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_release%2C%20parallel%2C%202%2F2%29

One observation for the join-order owners that this change does not address: a table with statistics but without basic estimates worse than a table with no statistics at all, and that estimate outranks an explicit cardinality passed in param__internal_join_table_stat_hints.

Related: #119305
Related: #119512

Changelog category (leave one):

  • CI Fix or Improvement

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

Not required.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/120084]

Version info

  • Merged into: 26.9.1.1502 (included in 26.9 and later)

`05182_join_order_conflict_detector_cast_null_propagation` asserts a join plan shape, and it makes
`t1` look expensive through `param__internal_join_table_stat_hints` to get the reordering it wants to
observe. When the table carries automatic statistics that do not include `basic`, the optimizer has
its own estimate, costs the join the other way, and both reassociation arms - the non-vacuity
controls - stop reassociating, so the test fails on the plan lines while every row and exception arm
still agrees.

`clickhouse-test` randomizes `auto_statistics_types` to a random subset of
`uniq, uniq_v2, tdigest, countmin, basic`, so a run reddens whenever the subset leaves `basic` out.
Measured against master `7fe32951` with `clickhouse local`: `uniq` alone, `uniq_v2` alone, `tdigest`
alone, `countmin` alone and `uniq_v2,tdigest` all flip the plan, while `''`, `basic`, `basic,uniq`,
`basic,tdigest`, `basic,countmin`, `basic, uniq_v2` (the default) and the full set of five keep the
plan the reference records. Creating the tables with `auto_statistics_types = ''` pins it: the whole
test output then matches its reference, and the three `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN` arms
still raise.

The test only became reachable this way when #119305
re-landed the OUTER-to-INNER conversion, which is what makes these joins reorderable at all: CIDB has
0 failures in 12428 runs over 1267 commits before `a88f878d7`, and 26 in 506 runs over 120 commits
after it.

Caused by: #119305

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [637a0e6]

Summary: ✅


AI Review

Summary

This PR pins auto_statistics_types = '' on the temporary MergeTree tables in 05182_join_order_conflict_detector_cast_null_propagation, which is the right way to keep that plan-shape test from inheriting randomized column statistics from clickhouse-test. I did not find a correctness, coverage, or PR-metadata problem in the current patch, and the referenced PR CI run is all green.

Final Verdict

✅ No review findings.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Stress test (arm_msan) here is unrelated to this change, which only adds a table setting to one stateless test: the hung check fired on a different test that happens to share the number prefix, 05182_json_empty_streams_not_prefetched. Its INSERT INTO ... t_json_empty_streams_prefetch SELECT ... CAST(concat(...), 'JSON') FROM numbers(65537) sat in the processlist for 789 s with is_cancelled: 1, 65409 of 65537 rows written and 25 MB of memory - a cancelled query that never finished, not a deadlock reached through anything in this pull request.

The hung check is failing fleet-wide independently of any change: 8 failures in the last 30 hours, 4 of them on master itself (arm_debug, arm_msan, arm_asan_ubsan, arm_asan_ubsan, s3). Log: https://s3.amazonaws.com/clickhouse-test-reports/PRs/120084/637a0e6852ff976b0ff60cf5b33b6c25c69b4a89/pr/stress_test_arm_msan/hung_check.log

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120084&sha=637a0e6852ff976b0ff60cf5b33b6c25c69b4a89&name_0=PR&name_1=Stress%20test%20(arm_msan) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

The hung INSERT sits in the one writer phase that has no cancellation point. Its single working thread:

MergeTreeSink::consume -> MergeTreeDataWriter::writeTempPart -> MergedBlockOutputStream::writeWithPermutation
  -> MergeTreeDataPartWriterWide::writeColumn -> getCurrentMarksForColumn
  -> SerializationObject/Dynamic/Variant::enumerateStreams -> ~Substream
  -> __msan::PoisonMemory -> StackDepotBase::Put

The for (const auto & granule : granules) loop in writeColumn polls nothing, so cancellation is only observed between blocks and the block already in flight runs to its end.

numbers(65537) is not the test's own literal: at 637a0e6 the test inserts FROM numbers(5), and the master run at 1f59f0fc got FROM numbers(2147483646). The stress fuzzer substitutes it, and the table's own DDL pins index_granularity = 1 with min_rows_for_wide_part = 0, so a single 65409-row block means 65409 getCurrentMarksForColumn calls, each walking the whole JSON substream tree, each Substream destructor going through the MSan stack depot. That is why this test is the carrier on the sanitizer builds: the uninterruptible phase lasts minutes instead of milliseconds.

The fix is already in progress. #108357 adds checkWriteCancellation() as the first statement of exactly that granule loop, and in MergeTreeDataPartWriterCompact::writeDataBlock plus the whole-column phases that run before the loop. The symbol does not exist anywhere at 637a0e6, and #108357 is the only pull request that introduces it, so I am not opening a duplicate.

On the fleet-wide count: pull_request_number = 0 also matches ReleaseBranchCI. For 2026-09-13 17:32 to 2026-09-14 23:32 that query returns 25 rows, 15 of them at pull_request_number = 0, and only 2 with head_ref = 'master'; 11 of the remaining 13 are 26.6. I read both master logs:

So both master hits in that window have an owner, and neither is reachable from this pull request.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 15, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 15, 2026
@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Sep 15, 2026
Merged via the queue into master with commit 2615840 Sep 15, 2026
347 of 348 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-05182-auto-statistics branch September 15, 2026 03:57
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 15, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 15, 2026
…d-codes-require-lazy

Pick up ClickHouse#120084, which pins the randomized `auto_statistics_types` away in
`05182_join_order_conflict_detector_cast_null_propagation`. That test is the
sole failure in this branch's `Stateless tests (arm_binary, parallel)` run and
is unrelated to this change, so the run needs the fix to be able to go green.

Co-Authored-By: Claude Opus 5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 15, 2026
qoega added a commit to qoega/ClickHouse that referenced this pull request Sep 15, 2026
Bring in the statistics-randomization fix for `05182` and refresh CI.
Preserve the existing profile-counter feature diff without modification.

Related: ClickHouse#118532
Related: ClickHouse#120084
harikrishnan94 added a commit that referenced this pull request Sep 15, 2026
The branch was 542 commits behind and CI kept failing on two tests that master
has already dealt with: `05182_join_order_conflict_detector_cast_null_propagation`
pinned away the statistics randomization in #120084, and the `plus`/`minus`
injectivity that made `03710_analyzer_limit_by_aggregate_validation` fail was
reverted in #120118. Re-running could not pick either up, because a re-run
rebuilds the merge ref computed when the run was created.

Related: #120167
Related: #120151

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... pr-ci 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.

3 participants