Repository navigation
Conversation
`IFunction::executeImplDryRun` defaults to an unqualified virtual call to
`executeImpl`, so a wrapper that overrides only `executeImpl` silently turns a
dry run into a real run of whatever it delegates to.
`FunctionMapToArrayAdapter` forwards `isVariadic`, `getNumberOfArguments`, the
`useDefaultImplementationFor*` predicates, `isHigherOrderFunction`,
`getLambdaArgumentTypes`, `getReturnTypeImpl` and `executeImpl` to `impl`, but
not `executeImplDryRun`, so every `map*` function that takes a user lambda
evaluated the lambda body for real during constant folding:
SELECT mapFilter((k, v) -> k IN (SELECT 1), map(1, 2));
`ActionsDAG::updateHeader` folds constants through `evaluatePartialResult` with
`dry_run = true`, and that flag exists so `FunctionIn::executeImplDryRun`
yields a dummy instead of throwing on a set the plan has not built yet. With
the flag lost, `FunctionIn::executeImpl` throws "Not-ready Set is passed as the
second argument for function 'in'": a release build rejects the valid query
with Code: 49, and a debug or sanitizer build aborts the server.
`FunctionArrayMapped` already honours the contract, with `executeImplDryRun`
and `executeImpl` both delegating to `executeImplCommon(..., dry_run)`. That is
why every `array*` higher-order function was correct, and this mirrors its
shape.
Measured: `mapFilter`, `mapApply`, `mapExists`, `mapAll`, `mapSort`,
`mapPartialSort`, `mapReverseSort` and `mapPartialReverseSort` all aborted,
while `arrayFilter`, `arrayMap` and `arraySort` did not. The split is exactly
the adapter boundary.
Related: ClickHouse#107619
Co-Authored-By: Claude Opus 5 <[email protected]>
`mapContainsKeyLike`, `mapContainsValueLike`, `mapExtractKeyLike` and `mapExtractValueLike` are registered as `FunctionWithLowCardinalityFastPath<FunctionMapToArrayAdapter<...>>`. The mixin turns off `useDefaultImplementationForLowCardinalityColumns` and `useDefaultImplementationForConstants` and restores both itself, deliberately by redoing the call on a plain delegate instead of reimplementing the rules, and its `getReturnTypeImpl` override answers for the type that path produces. Without this commit those four functions inherit the adapter's new `executeImplDryRun`, so a dry run would take neither the fast path nor the delegate redo while `getReturnTypeImpl` still answers for the mixin. I looked for a spelling where that is observable and did not find one: `mapExtractKeyLike` and `mapContainsKeyLike` on `Map(LowCardinality(String), String)`, and `mapExtractValueLike` on `Map(String, LowCardinality(String))`, return the same value and the same type either way. That the two paths agree by coincidence is not a property worth depending on, so they are kept in agreement explicitly, which also removes the hardcoded `dry_run = false` on the delegate call. `arrayElement` and `arrayElementOrNull`, the mixin's other two users, have a `Base` without an `executeImplDryRun` override, so theirs resolves to the `IFunction` default whose virtual `executeImpl` re-enters the mixin once and runs exactly the code it ran before. The only cost is one extra declined `tryExecuteLowCardinality` probe per dry run, on a zero-row call. Co-Authored-By: Claude Opus 5 <[email protected]>
`arrayFold` is the only higher-order function in the tree that is not derived
from `FunctionArrayMapped`. It called `ColumnFunction::reduce()` and took the
`bool dry_run = false` default argument, so there was no literal `false` to
find:
SELECT arrayFilter(k -> arrayFold((acc, x) -> x IN (SELECT 1), [k], toUInt8(0)), [1, 2]);
aborted with "Not-ready Set is passed as the second argument for function
'in'". Only the nested form reaches it: `arrayFold`'s `reduce()` sits inside
the per-slice loop, which does not run at zero rows, so a top-level
`arrayFold` is folded without ever evaluating the lambda. Nested under any
`array*` or `map*` lambda, the enclosing function correctly threads `dry_run`
into the lambda body and `arrayFold` then dropped it.
The test takes one case per distinct `FunctionMapToArrayAdapter` trait
combination rather than one per spelling: `mapFilter`
(`preserve_nested_low_cardinality`, no fixed params), `mapApply`
(`Impl = FunctionArrayMap`, so `preserve` is off), `mapExists` (scalar result,
boolean lambda), `mapSort` (`Impl = FunctionArraySort`, optional lambda) and
`mapPartialSort` (one fixed param), plus `arrayFold`, `arrayFilter` as the
already-correct reference and `mapExtractKeyLike` for the LowCardinality
mixin. `mapAll`, `mapReverseSort` and `mapPartialReverseSort` share a path
already covered.
Every expected value was taken independently, by replacing `IN (SELECT ...)`
with the equivalent literal set on an unpatched binary, so the test pins the
semantically correct answers rather than whatever the fix happens to produce.
Co-Authored-By: Claude Opus 5 <[email protected]>
This reverts the mixin's `executeImplDryRun`. No spelling makes it observable,
so it is a change with no reddening test, and it does not belong in this pull
request.
`mapContainsKeyLike`, `mapContainsValueLike`, `mapExtractKeyLike` and
`mapExtractValueLike` are registered as
`FunctionWithLowCardinalityFastPath<FunctionMapToArrayAdapter<...>>`, so without
the override they inherit the adapter's `executeImplDryRun` instead of taking the
mixin's own fast path or its delegate redo. I probed the three spellings where
that could differ and all three are value- and type-identical either way:
- `mapExtractKeyLike(m, 'a%')` over `Map(LowCardinality(String), String)`
returns `{'a':'b'}` of type `Map(String, String)`;
- `mapExtractValueLike(m, 'b%')` over `Map(String, LowCardinality(String))`
returns `{'a':'b'}` of type `Map(String, String)`;
- `mapContainsKeyLike(m, 'a%')` over `Map(LowCardinality(String), String)`,
wrapped in a subquery so the result goes through `ActionsDAG::updateHeader`,
returns `1`.
The remaining argument for the override was that the two paths agree by
coincidence rather than by construction. That is a defence against a defect
nothing reproduces, and it costs twenty lines in a mixin `arrayElement` and
`arrayElementOrNull` also use, so the narrower tree is the better one to ship.
The inherited path is pinned by a test case instead.
Co-Authored-By: Claude Opus 5 <[email protected]>
`mapAll`, `mapReverseSort` and `mapPartialReverseSort` reach the same adapter and aborted the same way before the fix, so the test now covers all eight spellings rather than five. Each expected value is derived on an unpatched binary by substituting the equivalent literal set for the subquery, so the reference records what the query should return rather than what the fix happens to return. The last case reaches the adapter through the LowCardinality fast-path mixin and now pins the result type as well as the value, which is what that case is there to hold: those four functions inherit the adapter's `executeImplDryRun`, and both their value and their type must stay as they are. Co-Authored-By: Claude Opus 5 <[email protected]>
`mapContainsKeyLike`, `mapContainsValueLike`, `mapExtractKeyLike` and
`mapExtractValueLike` are registered as
`FunctionWithLowCardinalityFastPath<FunctionMapToArrayAdapter<...>>`, and the
mixin inherits from the adapter rather than wrapping it. Adding
`executeImplDryRun` to the adapter therefore makes the mixin inherit it, so a dry
run takes neither the mixin's fast path nor its delegate redo, while the mixin's
`getReturnTypeImpl` still answers from the delegate.
That is observable whenever the delegate's resolver wraps the result in
`LowCardinality`, which `IFunctionOverloadResolver::getReturnType` does only when
two things hold at once: an argument whose own type is `LowCardinality` (not one
nested inside a `Map`) with every argument constant, and a result type for which
`canBeInsideLowCardinality` is true. Both hold for `mapContainsKeyLike` and
`mapContainsValueLike` called with a `toLowCardinality` pattern, since they
return `UInt8`. The analyzer folds such a call as a dry run and compares the
column it got against the type it declared:
SELECT mapContainsKeyLike(map('aa', toLowCardinality(1), 'bb', toLowCardinality(2)), toLowCardinality('a%'));
Logical error: 'Unexpected return type from mapContainsKeyLike.
Expected LowCardinality(UInt8). Got UInt8'
That query is `03002_map_array_functions_with_low_cardinality`, which aborts on a
debug or sanitizer build without this commit. `mapExtractKeyLike` and
`mapExtractValueLike` return `Map(...)`, which cannot be inside
`LowCardinality`, so no input exposes it through them.
Taking the dry run through the same delegate keeps the produced column and the
declared type in agreement by construction, and removes the hardcoded
`dry_run = false` on the delegate call.
`arrayElement` and `arrayElementOrNull`, the mixin's other two users, have a
`Base` without an `executeImplDryRun` override, so theirs resolves to the
`IFunction` default whose virtual `executeImpl` re-enters the mixin once and runs
exactly the code it ran before. The only cost is one extra declined
`tryExecuteLowCardinality` probe per dry run, on a zero-row call.
Co-Authored-By: Claude Opus 5 <[email protected]>
`05214_higher_order_lambda_dry_run_in_subquery` covered the four `map*Like` functions only through `mapExtractKeyLike`, which returns `Map(...)`. A `Map` cannot be inside `LowCardinality`, so the resolver never wraps that result and the arm cannot distinguish the mixin's dry-run path from the adapter's: it is a value and type pin, not an oracle. `mapContainsKeyLike` and `mapContainsValueLike` return `UInt8`, which can be. Two arms add the second condition the wrap needs, a `LowCardinality` argument of the function's own with every argument constant, and select the value together with `toTypeName`, so the declared `LowCardinality(UInt8)` is pinned as well as the value. Reverting the mixin's `executeImplDryRun` makes both fail. Expected values and type strings come from a build with none of this branch's changes. The `mapExtractKeyLike` arm stays, with its comment corrected to the no-regression pin it actually is. Co-Authored-By: Claude Opus 5 <[email protected]>
…tation `.claude/CLAUDE.md` asks for method names written as `f` rather than with a trailing empty argument list, and for class and function names wrapped in inline code blocks. The doc-block bullet this branch added to `FunctionWithLowCardinalityFastPath` spelled `executeImplDryRun` with parentheses and left `Base` and `getReturnTypeImpl` bare. Only the bullet this branch added is adjusted. The block's older bullets keep their existing style, so the diff stays on the lines under review. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review (click to expand)An independent model reviewed this change against the resulting code, without access to the
The one decision I am not making myself. The constant- Three claims were withdrawn along the way: a suspected silently-dropped row under a selective |
|
Workflow [PR], commit [5a0b578] Summary: ❌
AI ReviewSummaryThis PR forwards dry-run execution through Findings❌ Blockers
Final VerdictStatus: ❌ Block. Minimum required action: land the captured-set readiness fix, either here or as a prerequisite, with a regression proving that the constant |
|
|
||
| SELECT mapFilter((k, v) -> k IN (SELECT 1), map(1, 2, 3, 4)); | ||
| SELECT mapApply((k, v) -> (k, v IN (SELECT 2)), map(1, 2, 3, 4)); | ||
| SELECT mapExists((k, v) -> k IN (SELECT 1), map(1, 2, 3, 4)); |
There was a problem hiding this comment.
This still leaves one advertised surface broken: in a filter context the result can be frozen from the dry run instead of the real execution. FilterTransform::prepare re-evaluates the filter through updateHeader and trusts a constant result, but ExecutableFunctionCapture::executeImpl still wraps any all-constant capture into ColumnConst(ColumnFunction) without the suitability check that FunctionCapture::isSuitableForConstantFolding applies. On this branch, SELECT number FROM numbers(1) WHERE mapExists((k, v) -> k IN (SELECT 1), map(1, 2)) still drops the row even though mapExists is listed as fixed here. I think this needs either the capture-side fix plus a WHERE regression test, or a narrower PR scope/changelog that stops claiming mapExists is repaired.
There was a problem hiding this comment.
Confirmed, and I am taking your second option.
Measured on this head (caea5f6d9e903, debug, Build ID 82a50608e3420bc5732a5123e316d7cb3fe52958) against a master build carrying none of these changes (8ec7c5beabbf3), exit code captured on every probe:
| query | master | this branch |
|---|---|---|
SELECT number FROM numbers(1) WHERE mapExists((k, v) -> k IN (SELECT 1), map(1, 2)) |
rc 134, aborted | rc 0, no rows |
SELECT number FROM numbers(1) WHERE arrayExists(x -> x IN (SELECT 1), [1, 2]) (not touched here) |
rc 0, no rows | rc 0, no rows |
SELECT mapExists((k, v) -> k IN (SELECT 1), map(1, 2)) |
rc 134, aborted | rc 0, 1 |
SELECT number FROM numbers(2) WHERE mapExists((k, v) -> k IN (SELECT 1), map(number, 2)) |
rc 0, 1 |
rc 0, 1 |
So the row is dropped, as you say, and the description now says exactly that. Its earlier wording read as though the row were already dropped on master, when master aborts on that query instead; that is corrected. The description now states that this change removes the abort only, claims no repaired filter result, and leaves the constant-WHERE shape returning the wrong answer the untouched arrayExists equivalent already returns. The changelog entry names only the LOGICAL_ERROR and the Code: 49 rejection.
I am not folding the capture-side fix in here. Gating the const-wrap on lambda-body suitability was implemented and measured to change nothing, because the set is a captured argument rather than part of the lambda body; the predicate that does work inspects the captured arguments instead, which changes shared constant-folding machinery. It gets its own pull request, as #119907 (comment) already committed to. A WHERE arm belongs with it: added here, its expected output would be today's wrong answer.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+29.09 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units9 translation units recompiled, 62 s compile time in total, 9 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…-order-dry-run-not-ready-set Resolve the conflict in `src/Functions/array/arrayFold.cpp`: master added `[[nodiscard]]` to `executeImpl` (`modernize-use-nodiscard`, ClickHouse#126158), which this branch split into `executeImpl`, `executeImplDryRun` and `executeImplCommon`. All three now carry `[[nodiscard]]`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master enables clang-tidy `modernize-use-nodiscard` (ClickHouse#126158) and marks every `executeImpl` `[[nodiscard]]`; the `executeImplDryRun` and `executeImplCommon` overrides added by this branch get the same attribute. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #107619
Related: #119855
Related: #119938
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR(Not-ready Set is passed as the second argument for function 'in') when a lambda given to amap*higher-order function (mapFilter,mapApply,mapExists,mapAlland the fourmap*Sortvariants) or to a nestedarrayFoldcontains anINsubquery, for exampleSELECT mapFilter((k, v) -> k IN (SELECT 1), map(1, 2)). Such a query was rejected withCode: 49on release builds and aborted debug and sanitizer builds.Description
IFunction::executeImplDryRundefaults to an unqualified virtual call toexecuteImpl, so a wrapper overriding onlyexecuteImplturns a dry run into a real run.ActionsDAG::updateHeaderfolds constant-argument nodes withdry_run = trueso thatFunctionIn::executeImplDryRunyields a dummy for a set the plan has not built yet.Two wrappers dropped the flag:
FunctionMapToArrayAdapterforwards its other methods toimplbut not this one, so every lambda-takingmap*ran the lambda body for real.FunctionArrayFoldcalledColumnFunction::reduce, taking itsbool dry_run = falsedefault. Only the nested form reaches it: a top-level zero-row dry run returns before the loop callingreduce.FunctionArrayMappedalready threads it, soarray*was correct; both fixes mirror it.FunctionWithLowCardinalityFastPathinherits from the adapter, so the fourmap*Likefunctions would otherwise inherit the override and answer a dry run from a path itsgetReturnTypeImpldoes not describe, aborting03002_map_array_functions_with_low_cardinality. It now forwards the flag through the delegate it already uses.This PR removes the abort only, and claims no repaired filter result. A constant
WHEREover such a lambda is rejected or aborts on master and returns no rows here:ExecutableFunctionCapture::executeImplmakes an all-constant capture constant without the suitability check its analysis-time sibling applies, so the non-constant dry-run dummy becomes a definitivefalse. That defect is untouched here and pre-existing, asWHERE arrayExists(x -> x IN (SELECT 1), [1, 2])shows on master; the capture side gets its own pull request.Test expectations come from literal-set equivalents on an unpatched binary. The override is also missing on
26.3through26.8, so released versions are affected. CI provenance: Stress test (amd_tsan).Workflow [PR]
Sync PR [sync-upstream/pr/119907]