Skip to content

Cherry pick #131211 to 26.10: Keep the empty IN set early stop of a filter when its AND is JIT-compiled - #132187

Merged
robot-ch-test-poll4 merged 7 commits into
backport/26.10/131211from
cherrypick/26.10/131211
Nov 20, 2026
Merged

robot-ch-test-poll4 merged 7 commits into
backport/26.10/131211from
cherrypick/26.10/131211

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 6 commits November 13, 2026 06:16
…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
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 17, 2026
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]>
@groeneai

Copy link
Copy Markdown
Collaborator

Resolved. The only conflict is in src/Interpreters/ExpressionJIT.cpp: the new ActionsDAG::getCompiledConjuncts sits right above compileFunctions, whose parameter type is std::unordered_set on 26.10 (master changed it to UnorderedSetWithMemoryTracking in #129617, which is not labelled for backport, so the robot's retry cannot clear this). The resolution keeps the 26.10 signature, and its diff against backport/26.10/131211 is exactly the lines of #131211 (5 files, +114 -3). The JIT code it relies on (getCompilableDAG, CompileDAG) differs from master only in container types and [[nodiscard]].

26.10 is affected: on the official 26.10.5.45 build, the six assert_no_read queries of 05628_empty_in_set_short_circuit_compiled read 90725 to 100000 rows instead of 0.

Validated on the resolved tree, debug build: the test passes 6 of 6 runs with randomized settings and fails with the FilterTransform.cpp change reverted. The two changed .cpp files also compile with 26.10's clang-22. 188 related stateless tests (compile_expressions, empty sets, short circuit) show no new failure.

I cannot push to cherrypick/26.10/131211 (read-only access to this repository). The resolution is on my fork and this PR's head is its first parent, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse groeneai/resolve-26.10-cherrypick-131211
git push origin FETCH_HEAD:cherrypick/26.10/131211

(resolved head 24ef9a0672fe7f5c2ec61af18e321905c78a7c82)

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Dear @Manerone, @groeneai, this cherry-pick PR has not been updated for 3d0h3m48s. Please resolve the conflicts to backport #131211, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@Manerone

Copy link
Copy Markdown
Contributor

@groeneai solve the conflicts

@groeneai

Copy link
Copy Markdown
Collaborator

The conflicts are already resolved on my fork (details in #132187 (comment)). I can't push to cherrypick/26.10/131211 because I have read-only access to this repository. This PR's current head 5221e527 is the first parent of the resolution, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse groeneai/resolve-26.10-cherrypick-131211
git push origin FETCH_HEAD:cherrypick/26.10/131211

Resolved head: 24ef9a0672fe7f5c2ec61af18e321905c78a7c82. Its diff against backport/26.10/131211 is exactly the 5 files of #131211 (+114 -3).

@robot-ch-test-poll4
robot-ch-test-poll4 merged commit 63f3d68 into backport/26.10/131211 Nov 20, 2026
2 checks passed
@robot-ch-test-poll4
robot-ch-test-poll4 deleted the cherrypick/26.10/131211 branch November 20, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants