Skip to content

Fix mapKeys bloom_filter index over-pruning for FixedString default equality - #107076

Open
groeneai wants to merge 6 commits into
ClickHouse:masterfrom
groeneai:fix-map-bloom-filter-fixed-string-default-106924
Open

groeneai wants to merge 6 commits into
ClickHouse:masterfrom
groeneai:fix-map-bloom-filter-fixed-string-default-106924

Conversation

@groeneai

@groeneai groeneai commented Jun 10, 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):

Fixed wrong query results and spurious errors when a bloom_filter index on mapKeys(map) or mapValues(map) is used with a map[key] = const comparison. Index analysis compared the constant against the wrong default and hashed it without converting it to the indexed type, so map[k] = toFixedString('', N) returned no rows, a mapValues index dropped a matching granule for a constant storing a different representation of the indexed string type, and a valid predicate such as map[k] = 1.0 over a Map(String, UInt64) failed with BAD_GET.

Description

Closes: #106924

Three defects in MergeTreeIndexConditionBloomFilter::traverseTreeEquals, all reachable from map[key] = const.

1. The absent-key default was compared against the wrong type. An absent key makes map[key] return the map value type default, so a granule lacking the key still matches when default = const. The check compared the constant byte-wise against the constant's own type default: for toFixedString('', 3) that is 3 NUL bytes against an empty String, so every granule without the key was pruned although '' = toFixedString('', 3) is true at runtime. The real equals now runs on a default column of the map value type. A NULL result is not a match, so a Nullable value type stays prunable.

2. mapValues hashed a constant storing a different representation. Equality ignores trailing NUL padding, and an Enum constant carries its number while equality compares the name, so one constant can equal several stored values or hash to what none of them produces, dropping a matching granule. The index is now used only when the constant's primitive type equals the indexed string type. Wrappers are ignored, since a LowCardinality(String) constant stores the same String.

3. mapValues hashed the raw constant. hashWithField reads the Field via Field::safeGet, which tolerates only UInt64 <-> Int64, so any other constant type threw BAD_GET and failed a valid query. It is converted first, as the ordinary column path and the sibling mapContainsValue and IN paths already did, and the index is declined when the constant is not representable. A resource limit, stack overflow, cancellation or internal error still reaches the caller rather than quietly disabling the index.

The test asserts both directions per case: granules-read < granules-total where pruning must survive, INDEX_NOT_USED where it must decline.

Measured carriers

BAD_GET on a valid predicate (defect 3), all on master before this change:

indexed mapValues type constant type
UInt64 Float64, Int128, Decimal64
Float64 UInt64
Date, Enum8 String
Int128 Int64

A matching granule dropped (defect 2), against an indexed String: a FixedString of a different width, Enum8, LowCardinality(FixedString(3)), Variant(FixedString(3), UInt64). The last two also predate this PR.

A resource limit, a stack overflow, a cancellation or an internal error is not a statement about the constant, so it still reaches the caller rather than quietly disabling the index.

mapKeys needs no conversion, since arrayElement resolves the key constant to the map key type first. Heterogeneous integers were already sound: both signednesses share one Field slot and getNumberTypeHash casts to the indexed type.

…quality

When a key is absent from a map, arrayElement returns the map value type
default, so a granule lacking the key still satisfies `map[key] = const`
when `default = const` holds at runtime. The bloom_filter index condition
only prunes by key presence when the constant differs from that default.

MergeTreeIndexConditionBloomFilter::traverseTreeEquals compared the constant
byte-wise against value_type->getDefault(), where value_type is the
constant's own type. For toFixedString('', N) the constant is N NUL bytes
while DataTypeFixedString::getDefault() is an empty String, so the byte-wise
check reported "not default" and the index pruned every granule without the
key. At runtime `'' = toFixedString('', N)` is true (String/FixedString
equality coerces to String and ignores trailing NUL bytes), so those rows
match and must not be pruned. The String form worked only because the
constant type matched the map value type.

Evaluate the real `equals` function on a default column of the map value
type and a constant column of the comparison constant, matching the engine's
runtime semantics. Pruning is preserved whenever the constant cannot match
the default. The IN path already handled this correctly via
prepared_set->execute on a default column.

Closes: ClickHouse#106924

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. On master HEAD fc73f46fae65, SELECT count() FROM mk WHERE map[''] = toFixedString('', 3) with a bloom_filter index on mapKeys(map) returns 0; SETTINGS use_skip_indexes=0 returns the correct 2. Reproduces every run.
b Root cause explained? Yes. traverseTreeEquals guards "key absent => no match" pruning with value_field == value_type->getDefault(), where value_type is the constant's own type and the comparison is byte-wise Field equality. For toFixedString('', 3) the constant is 3 NUL bytes and DataTypeFixedString::getDefault() is an empty String, so byte-wise they differ, the guard is false, and the index prunes every granule lacking key ''. But runtime '' = toFixedString('', 3) is true (String/FixedString equality coerces to String, dropping trailing NULs), so absent-key rows (value default '') match and must not be pruned.
c Fix matches root cause? Yes. The guard now evaluates the real equals function on a default column of the map value type (key_node.getDAGNode()->result_type) and a constant column of the comparison constant, replicating runtime semantics instead of byte-wise Field comparison against the constant's own type default.
d Test intent preserved / new tests added? New test 04327_map_bloom_filter_index_fixed_string_default added. It covers the FixedString-default bug, confirms a present key with a FixedString constant still uses the index (force_data_skipping_indices), confirms an absent key with a non-default constant is still pruned, and covers integer-default cross-type. No existing test weakened.
e Both directions demonstrated? Yes. The committed .sql returns 0 on the pre-fix binary and 2 on the fixed binary for the buggy line. EXPLAIN indexes=1 confirms: absent-key-vs-default reads 1000/1000 granules (no false pruning), while an existing key still drops granules (42/1000), so pruning is preserved.
f Fix is general, not a narrow patch? Yes. The fix targets the root cause (analysis must use runtime equality on the map value type), not the single FixedString symptom, so it is correct for any value type / constant type pair. Sibling paths were checked: the IN path already handles this correctly via prepared_set->execute on a default column; notEquals and numeric types were verified consistent on the old binary; the text-index guard (MergeTreeIndexBloomFilterText.cpp) uses the same pattern but does not exhibit the bug in practice because an empty/short key produces no tokens to prune on.

Session id: cron:clickhouse-worker-slot-20:20260610-193400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @CurtizJ — could you review this? It fixes a bloom_filter index on mapKeys(map) over-pruning: the index analysis compared the constant byte-wise against the constant's own type default, so map[k] = toFixedString('', N) pruned every granule even though '' matches the empty-String default at runtime. The fix evaluates the real equals function on the map value type's default, matching runtime semantics; pruning is preserved when the constant cannot match the default (verified with EXPLAIN indexes=1).

@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3a2ad29]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
04357_distributed_alias_same_expression FAIL cidb

AI Review

Summary

This PR fixes several bloom_filter skip-index misclassifications for map[key] = const, aligns mapValues(map) hashing with runtime comparison semantics, and hardens the new regression test against analyzer-dependent EXPLAIN evaluation order. After reviewing the current diff, the full prior discussion, and the current = / IN code paths, I did not find a remaining correctness issue at the current head.

Missing context / blind spots
  • ⚠️ I did not build or run the changed test locally in this environment; the remaining confidence gate is the still-pending CI matrix on commit 3a2ad299a2e65cc121d87eb8abb0da6f924f0797.
Final Verdict

✅ No new review findings on the current head.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 10, 2026
The mapKeys bloom_filter skip-index analyzer evaluates the real equals
function to decide whether an absent map key's default value can match
the comparison constant. The previous catch(...) failed open for every
exception, so MEMORY_LIMIT_EXCEEDED, query cancellation, allocation
failures, and internal errors were swallowed and the query silently
continued with the index disabled instead of failing.

The predicate was already accepted by the query analyzer, so the only
expected failure here is a genuine type mismatch. Catch only the two
type-compatibility codes the comparison raises (ILLEGAL_TYPE_OF_ARGUMENT,
NO_COMMON_TYPE) and rethrow everything else.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (fixup 055a575 — bot change-request)

# Question Answer
a Deterministic repro? Yes. With a tiny memory limit the comparison path now fails on demand: SELECT count() FROM t WHERE map[''] = '' SETTINGS use_skip_indexes=1, max_memory_usage=1; returns MEMORY_LIMIT_EXCEEDED (Code 241) rather than silently disabling the index. Type-mismatch tolerance: WHERE map[''] = ['x'] (String vs Array) is handled gracefully.
b Root cause explained? The helper mapElementDefaultCanMatchConstant evaluates the real equals to decide if an absent key's default can match the constant. The original catch (...) failed open for ALL exceptions, so MEMORY_LIMIT_EXCEEDED, query cancellation, allocation failures, and internal/logic errors were swallowed and the query continued with the index disabled instead of failing.
c Fix matches root cause? Yes. The catch is narrowed to catch (const Exception & e) and only ILLEGAL_TYPE_OF_ARGUMENT / NO_COMMON_TYPE (the two codes the comparison build/execute raises for genuinely-incomparable types) are tolerated; everything else is rethrown via bare throw;. This directly addresses "tolerate the type-mismatch case, propagate resource/cancellation/internal errors".
d Test intent preserved / new tests added? Preserved. The over-pruning regression test 04327_map_bloom_filter_index_fixed_string_default still passes 10/10 with randomization. A negative test asserting that MEMORY_LIMIT_EXCEEDED propagates from inside index analysis is not added: the throw point depends on internal allocation and cannot be triggered deterministically from a stateless .sql test without being fragile. The behavior is demonstrated manually (see a).
e Both directions demonstrated? Yes. Before the fixup: any exception → index silently disabled, query continues. After: type-mismatch (['x'], NO_COMMON_TYPE) tolerated → index disabled, query runs; max_memory_usage=1 (Code 241) now propagates; over-pruning cases (FixedString default → count 2; non-default → count 0) unchanged.
f Fix is general, not a narrow patch? Yes. This was the only catch (...) fail-open in the bloom-filter index files (grep "catch (\.\.\.)" MergeTreeIndexBloomFilter*.cpp finds no others). The two tolerated codes are the only ways FunctionsComparison::getReturnTypeImpl / supertype resolution signal incompatible types; we are not guarding a symptom but matching exactly the expected-vs-unexpected failure boundary the analyzer already established.

Session id: cron:clickhouse-worker-slot-14:20260610-215800

… constant

The mapValues(map) branch of traverseTreeEquals hashed the comparison
constant's raw bytes against the bloom filter without accounting for
String/FixedString equality semantics. String/FixedString equality
ignores trailing NUL padding, so `map[k] = toFixedString('V0', 3)`
matches a stored String 'V0' at runtime, but the bloom filter stored the
hash of the 2-byte 'V0' while the branch hashed the 3-byte 'V0\0'. The
hashes differ, so forcing the mapValues index dropped a granule that
actually matched, producing wrong (empty) results.

This cannot be fixed by converting the constant: the match is many-to-one
(stored 'V0' and 'V0\0' both equal toFixedString('V0', 3) at runtime but
hash differently), so no single hash represents the match set. When the
indexed value type and the constant type differ and either is a
String/FixedString, skip the values index and fall back to a full scan,
which never wrongly prunes. Equal types and numeric cross-width compares
are unaffected (the hash normalizes numbers; equal types hash identically).

Extends test 04327_map_bloom_filter_index_fixed_string_default with
mapValues cases over String and FixedString value indexes, including the
many-to-one soundness case.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (commit 63e31a5)

Covers the second bot change-request on the mapValues(map) branch (comment 3391943378).

# Question Answer
a Deterministic repro? Yes. Map(String,String) + INDEX mapValues(map) TYPE bloom_filter, INSERT {'K0':'V0'}, then SELECT count() FROM t WHERE map['K0'] = toFixedString('V0', 3) returns 0 with the index but 1 without it (use_skip_indexes = 0). Fails every time on the unfixed binary.
b Root cause explained? The values branch hashes the comparison constant's raw bytes (getStringTypeHash = CityHash64 over the bytes). String/FixedString equality ignores trailing NUL padding, so map[k] = toFixedString('V0', 3) matches a stored String V0 at runtime, but the index stored the hash of 2-byte V0 while the branch hashed 3-byte V0\0 — the hashes differ, so the matching granule is pruned. The bot's suggested convertFieldToType does not strip the NUL (it returns the String field unchanged), and even a NUL-stripping cast would be unsound: the match is many-to-one — stored V0 and V0\0 both equal toFixedString('V0', 3) at runtime but hash differently, so no single hash represents the match set.
c Fix matches root cause? Yes. When the indexed value type and the constant type differ and either is String/FixedString, the values index is skipped (return false → full scan), which can never wrongly prune. Equal types and numeric cross-width compares are unaffected (the hash normalizes numbers; equal types hash identically), so those keep using the index.
d Test intent preserved / new tests added? Yes. Extended 04327_map_bloom_filter_index_fixed_string_default with mapValues cases over String and FixedString value indexes: present-key FixedString match (was over-pruned), String-constant still uses the index, non-matching present key returns nothing, different-width FixedString over a FixedString index, and the many-to-one soundness case (two distinct stored values both matching one FixedString constant must both be kept). The earlier mapKeys cases are unchanged and still pass.
e Both directions demonstrated? Yes. On the unfixed binary the index path returns 0 (bug) and the soundness case returns 1 instead of 2; with the fix both return the correct 1 and 2, matching the no-index path. EXPLAIN indexes=1 confirms the index is still used for the sound String-constant case (granules 1/3) and skipped for the FixedString constant (granules 3/3).
f Fix is general, not a narrow patch? Yes. Checked sibling paths: the mapKeys key path is byte-exact (map key lookup needs exact bytes, so runtime and index agree — verified no over-pruning), and the traverseTreeIn mapValues path already converts via castColumn. The same latent bug also exists on the ordinary (non-map) String column path, but that is pre-existing and out of scope for this PR; this fix covers the mapValues equals path the report identified.

Session id: cron:clickhouse-worker-slot-31:20260610-231020

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on `63e31a5bf99a`. The only failure is infrastructure, not caused by this PR (which touches `MergeTreeIndexBloomFilter.cpp` + the regression test):

  • `Stateless tests (arm_asan_ubsan, azure, sequential)` — `Server died` / `Segmentation fault` (STID 0883-49e8): the Azure arm_asan_ubsan mass outage of 2026-06-10/11 (ASan secondary-allocator OOM, no ClickHouse frames). 75 distinct tests across 42 PRs hit the same signature on 06-11. Not PR-related.

Both bot review threads are addressed (catch-all narrowed to specific type-mismatch codes in 055a575b; mapValues FixedString-vs-String hash mismatch fixed by skipping the values index on String/FixedString cross-type compares in 63e31a5). Ready for review.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI summary, covered HEAD 63e31a5b

CI fully finished (run=0, aggregator complete, >19h buffer). The single failure is the inherited azure-outage corruption; the mapKeys bloom-filter fix is not implicated.

Check Failure Classification Disposition
Stateless tests (arm_asan_ubsan, azure, sequential) Segmentation fault (STID 0883-49e8), then Server died Inherited trunk corruption (multistage distributed-queries thread-teardown UAF, STID 0883-* family) NOT PR-caused. This HEAD predates the master revert #107122 (merged 01:37 UTC 06-11), so it inherited the now-fixed corruption. The arm_asan_ubsan, azure, sequential check is clean on master across 55 commits since 03:00 UTC 06-11 (0 failures); the same pre-revert window shows STID 0883-49e8 on 16+ unrelated PRs. A rebase past 01:37 UTC 06-11 clears it.

No PR-caused failures. The fix (mapKeys bloom_filter false-pruning for FixedString default-equality; regression test 04327) is unaffected.

@shankar-iyer shankar-iyer self-assigned this Jun 19, 2026
@shankar-iyer

Copy link
Copy Markdown
Member

Started review. I have seen this reported in public repo, let me find that.

@shankar-iyer

Copy link
Copy Markdown
Member

@groeneai Ignoring skip index and bloom filter, check the below example from 26.6. What is the exact semantics of the return value when the key does not exist in the map?

clickhouse-cloud :) INSERT INTO t_map_bf_fixed_string VALUES (0, {'K0':'V0'}), (1, {'K1':'V1'});

INSERT INTO t_map_bf_fixed_string FORMAT Values

Query id: b1c1c6ab-2dda-4d2b-975e-c179678bc2bf

Ok.

2 rows in set. Elapsed: 0.126 sec.

clickhouse-cloud :) select * from t_map_bf_fixed_string where map['K1']='';

SELECT *
FROM t_map_bf_fixed_string
WHERE (map['K1']) = ''

Query id: 4993f215-9298-41b8-9da0-d1895c6dbaa0

   ┌─row_id─┬─map─────────┐
1. │      0 │ {'K0':'V0'} │
   └────────┴─────────────┘

1 row in set. Elapsed: 0.011 sec.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@shankar-iyer map[key] (arrayElement(map, key)) for an absent key returns the default of the map's value type, never NULL. The map path runs arrayElement in Zero mode (Functions/array/arrayElement.cpp: "Fill with zero or default if array index out of range or map key not found"), and getReturnTypeImpl returns the value type itself (non-nullable for the plain map[key] form). So:

  • Map(_, String) -> ''
  • Map(_, Int64) -> 0
  • Map(_, FixedString(3)) -> 3 NUL bytes (which equals '' and toFixedString('', 3))

That is why row 0 comes back in your example: row 0 has no K1, so map['K1'] evaluates to the String default '', and '' = '' is true. Rows missing the key where default = const are genuine matches.

This is the premise the PR rests on: a bloom_filter index on mapKeys/mapValues must keep the granules for those absent-key rows whenever the searched constant equals the value-type default. The original bug (#106924) was that the pruning guard compared the constant against its own type's default under Field equality instead of the map value type's default under runtime (column) equality, so map[k] = toFixedString('', N) wrongly pruned the absent-key granules. The fix makes the guard follow runtime semantics.

@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Dear @shankar-iyer, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

…rted constant

Two defects in the `mapValues` arm of `MergeTreeIndexConditionBloomFilter::traverseTreeEquals`,
both reachable from `map[key] = const`, plus a refinement of the absent-key check this PR
already changed.

The arm hashed the comparison constant exactly as the query wrote it.
`BloomFilterHash::hashWithField` selects its hash from the indexed type and then reads the
`Field` through `Field::safeGet`, which tolerates only `UInt64 <-> Int64`, so a constant of any
other type threw `BAD_GET` and failed a query that is valid: a `Float64`, `Int128` or `Decimal`
constant against an integer index, a `UInt64` constant against a `Float64` index, a `String`
constant against a `Date` or `Enum8` index, an `Int64` constant against an `Int128` index. The
constant is now converted first, as the ordinary column path and the sibling
`mapContainsValue` and `IN` paths already did. A constant with no representation in the indexed
type cannot be described by a single hash, so the index is declined rather than used with a
rounded bound. `convertFieldToType` reports that either by returning Null or by throwing, and
the throw carries codes raised both there and by the target type itself, so they are recognized
by excluding the ones that are not statements about the constant: a resource limit, a stack
overflow, a cancellation and an internal error still reach the caller.

For an indexed `String` or `FixedString` the index is now used only when the constant stores
the very same representation. Equality ignores trailing NUL padding, so at a different width
several stored values compare equal to one constant that no single hash represents; and an
`Enum` constant stores its numeric value, which the conversion stringifies while equality
compares against the name. A `LowCardinality(FixedString(3))` and a
`Variant(FixedString(3), UInt64)` constant each dropped a matching granule this way before this
PR as well. Wrappers are ignored, since a `LowCardinality(String)` constant stores the same
`String` and stays usable.

The absent-key check now treats a NULL comparison result as not-a-match. A `Nullable` value
type has a NULL default and `NULL = const` is NULL, which is true for neither `equals` nor
`notEquals`, so an absent key cannot satisfy the predicate and the granule stays prunable.
Treating it as a possible match declined the `mapKeys` index for every map with a `Nullable`
value type.

Heterogeneous integers were already sound and are unchanged: both signednesses share one
`Field` slot and `getNumberTypeHash` casts to the indexed type, which is the same
reinterpretation the runtime comparison performs. `mapKeys` needs no conversion, because
`arrayElement` resolves the key constant to the map key type before index analysis sees it.

The test asserts both directions per case: granules read below granules total where pruning has
to survive, and `INDEX_NOT_USED` where the index has to be declined. It pins
`optimize_functions_to_subcolumns`, which the runner randomizes, so both map access rewrites
are covered.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 3ef5ee3

Every failure below has an owner: a fixing PR (mine 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
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 1/3) / 04327_map_bloom_filter_index_fixed_string_default PR-caused: this is the test this PR adds, and Code: 32 ATTEMPT_TO_READ_AFTER_EOF reproduces 3/3 on rerun. The only CI sighting of this test in 10 days is on this PR fixed in this PR
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / 01666_merge_tree_max_query_limit Code: 202 TOO_MANY_SIMULTANEOUS_QUERIES under parallel replicas; reproducible 3/3 on rerun, not caused by this diff #112385 (mine, open)

Session id: cron:our-pr-ci-monitor:20260729-140000

…ilure

The pruning assertions extracted the granule counts out of `EXPLAIN indexes = 1`
and converted them with `toUInt64`, relying on the `explain LIKE '%Granules: %/%'`
conjunct to keep the conversion away from the plan rows that carry no counts.
Nothing guarantees that evaluation order: the old analyzer plans the `WHERE` as
`and(and(less(...), like(...)), ...)`, so `less` runs on every row, `extract`
returns an empty string for the rows without a `Granules:` line, and
`toUInt64('')` raises ATTEMPT_TO_READ_AFTER_EOF. Writing the `less` conjunct
first reproduces it under the new analyzer too, so this is about the order the
executor picks rather than about one analyzer. `toUInt64OrZero` makes the
conversion total, and stays fail-closed because a row without counts yields
`0 < 0`, so the surrounding `count() > 0` reports no pruning.

Six further cases asserted only the row count under `force_data_skipping_indices`,
which shows the analyzer classified the index as useful but not that a granule was
skipped, and three asserted only that a keyed read agrees with an unindexed one,
which a granule-dropping bug also satisfies when the dropped granule holds no
matching row. Add a granule-reduction assertion to the five cases that claim
pruning and an INDEX_NOT_USED assertion to the two `mapValues` cases where a
FixedString constant against an indexed String has to decline the index. Also
correct a comment that claimed every constant other than String or FixedString
stays usable, which the Enum8 and Variant cases in the same file contradict.

Separately, `convertFieldToType` calls `checkStackSize`, which throws
CANNOT_PTHREAD_ATTR when its `pthread_getattr_np` or `pthread_attr_getstack`
probe fails. That says nothing about whether the constant is representable in the
indexed type, so it now reaches the caller instead of quietly disabling the
index, next to TOO_DEEP_RECURSION which the same probe raises.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate, head 3a2ad299a2e65c

# Check Result
a Reproduced the reported failure 04327 failed Code: 32 ATTEMPT_TO_READ_AFTER_EOF in Stateless tests (amd_llvm_coverage, old analyzer, ...), 3 of 3 reruns. Reproduced locally under --enable_analyzer=0 with a message byte-identical to CI's. Passes under --enable_analyzer=1, which is why only an old-analyzer job caught it.
b Root cause The pruning assertions parsed the granule counts with toUInt64(extract(...)) and relied on the explain LIKE '%Granules: %/%' conjunct to keep the conversion off the plan rows that carry no counts. EXPLAIN actions=1 shows the old analyzer plans the filter as and(and(less(...), like(...)), and(like(...), less(...))), so less runs on every row, extract returns an empty string, and toUInt64('') throws. Writing the less conjunct first throws under the new analyzer too, so this is the order the executor picks, not one analyzer.
c Fix toUInt64OrZero makes the conversion total. It stays fail-closed: a row without counts yields 0 < 0, so the surrounding count() > 0 reports no pruning. Additionally, five cases that claim pruning gained a granule-reduction assertion, two mapValues cases gained INDEX_NOT_USED, and CANNOT_PTHREAD_ATTR from checkStackSize now propagates instead of silently disabling the index.
d Both directions Reverting toUInt64OrZero reddens the test under the old analyzer (5 of 6 runs, 5 Code: 32) and leaves it green under the new one. Inverting the String/FixedString decline guard reddens the new assertions. Disabling use_skip_indexes drops each new granule assertion from 1 to 0, so none passes vacuously.
e Randomized runs 25 of 25 OK under enable_analyzer=0 and 25 of 25 OK by default, --jobs 4, randomization on. Output byte-identical to the reference under both analyzers. Server buildId() verified equal to the ELF build id at every measurement.
f Scope Test-only apart from one error code added to the propagate list. Not folded in: a bloom_filter on an ordinary (non-map) String column drops a matching granule for a FixedString constant (oracle 2 vs keyed 1). That reproduces identically on a pristine master build whose copy of the file is md5-identical to master, so it is pre-existing and outside this PR's map-access scope. A fix task is created for it.

@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.30% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.50% 78.50% +0.00%

Changed lines: Changed C/C++ lines covered: 37/42 (88.10%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3a2ad29

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
Stateless tests (amd_debug, parallel) / 04357_distributed_alias_same_expression result differs with reference; the runner's own randomized-settings diagnosis reports "Failure is flaky (15/81 reruns failed)" #108855 (ours, open)

All 174 check-runs on this commit are completed; this is the only failing check.

Not caused by this PR. This PR touches src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp plus
its own 04327_map_bloom_filter_index_fixed_string_default test pair, and cannot affect a
Distributed duplicate-ALIAS GROUP BY result. Over 30 days that test has 54 failures across 45
distinct PRs, so it is a broad pre-existing flake rather than anything specific to this branch.

The failure belongs to the duplicate-ALIAS GROUP BY family: the reference line it disagrees with was
introduced with the test itself in #107913, and #108855 is the open fix for the remaining
wrong-results case (un-merged GROUP BY groups under two-level / memory-efficient aggregation). It
both carries the engine fix and updates this test, so it is the owner of this line. A 14-day
settings fingerprint over the non-flaky-check rows shows group_by_two_level_threshold_bytes=1 in
36 of 36 and prefer_localhost_replica=0 in 36 of 36, which is what ties the flake to that code
path rather than to test-local non-determinism.

Session id: cron:our-pr-ci-monitor:20260729-223000

@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

#117318 now fixes both paths this PR touches: the missing-key check (missingMapKeyMayCompareEqual, the same equals-on-the-value-type-default approach as here) and the mapValues constant coercion. It also fixes the #106924 repro: map[''] = toFixedString('', 3) returns 2 rows with its build and 0 on master.

I ran this PR's test 04327_map_bloom_filter_index_fixed_string_default with clickhouse local against the amd_release CI build of #117318 (95d73ba): 96 of 97 reference lines and 14 of 15 INDEX_NOT_USED expectations match. On master (eef0f17) the same test has 10 statements failing with BAD_GET and 33 differing lines. The only difference is map['K'] = toDecimal64(2, 0) over a Map(String, UInt64) mapValues index: #117318 throws TYPE_MISMATCH where this PR declines the index. A plain UInt64 column with a bloom_filter index throws the same error on master, so that case is not specific to maps.

@shankar-iyer, should I close this PR in favour of #117318, or keep it and merge master? I am leaving the conflict unresolved until then, so the two PRs do not both edit the same function.

This branch has not been deployed

No deployments
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 comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. groeneai-origin-unknown PR origin: unclassified (legacy task) pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mapKeys bloom_filter index prunes everything for map[k] = toFixedString('\', N) (String form works, FixedString does not)

5 participants