Skip to content

Fix logical error !subranges.empty() - #100543

Merged
al13n321 merged 14 commits into
ClickHouse:masterfrom
zoomxi:fix_subranges_empty
Apr 15, 2026
Merged

al13n321 merged 14 commits into
ClickHouse:masterfrom
zoomxi:fix_subranges_empty

Conversation

@zoomxi

@zoomxi zoomxi commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

When processing Parquet files with bloom filter push down enabled, empty IN/NOT IN clauses can cause an assertion failure.

CI Report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=94140&sha=7fe6f50be1ff4259ae0673f2827b8de691661827&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
#94140

Changelog category (leave one):

  • Improvement

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

Fix assertion failure in Parquet bloom filter push down when using empty IN/NOT IN clauses.

Version info

  • Merged into: 26.4.1.947

@zoomxi zoomxi changed the title Fix loginal error !subranges.empty() Fix logical error !subranges.empty() Mar 24, 2026
@Algunenano Algunenano added the can be tested Allows running workflows for external contributors label Mar 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fb6ba09]

Summary: ✅


AI Review

Summary

This PR fixes an assertion failure in Parquet bloom-filter pushdown for empty IN/NOT IN predicates by guarding splitRange when no bloom-filter blocks are selected. The code change is small and targeted, and the added stateless test covers the failing empty-set scenarios. I did not find additional correctness, safety, performance, or compatibility issues beyond already-discussed review threads.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 24, 2026
@zoomxi
zoomxi force-pushed the fix_subranges_empty branch from 65f8644 to 1b3baf1 Compare March 24, 2026 11:30
@zoomxi

zoomxi commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

Bugfix validation (functional tests)
The Bugfix validation step runs the new test against the master branch's release build. The original bug manifests as a chassert(!subranges.empty()) failure.

@zoomxi

zoomxi commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

@Algunenano Would you mind reviewing this when you have a moment?

Comment on lines 493 to 494
if (!hashes.has_value() || hashes->empty())
return std::nullopt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, doesn't this mean read all rows if there's IN ()? We should read none of the rows instead (unless it's something like (IN ()) OR 1). Or rather we shouldn't do anything special in this case, empty set can be handled the same way as any other set, AFAICT nothing will break except that assert in splitRange.

I think a better fix is to just skip the splitRange in processBloomFilterHeader if no blocks are needed:

    std::vector<PrefetchHandle> prefetches;
    if (!subranges.empty()) // can be empty e.g. if `WHERE x IN ()`
        prefetches = prefetcher.splitRange(std::move(column.bloom_filter_data_prefetch), subranges, /*likely_to_be_used*/ false);

(The reason splitRange requires nonempty list of subranges is that it transfers the memory tracking token from the original range into the subranges. If there are no subranges, it's unclear what to do with the memory tracking state. This proposed solution just leaves the token in bloom_filter_data_prefetch) until ReadManager::clearColumnChunk clears it soon after. This is fine.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as suggested, thanks.

@al13n321 al13n321 self-assigned this Apr 1, 2026
@al13n321

al13n321 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

If the test doesn't repro it, try adding input_format_parquet_filter_push_down = 0.

@zoomxi
zoomxi force-pushed the fix_subranges_empty branch from 1b3baf1 to 19c9108 Compare April 1, 2026 13:45
@al13n321

al13n321 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

(Changed category in PR description so that Bugfix validation CI check is not required. That check fails to repro this because it uses non-debug build with asserts disabled. I checked that the added test fails without the fix in debug build.)

@al13n321
al13n321 enabled auto-merge April 1, 2026 19:45
@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Apr 1, 2026
@zoomxi

zoomxi commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@alexey-milovidov

Copy link
Copy Markdown
Member

The test 02859_replicated_db_name_zookeeper is fixed in #101952

@alexey-milovidov

Copy link
Copy Markdown
Member

The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158

@alexey-milovidov

Copy link
Copy Markdown
Member

The Can't adjust last granule error in CI is a known issue. The fix is in #101641

@alexey-milovidov

Copy link
Copy Markdown
Member

The flaky check failure is fixed in #102148, let's update the branch.

@zoomxi

zoomxi commented Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

@clickhouse-gh

clickhouse-gh Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 100.00% (8/8) · Uncovered code

Full report · Diff report

@al13n321
al13n321 added this pull request to the merge queue Apr 15, 2026
Merged via the queue into ClickHouse:master with commit 93fde6a Apr 15, 2026
161 checks passed
@zoomxi
zoomxi deleted the fix_subranges_empty branch April 15, 2026 06:07
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 15, 2026
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-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants