Repository navigation
Plan-based parallel replicas: do not ship a read of a temporary table - #129223
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [189b47b] Summary: ✅
AI ReviewSummaryReviewed head Final Verdict✅ Approve. No new inline findings. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l replicas Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes `clang-analyzer-core.CallAndMessage` in the `arm_tidy` build: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129223&sha=ca134fc701fa6a4d0e85a1a26605473cacfe3740&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
Reviewed at ef768bd: I built it (debug) and ran it against a 3-replica localhost cluster with process_query_plan_packet. 05497 passes with parallel_replicas_local_plan 0 and 1, and a regular Set or Join table is still read by the replicas.
- A temporary
Setinside a lambda still ships and fails withDATABASE_ACCESS_DENIED, and not only in the folded form from the bot's comment. Same fixtures as05497, local result in the comment:
-- the lambda also captures `v`, so it stays a `FunctionCapture` node instead of being folded
SELECT count() FROM t_pr_regular WHERE arrayExists(x -> (x IN t_pr_tmp_set) AND (v >= 0), [k]); -- 10
SELECT count() FROM t_pr_regular PREWHERE arrayExists(x -> x IN t_pr_tmp_set, [k]); -- 10
SELECT sumIf(v, arrayExists(x -> x IN t_pr_tmp_set, [k])) FROM t_pr_regular; -- 450
SELECT count() FROM t_pr_regular ARRAY JOIN arrayFilter(x -> x IN t_pr_tmp_set, [k]) AS a; -- 10ActionsDAG::serialize registers the sets of a FunctionCapture body (ActionsDAG.cpp:5610) and of a folded ColumnFunction's body and captured columns (:5370, :5377), while dagReadsTemporaryTable looks only at top-level set nodes. The inline suggestion follows the same three places. With it, all of the above plus the bot's folded and nested-lambda queries stay local and return the local result, a regular Set (plain and inside a lambda) is still distributed, and 05497 passes in both modes. It needs #include <Columns/ColumnFunction.h> and #include <Functions/FunctionsMiscellaneous.h>. The first query above is worth adding to 05497.
- Not covered either:
joinGet(t_pr_tmp_join, 'w', k)andjoinGetOrNullover a temporaryJointable fail on the replica withUNKNOWN_TABLE(Table default.t_pr_tmp_join does not exist). This fails the same way withparallel_replicas_plan_based = 0, so it may be out of scope here.
…`IN` set Co-Authored-By: Claude Opus 5.5 <[email protected]>
This PR keeps only a query that reads a temporary table directly local. Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
Re-reviewed at c49f10c (debug build, 3-replica localhost cluster). Moving the IN cases to #129273 is fine with me.
05497 matches the reference with parallel_replicas_local_plan 0 and 1 (also with max_threads = 1) and fails on master 4f752f7 with DATABASE_ACCESS_DENIED in both modes. I also checked 23 direct-read shapes with a temporary MergeTree table: subquery in FROM, CTE, UNION ALL/DISTINCT, INTERSECT, EXCEPT, GLOBAL JOIN, LEFT/RIGHT/FULL/CROSS/PASTE JOIN, correlated EXISTS, aggregated subquery, 3-way join, view(), ReplacingMergeTree ... FINAL, parallel_hash/full_sorting_merge/grace_hash, window and ARRAY JOIN above the join, merge() joined with it. All stay local and return the same result as enable_parallel_replicas = 0 in both modes; 15 of them fail on master with local_plan = 0. A join of regular tables is still distributed.
One behaviour change, inline.
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. |
…whole query Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
Re-reviewed at 189b47b (debug build, 3-replica localhost cluster). 05497 matches the reference with parallel_replicas_local_plan 0 and 1 (max_threads 1 and 8) and fails on master 4f752f7 in every run of both modes.
The 23 shapes from my earlier review and 18 more (a temporary table on the coordinated or the broadcast side, nested and 3-way joins, runtime filters, ORDER BY ... LIMIT and GROUP BY above the join, SEMI/ANTI/ANY, join_use_nulls, query_plan_join_swap_table false/auto/true) return the same result as without parallel replicas in both modes, with the regular reads still going through ReadFromParallelReplicas (an aggregation, the coordinated side of a join, a UNION ALL branch). Joins with Memory, Log and --external temporary tables now get the same plan as on master and are correct, so my ReadFromMemoryStorageStep point is resolved.
Add the subquery query result cache tests: the cache is not used with plan-based parallel replicas since #130376. Add `03707_autopr_unsupported_cases` (the `LIMIT` is shipped since #129811) and `03401_..._no_sorting` (#128537). Remove the tests that pass now: the temporary table ones (#129223), the `LIMIT` ones (#129811), and those fixed on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#129223 plan-based parallel replicas keep the read of a temporary table on the initiator (`mergeTreeReadCanBeShipped`) and still distribute the other subtrees of the query, e.g. an aggregation over a regular table joined with a temporary table. Turning parallel replicas off for the whole query in `DisableParallelReplicasPass` took that away and broke `05497_pr_plan_based_temporary_table_read_stays_local` (10/10 runs). The finder now fires only for task-based and custom-key parallel replicas, the modes that send the query to the replicas as is. `05345_parallel_replicas_temporary_table` covers the task-based mode, so it sets `parallel_replicas_plan_based = 0` and keeps its result in the plan-based CI configuration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With
parallel_replicas_plan_based = 1, a read of a temporary table was shipped to the replicas. A temporary table exists only in the session of the initiator, so every replica rejects the fragment withDATABASE_ACCESS_DENIED(Direct access to _temporary_and_external_tables database is not allowed). The client sees the error only when a replica's failure arrives before the local replica finishes the read, so withparallel_replicas_local_plan = 1it fails intermittently (almost always withmax_threads = 1), and withparallel_replicas_local_plan = 0it always fails.mergeTreeReadCanBeShippednow rejects a read of the temporary database, so the read never gets into a fragment: no split marker is planted above it, and a join whose broadcast side reads it is not lifted into one. The other subtrees of the query are still distributed, e.g. an aggregation over a regular table that is then joined with a temporary table. AMemory(orLog, or external) temporary table was already kept out of fragments, because its read is not serializable. A temporary table used only through anINset is left to #129273.05497_pr_plan_based_temporary_table_read_stays_localruns withparallel_replicas_local_plan = 0, so a shipped read of a temporary table always fails: a read of a temporary table has noReadFromParallelReplicas, an aggregation joined with a temporary table is distributed while the join stays local, and joins withMergeTreeandMemorytemporary tables return the right result. It fails on master every time.00542_access_to_temporary_table_in_readonly_mode,02525_different_engines_in_temporary_tables,02766_prql,02995_bad_formatting_union_intersectand03156_nullable_number_tipspass with plan-based in bothparallel_replicas_local_planmodes; they are intermittent failures in the plan-based job of #128413.Related: #128413
Related: #129273
Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129223]
Version info
26.11.1.1548-master(included in26.11and later)