Repository navigation
Cherry pick #131211 to 26.10: Keep the empty IN set early stop of a filter when its AND is JIT-compiled - #132187
Conversation
…iled FilterTransform::prepare ends the read when the filter is false for every row once the sets are built. isAlwaysFalseByEmptySet (#116538) finds an `in`/`globalIn` over an empty set by following `and` nodes by name. With compile_expressions, ActionsDAG::compileFunctions replaces a compilable `and` with an LLVMFunction whose name is the CompileDAG dump and whose children are the INPUT nodes of the compiled DAG. The `in` (not compilable) becomes one of those children, but the walk stops at the compiled node because it is not named `and`. The updateHeader dry run does not fold it either: a 0-row `in` over a Nullable column is not constant, and LLVMExecutableFunction folds only when all arguments are constant. So the source is read to the end of the key range and every row is filtered out afterwards (#131133: 14 ms -> 203 ms on the synthetic repro, 29.7 s -> 214.6 s on the original query). ActionsDAG::getCompiledConjuncts, next to getCompiledFunctions, maps the i-th INPUT of the compiled DAG to the i-th child of the node (the order getCompilableDAG appends them in and compileFunctions swaps them in) and returns the children reached from the root through `and` FUNCTION nodes only. isAlwaysFalseByEmptySet recurses into them for a compiled node. Any other shape (non-LLVM function, a root that is not `and`, an input count mismatch) returns nothing, which is the previous behaviour. With query_plan_merge_filters (default), FilterStep splits AND atoms into separate filters, so a flat `a > 10 AND x IN (...)` leaves `and(<input>, in)` with no compilable child and is never compiled. The `and` is compiled when the remainder keeps a nested `and` (the issue's shape) or with query_plan_merge_filters = 0; the test covers both. Closes #131133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
isAlwaysFalseByEmptySet ends the read at prepare time when a conjunct is an IN over an empty set. It did not check FutureSet::isMutableDuringQuery: the set of an ENGINE = Set table is the very Set object that StorageSet::insertBlock fills, so a concurrent INSERT can make it non-empty while the query runs. Index analysis already refuses such sets (05078); with the previous commit every JIT-compiled AND reaches this walk, so a compiled filter over an empty Set table would now stop reading. Refuse mutable sets, for the uncompiled walk as well, so both paths agree. With transform_null_in = 1 the analyzer rewrites IN to nullIn. Without the JIT the header dry run folds it (05045), but under a compiled AND it cannot fold (LLVMExecutableFunction folds only all-constant arguments) and the walk rejected the name, so the slowdown from #131133 remained for the same query under that setting. nullIn(x, empty set) is 0 for every x, NULL included, so accept nullIn and globalNullIn. The test gains a transform_null_in = 1 assert and an empty ENGINE = Set table that must still be read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reword the empty-set fold comment: the negative variants never make the filter always false (NULL NOT IN () is NULL, not true). Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Interpreters/ExpressionJIT.cpp
The walk returns only the INPUTs of the compiled `and` chain. That finds every `in` conjunct because `FunctionIn` does not override `isCompilableImpl` and a `Set` argument fails `canBeNativeType`, so an `in` always stays a child of the compiled node. Make that dependency visible where it lives. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rly-stop Keep the empty `IN` set early stop of a filter when its `AND` is JIT-compiled
Resolve the conflict in src/Interpreters/ExpressionJIT.cpp: the new ActionsDAG::getCompiledConjuncts sits right above compileFunctions, whose parameter type differs on 26.10 (std::unordered_set; master switched it to UnorderedSetWithMemoryTracking in #129617, which is not on 26.10). Keep the 26.10 signature and add only the lines of #131211. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Resolved. The only conflict is in 26.10 is affected: on the official 26.10.5.45 build, the six Validated on the resolved tree, debug build: the test passes 6 of 6 runs with randomized settings and fails with the I cannot push to (resolved head |
|
@groeneai solve the conflicts |
|
The conflicts are already resolved on my fork (details in #132187 (comment)). I can't push to Resolved head: |
Original pull-request #131211
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job