You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stable-25.8: correlated subquery over MergeTree crashes under parallel replicas — Cannot clone ReadFromPreparedSource (NOT_IMPLEMENTED) #2051
Bug report — latent 25.8 bug (present upstream 25.8, fixed on master) exposed by the ParallelReplicas CI config.
Describe the situation
Test 04299_constraint_subst_correlated_subquery_root fails consistently on stable-25.8 in the job Stateless tests (amd_binary, ParallelReplicas, s3 storage, parallel) (7/7 failures in that config; all other configs OK).
The cause: constraint-optimization decorrelation of a correlated subquery clones the query plan (PlannerCorrelatedSubqueries.cpp:273, context.query_plan.clone()). Under parallel replicas the source read is a ReadFromPreparedSource step, whose clone() is not implemented, so the query aborts with Code: 48 ... Cannot clone ReadFromPreparedSource plan step (NOT_IMPLEMENTED).
This is not a regression and not Altinity-specific: the identical code exists in upstream 25.8. It never fails in upstream's 25.8 CI because that branch's stateless matrix runs only amd_asan, distributed plan — it does not run the ParallelReplicas config (confirmed: 0 of ~1.95M rows). Altinity MasterCI runs the broader matrix (incl. ParallelReplicas), so it surfaces. It is fixed on upstream master by commit dc187196cd5 ("Implement subplan reference materialization as plan optimization"), which removes the plan clone.
CREATETABLEt (a Nullable(String), b String, c LowCardinality(String), d String,
CONSTRAINT c1 ASSUME (a <= b) AND (b <= c) AND (c <= d) AND (d <= a))
ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t VALUES ('1','2','3','4');
-- with parallel replicas enabled:SELECTcount() FROM t WHERE (b < d) OR (SELECT a < c)
SETTINGS enable_analyzer=1, convert_query_to_cnf=1, optimize_substitute_columns=1, optimize_using_constraints=1;
Expected behavior
Query returns a result (as it does without parallel replicas / on master).
Proper fix: upstream master commit dc187196cd5 ("Implement subplan reference materialization as plan optimization") removes the plan clone in decorrelation. Note: this fix is not in upstream 25.8 either, and it's a large, non-trivial backport — 14 files (+265/-71) introducing new plan infrastructure (SaveSubqueryResultToBufferStep, ReadFromCommonBufferStep, a new materializeQueryPlanReferences optimization pass), not an isolated cherry-pick.
CI mitigation (separate PR): tag 04299_constraint_subst_correlated_subquery_root with no-parallel-replicas.
Reproduced with a local 3-replica cluster (all replicas on localhost) so parallel replicas engages on a non-replicated MergeTree.
Query:
CREATETABLEt_constraint_corr_root
(
a Nullable(String), b String, c LowCardinality(String), d String,
CONSTRAINT c1 ASSUME (a <= b) AND (b <= c) AND (c <= d) AND (d <= a)
)
ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t_constraint_corr_root VALUES ('1','2','3','4');
SELECTcount() FROM t_constraint_corr_root
WHERE (b < d) OR (SELECT a < c)
SETTINGS
enable_analyzer =1, convert_query_to_cnf =1,
optimize_substitute_columns =1, optimize_using_constraints =1,
enable_parallel_replicas =2,
cluster_for_parallel_replicas ='test_cluster_one_shard_three_replicas_localhost',
parallel_replicas_for_non_replicated_merge_tree =1,
max_parallel_replicas =3, parallel_replicas_local_plan =1;
On 25.8 it fails with Code 48:
Received exception from server (version 25.8.28):
Code: 48. DB::Exception: Received from localhost:9000.
DB::Exception: Cannot clone ReadFromPreparedSource plan step. (NOT_IMPLEMENTED)
On 26.1 it fails even worse: instead of the clean NOT_IMPLEMENTED, the query crashes the server (segfault in the correlated-subquery planner — a different, worse code path). But the antalya-26.1 crash is identical to upstream 26.1, and we do not plan to ship a new antalya-26.1 release, so no fix is needed there.
On 25.8, the failure matches upstream 25.8 and is fixed from 26.3 onward (both upstream and Altinity).
Decision: no backport to 25.8. Mark 04299_constraint_subst_correlated_subquery_root as broken on both stable-25.8 and antalya-25.8.
Activity
CarlosFelipeOR commentedon Jul 27, 2026
Manual reproduction
Reproduced with a local 3-replica cluster (all replicas on localhost) so parallel replicas engages on a non-replicated MergeTree.
Query:
On 25.8 it fails with Code 48:
Cross-version results (same query)
Code: 48— Cannot clone ReadFromPreparedSource (NOT_IMPLEMENTED)Code: 48NOT_IMPLEMENTEDColumnNode::getColumnSource)On 26.1 it fails even worse: instead of the clean
NOT_IMPLEMENTED, the query crashes the server (segfault in the correlated-subquery planner — a different, worse code path). But the antalya-26.1 crash is identical to upstream 26.1, and we do not plan to ship a new antalya-26.1 release, so no fix is needed there.On 25.8, the failure matches upstream 25.8 and is fixed from 26.3 onward (both upstream and Altinity).
Decision: no backport to 25.8. Mark
04299_constraint_subst_correlated_subquery_rootas broken on both stable-25.8 and antalya-25.8.