Skip to content

Fix flaky test 04502_autopr_input_bytes_estimation_window_function under randomized sparse serialization - #125877

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04502-autopr-sparse-serialization
Oct 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04502-autopr-sparse-serialization

Conversation

@groeneai

@groeneai groeneai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Requested in #125131 (comment). Failing run: Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 2/2), where 04502_autopr_window_function_query_plan_based printed 0 and the rerun with the same settings failed 19/46.

The failing check is the Output <= 2 * Input bound, not a zero. The harness randomizes ratio_of_defaults_for_sparse_serialization, and that job drew 0. key and value each hold one default, so both were stored Sparse. The output estimate sums byteSize() of the ColumnSparse chunk (values plus offsets) but divides by a compression ratio measured on the Native-serialized Sparse sample, so the same rows are priced about 1.7x higher than dense ones (OutputChunk bytes=33.0M vs 17.0M for 1M rows). Which chunks get sampled varies run to run, so Output/Input ranged 1.28-2.21 in that job and both arms crossed 2x. Dense columns stay at 0.21-1.24 in every configuration I tried.

The change pins ratio_of_defaults_for_sparse_serialization = 1.0 on the test's only table, the same pin as the autopr statistics tests in #122570. The explicit table setting wins over the randomized one. .reference is unchanged.

Validation, local, with that job's own settings blobs and server codec ZSTD(3): unfixed 4/200 and 2/200 failures (Output/Input up to 2.14); fixed 200/200 on two builds (max 1.13), 50/50 randomized under each server codec LZ4 / ZSTD(1) / ZSTD(3), and 100/100 with --replicated-database.

The Sparse inflation of the output estimate itself is not changed here: I measured no user-visible consequence of it.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.38-master (included in 26.11 and later)

…function

The `output_measured_above_read` check failed on the `Output <= 2 * Input`
bound. The test harness randomizes the MergeTree setting
`ratio_of_defaults_for_sparse_serialization`, and 30% of draws are 0. `key` and
`value` each hold one default, so with 0 both columns are stored Sparse. The
runtime output estimate then sums `byteSize()` of the `ColumnSparse` chunk
(values plus offsets, ~16 bytes per row per column) but divides it by a
compression ratio measured on the Native-serialized Sparse sample (~9 bytes per
row per column), so the same rows are priced ~1.7x higher than dense ones
(33 vs 17 bytes per row for the bare-scan output). Which chunks the 1-in-5
sampler hits varies, so Output/Input ranged 1.28-2.21 in the failing job
(rerun 19/46 failed) and either arm could cross 2x, while dense columns stay at
0.21-1.24.

Pin `ratio_of_defaults_for_sparse_serialization = 1.0` on the test's only
table. An explicit table setting is never overridden by the randomized one
(`ClientBase::addMergeTreeSettings` adds only absent settings), also under an
explicit `--merge-tree-settings` replay.

Locally, with the failing job's own settings blobs and server codec ZSTD(3):
unfixed 4/200 and 2/200 failures (ratio up to 2.14), fixed 200/200 on two
builds (max 1.13), 50/50 randomized under LZ4, ZSTD(1) and ZSTD(3), and
100/100 with `--replicated-database`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus a separate cold review of the diff (0 findings).

No findings to adjudicate.

Session id: cron:clickhouse-review-slot-9:20261014-205200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Trigger isolated: ratio_of_defaults_for_sparse_serialization = 0 (flipping only it to 1 in the failing job's blobs: 0/50, max Output/Input 1.125). With it every run is shifted to >= 1.27x, and the runner with the job's own blobs fails 2/50 and 4/200 locally with the exact CI diff on either arm (the 2x crossing depends on which chunks the 1-in-5 sampler hits).
b Root cause explained? Zero sparse ratio -> key/value stored Sparse -> output estimate sums ColumnSparse::byteSize() but divides by a ratio measured on the Native Sparse sample, about 1.7x too high (33 vs 17 bytes per row) -> sampling noise pushes it past Output <= 2 * Input.
c Fix matches root cause? Yes: pins the table dense, removing the layout the bound does not cover; no bound widened, no blanket tag.
d Test intent preserved / new tests added? All three oracles unchanged and passing; the 2x bound still discriminates on dense columns (0.21-1.24). Test-only change.
e Both directions demonstrated? Unfixed: 2/50, 4/200, 2/200 FAIL (ratio up to 2.14). Fixed: 200/200 on the master snapshot and on a HEAD build (max 1.13).
f Fix is general across code paths? The one table feeds all three oracles, both the query-based and plan-based arms.
g Fix generalizes across inputs (params/datatypes/wrappers)? 50/50 randomized under server codecs LZ4, ZSTD(1), ZSTD(3); --no-random-settings, --no-random-merge-tree-settings, --replicated-database all green.
h Backward compatible? (maintainer-approved exception only) N/A (test-only).
i Invariants and contracts preserved? .reference, schema and data unchanged; the logged CREATE shows the pinned 1. in 200/200 runs even with a blob that says 0.0.

Session id: cron:clickhouse-impl-slot-5:20261014-202100

@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [817f5b1]

Summary: ✅


AI Review

Summary

PR #125877 stabilizes 04502_autopr_input_bytes_estimation_window_function by pinning ratio_of_defaults_for_sparse_serialization = 1.0 on its table. This keeps the columns dense while preserving the existing dataflow statistics assertions. No actionable findings.

Missing context / blind spots
  • ⚠️ Targeted and flaky-check CI jobs for 817f5b1412f8 remain pending. The affected test passed in Fast test; the author also reports repeated randomized and replicated-database validation in the validation record. Those pending jobs would provide independent confirmation across the remaining CI configurations.
Final Verdict

✅ Approve. No changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nickitat, could you review this and add can be tested? I cannot request a review or add the label right now, so no CI has run. The test pins ratio_of_defaults_for_sparse_serialization = 1.0 on its table (the same pin as in #122570): a randomized 0 stores key/value Sparse, which inflates the output estimate past the Output <= 2 * Input bound.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 14, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 15, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit a21868c Oct 16, 2026
523 of 525 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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

can be tested Allows running workflows for external contributors comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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