Repository navigation
Disable parallel replicas for FINAL on a table function - #122492
Conversation
The planner disables task-based parallel replicas when a table expression carries FINAL (or STREAM on the initiator), but the check only looked at table nodes. FINAL written on a table function is stored on the table function node, so it was skipped and the setting stayed on. A table function that resolves directly to a MergeTree table, such as the TimeSeries target functions (`timeSeriesTags` and the like), then took the storage-level parallel replicas read with FINAL still set. With `parallel_replicas_local_plan = 1` the coordinated local read hit the `'!is_parallel_reading_from_replicas'` assertion in `spreadMarkRanges` (STID 2508-3f82 / 2508-3ce3). With `parallel_replicas_local_plan = 0` every replica read the whole table, so each row came back once per replica. Read the modifiers from a table function node too. FINAL on a table function now behaves like FINAL on a table: refused with `enable_parallel_replicas = 2`, run without parallel replicas otherwise. Related: ClickHouse#100377 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rename the test to `05272_streaming_queries_...`, because the style check requires that name for any test that enables streaming queries. 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 in the first round, none on the fixed head) plus my own cold reviews (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20260927-005800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260926-204100 |
|
Workflow [PR], commit [8e59092] Summary: ✅
AI ReviewSummaryThis PR extends the analyzer-side parallel-replicas guard to read Final Verdict✅ Approve. No new findings. LLVM Coverage ReportMeasured on commit 8e59092.
Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code |
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, 18 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - f6b330aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 169 check runs completed (127 pass, 41 not selected, 1 red), Session id: cron:our-pr-ci-monitor:20260927-123259 |
|
Fixing PR for the |
|
📊 Cloud Performance Report ✅ AI verdict: No query shows a performance change that can be tied to this PR. The only flagged row, ClickBench Q8 (+10.3%, median 376 ms vs 341 ms), was held at not_sure because its value falls inside master's recent range of 307-383 ms, and the diff supports that call. The diff only extends the planner's parallel-replicas FINAL/STREAM check so it also covers table functions. That check runs once while a query is being planned, and it does nothing for queries without FINAL or STREAM. The PR measurements on this query were also noisier than usual, and the ClickBench and TPC-H runs for this PR shared a machine, which fits run-to-run variance rather than a code effect. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…oint sorting key `trySplitNonIntersectingParts` returns "not replaced" for a primary key the parts splitter cannot compare (`isSafePrimaryKey`: `Nullable`, `Float*`, `BFloat16`, `Variant`, `Dynamic`, `JSON`, also nested), for mixed `ASC`/`DESC` key columns, and when a full non-intersecting replacement selects nothing. All three return before the checks that keep a direct read from a text index (ClickHouse#106894) and a query that stops reading early (ClickHouse#110576) away from the set-building plan, so `optimizeLazyFinal` built that plan anyway. Its read inherits the `__text_index_*` column name from `getAllColumnNames` but not the index read tasks that produce it: the filter drops rows, and when the `WHERE` repeats the `PREWHERE` predicate, `set_plan.optimize` rewrites the copy to the same name and `createReadTasksForTextIndex` throws `Column __text_index_... already added for reading`. Apply the same two conditions right after the split. On every path that reaches the new check with either condition true the reading step is still untouched, so the query keeps the regular `FINAL` read, as it already does for a comparable key. The in-split checks stay, as they must run before the partial split narrows the reading step. With both conditions false the control flow is unchanged. On 26.8.10.6, `SELECT count() FROM tab FINAL WHERE str = 'ccc'` with only `query_plan_optimize_lazy_final = 1`, over a `ReplacingMergeTree` with a `Nullable(UInt64)` sorting key and a text index on `str`, returns 0 instead of 1. Found by `AST fuzzer (amd_debug, targeted, old_compatibility)` (STID 4792-5e4c) on ClickHouse#122492: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122492&sha=f6b330abde632fb2c271eb66e098d4230b4a7004&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Tests: `02346_text_index_bug106809` gains a `Nullable`-key section (its `PREWHERE` + `WHERE` row is 1 because `PREWHERE` is evaluated before `FINAL`), and `04539_lazy_final_read_in_order_limit_disabled` gains `Float64`-key rows for both gates plus a positive control. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #100377
Related: #118130
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
FINALon a table function now disables parallel replicas the same way asFINALon a table: the query runs without parallel replicas, or is rejected whenenable_parallel_replicas = 2. Reading aTimeSeriestable function such astimeSeriesTagswithFINALunder parallel replicas now returns each row once.Description
FINAL(andSTREAMon the initiator) disables task-based parallel replicas inPlanner::buildPlanForQueryNode, but that check only looked atTableNode. Forf(...) FINALthe modifier is stored on theTableFunctionNode, so the setting stayed on. A table function that resolves directly to a MergeTree table (theTimeSeriestarget functions) then took the storage-level parallel read withFINALstill set:parallel_replicas_local_plan = 1:Logical error: '!is_parallel_reading_from_replicas'inReadFromMergeTree::spreadMarkRanges(STID 2508-3f82 / 2508-3ce3), for example Stress test (amd_asan_ubsan) on #121062 and AST fuzzer (amd_debug, targeted, old_compatibility) on #114038;parallel_replicas_local_plan = 0: every replica reads the whole table, so each row is returned once per replica.The check now reads the modifiers from a
TableFunctionNodetoo. This is the same hunk that the drafts #118518 and #119350 carry; those are about #118130 (duplicates withoutFINAL,UNKNOWN_TABLE), which this PR does not touch.Behavior change: with
enable_parallel_replicas = 2,FINALon any table function (andSTREAMon the initiator) now throwsSUPPORT_IS_DISABLED, like the table form. For example,merge(...) FINALran silently before, while aMergetable withFINALthrew.Validation on a debug build of master with a local 3-replica cluster: the unfixed binary aborts every time, including with the stress test settings. The new test
05272fails on it and passes 50/50 randomized runs with the fix, plus 20/20 each withparallel_replicas_plan_based = 1and withserialize_query_plan = 1. JOIN, CTE andUNION ALLqueries that also aborted before now pass.Workflow [PR]
Sync PR [sync-upstream/pr/122492]
Version info
26.10.1.1782-master(included in26.10and later)