Skip to content

Fix bloom_filter index skipping granules for IN with an empty array in the set - #116449

Merged
fm4v merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-116431-bloom-filter-array-in-empty-array
Aug 31, 2026
Merged

fm4v merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-116431-bloom-filter-array-in-empty-array

Conversation

@groeneai

@groeneai groeneai commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix a bloom_filter skip index returning fewer rows for IN on an Array column when the set contains an empty array, for example WHERE x IN ([]).

Description

Closes #116431.

An Array bloom_filter index stores one hash per element, so a set array is looked up by its elements. An empty set array contributes no element, so no hash in a granule filter can stand for it, and a granule holding [] next to non-empty arrays is skipped even though it matches.

CREATE TABLE t (x Array(UInt32), INDEX idx x TYPE bloom_filter GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 2;
INSERT INTO t VALUES ([]), ([1]), ([2]), ([3]);

SELECT count() FROM t WHERE x IN ([]);      -- 0, expected 1
SELECT count() FROM t WHERE x IN ([], [2]); -- 1, expected 2

Default settings; transform_null_in is not involved. It also reaches a subquery set, a tuple IN with an array component, and Array(String) / Array(LowCardinality(String)).

The unsound shape is narrower than "the index column is an Array": it is "the set contains an empty array". A non-empty set array always contributes at least one element hash, so bailing out for every Array index would drop pruning that works today. The guard therefore withholds the array predicate only when the set holds an empty array. It withholds the predicate rather than only the FUNCTION_IN assignment because traverseTreeIn accumulates every tuple component into one RPNElement, where a scalar sibling would otherwise re-enable the array lookup.

notIn/globalNotIn are unaffected: FUNCTION_NOT_IN inverts the mask and never skips a granule. The equals handler already refuses an Array index for the same reason. This is the in/globalIn sibling of the nullIn guard added in #111329.

Reproduced on 25.8.33.6 and 26.3.23.7. Validated with builds of this branch and its base differing only by this patch: 9 of the new test's assertions fail on the base, and an absent value still prunes to Granules: 0/24 over 200k rows.


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

Version info

  • Merged into: 26.9.1.453 (included in 26.9 and later)
  • Backported to: 26.8.2.5, 26.7.6.54, 26.6.4.63

An Array bloom_filter index stores one hash per element, so a set array is
looked up by its elements. An empty set array contributes no element, so no
hash in a granule filter can stand for it, and a granule holding [] together
with non-empty arrays is skipped even though it matches.

WHERE x IN ([]) on Array(UInt32) therefore returned 0 rows instead of 1 at
use_skip_indexes = 1, and WHERE x IN ([], [2]) returned 1 row instead of 2.
Default settings; transform_null_in is not involved.

The unsound shape is narrower than "the index column is an Array": it is "the
set contains an empty array". A non-empty set array always contributes at least
one element hash, so it is looked up soundly. Bailing out for every Array index
would drop pruning that works today, so the guard declines pruning only when
the set actually holds an empty array. Measured on 200k rows over 24 granules,
an absent value is still pruned to 0/24 with the guard in place.

notIn/globalNotIn are unaffected, because FUNCTION_NOT_IN inverts the mask and
never skips a granule.

The equals handler already refuses an Array index for the same reason.
…lookup

Suppressing only the `FUNCTION_IN` assignment is not enough. `traverseTreeIn`
accumulates every tuple component into one `RPNElement`, so with a single index
over both components the array component still appended its predicate and a
scalar sibling then set `FUNCTION_IN`, which re-enabled the unsound array
lookup:

    CREATE TABLE t (x Array(UInt32), y UInt32,
      INDEX idx_xy (x, y) TYPE bloom_filter GRANULARITY 1)
    ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 2;
    INSERT INTO t VALUES ([], 1), ([1], 2), ([2], 3), ([3], 4);
    SELECT count() FROM t WHERE (x, y) IN (([], 1), ([2], 3)); -- 1, expected 2

Contribute nothing from that component instead. The remaining components still
restrict the granule, so pruning is only weakened, never made unsound.

The earlier tuple arms used one index per column, where the array index never
sees the sibling that sets `FUNCTION_IN`, so they passed without covering this.
They are replaced by arms over a single `(x, y)` index in both component orders.

Read the array sizes through the public `ColumnArray::getSize` instead of
indexing the offsets directly.
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8fe1f26]

Summary: ❌

job_name test_name status info comment
Docker server image FAIL
clickhouse/clickhouse-server:head-distroless-arm64 FAIL cidb IGNORED

AI Review

Summary

This PR fixes bloom_filter skip-index false pruning for IN predicates on Array-typed index expressions when the right-hand set contains an empty array, by declining to build a bloom predicate for that unsupported value shape. I reviewed the current diff, the touched MergeTreeIndexBloomFilter paths, the PR metadata, and the added stateless coverage, and I did not find an actionable correctness, safety, or metadata issue in the current revision.

Final Verdict

✅ No actionable findings in the current diff.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.30% 87.30% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.50% +0.10%

Changed lines: Changed C/C++ lines covered: 17/18 (94.44%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 26, 2026
@groeneai groeneai added the can be tested Allows running workflows for external contributors label Aug 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8fe1f2640 with master 4ad204f1c (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 66b113278; 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 710.23 MiB 707.19 MiB -3.04 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, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

The keep-pruning control asserted `Granules: 0/N`, that is, that every granule
is skipped for an absent value. That is a property of the filter's false
positive draw rather than of the guard, and the draw is taken over however many
granules the part has. `index_granularity_bytes` is randomized in
[1024, 30Mi], and the table pins only `index_granularity`, so the same 200000
rows form anywhere from 25 to 3922 granules. Below about 160000 bytes some
granule takes a false positive and the assertion fails:

    index_granularity_bytes    granules    skip index
    1024                       3922        171/3922
    57942                       69            3/69     <- the CI failure
    163840                      25            0/24

The draw has no margin even at a fixed layout: of twelve absent probe pairs
against the 8192-row layout, only seven skip every granule.

Assert instead what the control is for: the index is still reached for a set
with no empty array, and it still skips granules. An over-declining guard
returns no predicate, the condition becomes unknown, and the index drops out of
the plan with no `Skip` block at all, so the control still fails.
@groeneai

groeneai commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8fe1f26

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Docker server image / clickhouse/clickhouse-server:head-distroless-arm64 CI infra: the image build's apt-get step failed against the EC2 mirror and the Canonical fallback never engaged #116441 (ours, open)

The failing step is Dockerfile.distroless:31. Its apt-get update logged W: Some index files failed to download six times, then the install failed with E: Package 'ca-certificates' has no installation candidate and E: Unable to locate package wget against
us-east-1.ec2.archive.ubuntu.com. The job log carries apt mirror 1/2 six times and apt mirror 2/2 zero times, and no line reporting exhausted retries, so the Canonical fallback never ran.
Merged #115726 added that fallback and is present in this tree, so I am not linking it: its guard
anchors on the string ERROR: failed to solve:, which occurs 0 times in the log, whereas buildx
prints ERROR: failed to build: failed to solve:, which occurs 3 times, so the guard fails closed.
#116441 repairs exactly that anchor in ci/jobs/docker_server.py.

⚠️ Measured residual, so this row has an owner but is not fully closed by it. Running #116441's own
repaired predicate against this job's output does recover the terminal step, with
terminal_build_failure going from 0 to 2242 characters, yet is_apt_mirror_failure still returns
False. The reason is that the mirror withheld the package index rather than a .deb: apt-get update reported that as W: Some index files failed to download and carried on, and the terminal
E: lines are the downstream consequence, E: Package 'ca-certificates' has no installation candidate and E: Unable to locate package wget, neither of which matches an APT_MIRROR_ERRORS
token. Harness liveness for that measurement: the same predicate returns True on the shape #116441
itself asserts, E: Failed to fetch ... 503, and False on empty input. So #116441 owns the anchor
half of this failure, and the index-phase half is already recorded on the tracking work behind
#116441 as a second, independent defect, so I am not opening a separate fix task for it here.

Not caused by this PR: the diff is src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp plus one
stateless test and its reference, none of which is read while building a Docker image. All five
flaky check arms are green on this head, and CIDB at this commit returns exactly the one failing
row above, against a control of 304,982 rows at the same commit.

Session id: cron:our-pr-ci-monitor:20260826-130000

@kirillshokhin kirillshokhin self-assigned this Aug 27, 2026
@fm4v
fm4v enabled auto-merge August 31, 2026 09:04
@fm4v
fm4v added this pull request to the merge queue Aug 31, 2026
Merged via the queue into ClickHouse:master with commit cf7587e Aug 31, 2026
177 of 179 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 31, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 31, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 31, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 31, 2026
Backport #116449 to 26.7: Fix `bloom_filter` index skipping granules for `IN` with an empty array in the set
clickhouse-gh Bot added a commit that referenced this pull request Aug 31, 2026
Backport #116449 to 26.8: Fix `bloom_filter` index skipping granules for `IN` with an empty array in the set
clickhouse-gh Bot added a commit that referenced this pull request Aug 31, 2026
Backport #116449 to 26.6: Fix `bloom_filter` index skipping granules for `IN` with an empty array in the set
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
… granules for `IN` with an empty array in the set
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
… granules for `IN` with an empty array in the set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

bloom_filter IN on Array column misses rows: Array guard only on new nullIn branch

6 participants