Skip to content

Keep the ProfileEvents-checked reads of 05345_text_index_prewhere_read_step_order off parallel replicas - #125892

Merged
ahmadov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-05345-text-index-prewhere-parallel-replicas
Oct 16, 2026
Merged

ahmadov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-05345-text-index-prewhere-parallel-replicas

Conversation

@groeneai

@groeneai groeneai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124880
Related: #124911

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

05345_text_index_prewhere_read_step_order (added in #124880) fails only in Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel): 5 of 36 runs, always the single line read_order_index_first 0 -> 1, with every result row matching. Reports: #124880, #118662, #123144, #123537.

The oracle compares RowsReadByPrewhereReaders with SelectedRows on the initiator's query_log row. Under parallel replicas the initiator's SelectedRows covers the whole read, but a remote replica that wins marks counts its reads on its own row (current_database = 'default'), which the filter drops. The numerator shrinks and the ratio falls below 1.5. Summed over all replicas the ratio stays exactly 2, so the replicas read in the same order and the engine is fine.

The change runs only the four measured reads with enable_parallel_replicas = 0, as #124911 did for the string filter tests. The other reads keep running under parallel replicas in that lane.

Validation on a local ParallelReplicas rig, same binary: unmodified, the test fails 10 of 30 runs (5 of 30 with a failpoint that delays the local replica), each time only when a remote replica did the read; fixed, 30/30 and 30/30. Removing the pin from read_order_index_first alone fails it again. 50/50 with randomized settings on a plain server.


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

Version info

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

…d_step_order off parallel replicas

The test compares `RowsReadByPrewhereReaders` with `SelectedRows` on the
initiator's `query_log` row. In the `ParallelReplicas` lane the initiator's
`SelectedRows` covers the whole read, while a remote replica that wins marks
counts its reads on its own row (`current_database = 'default'`), which the
`current_database = currentDatabase()` filter drops. The numerator then
shrinks and `read_order_index_first` flips from 0 to 1. Initiator plus
remote rows always give the expected ratio, so the replicas read in the
same PREWHERE step order.

Run only the four measured reads with `enable_parallel_replicas = 0`, as
ClickHouse#124911 did for the string filter tests; the other reads keep running under
parallel replicas in that lane.

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: a cold code review that had not seen the implementation notes, plus an independent second-model gate (engine: codex), both on this head. 0 findings from either.

Checked: the query-level enable_parallel_replicas = 0 overrides the lane's profile setting and also disables the automatic parallel replicas route; the unmeasured reads still run under parallel replicas in that lane; every other test reading RowsReadByPrewhereReaders is already blacklisted, tagged no-parallel-replicas, or sums the replicas' rows by design.

Severity: ❌ blocker / ⚠️ major / 💡 nit. No rows.

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

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Local ParallelReplicas rig (both enable_parallel_replicas.xml overlays, default_parallel_replicas with is_local 1/0/0, the lane's runner flags): the unmodified test fails 10/30 runs, and 5/30 with the slowdown_parallel_replicas_local_plan_read failpoint, every time with exactly the CI diff (read_order_index_first 0 -> 1).
b Root cause explained? Yes. The oracle reads RowsReadByPrewhereReaders and SelectedRows from the initiator's query_log row only. Under parallel replicas the initiator's SelectedRows covers the whole read, while a remote replica that wins marks counts its reads on its own row (current_database = 'default'), which the filter drops. Every flip coincided with a remote read (15/15 locally, 0 exceptions either way); initiator plus remote rows always give the expected ratio 2.0, so the read-step order is the same on the replicas.
c Fix matches root cause? Yes. Only the four measured reads get enable_parallel_replicas = 0, which removes the variable the oracle cannot see. No widened bound, no blanket tag, no reference change.
d Test intent preserved / new tests added? Yes. The oracle keeps its sensitivity, and gains it in this lane, where a full index read was invisible whenever the local replica read less than 75% of the marks. Negative control: removing the pin from read_order_index_first alone fails again (2/30). The unmeasured reads still run under parallel replicas (418 secondary rows in one 30-run arm).
e Both directions demonstrated? Yes, same binary and rig: unmodified 10/30 and 5/30 FAIL, fixed 0/30 and 0/30. With parallel_replicas_local_plan = 0: unmodified 10/10 FAIL, fixed 10/10 OK.
f Fix is general across code paths? Yes. Every other test reading RowsReadByPrewhereReaders is already safe: 03143 is in tests/parallel_replicas_blacklist.txt, 03364 sums the secondary rows by design, 03533 and 04631 are tagged no-parallel-replicas.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only oracle fix). The pin also holds against the runner's automatic_parallel_replicas_mode = 2 bundle in other lanes: in 19 such runs the measured reads logged enable_parallel_replicas = 0.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only change, no setting or reference change.
i Invariants and contracts preserved? Yes. The four measured reads are now local reads fully observed by the initiator's row in every lane; result rows are unchanged; 50/50 with randomized settings on a plain server.

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

@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fbaee94]

Summary: ✅


AI Review

Summary

This PR sets enable_parallel_replicas = 0 on the four reads in 05345_text_index_prewhere_read_step_order whose counters are checked in system.query_log. This keeps the measured work on the initiator, preserves the existing assertions, and leaves the other reads available for parallel replica coverage. No actionable findings. The relevant CI test passed on 08bbbefbcd24, and the reviewed SQL file is identical at PR head fbaee94f0d57.

Final Verdict

Status: ✅ Approve

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

Copy link
Copy Markdown
Collaborator Author

cc @ahmadov, could you review this and add the can be tested label (I cannot add labels right now)? Under parallel replicas a remote replica that reads part of the marks logs its RowsReadByPrewhereReaders on its own query_log row, so the initiator-only oracle in 05345_text_index_prewhere_read_step_order flips; this pins enable_parallel_replicas = 0 on the four measured reads only.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 14, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 08bbbef

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05350_comparison_tuple_elimination_shared_alias not from this PR (it only changes test 05345_text_index_prewhere_read_step_order, which passed in this job): NOT_FOUND_COLUMN_IN_BLOCK for a tuple comparison with a false constant element through parallel replicas, 126 of 126 reruns passed; the tested tree of this run predates the fix #125195 (mine, merged)
Mergeable Check, PR praktika rollups of the row above #125195 (mine, merged)

CIDB has no other FAIL or ERROR row from the finished run on this head.

Session id: cron:our-pr-ci-monitor:20261015-230015

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, as the fix for 05350_comparison_tuple_elimination_shared_alias is merged, update the branch here.

@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done: merged master in fbaee94, which includes #125195. The PR diff itself is unchanged.

@devcrafter

Copy link
Copy Markdown
Member

@groeneai why do not use no-parallel-replicas tag for this test, so it'll not be run in parallel replicas CI run at all?

@groeneai

Copy link
Copy Markdown
Collaborator Author

The pin is only on the four reads whose ProfileEvents the test checks. The other seven reads (direct read vs query_plan_direct_read_from_text_index = 0 on tab, and tab_partial, where only one part has the index) still go through parallel replicas in that job: in 30 runs on my local ParallelReplicas rig they produced 418 query_log rows on remote replicas. So that job keeps comparing the text index direct read with the plain read while the marks are split between replicas, and a no-parallel-replicas tag would drop that. Same shape as #124911. If you prefer the tag anyway, I'll send a follow-up PR that switches to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... 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.

5 participants