Skip to content

Restore short-circuit of a filter on an empty IN set over a Nullable column - #116538

Merged
fm4v merged 6 commits into
masterfrom
yarik/fix-empty-in-set-short-circuit
Aug 28, 2026
Merged

fm4v merged 6 commits into
masterfrom
yarik/fix-empty-in-set-short-circuit

Conversation

@yariks5s

@yariks5s yariks5s commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Fixed a performance regression since 26.6: a query filtering a Nullable column with IN (subquery) read the whole table instead of skipping the read when the subquery returned no rows. Closes #116450


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

Version info

  • Backported to: 26.8.1.2038, 26.7.6.48, 26.6.4.48

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


yariks5s seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [94532e4]

Summary: ✅


AI Review

Summary

This PR restores the empty-set short-circuit in FilterTransform::prepare() for Nullable IN (subquery) filters by inspecting the built ColumnSet directly instead of relying on the size-0 updateHeader() fold that lost constness after #100226. I did not find any remaining code-level correctness or performance issues in the current diff.

Final Verdict

✅ No review findings in the current patch.

LLVM Coverage Report

Measured on commit 94532e4.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 28/31 (90.32%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 94532e465 with master e9fc4b47c (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 712.33 MiB 709.27 MiB -3.06 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

no significant changes detected. K_source=6 K_base=29 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: e41af880-650e-4c91-a34b-0409e114f988
  • MIRAI run: 97be3c03-c8ae-4074-879b-6a1c05d1cf93
  • PR check IDs:
    • clickbench_38714_1787858547
    • clickbench_38726_1787858544
    • clickbench_38732_1787858545
    • tpch_adapted_1_official_38745_1787858546
    • tpch_adapted_1_official_38770_1787858544
    • tpch_adapted_1_official_38784_1787858544

@fm4v
fm4v added this pull request to the merge queue Aug 28, 2026
Merged via the queue into master with commit 4aee642 Aug 28, 2026
530 of 532 checks passed
@fm4v
fm4v deleted the yarik/fix-empty-in-set-short-circuit branch August 28, 2026 22:41
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 28, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 29, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Aug 29, 2026
Cherry pick #116538 to 26.6: Restore short-circuit of a filter on an empty IN set over a Nullable column
robot-clickhouse added a commit that referenced this pull request Aug 29, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Aug 29, 2026
Cherry pick #116538 to 26.7: Restore short-circuit of a filter on an empty IN set over a Nullable column
robot-clickhouse added a commit that referenced this pull request Aug 29, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Aug 29, 2026
Cherry pick #116538 to 26.8: Restore short-circuit of a filter on an empty IN set over a Nullable column
robot-clickhouse added a commit that referenced this pull request Aug 29, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 29, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #116538 to 26.6: Restore short-circuit of a filter on an empty IN set over a Nullable column
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #116538 to 26.8: Restore short-circuit of a filter on an empty IN set over a Nullable column
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #116538 to 26.7: Restore short-circuit of a filter on an empty IN set over a Nullable column
alexey-milovidov pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 17, 2026
…iled

FilterTransform::prepare ends the read when the filter is false for every
row once the sets are built. isAlwaysFalseByEmptySet (ClickHouse#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 (ClickHouse#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 ClickHouse#131133

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FINAL + empty IN (subquery) on a non-sort-key column stops short-circuiting since 26.6

6 participants