Repository navigation
Add a regression test for a failed in-place set build with GLOBAL IN - #102308
alexey-milovidov merged 67 commits into
Conversation
The real bug is in : and consume the source before they know whether the set was actually created. If the in-place path stops early, the delayed build path loses the subquery and sees an empty set. Store a query-plan rebuild callback for analyzer and old-analyzer paths, use a temporary while building in place, and restore the source plan for the fallback path when the in-place attempt does not finish. Add a failpoint-based regression test that covers both and . Ref: ClickHouse#102192
|
Workflow [PR], commit [9d09cac] Summary: ✅ AI ReviewSummaryThis PR adds a focused regression test for recovering from a failed speculative set build with Final VerdictStatus: ✅ Approve. |
When falls back after or , restoring the subquery from analyzer state can still diverge from the original plan. Keep an exact cloned for retry, and only use if plan cloning is unavailable. Also make preserve held resources so restored plans keep the same execution context, and add a CTE regression for the failpoint-driven fallback path.
When a set subquery is snapshotted for retry, `QueryPlan::clone` could build fresh steps through ordinary constructors. That advanced per-query step ids and changed `EXPLAIN` / processor ids, which broke `03269_explain_unique_ids`. The same retry path could also fail for builder-less plans from `JOIN -> IN` optimization when the source plan contained `ReadFromSystemOneBlock`, which broke `03355_join_to_in_optimization`. Fix it by preserving original step ids while cloning query plans, falling back to restoring the just-built plan when no retry snapshot is available, and adding `clone` for `ReadFromSystemOneBlock`. PR: ClickHouse#102308 CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102308&sha=f28c5bae19e13979cef7801cd0264b78a4c9b578&name_0=PR&name_1=Fast%20test
…ause # Conflicts: # src/Common/FailPoint.cpp # src/Interpreters/PreparedSets.cpp
The `catch (...)` in `FutureSetFromSubquery::createQueryPlanForRetry` silently returned `nullptr` when `source->clone` threw and no `query_plan_builder` fallback was available. The style check (`catch_all`) flagged this as silently swallowing exceptions. Rethrow the original exception when there is no `query_plan_builder` fallback so real clone failures propagate, and document the fall-through to the builder path. Fixes style check failure at https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102308&sha=747be12badb189f41ba65dc7737c12c6f9c4e751&name_0=PR&name_1=Style%20check Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…_union` parameter After merging master, two `GlobalPlannerContext` constructor invocations in the rebuilt subquery planner code paths were left with three arguments instead of four — the new `parallel_replicas_table_union_` parameter (introduced on master in the parallel-replicas-no-local-preference work) was not added. This broke the `Fast test` and `Build (arm_tidy)` builds with `no matching function for call to '__construct_at'` (the constructor substitution failure from `make_shared`). Pass `nullptr` as the third argument to match the rest of the codebase (see `Planner.cpp:1657`, `StorageMergeTreeAnalyzeIndexes.cpp:171`, etc.). CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102308&sha=c38d67289313754ff37a1f5e80539ac7309f71f3 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Many `IQueryPlanStep` subclasses do not implement `clone` (`LimitStep`, `SortingStep`, etc). `createQueryPlanForRetry` was rethrowing the `NOT_IMPLEMENTED` exception when both `source->clone` failed and `query_plan_builder` was absent, even though the calling code in `buildSetInplace` and `buildOrderedSetInplace` already has a third fallback that recovers the source plan via `extractSubplan` on the executed plan. Catch only `NOT_IMPLEMENTED` from `clone`, return `nullptr`, and let the caller restore the source through `extractSubplan` after the in-place build (succeeded or not). Other exceptions still propagate. Fixes failures in: - 02949_parallel_replicas_in_subquery - 03525_distributed_product_mode_local_IN_cross_replication_analyzer_bug - 01103_distributed_product_mode_local_column_renames Reports: ClickHouse#102308
The `future_set_from_subquery_skip_inplace_build` failpoint added in this PR is `ONCE`-scoped, which means once enabled it fires on the next call to `fiu_do_on(...)` from any concurrent query. Tests `04093` and `04094` enable this failpoint to exercise the in-place set build fallback, but without `no-parallel` they can race with parallel tests and steal the failpoint trigger. This caused `03620_mergeTreeAnalyzeIndexes_sets` to flake: while running in parallel with `04093`, the index-analysis call into `buildOrderedSetInplace` for `key in keys_1` consumed the global ONCE failpoint, skipping the in-place build and producing the full mark range `[(0,12)]` instead of the expected `[(0,1)]`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102308&sha=8ac5000171b9e60f91591e89471b09c0ba5456d9&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 PR: ClickHouse#102308
The local environment's gh CLI token lacks the `workflow` scope, so pushes that change `.github/workflows/*` are rejected. Master moved those files from the long form to the short `--timestamp` form; this commit restores the long form (byte-identical to the previous PR tip) so the merge can be pushed. The downside is the `Config Workflow -> Check Workflows` CI step will fail until someone with the workflow scope re-runs `python3 -m praktika yaml`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The previous commit reverted workflow file updates from a master merge to avoid push rejection caused by missing `workflow` token scope, but this made the praktika `Check Workflows` job fail because the workflow files no longer match what `python3 -m praktika yaml` produces from the current configuration. Restoring the workflow files to their current `master` state so the check passes.
When `buildSetInplace` and `buildOrderedSetInplace` could not snapshot `source` for retry (no `query_plan_builder` and `clone` failed), the fallback path used `QueryPlan::extractSubplan` to splice the original subquery node tree out of the executed plan. `extractSubplan` only moves the node tree — it does not carry over `interpreter_context`, table locks, storage holders, or `max_threads`/`concurrency_control`. That left the rebuilt source plan without the resources keeping its storage and contexts alive, which could resurface as `Context has expired` once the delayed build runs. This adds `QueryPlan::detachResources` and threads `interpreter_context`/table locks/storage holders/thread settings from the executed plan into the restored source in both fallback sites in `FutureSetFromSubquery`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`cloneSubplanAndReplace` is used by `materializeQueryPlanReferences` to duplicate the same subplan at multiple reference sites. Preserving `step_index` from the source step here would make every duplicated copy share the same `step_uniq_id`, breaking the uniqueness contract used by diagnostics and `system.processors_profile_log.step_uniq_id`. Restore the original behavior in `cloneSubplanAndReplace` (allocate fresh indices via the constructor) and keep `step_index` preservation only in `cloneInplace`, which is used by `QueryPlan::clone` for retry snapshots where identity must be stable. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
A plain `WITH A AS (...)` is inlined at each reference, so `04094` collapsed to the ordinary `IN` shape already covered by `04489_not_ready_set_inplace_build`. Use `AS MATERIALIZED` so the CTE survives planning as a real CTE table node. Both tests now also assert that `prepared_sets_build_ordered_set_inplace_fail` flips from enabled to spent around the query, so they fail if the query stops taking the faulted in-place build path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
|
🕵 Merged |
|
🕵 Merged |
…lace build Address review: the single-use `AS MATERIALIZED` CTE was inlined by `inlineMaterializedCTEIfNeeded`, so the test only covered the plain `IN` shape already tested by `04489_not_ready_set_inplace_build`. A genuinely reused materialized CTE survives planning, but its set source contains a `DelayedMaterializingCTEsStep`, which cannot be cloned, so `FutureSetFromSubquery::buildSetInplace` takes the destructive fallback. The `prepared_sets_build_ordered_set_inplace_fail` failpoint only fires for recoverable builds, so it never fires for that shape (checked locally: `enabled` stays `1`). No distinct CTE restore path exists to test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
…eplicas in the `GLOBAL IN` test With randomized `prefer_localhost_replica = 0` both shards use TCP and the initiator-local recovery path is not exercised. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
A regression test for a speculative in-place
INset build that stops without creating the set.This PR originally replaced the approach in #102192 with a source-level fix in
FutureSetFromSubquery: it stored a query-plan rebuild callback and built into a temporarySet, so that a failed in-place build inbuildSetInplace/buildOrderedSetInplacedid not consume the subquery plan and leaveINwith an empty or not-ready set.Since then
masterfixed the same bug with its own clone-based speculative build (#107924) and kept extending it (in_place_build_failure,inplace_build_mutex, the recoverable-build scope of theprepared_sets_build_ordered_set_inplace_failfailpoint, distributed-plan support). The old analyzer, which theGLOBAL INpart of this PR was mostly about, was removed in v26.10. The branch's implementation could no longer be merged withmasterwithout re-implementing all of that, so the merge tookmaster's implementation, and the PR now only adds a regression test on top of it, usingmaster's failpoint:04095_future_set_inplace_build_restore_global_in:GLOBAL INoverremote('127.0.0.{1,2}', ...), where the initiator builds the set in place for the local shard; the external table sent to the remote shard must still be filled.A CTE test was dropped: a single-use
MATERIALIZEDCTE is inlined into the plainINshape already covered by04489_not_ready_set_inplace_build, and a reused one has a non-clonable source, so its in-place build is not recoverable and the failpoint does not apply.Related: #102192
Related: #107924
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
N/A
Documentation entry for user-facing changes
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/102308]
Version info
26.11.1.2694-master(included in26.11and later)