Skip to content

Tag 05316_top_k_primary_key_skip_query_condition_cache as no-parallel - #125152

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05316-top-k-pk-qcc-no-parallel
Oct 11, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05316-top-k-pk-qcc-no-parallel

Conversation

@groeneai

@groeneai groeneai commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121145

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 sometimes prints 1 0 instead of 1 1: the repeated read was not made cheaper by the query condition cache (arm_binary, parallel, amd_asan_ubsan, targeted; no failures on master).

The second read relies on the cache entries written by the first one, and in the parallel phase another test can empty the server-wide cache in between. In both failing runs the server log shows it happening a few milliseconds after the first read: a DROP DATABASE (05060_database_max_tables_rename_inner_tables) and a RENAME TABLE (05213_timeseries_metric_families_target) of MergeTree tables in an Ordinary database. A MergeTree table without a UUID calls Context::clearCaches() on drop and rename, which also clears the query condition cache. An explicit SYSTEM CLEAR QUERY CONDITION CACHE in another parallel test has the same effect.

The test is now tagged no-parallel, like the other tests that rely on query condition cache entries surviving between queries (e.g. 05320_object_storage_top_k_query_condition_cache_fallback_files). Test-only change, reference unchanged.

Validation on a master debug build: putting SYSTEM CLEAR QUERY CONDITION CACHE or a create and drop of a MergeTree table in an Ordinary database between the two reads gives 1 0 3/3 (with an Atomic database: 1 1 3/3). Running the test 40 times next to 40 runs of 05060_database_max_tables_rename_inner_tables with -j 8 fails 3/40 with the CI diff before the change and 0/40 after it, since the runner now puts it in the sequential group. 50/50 randomized runs pass.


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

Version info

  • Merged into: 26.10.1.2142-master (included in 26.10 and later)

The second read of the test relies on the query condition cache entries
written by the first one. The cache is server-wide, and in the parallel
phase another test can empty it between the two reads, so the second read
reads as many rows as the first and the test prints `1 0`.

In both failing CI runs the eraser was a DROP DATABASE / RENAME TABLE of
MergeTree tables in an Ordinary database (05060_database_max_tables_rename_inner_tables,
05213_timeseries_metric_families_target): a MergeTree table without a UUID
calls Context::clearCaches() on drop and rename, which also clears the
query condition cache. An explicit SYSTEM CLEAR QUERY CONDITION CACHE in
another parallel test has the same effect.

Run the test in the sequential group, like the other tests that check
QueryConditionCacheHits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 11, 2026
@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 on the code). The independent cold review found 0 code findings; its two wording nits on the PR description were applied before publication.

Session id: cron:clickhouse-review-slot-8:20261011-042600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Putting SYSTEM CLEAR QUERY CONDITION CACHE, or a create and drop of a MergeTree table in an Ordinary database, between 05316_first and 05316_second gives the CI output 1 0 3/3 each (QueryConditionCacheHits 0, 4032 rows read by both). Through the runner, -j 8 --test-runs 40 with 05060_database_max_tables_rename_inner_tables reproduces the exact CI diff (3/40).
b Root cause explained? The query condition cache is server-wide. In the parallel phase another test empties it between the two reads: in both CI failures it was a DROP DATABASE / RENAME TABLE of MergeTree tables in an Ordinary database, and a MergeTree table without a UUID calls Context::clearCaches() on drop and rename, which clears this cache too. The second read then misses and reads as many rows as the first, so the comparison prints 0.
c Fix matches root cause? Yes. The erasers are other tests, so no setting pin or test-local rename can scope the state; the test must not overlap them. no-parallel does that, as for the other tests that check QueryConditionCacheHits. Randomized settings stay on.
d Test intent preserved / new tests added? Yes. No assertion, setting or reference line changes; a first read that does not record its entries still fails the test in the sequential group. Test-only fix, so no new test.
e Both directions demonstrated? Yes. Runner pool with 05060_...: 3/40 FAIL with the CI diff before the tag (Found 80 parallel tests and 0 sequential tests), 0/40 after (Found 40 parallel tests and 40 sequential tests). Mechanism: 1 0 with an eraser vs 1 1 for the control and for an Atomic database drop.
f Fix is general across code paths? Yes. With this change 30 of the 31 stateless tests asserting QueryConditionCacheHits are no-parallel; the remaining one does not assert that an entry survives between statements. All eraser kinds (explicit clear, clearCaches() from a UUID-less drop/rename, cache eviction) need a concurrently running query, and none runs during the sequential group.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test scheduling fix, not a code bug). 50/50 randomized runs with random settings and random MergeTree settings pass.
h Backward compatible? (maintainer-approved exception only) N/A (test-only change, no settings or formats).
i Invariants and contracts preserved? Yes. The test's invariant, nothing clears the cache between the two reads, holds in the sequential group. No source code touched.

Session id: cron:clickhouse-impl-slot-41:20261011-041400

@groeneai
groeneai requested a review from rschu1ze October 11, 2026 04:43
@clickhouse-gh

clickhouse-gh Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e9c97ba]

Summary: ✅


AI Review

Summary

This PR moves 05316_top_k_primary_key_skip_query_condition_cache into the sequential stateless bucket by adding no-parallel, which matches the test’s reliance on server-global query condition cache state surviving across two statements. I did not find any correctness, safety, or CI-contract issues in the current diff.

Final Verdict

✅ No findings.

@alexey-milovidov alexey-milovidov self-assigned this Oct 11, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 11, 2026
Merged via the queue into ClickHouse:master with commit e830e6e Oct 11, 2026
165 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 11, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 8, 2026
…equentially

The cache arm compares SelectedMarks of two identical queries: the first one
writes a query condition cache entry for the PREWHERE
`and(__topKFilter(s), notEmpty(s))`, the second one must read it and select
fewer marks. The query condition cache is server-wide. In the failing
`Stateless tests (arm_binary, parallel)` run on PR ClickHouse#129954, the parallel test
05213_timeseries_metric_families_target dropped an inner MergeTree table of a
TimeSeries table in an Ordinary database between the two queries.
MergeTreeData::dropAllData() calls Context::clearCaches() for a table without
a UUID, which also clears the query condition cache, so the second query read
all 100 marks again and the arm printed 0 instead of 1.

Tag the test no-parallel, like 05316 (ClickHouse#125152) and 05258 (ClickHouse#125702), which
failed the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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. groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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