Skip to content

Fix bloom_filter index mistaking a column named mapKeys(m) for the Map index - #130814

Merged
alexey-milovidov merged 4 commits into
masterfrom
ahmadov/fix-bf-index-name
Nov 13, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
ahmadov/fix-bf-index-name

Conversation

@ahmadov

@ahmadov ahmadov commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

A bloom_filter index on a table column literally named mapKeys(m) or mapValues(m) was resolved by name as an index on the mapKeys/mapValues expression over the Map column m. A SELECT with m['k'] = 'v' then crashed the server for a FixedString column and pruned matching granules for a LowCardinality(String) column.

Collect the positions of the genuine mapKeys/mapValues functions from the index expression and accept a name match only at those positions.

Fixes https://github.com/ClickHouse/clickhouse-private/issues/85653.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix a crash and wrong query results when a table has a column literally named mapKeys(m) or mapValues(m) with a bloom_filter index on it.


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

Version info

  • Merged into: 26.11.1.2222-master (included in 26.11 and later)
  • Backported to: 26.10.5.31, 26.9.29.3, 26.8.38.3, 26.3.64.3

…e `Map` index

A `bloom_filter` index on a table column literally named `mapKeys(m)` or
`mapValues(m)` was resolved by name as an index on the `mapKeys`/`mapValues`
expression over the `Map` column `m`. A `SELECT` with `m['k'] = 'v'` then
crashed the server for a `FixedString` column and pruned matching granules
for a `LowCardinality(String)` column.

Collect the positions of the genuine `mapKeys`/`mapValues` functions from the
index expression and accept a name match only at those positions.

Fixes ClickHouse/clickhouse-private#85653.
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [903c7e4]

Summary: ✅


AI Review

Summary

The PR prevents bloom_filter indexes from confusing physical column names with expressions and validates ownership of JSON subcolumns. The current code addresses all three previous findings; no new actionable issues were found. All 45 stateless regression outputs match the reference using the CI binary for 903c7e425919f2dc6af665aca823c7242294421c. Additional expression and lambda probes showed no regressions against the earlier implementation.

Missing context / blind spots
  • ⚠️ Full CI for the current head is still running. The focused regression passed locally; the remaining CI jobs provide broader validation.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 11, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. label Nov 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 903c7e425 with master 43871b94f (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

10 object files changed (+39.48 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp.o 433.67 KiB 461.37 KiB +27.70 KiB (+6.39%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.61, programs/clickhouse-keeper ×0.66 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.6 s 12.9 s +9.5 s (+280%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.2 s +5.2 s (+259%)
Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×0.92 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -206.3 s (-6%) in total before that adjustment.

Job report

Matching names and the set of input columns does not prove that two
expressions are equal: for a column named `'k'`, ``map(`'k'`, 'k')`` and
``map('k', `'k'`)`` render identically and read the same column, but
contain different keys, so the index skipped matching rows.

Compare the query expression with the index expression node by node,
keeping node kinds, function names, argument order and constant values.
Lambdas are compared by their bodies, whether they are `Capture`
functions or were folded to constants by the analyzer.

`JSON` subcolumn predicates matched a column literally named
`JSONAllPaths(j)` by name too; only a call to `JSONAllPaths` over the
table column is used now.
@alexey-milovidov alexey-milovidov self-assigned this Nov 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 13, 2026
Merged via the queue into master with commit 4460aac Nov 13, 2026
203 checks passed
@alexey-milovidov
alexey-milovidov deleted the ahmadov/fix-bf-index-name branch November 13, 2026 18:24
@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 Nov 13, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
CurtizJ added a commit to groeneai/ClickHouse that referenced this pull request Nov 14, 2026
…tion-per-skip-index-condition

Resolve conflicts with ClickHouse#130814: keep its expression
matching (`index_nodes`) and the `IsShadowingJSONSubcolumn` check, and keep passing the
`StorageMetadataPtr` instead of the removed `IsShadowingColumn` callback for Map key subcolumns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 14, 2026
Resolve conflicts by porting the fix of #130814 onto the 26.3 versions of
`MergeTreeIndexBloomFilter`:
- Add `ExpressionMatcher`, `findIndexPosition` and `findMapIndexPosition`, pass
  the index expression outputs to `MergeTreeIndexConditionBloomFilter`, and use
  them instead of matching index columns by name for plain keys, `IN`, map
  element access, map subcolumns and `mapContains*`/`has`.
- 26.3 has no `ActionsDAG::Node::getWithoutAlias`, so add a local helper.
- Drop the `JSON` parts of the original change (`MergeTreeIndexJSONSubcolumnHelper`,
  `getJSONSubcolumnShadowingCheck`): 26.3 has no `JSON` support in the
  `bloom_filter` index, so they do not apply. Drop the map subcolumn shadowing
  check arguments for the same reason, and the `ARRAY JOIN` lookup changes,
  as 26.3 has no such code.
- Remove the `JSON` cases from the test.

The 26.3 release binary hits a segmentation fault on the test's
`t_bf_fixed` queries, so the backport is relevant there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 14, 2026
Resolve conflicts by porting the fix of #130814 onto the 26.9 versions of
`MergeTreeIndexBloomFilter`, `MergeTreeIndexJSONSubcolumnHelper` and
`MergeTreeIndices`:
- Add `ExpressionMatcher`, `findIndexPosition`, `findMapIndexPosition` and
  `collectJSONIndexColumns`, pass the index expression outputs to
  `MergeTreeIndexConditionBloomFilter`, and use them instead of matching index
  columns by name for plain keys, `IN`, `arrayJoin`, map element access, map
  subcolumns, `mapContains*`/`has` and `JSON` subcolumns.
- 26.9 has no `ActionsDAG::Node::getWithoutAlias`, so add a local helper.
- 26.9 has no `JSONIndexArgumentTypes`, no lazy `IsShadowingColumn` check and no
  `emptyArrayToSingle` handling for `ARRAY JOIN`, so keep its
  `getColumnsShadowingMapSubcolumns` and its `arrayJoin` lookup, only adding
  the expression check. Port `getJSONSubcolumnShadowingCheck` and the
  `is_shadowing_subcolumn` argument of the `JSON` matchers as is.

The 26.9 release (26.9.28.166) gives wrong results for 26 of the 45 queries of
the test, so the backport is relevant there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
Cherry pick #130814 to 26.3: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
… named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
Cherry pick #130814 to 26.8: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
… named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
Cherry pick #130814 to 26.9: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
… named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
Cherry pick #130814 to 26.10: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
robot-clickhouse added a commit that referenced this pull request Nov 14, 2026
…n named `mapKeys(m)` for the `Map` index
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 14, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 14, 2026
Backport #130814 to 26.9: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
clickhouse-gh Bot added a commit that referenced this pull request Nov 14, 2026
Backport #130814 to 26.8: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
alexey-milovidov added a commit that referenced this pull request Nov 15, 2026
Backport #130814 to 26.3: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
clickhouse-gh Bot added a commit that referenced this pull request Nov 16, 2026
Backport #130814 to 26.10: Fix `bloom_filter` index mistaking a column named `mapKeys(m)` for the `Map` index
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 21, 2026
…index-element

Master (ClickHouse#130814) matches a bloom_filter `mapKeys(m)` / `mapValues(m)` index by
the structure of its expression in `findMapIndexPosition`, not by name. An
index declared on `m.keys` / `m.values` is an INPUT node, so a plain merge
would stop using it for `m['k']`, `mapContains*` and `has`. `findMapIndexPosition`
now takes the subcolumn mapping: a mapped name resolves to the subcolumn index
column, and an `arrayElement` map argument must be the table column itself,
which is what `ExpressionMatcher::isSame` requires of the function index.

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

comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants