Skip to content

Keep 64-row granules in test 05316_top_k_primary_key_skip_query_condition_cache - #126583

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-05316-index-granularity-bytes-clamp
Oct 19, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-05316-index-granularity-bytes-clamp

Conversation

@groeneai

@groeneai groeneai commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125152

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

05316_top_k_primary_key_skip_query_condition_cache printed 1 0 instead of 1 1 (the repeated read was not cheaper) in arm_binary, AsyncInsert, s3 storage, sequential. The runner's own diagnosis: 179/179 failures with the same settings, 194/194 passes without them, culprit the random MergeTree setting index_granularity_bytes = 1538. There is no GitHub issue for it.

The test needs a granule that the first read reads and the PREWHERE then empties: that is what the query condition cache saves the second read. With 64-row granules every 1024-row group of a starts on a granule boundary, so the last granule of each group is read (the primary key cannot bound b there) and has no row within the top-K threshold: 4032 rows, then 2048. With index_granularity_bytes = 1538 the granules are 53 rows and 1024 % 53 != 0, so each such granule also holds the next group's smallest b and nothing read can be dropped: 1749 rows both times, although the cache hits (QueryConditionCacheHits = 1, SelectedMarks 618 -> 33). The engine behaves correctly: the test has not pinned the layout since c155740 dropped index_granularity_bytes = 0.

The test now clamps that one setting with -- Random settings limits: index_granularity_bytes=(100000, None) (64-row granules need about 2 KB; the same clamp as 01780_column_sparse_alter), and keeps the rest of the randomization. Test-only change, reference unchanged.

Validation on a master debug build, with the runner's randomizer forced to draw index_granularity_bytes = 1538: 10/10 failures with the CI diff before the change, 10/10 passes after it (system.query_log shows the clamped value in the CREATE). With the clamp line's prefix misspelled, lower values get through again. 50/50 randomized runs pass.


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

Version info

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

…tion_cache

The test asserts that the second `ORDER BY b LIMIT 5` read reads fewer rows than
the first, thanks to the query condition cache. That needs a granule which the
first read reads and the PREWHERE then empties: with 64-row granules every
1024-row group of `a` starts on a granule boundary, so the last granule of each
group cannot be skipped by the primary key but has no row within the top-K
threshold (4032 rows, then 2048).

A random `index_granularity_bytes = 1538` sizes granules by bytes to 53 rows.
Since 1024 % 53 != 0, each such granule also holds the next group's smallest
`b`, every granule the first read reads has a qualifying row, and the cache,
although it hits, has nothing to drop (1749 rows both times). Only release-build
lanes can draw such a value.

Clamp just that setting with `-- Random settings limits:` to at least 100000,
which keeps adaptive granularity and the rest of the randomization.

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 my own cold review of the diff (0 findings).
Checked: the runner parses the clamp line and applies it to the MergeTree draw (tests/clickhouse-test, apply_random_settings_limits on the MergeTree settings), no dependent setting is derived from index_granularity_bytes, index_granularity stays pinned by the table, and the sibling top-K / query condition cache tests assert results rather than read_rows.

Severity: ❌ blocker / ⚠️ major / 💡 nit. No findings to adjudicate.

Session id: cron:clickhouse-review-slot-8:20261018-114600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. --no-random-settings --merge-tree-settings "--index_granularity_bytes 1538": 5/5 FAIL with the CI diff (-1 1 / +1 0); with the runner's debug-lane draw forced to 1538: 10/10 FAIL on the master file.
b Root cause explained? Yes. 64-row granules align with the 1024-row a groups, so the last granule of each group is read and emptied by PREWHERE (4032 -> 2048 rows). 53-row granules (1024 % 53 != 0) leave no read granule to drop, although the cache hits (1749 -> 1749).
c Fix matches root cause? Yes. It pins the one input of the granule layout the test did not pin (index_granularity is already fixed by the table), per setting, keeping randomization above 100000.
d Test intent preserved / new tests added? Yes. The oracle is unchanged (the second read must read fewer rows), the reference is unchanged; test-only change, no new test needed.
e Both directions demonstrated? Yes. Forced draw 1538: master file 10/10 FAIL, edited file 10/10 PASS (CREATE carries 100000); misspelled clamp prefix: 1538 kept.
f Fix is general across code paths? N/A (test layout fix, no product defect). The other QCC / top-K tests do not compare read_rows and never failed with index_granularity_bytes <= 5000 in 60 days of CIDB.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for types. Every value at or above the floor yields the same 64-row layout; 50/50 randomized runs (drawn 802233..30977737) pass with that layout in every run.
h Backward compatible? (maintainer-approved exception only) Yes, test-only; no settings or formats touched.
i Invariants and contracts preserved? Yes. The table stays on adaptive granularity, with the shape of the passing runs in the failing CI job (512 marks, 4032 -> 2048 rows).

Session id: cron:clickhouse-impl-slot-4:20261018-113400

@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1016381]

Summary: ✅


AI Review

Summary

This PR clamps randomized index_granularity_bytes to at least 100000 for 05316_top_k_primary_key_skip_query_condition_cache, preserving the 64-row granules required by its query condition cache assertion. The assertion and expected results remain unchanged. No actionable findings at commit 10163815ae4c3b082c89a604cd2a52a70be39e5e.

Missing context / blind spots
Final Verdict

Status: ✅ Approve. No required changes.

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

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov, could you review this and add the can be tested label so CI runs? Since index_granularity_bytes = 0 was dropped, a random index_granularity_bytes below about 2 KB gives 53-row granules that no longer align with the 1024-row groups of a, so the second read has no emptied granule left to skip; the test now clamps that one setting to (100000, None).

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 18, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 18, 2026
Merged via the queue into ClickHouse:master with commit 24ece61 Oct 19, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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