Skip to content

Fix flaky test 02317_distinct_in_order_optimization_explain - #125742

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-02317-fair-share-max-threads
Oct 14, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-02317-fair-share-max-threads

Conversation

@groeneai

@groeneai groeneai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125085
Related: #125715

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):

Not required.

Description

Since #125085, an auto max_threads is lowered to the fair share of CPU slots under load. The two --max_threads=0 checks of algorithm: Thread can then get one stream, ReadFromMergeTree reads in order, and the line disappears. Failures on three unrelated PRs: #125715 arm_binary, #112805 Fast test, #125717 Fast test. In the arm_binary server log, the failing query has Lower number of threads for query to the fair share of CPU slots 1 (32 requested).

The fix adds --use_concurrency_control_for_max_threads=0 to those two invocations, as #125715 does for 02149_read_in_order_fixed_prefix.

Validation (debug build): with concurrent_threads_soft_limit_num = 1 on the server (fair share always 1), the old test fails 20/20 with the CI diff, and the fixed one passes 50/50 with randomized settings. The fixed test also passes 50/50 with the default server config.

🤖 Generated with Claude Code


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

Version info

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

Since ClickHouse#125085 an auto `max_threads` is lowered to the fair share of CPU
slots (`getEffectiveMaxThreads`). Under the test runner's concurrent load
the two `--max_threads=0` EXPLAIN PIPELINE checks of `algorithm: Thread`
can get a single stream; `ReadFromMergeTree` then reads in order
(`readInOrder` instead of `readFromPool`) and the line disappears. The
failing arm_binary job's server log shows `fair share of CPU slots 1
(32 requested)` for exactly the query that lost its line.

Pin `use_concurrency_control_for_max_threads = 0` on those two
invocations, as ClickHouse#125715 does for `02149_read_in_order_fixed_prefix`.
The other invocations do not depend on the number of streams.

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

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9fd9a9c]

Summary: ✅


AI Review

Summary

This test-only fix disables use_concurrency_control_for_max_threads for the two EXPLAIN PIPELINE checks that require algorithm: Thread, preserving their assertions and reference output. No actionable findings. The affected test passes in Fast test at the reviewed PR head, 9fd9a9cbd1dbacbd684a4f848611dae7eee14168.

Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 14, 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; 1 finding) plus my own cold review (0 findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ The free-memory limiter (max_threads_min_free_memory_per_thread) can still lower the two checks to one stream DISAGREE Since that limiter landed (2026-03-22), 853,616 runs of this test show no algorithm: Thread loss from it; the only 2 such failures came from PRs changing planning/read streams. The fair share caused 3 in about 1,000 runs. #125715 pins the same single setting.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

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

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A server with concurrent_threads_soft_limit_num = 1 makes the fair share 1 for every auto query; the unfixed test then fails 1/1 without randomization and 20/20 with it, always losing exactly the two algorithm: Thread lines.
b Root cause explained? Yes. Since #125085 an auto max_threads is lowered to the fair share of CPU slots; with one stream ReadFromMergeTree uses readInOrder instead of readFromPool, so EXPLAIN PIPELINE shows algorithm: InOrder.
c Fix matches root cause? Yes. The two checks depend on the stream count, so they pin it with use_concurrency_control_for_max_threads = 0, the same pin as #125715 for 02149. No other line is changed.
d Test intent preserved / new tests added? Yes. Both checks still verify default (not in-order) reading; the reference is unchanged. Test-only fix.
e Both directions demonstrated? Yes. Same binary and server: unfixed 20/20 FAIL, fixed 50/50 OK (randomized). Per query, only the two pinned queries are no longer lowered.
f Fix is general across code paths? N/A (test fix). The other stateless tests using max_threads = 0 had no failure since #125085 except 02149, which #125715 fixes.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test fix). Fixed test 50/50 with randomized settings on both the default and the 1-slot server config.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only; no setting, default or format change.
i Invariants and contracts preserved? Yes. All other invocations are unchanged; with fair share 1 they still print the reference.

Session id: cron:clickhouse-impl-slot-4:20261014-061000

@groeneai

groeneai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

cc @serxa, could you review this and add the can be tested label? My account lost its triage role today, so CI has not started. Since #125085, an auto max_threads is lowered to the fair share of CPU slots, so under load the two --max_threads=0 EXPLAIN PIPELINE checks get a single stream and lose algorithm: Thread; the test now pins use_concurrency_control_for_max_threads=0 on those two invocations only.

@alexey-milovidov alexey-milovidov self-assigned this Oct 14, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 14, 2026
Merged via the queue into ClickHouse:master with commit 4efc791 Oct 14, 2026
520 of 522 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 14, 2026
robinld added a commit to robinld/ClickHouse that referenced this pull request Oct 14, 2026
Bring in the upstream fix for flaky `02317_distinct_in_order_optimization_explain` while keeping the projection codec changes on current master.

Related: ClickHouse#125742
Related: ClickHouse#120281
@clickhouse-gh clickhouse-gh Bot added comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... 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-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... 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