Skip to content

Fix flaky test 05507_autopr_direct_read_from_text_index - #132192

Merged
fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-05507-autopr-text-index
Nov 18, 2026
Merged

fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-05507-autopr-text-index

Conversation

@groeneai

@groeneai groeneai commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #129339

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

05507_autopr_direct_read_from_text_index (added in #129339) failed 4 times in 30 days, always on reference line 8 (1 1 -> 0 0: the 05507_applied query did not apply automatic parallel replicas), e.g. in Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) and Stateless tests (amd_debug, distributed plan, s3 storage, parallel). The runner's own diagnosis blames random MergeTree settings: text_index_posting_list_codec = 'none' with a posting list block size of 16 or 64 and a small index_granularity.

The first query (mode 2) collects the statistics on 669 marks and, through its PREWHERE hasToken(str, 'rare'), fills the server-wide query condition cache. With those settings the text index analysis is coarser than the filter, so the cache prunes the second query (mode 1) to 100 marks. The job's server log shows Significant difference in total rows from storage detected ... (previously 99012, now 14800). Recollecting statistics, and mode 1 keeps the single-node plan. The engine is right to recollect; the test depended on the cache.

The test now sets use_query_condition_cache = 0, as 05565_autopr_statistics_drift_ratio and 05100_autopr_skip_index_on_data_read do. A Random settings limits clamp would not help: the cache is on by default.

Validation (debug build, with the CI users.d/limits.yaml profile): with --index_granularity 148 --text_index_posting_list_block_size 64 --text_index_posting_list_codec none and no other random settings, the unchanged test fails 5/5 with the CI diff and passes 5/5 with the fix. With those MergeTree settings plus random settings it failed 24/50 before and 0/50 after; 50/50 OK with default randomization.

🤖 Generated with Claude Code


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

Version info

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

The first query (automatic_parallel_replicas_mode = 2) collects the
statistics on its read and, through its PREWHERE hasToken(str, 'rare'),
fills the server-wide query condition cache with the marks that hold no
'rare' row. With text_index_posting_list_codec = 'none', a posting list
block size of 16 or 64 and a small index_granularity, the text index
analysis keeps only per-block row ranges for 'rare', so it is coarser than
the filter, and the cache prunes the index analysis of the second query
(mode 1) from 669 to 100 marks. The drift check then sees 14800 rows
instead of the 99012 the statistics were collected on, recollects the
statistics and keeps the single-node plan, so the test reads 0 0 instead
of 1 1.

Disable the query condition cache in the test, as
05565_autopr_statistics_drift_ratio and 05100_autopr_skip_index_on_data_read
do. A Random settings limits clamp cannot work: the cache is on by default.

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 review (0 findings).

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

Session id: cron:clickhouse-review-slot-9:20261117-012600

@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 148 --text_index_posting_list_block_size 64 --text_index_posting_list_codec none" with the CI users.d/limits.yaml profile: the unchanged test fails 5/5 on reference line 8 (1 1 -> 0 0).
b Root cause explained? Yes. The mode 2 query fills the query condition cache through its PREWHERE hasToken; with a coarse text index analysis (small granularity, multi-block posting list) the cache prunes the mode 1 query from 669 to 100 marks, so the drift check recollects statistics (previously 99012, now 14800) instead of applying parallel replicas.
c Fix matches root cause? Yes. SET use_query_condition_cache = 0 removes the state shared between the two runs, as the sibling 05565_autopr_statistics_drift_ratio and 05100_autopr_skip_index_on_data_read do. No tag, no clamp (the cache is on by default, so a clamp cannot reach it).
d Test intent preserved / new tests added? Yes. Every reference line is unchanged and still asserted; the culprit MergeTree settings keep running. Test-only change.
e Both directions demonstrated? Yes. Same command: 5/5 FAIL before, 5/5 PASS after. With those MergeTree settings plus random settings: 24/50 FAIL before, 50/50 PASS after. Negative controls (codec pfor, block size 256, granularity 8192): 5/5 PASS each before the fix.
f Fix is general across code paths? N/A (test-only). Other tests that collect statistics in mode 2 and decide in mode 1 either already pin the cache or have no filter the cache could prune.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test setting fix). 50/50 with default randomization.
h Backward compatible? (maintainer-approved exception only) N/A (test-only).
i Invariants and contracts preserved? Yes. Both runs of each pair now select the same rows (669 = 669 marks; same_rows_as_single_node still 1); a runner-injected use_query_condition_cache 1 is overridden by the test's SET (5/5 PASS).

Session id: cron:clickhouse-impl-slot-41:20261117-010900

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cb6ffb7]

Summary: ✅


AI Review

Summary

Disables use_query_condition_cache in 05507_autopr_direct_read_from_text_index so cache warm-up cannot change the selected-row estimate between statistics collection and the automatic parallel-replica decision. The existing assertions remain intact. No actionable findings. The author reports repeated before/after reproductions with the minimized failing settings, and the focused test passes in Fast test at the reviewed head. No local tests were run.

Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 17, 2026
@fm4v
fm4v added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ClickHouse:master with commit d2ff9fb Nov 18, 2026
384 of 385 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 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