Repository navigation
Scope the in-place set-build fault injection to the build that can be redone - #118817
alexey-milovidov merged 4 commits into
Conversation
`prepared_sets_build_ordered_set_inplace_fail` was added in ClickHouse#107924 to simulate a *speculative* in-place set build that stops without creating its set, so that the runtime deferred build has to recover it. The injection lives in `CreatingSetsTransform::generate()`, but that transform serves both builds: the in-place one (`FutureSetFromSubquery::buildSetInplace` / `::buildOrderedSetInplace`) and the ordinary runtime one under `DelayedCreatingSetsStep`. The failpoint's own comment asserted the narrow scope, and nothing enforced it: it held only while an in-place build happened to be the first `generate()` call after the arm. `SYSTEM ENABLE FAILPOINT` is server-wide and a `ONCE` arm survives until the first `generate()` call anywhere in the process. When that call belongs to an unrelated query's runtime build, `generate()` returns before `Set::finishInsert()`, so `Set::isCreated()` stays false, `FutureSetFromSubquery::get()` returns nullptr, and `FunctionIn::executeImpl` raises LOGICAL_ERROR from inside an already-running `FilterTransform`, aborting a debug or sanitizer server. Only the in-place path has a recovery, so nothing rescues the runtime build. In CI this is armed on purpose by BuzzHouse and replayed verbatim by the AST fuzzer out of the corpora of 04489_not_ready_set_inplace_build.sql and 04697_shared_set_error_not_inherited.sh, which is why the abort lands on queries that never asked for a set at all. Carry the discriminator on the individual set build: `CreatingSetStep` gains `speculative_build`, threaded through `FutureSetFromSubquery::build()` and set true only at the three in-place construction sites, and `CreatingSetsTransform::generate()` consults it before `fiu_do_on`. The check precedes the injection rather than sitting inside it, because `fiu_fail` on a `FIU_ONETIME` point consumes the shot: an inside check would let a runtime build spend the shot and leave the speculative build it was armed for running unfaulted. The flag deliberately travels on the step and not on `BuildQueryPipelineSettings`. One settings object serves an entire plan, and `addPlansForSets` splices runtime set plans in as children of that same plan, so a pipeline-wide flag would also mark runtime `CreatingSetStep`s nested inside an in-place build's plan, including lazy FINAL's internal set. That is a narrower version of the same bug. For the same reason the nested `DelayedCreatingSetsStep` an in-place destructive fallback can carry expands through `makePlansForSets` with the flag false, so its inner canonical sets stay classified as runtime and the shot cannot abandon them. Every new parameter is defaulted, and all five `build()` call sites state their value explicitly so a future caller has to make the choice rather than inherit it. The injected state is otherwise byte-identical, which is why 04489 and 04697 pass unchanged; they remain the live proof that the in-place injection still fires. Related: ClickHouse#118722 Co-Authored-By: Claude Opus 5 <[email protected]>
Narrows the previous commit on this branch, which marked all three in-place set builds faultable. Review measured that the resulting binary still aborted with the very error this branch removes: with the failpoint armed, `SELECT count() FROM system.tables WHERE database IN (SELECT 'system')` raised "Not-ready Set is passed as the second argument for function 'in'" at `src/Functions/in.cpp:155` and aborted with signal 6. The rule is narrower than "in-place versus runtime". `FutureSetFromSubquery::build()` does `auto plan = std::move(source)`, and a build that stops without creating its set throws nothing, so `in_place_build_failure` stays unset and the next `build()` returns nullptr. Only one build therefore survives being abandoned: the in-place build that runs its pipeline against `source->clone()`, because `buildOrderedSetInplace` returns before it resets `source`, leaving the original plan for `DelayedCreatingSetsStep::makePlansForSets` to build. Every other build goes through `build()` and consumes `source`: `buildSetInplace`, the destructive fallback `buildOrderedSetInplace` takes for a non-clonable source, and every runtime build. Abandoning any of those leaves the set uncreated for good, and `FunctionIn::executeImpl` then raises LOGICAL_ERROR from inside an already-running `FilterTransform`, aborting a debug or sanitizer server. The two in-place builds that are now excluded are ordinary rather than exotic: `ReadFromMergeTree::applyFilters` reaches `VirtualColumnUtils::buildSetsForDAG` for PREWHERE and the row-level filter, and some twenty further callers do too, from `StorageFile` and `StorageURL` to the system tables and `CheckConstraintsTransform`. All of that runs in `optimizeTreeSecondPass`, before `addStepsToBuildSets`, so those builds go first and they are the ones that consume `source`. So `CreatingSetStep::recoverable_build` (renamed from `speculative_build`, which misled: the file calls all three in-place builds speculative and two of them cannot recover) is true at exactly one construction site, the clone-backed one. `CreatingSetsTransform::generate()` consults it before `fiu_do_on`. The check precedes the injection rather than sitting inside it, because `fiu_fail` on a `FIU_ONETIME` point consumes the shot: an inside check would let any build spend the shot and leave the recoverable build it was armed for running unfaulted. The flag deliberately travels on the step and not on `BuildQueryPipelineSettings`. One settings object serves an entire plan, and `addPlansForSets` splices runtime set plans in as children of that same plan, so a pipeline-wide flag would also mark runtime `CreatingSetStep`s nested inside an in-place build's plan, including lazy FINAL's internal set. That is a narrower version of the same bug. `build()` loses its default so a future caller has to choose; the three other signatures keep `= false` for out-of-file callers, `false` being the fail-safe value. The injected state is otherwise byte-identical, which is why 04489 and 04697 pass unchanged; they remain the live proof that the in-place injection still fires, 04697 through its `max(builds) >= 2` assertion. 05137 gains an arm for the destructive in-place path, which is the direct regression test for this commit, and a pre-arm `EXPLAIN PIPELINE` assertion so the runtime arm cannot go vacuous if `1 IN (SELECT 1)` is ever folded into a scalar comparison. In CI the failpoint is armed on purpose by BuzzHouse and replayed verbatim by the AST fuzzer out of the corpora of 04489_not_ready_set_inplace_build.sql and 04697_shared_set_error_not_inherited.sh, which is why the abort lands on queries that never asked for a set at all. Related: ClickHouse#118722 Co-Authored-By: Claude Opus 5 <[email protected]>
05137 asserts that the in-place set-build failpoint spends its one shot only on the build that can be redone, but it covered two of the three sites this branch classifies. `FutureSetFromSubquery::buildOrderedSetInplace` falls back to a destructive build when the subquery source cannot be cloned, and that site was a separately written `/*recoverable_build=*/false` that no test protected: flipping just that literal reddened nothing in the tree, so the classification which is this branch's whole contract was only two thirds asserted. Add an arm that reaches the fallback with the shot armed. `system.build_options` is read through `ReadFromSystemOneBlock`, which overrides neither `clone()` nor any base that does, so it inherits `IQueryPlanStep::clone()` and throws NOT_IMPLEMENTED; a primary key `IN` over it therefore lands on the fallback rather than on the clone-backed path. Which path it took is asserted rather than assumed: the arm brackets its query with `system.errors['NOT_IMPLEMENTED']` readings and requires the counter to grow, the technique 04489 already uses. So the arm cannot quietly turn into a second clone-backed arm should that source ever become clonable, which would also spend the shot early and make the arm after it vacuous. Measured, the delta is 1 for this shape and 0 for the clone-backed one. Also read `system.tables` once in the arm above it. It compared the outer read against a scalar subquery over the same table, and the two are evaluated at different times, so a system log table created lazily on its first flush in between would have flipped the assertion. `min(database = 'system')` keeps the property that the filter was really applied, and additionally pins which database survived it. Related: ClickHouse#118722 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex), three cold rounds, each paired with an Round 1, on the first binary:
Round 2, on the corrected binary, re-reviewed cold against the round-1 delta:
Round 3, on the test-only round-2 delta. No blocker and no major; the round-1 and round-2 findings
Checked without producing a finding, across the three rounds: every construction site of the new flag, Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260908-135600 |
Pre-PR validation gate (click to expand)
Mutation-tested: 5 mutants, each on its own verified Build ID with the running server's Session id: cron:clickhouse-impl-slot-4:20260908-131900 |
|
Workflow [PR], commit [b6f91e1] Summary: ✅
AI ReviewSummaryThis PR narrows Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit b6f91e1.
Changed lines: Changed C/C++ lines covered: 62/74 (83.78%) · Uncovered code |
|
cc @yariks5s @antaljanosbenjamin, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units481 translation units recompiled, 3985 s compile time in total, 481 of them have a recent master baseline. |
…uild-failpoint # Conflicts: # src/Interpreters/PreparedSets.h
b631947
Related: #118722
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
prepared_sets_build_ordered_set_inplace_failfault injection now fires only for the in-place set build that preserves its subquery source, so an armed failpoint can no longer leave another query's set uncreated and abort the server.Description
prepared_sets_build_ordered_set_inplace_fail(added in #107924 to simulate an in-place set build that stops without creating its set) is injected inCreatingSetsTransform::generate(), which serves every set build, in-place or runtime.SYSTEM ENABLE FAILPOINTis server-wide and aONCEarm survives until the firstgenerate()call anywhere, so the shot lands on whatever set build comes next. Where that build cannot be redone,finishInsert()is skipped andFunctionInraisesLOGICAL_ERROR"Not-ready Set is passed as the second argument", aborting a debug or sanitizer server. BuzzHouse arms failpoints deliberately and the AST fuzzer replays them out of test corpora, so the abort lands on queries that never asked for a set.Two lines reproduce it (
system.onehas no index, so the only build is the runtime one):Exactly one build survives being abandoned:
buildOrderedSetInplaceruns its speculative pipeline against a clone of the subquery source, so the deferred build still creates the set.FutureSetFromSubquery::buildmovessourceout, so the runtime build and the two in-place builds that go through it leave the set uncreated for good. Fix: carryrecoverable_buildonCreatingSetStep, set it at that one site, and consult it before thefiu_do_on, not inside it:fiu_failon a one-shot point spends the shot. Nothing changes when no failpoint is armed.The new test pins all three directions through
system.fail_points.enabled: still armed after a runtime build and after each of the two source-consuming in-place builds, spent after the recoverable one.04489and04697still pass.This removes one producer of #118722, which stays open, and overlaps @ alexey-milovidov's open #102308 / #102192, which change the recovery after a failed in-place build rather than the injection scope.
Carrier report: BuzzHouse (amd_debug), 2026-09-05; census in #118722.
Workflow [PR]
Sync PR [sync-upstream/pr/118817]
Version info
26.9.1.1409(included in26.9and later)