Repository navigation
Conversation
`addWindowSteps` does not sort a window again when its sort description is a prefix of the previous window's, and when `getEffectiveMaxThreads` returns 1 it skips the sort even if the `PARTITION BY` differs (ClickHouse#58739), assuming the pipeline has a single stream. The previous window's `SortingStep` scatters by the pipeline's thread count, which is `QueryPlan::max_threads` set by the read from its own sample. When the read sees several threads and the window planning sees one, the first window scatters by the longer key and the second window runs one `WindowTransform` per stream, so one of its partitions is split in two. This happens with an outer `SETTINGS max_threads = 1` over a subquery with a larger `max_threads`, and, since ClickHouse#125085 made `getEffectiveMaxThreads` return the live fair share of CPU slots for each call, with the default automatic `max_threads` under load. That is the wrong result of `02962_parallel_window_functions_different_partitioning` in CI (the read got 2 threads, the windows 1). When a window reuses a sorting with another partitioning, the window sortings of the call are now planned without scatter partitions, so each of them merges its streams into one sorted stream, the same way windows whose keys break hash sharding are handled. A pipeline that really has one thread gets the same processors as before, and plans for more than one thread are unchanged. The effective `max_threads` is sampled once per call so both decisions agree. The test gets the deterministic subquery variant as a third query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sure An explicit `max_threads = 2` is still lowered by the free-memory limiter (`max_threads_min_free_memory_per_thread`, 1 GiB by default), so with less than 2 GiB free under `max_server_memory_usage` the subquery is read with one thread, nothing is scattered, and the query cannot fail without the fix. Pin the limit to 0 in the subquery. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the sentence restating the lambda name; state why the thread count is sampled once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261105-231900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261105-221100 |
|
cc @novikd @KochetovNicolai, could you review this and add the |
|
Workflow [PR], commit [a0cafd0] Summary: ❌
AI ReviewSummaryPR #129641, reviewed at Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline. |
…n-split-single-thread-plan Resolve the conflict in src/Planner/Planner.cpp: master moved addWindowSteps to src/Planner/PlannerSteps.cpp, so the change is re-applied there, with master's getEffectiveMaxThreads(*query_context). The comment about sampling the value once is dropped: since ClickHouse#125946 the value comes from a per-query snapshot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - a0cafd0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261120-170043 |
|
Fixing PR for the |
Related: #126627
Related: #125085
Related: #125946
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results of window functions with different
PARTITION BY, such assum(x) OVER (PARTITION BY a ORDER BY b)withmin(x) OVER (PARTITION BY a, b ORDER BY c), when the windows were planned for one thread but the data was read by several, for example withmax_threads = 1over a subquery with a largermax_threads, or with the automaticmax_threadslowered by the fair share of CPU slots. One partition could be split in two.Description
02962_parallel_window_functions_different_partitioningreturned a wrong result in Stateless tests (amd_debug, distributed plan, s3 storage, parallel) on #126627, and the same diff on #126386: onePARTITION BY depnamepartition summed to 14400 instead of 43800.On 26.10.2.103 (also 26.3.60.2, 26.8 and 26.9), two windows where the second one's sort is a prefix of the first one's but its
PARTITION BYis shorter return wrong results when the windows are planned for one thread while the source is read by several. A deterministic example:SETTINGS max_threads = 1over(SELECT * FROM empsalary SETTINGS max_threads = 2), as in the new test query.addWindowStepsskips the second sort whengetEffectiveMaxThreadsreturns 1, assuming a single stream, but the first window's sort scatters by the pipeline's thread count, which comes from the read's own sample. Since #125085 that value was the live fair share of CPU slots, sampled at each call (2 for the read, 1 for the windows in the failing run). #125946 now takes it once per query; the subquery example still returns 14400 on master.Now, when a window reuses a sort with another partitioning, the window sorts of that query level merge their streams into one sorted stream instead of scattering, as windows with keys that break hash sharding already do. A real one-thread pipeline runs the same processors, and plans for more threads do not change.
Validation: the new query fails 50/50 on master and passes 50/50 with the fix (random settings). Under CPU-slot contention the original query was wrong in 438 of 9000 runs on master and in none with the fix. The other 302 window tests give the same results on both binaries, also with
max_threads = 1.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129641]