Skip to content

Fix flaky test 04011_predicate_statistics_log with small randomized index_granularity_bytes - #128769

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04011-predicate-statistics-log-index-granularity-bytes
Nov 3, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04011-predicate-statistics-log-index-granularity-bytes

Conversation

@groeneai

@groeneai groeneai commented Nov 2, 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):

The test 04011_predicate_statistics_log now keeps the randomized index_granularity_bytes at its default or above, so the 8192-row granules its Q6 consistency check relies on are not shrunk by the runner.

Description

Failing job: Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel), https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=124859&sha=755db441f8c998cc203a5e01aed832ff2b01feac&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 (the runner's own diagnosis: 36/36 fail with the drawn settings, 37/37 pass without, culprit --index_granularity_bytes 116964). No related open issue found.

Q6 checks that total_selectivity rounds to the same value on every system.predicate_statistics_log row of the query. Those rows are emitted per MergeTreeSelectProcessor, so each one carries its own reader's selectivity. The table pins index_granularity = 8192 but not index_granularity_bytes, which the runner randomizes down to 1 KiB. With 116964 the part gets 48 granules of 2083 rows and a 16-row last granule. On remote storage the read is split across readers, and under parallel replicas one reader gets only that granule and logs 1/16 = 0.06 instead of 0.03, so Q6 prints 0 1.

The fix adds Random settings limits: index_granularity_bytes=(10485760, None): the engine default as a lower bound, randomized above it. Granules stay 8192 rows, the shortest reader share is the 1696-row tail, and every share rounds to 0.03. The queries and the reference are unchanged.

Validation (debug build, s3-backed server with the CI parallel-replicas profile):

  • old file with index_granularity_bytes = 116964: 40/40 fail with exactly the CI diff, at both parallel_replicas_local_plan values;
  • runner forced to draw 116964: the new file passes 40/40 and the logged CREATE shows the value raised to 10485760; with the limits line misspelt it fails 40/40;
  • 50/50 randomized runs pass on s3 with parallel replicas, on local disk with parallel replicas, and in the default lane, every draw at or above the floor.

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

Version info

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

…arity_bytes

Q6 compares `total_selectivity` across `system.predicate_statistics_log`
rows. Those rows are emitted per `MergeTreeSelectProcessor`, so each one
carries its own reader's selectivity. The table pins
`index_granularity = 8192` but not `index_granularity_bytes`, which the
runner randomizes down to 1 KiB. With 116964 the part gets 48 granules of
2083 rows and a 16-row last granule. On remote storage the read is split
across readers, and under parallel replicas one reader gets only that
granule and logs 1/16 = 0.06 instead of 0.03, so Q6 prints `0 1`
(Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)).

Floor `index_granularity_bytes` at its engine default with a per-setting
random settings limit. Granules stay 8192 rows, the shortest reader share
is the 1696-row tail and rounds to 0.03 like every other share. Values
above the floor are still randomized; queries and reference are unchanged.

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

groeneai commented Nov 2, 2026

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

Own cold review + Gate B (codex) on b5c41f6d2c7b7: 0 blockers, 0 majors, 2 nits, both agreed.

Finding Verdict
💡 Failing-job link lacked the check name parameter AGREE, fixed in the PR description
💡 Comment should write total_selectivity as inline code AGREE, nit, left as is (comment formatting only, no behaviour change)

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b5c41f6]

Summary: ✅


AI Review

Summary

Reviewed PR head b5c41f6d2c7b708218218401651fd1ad941572f1. The change sets a 10 MiB lower bound on randomized index_granularity_bytes for 04011_predicate_statistics_log, preventing small adaptive granules from invalidating Q6's comparison of per-reader selectivities. The existing assertions remain intact, and the reported reproduction and repeated validation support the fix. No actionable findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Nov 2, 2026
@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On an s3-backed server with the CI parallel-replicas profile, tests/clickhouse-test 04011_predicate_statistics_log --no-random-settings --merge-tree-settings "--index_granularity_bytes 116964" fails 40/40 (both parallel_replicas_local_plan values) with exactly the CI diff (q6 1 1 -> 0 1). Local disk does not reproduce: the 100000-row read stays below merge_tree_min_rows_for_concurrent_read, so one reader reads it all.
b Root cause explained? Q6 compares total_selectivity across predicate_statistics_log rows, which are emitted per reader. An unpinned small index_granularity_bytes leaves a 16-row last granule (48 x 2083 + 16); a reader whose whole share is that granule logs 1/16 = 0.06 instead of 0.03.
c Fix matches root cause? Yes. The test already pins 8192-row granules via index_granularity; the per-setting floor index_granularity_bytes=(10485760, None) stops adaptive granularity from undercutting that pin. Not a blanket tag, Q6 unchanged.
d Test intent preserved / new tests added? Yes. Queries and reference unchanged; index_granularity_bytes is still randomized above 10 MiB, all other settings stay randomized. Test-only fix.
e Both directions demonstrated? Yes. Runner forced to draw 116964: new file 40/40 OK (logged CREATE shows 10485760), same file with the limits line misspelt 40/40 FAIL. Clamp also verified with the normal randomizer plus a misspelt-prefix negative control. 50/50 randomized runs pass on three topologies.
f Fix is general across code paths? N/A (flaky test fix). The other assertions in the file aggregate with sums or bounds and do not depend on the split; no other test reads this log.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test fix). Other granule-shrinking MergeTree settings are already pinned by the table (index_granularity, min_bytes_for_wide_part); use_const_adaptive_granularity gives 8192 rows above the floor.
h Backward compatible? (maintainer-approved exception only) N/A (test-only change).
i Invariants and contracts preserved? N/A (no source change). The test's own precondition, every reader share large enough to round to the table's selectivity, now holds for every draw.

Session id: cron:clickhouse-impl-slot-6:20261102-205400

@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @yariks5s, could you review this and add the can be tested label so CI runs? Q6 compares total_selectivity across per-reader rows, and a randomized small index_granularity_bytes leaves a 16-row last granule whose reader logs 0.06 instead of 0.03, so the test now clamps index_granularity_bytes to the 10 MiB default or above.

@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 2, 2026
@yariks5s yariks5s self-assigned this Nov 2, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 3, 2026
Merged via the queue into ClickHouse:master with commit bb247ca Nov 3, 2026
354 of 355 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 3, 2026
@clickhouse-gh clickhouse-gh Bot added comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). 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-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). 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.

4 participants