Repository navigation
Plan-based parallel replicas: run IN (subquery) locally instead of failing - #112443
Conversation
…iling Under plan-based parallel replicas (`parallel_replicas_plan_based = 1`), a `WHERE x IN (SELECT ...)` predicate made the query fail: with `parallel_replicas_local_plan = 0` it threw a `LOGICAL_ERROR` "Cannot serialize FutureSetFromSubquery with no query plan", and with `parallel_replicas_local_plan = 1` it hit "Next task callback is not set" (#111677). The shipped fragment is captured (as a clone) during `optimizeTreeSecondPass` while the `FutureSetFromSubquery` still holds its subquery query plan, but the later `addStepsToBuildSets` pass calls `FutureSetFromSubquery::build`, which moves that plan out. Serializing the fragment at execution time then finds a null plan and throws. Properly shipping the subquery set requires serializing it while its plan is still populated; until that is done, disable distribution for any query that builds a set from a subquery and run it as the plain local plan (correct results, no parallel replicas) - mirroring the existing FINAL handling in `insertParallelReplicasSplit`. The still-intact `DelayedCreatingSetsStep` (present before `addStepsToBuildSets` converts it) is the signal; it carries only `FutureSetFromSubquery` sets, so a plain tuple `IN (1, 2, 3)` keeps being distributed. A `TODO(#111876)` records the follow-up. Closes: #111876 Related: #111677 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [2aa1567] Summary: ❌
AI ReviewSummaryThis PR avoids the Findings
Final VerdictChanges requested: the local fallback is fine for the default mode, but the enforce-parallel-replicas contract still needs to be preserved. |
Address review feedback: the regression previously proved only that the query returns the right rows, not that plan-based parallel replicas keeps the outer `IN (subquery)` read local. A later change could distribute it again, still return the same rows on this self-subquery, and stay green while re-introducing the known-unsafe plan shape. Add EXPLAIN optimize = 1 assertions (both parallel_replicas_local_plan modes) that the outer read is not distributed: no `ReadFromParallelReplicas`, still a local `ReadFromMergeTree`. The subquery appears as a reference in the plan, so the count reflects only the outer read. A tuple `IN (1, 2, 3)` guard confirms distribution is still applied where it is safe. Verified against a local server. The TODO now points at flipping these assertions once #111876 is fixed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| if (planHasFinalMergeTreeRead(root)) | ||
| return; | ||
|
|
||
| if (planHasSubquerySet(root)) |
There was a problem hiding this comment.
allow_experimental_parallel_reading_from_replicas >= 2 is the "enforce parallel replicas" mode, and every other unsupported shape handles that by throwing instead of silently falling back to a local plan (FINAL in InterpreterSelectQuery, parallel_replicas_allow_in_with_subquery = 0 in Planner). This unconditional return bypasses that contract for the new unsupported IN (subquery) case: the query will now succeed locally even though the user explicitly required parallel replicas. If this combination must stay unsupported until #111876, it needs the same disable-or-throw handling as the existing guards instead of quietly ignoring the request.
There was a problem hiding this comment.
Valid point. In enforce mode (allow_experimental_parallel_reading_from_replicas >= 2) this should throw SUPPORT_IS_DISABLED like the existing IN with subquery (Planner.cpp, parallel_replicas_allow_in_with_subquery = 0) and FINAL guards, rather than silently running locally when the user required parallel replicas. Since that edits the planHasSubquerySet guard introduced in this PR, I'll add it in a follow-up PR off master once this one merges — keeping it out of a stacked PR that CI wouldn't run.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-in-subquery' into fix-111876-pr-plan-based-disable-in-subquery
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/17 (88.24%) · Uncovered code |
Description
Under plan-based parallel replicas (
parallel_replicas_plan_based = 1), aWHERE x IN (SELECT ...)predicate made the query fail: withparallel_replicas_local_plan = 0it threw aLOGICAL_ERRORCannot serialize FutureSetFromSubquery with no query plan, and withparallel_replicas_local_plan = 1it hitNext task callback is not set(#111677).The shipped fragment is captured (as a clone) during
optimizeTreeSecondPasswhile theFutureSetFromSubquerystill holds its subquery query plan, but the lateraddStepsToBuildSetspass callsFutureSetFromSubquery::build, which moves that plan out. Serializing the fragment at execution time then finds a null plan and throws.Properly shipping the subquery set requires serializing it while its plan is still populated. This is a feature under active development, so until that is done this change disables distribution for any query that builds a set from a subquery and runs it as the plain local plan (correct results, no parallel replicas) — mirroring the existing
FINALhandling ininsertParallelReplicasSplit. The still-intactDelayedCreatingSetsStepis the signal; it carries onlyFutureSetFromSubquerysets, so a plain tupleIN (1, 2, 3)keeps being distributed. ATODO(#111876)records the follow-up.Closes: #111876
Related: #111677
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not for changelog: fixes behavior of the experimental
parallel_replicas_plan_basedfeature, which is under active development.Version info
26.8.1.392(included in26.8and later)