Skip to content

Add a regression test for a failed in-place set build with GLOBAL IN - #102308

Merged
alexey-milovidov merged 67 commits into
ClickHouse:masterfrom
alexey-milovidov:fix-pr102192-root-cause
Nov 18, 2026
Merged

alexey-milovidov merged 67 commits into
ClickHouse:masterfrom
alexey-milovidov:fix-pr102192-root-cause

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

A regression test for a speculative in-place IN set 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 temporary Set, so that a failed in-place build in buildSetInplace / buildOrderedSetInplace did not consume the subquery plan and leave IN with an empty or not-ready set.

Since then master fixed 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 the prepared_sets_build_ordered_set_inplace_fail failpoint, distributed-plan support). The old analyzer, which the GLOBAL IN part of this PR was mostly about, was removed in v26.10. The branch's implementation could no longer be merged with master without re-implementing all of that, so the merge took master's implementation, and the PR now only adds a regression test on top of it, using master's failpoint:

  • 04095_future_set_inplace_build_restore_global_in: GLOBAL IN over remote('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 MATERIALIZED CTE is inlined into the plain IN shape already covered by 04489_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):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

N/A

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/102308]

Version info

  • Merged into: 26.11.1.2694-master (included in 26.11 and later)

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
@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9d09cac]

Summary: ✅


AI Review

Summary

This PR adds a focused regression test for recovering from a failed speculative set build with GLOBAL IN, including population of the external table for the remote shard. The test pins the initiator-local path, verifies failpoint consumption, and checks the result across both shards. Earlier findings are addressed or concern changes removed from the PR; no actionable findings remain. Published CI for head 9d09caccc1c0 confirms the test passes in the sequential debug job and all 50 targeted ASan/UBSan runs.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Apr 10, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as draft April 10, 2026 02:40
alexey-milovidov and others added 5 commits April 10, 2026 07:34
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]>
alexey-milovidov and others added 15 commits April 27, 2026 08:52
…_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.
Comment thread src/Interpreters/PreparedSets.cpp Resolved
alexey-milovidov and others added 2 commits May 10, 2026 11:39
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]>
Comment thread src/Processors/QueryPlan/QueryPlan.cpp Resolved
`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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (6d724847805 → 0e284144335): the merge base was from 2026-10-04 and master has since changed src/Interpreters/PreparedSets.cpp (#123860). The merge was clean, and the PR diff is still only the two tests. Both 04094_future_set_inplace_build_restore_cte and 04095_future_set_inplace_build_restore_global_in pass locally on the merged tree. CI on the previous head was fully green, with no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (0e284144335 → af8c1eb37fc): the merge base was from 2026-10-12. The merge was clean and the PR diff is still only the two tests. Since the last merge master changed FutureSetFromSubquery::buildOrderedSetInplace (spill_state is now copied together with the set). I rebuilt on the merged tree, and 04094_future_set_inplace_build_restore_cte and 04095_future_set_inplace_build_restore_global_in pass locally, twice each with randomized settings. CI on the previous head was green apart from the pending CH Inc sync, and there are no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (af8c1eb37fc → 828826a2904) because the merge base was from 2026-10-19. The merge was clean and the PR diff is still only the two tests. The prepared_sets_build_ordered_set_inplace_fail failpoint they use still exists on master. Before the merge, CI was green except for the pending CH Inc sync, and there were no unresolved review threads.

alexey-milovidov and others added 2 commits October 27, 2026 08:16
…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]>
@alexey-milovidov alexey-milovidov changed the title Add regression tests for a failed in-place set build Add a regression test for a failed in-place set build with GLOBAL IN Oct 28, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (b16d0a55bc1 → 5c19f13cd05). CI on the previous head was green except for the pending CH Inc sync, and there are no unresolved review threads. I merged anyway because #127786 landed on master on 2026-11-02 and changed how the prepared_sets_build_ordered_set_inplace_fail failpoint in CreatingSetsTransform::generate works: it now returns without calling finishSubquery. The set is still left uncreated, which is the condition this test depends on, but the new CI run is needed to confirm 04095_future_set_inplace_build_restore_global_in still passes with the new failpoint behaviour. The merge was clean, and the PR diff is still only that one test (the 04094 CTE test was dropped in b16d0a55bc1).

alexey-milovidov and others added 2 commits November 4, 2026 07:14
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (bfb32f07b7e → 9d09caccc1c) because the branch had not been updated since 2026-11-04. The merge was clean, and the PR diff is still only the two test files. CI on the previous head had no failures, only the pending CH Inc sync. There are no unresolved review threads. Since the last merge, master has not changed CreatingSetsTransform.cpp, PreparedSets.cpp or Set.cpp, and the prepared_sets_build_ordered_set_inplace_fail failpoint is still there.

@alexey-milovidov
alexey-milovidov marked this pull request as ready for review November 16, 2026 16:41

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@alexey-milovidov alexey-milovidov self-assigned this Nov 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ClickHouse:master with commit 7d9966c Nov 18, 2026
391 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-pr102192-root-cause branch November 18, 2026 09:34
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 2026
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants