Repository navigation
Description
Wrong result: mapKeys bloom-filter index prunes rows where map[k] = <FixedString default> is true — index analysis and runtime disagree on String vs FixedString equality
Summary
With a bloom_filter index on mapKeys(map), the condition
map[k] = v is pruned by key presence. For rows where the key is absent,
map[k] returns the value-type default (''), and ClickHouse's runtime
comparison treats '' = toFixedString('', N) as true (trailing-NUL
insensitive). The skip-index analysis, however, evaluates the
default-vs-constant comparison byte-wise ('' != '\0\0\0'), concludes no
row can match, and prunes every granule — returning 0 rows where the correct
answer is "all rows without the key".
A plain String constant works (map[''] = '' correctly returns the rows);
only the FixedString (or otherwise type-coerced) form diverges.
Found by the AST-fuzzer correctness-oracle suite from PR
#99980 (TLP WHERE oracle:
reference 2 rows, all three partitions empty — a logical impossibility).
Minimal repro
CREATE TABLE mk
(
row_id UInt32,
map Map(String, String),
INDEX i mapKeys(map) TYPE bloom_filter GRANULARITY 1
) ENGINE = MergeTree ORDER BY row_id SETTINGS index_granularity = 1;
INSERT INTO mk VALUES (0, {'K0':'V0'}), (1, {'K1':'V1'});
SELECT count() FROM mk WHERE map[''] = toFixedString('', 3);
-- index ON (default): 0 (WRONG)
-- SETTINGS use_skip_indexes=0: 2 (correct)
-- Runtime agrees the predicate is true for both rows:
SELECT count() FROM mk WHERE (map[''] = toFixedString('', 3)) OR rand() < 0; -- 2 (index unusable)
SELECT row_id, map[''] = toFixedString('', 3) FROM mk; -- 1 for both rows
-- Control cases that work correctly:
SELECT count() FROM mk WHERE map[''] = ''; -- 2 (String form OK)
SELECT count() FROM mk WHERE map['K0'] = toFixedString('V0', 2); -- 1 (present key OK)Reproduced on 26.6.1.1 (master 76c2edca2fd, release build), default
settings.
Fix area
The bloom-filter index condition for mapKeys /
map[k] = const (src/Storages/MergeTree/MergeTreeIndexConditionBloomFilter
or the common KeyCondition-style analysis for map element access): when
deciding that "key absent ⇒ no match", the default-value-vs-constant
comparison must use the same String/FixedString equality semantics as
runtime execution (trailing NULs insignificant), or conservatively refuse to
prune when the constant's type differs from the map value type.
Original fuzzer hit (for reference)
2026-06-10 02:37:43, fuzz-lab cycle 9e instance 01 (release), run dir
tmp/fuzz_lab/runs/20260610-0214-dd73eb7e3a9/inst/01/
(mismatch_artifacts/run_2/). Fuzzed predicate:
(map['']) != toLowCardinality(toFixedString('', 1048576)) over the
2-row table from test 02021_map_bloom_filter_index — reference 2 rows,
p/NOT p/p IS NULL partitions all 0 rows.
Activity
qoega commentedon Jun 10, 2026
@groeneai could you please reproduce and fix this one? Repro is in the issue body — deterministic on master
76c2edca2fd, default settings.groeneai commentedon Jun 10, 2026
Reproduced on master
fc73f46fae65and fixed in #107076.Root cause: in
MergeTreeIndexConditionBloomFilter::traverseTreeEquals, the "key absent => no match" pruning guard compared the constant byte-wise againstvalue_type->getDefault(), wherevalue_typeis the constant's own type. FortoFixedString('', N)the constant is N NUL bytes andDataTypeFixedString::getDefault()is an emptyString, so the byte-wise check reported "not default", the index built a key-presence predicate and pruned every granule lacking the key. At runtime'' = toFixedString('', N)is true (String/FixedString equality coerces toStringand ignores trailing NULs), so the absent-key rows match and must not be pruned. The plainStringform worked only because the constant type matched the map value type. TheINpath was already correct because it evaluates the comparison on a default column of the map value type.Fix: evaluate the real
equalsfunction on a default column of the map value type and a constant column of the comparison constant, matching runtime semantics.EXPLAIN indexes=1confirms a present key still drops granules while an absent key compared with the default no longer does. Added regression test04327_map_bloom_filter_index_fixed_string_default.