Repository navigation
Conversation
…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]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-20:20260610-193400 |
|
cc @rschu1ze @CurtizJ — could you review this? It fixes a |
|
Workflow [PR], commit [3a2ad29] Summary: ❌
AI ReviewSummaryThis PR fixes several Missing context / blind spots
Final Verdict✅ No new review findings on the current head. |
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]>
Pre-PR validation gate (fixup 055a575 — bot change-request)
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]>
Pre-PR validation gate (commit 63e31a5)Covers the second bot change-request on the
Session id: cron:clickhouse-worker-slot-31:20260610-231020 |
|
CI finished on `63e31a5bf99a`. The only failure is infrastructure, not caused by this PR (which touches `MergeTreeIndexBloomFilter.cpp` + the regression test):
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. |
CI summary, covered HEAD
|
| 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.
|
Started review. I have seen this reported in public repo, let me find that. |
|
@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? |
|
@shankar-iyer
That is why row 0 comes back in your example: row 0 has no This is the premise the PR rests on: a |
|
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.
CI finish ledger — 3ef5ee3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
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]>
Pre-PR validation gate, head
|
| # | 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. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 37/42 (88.10%) · Uncovered code |
CI finish ledger - 3a2ad29Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
All 174 check-runs on this commit are completed; this is the only failing check. Not caused by this PR. This PR touches The failure belongs to the duplicate-ALIAS GROUP BY family: the reference line it disagrees with was Session id: cron:our-pr-ci-monitor:20260729-223000 |
|
#117318 now fixes both paths this PR touches: the missing-key check ( I ran this PR's test @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. |
Changelog category (leave one):
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_filterindex onmapKeys(map)ormapValues(map)is used with amap[key] = constcomparison. Index analysis compared the constant against the wrong default and hashed it without converting it to the indexed type, somap[k] = toFixedString('', N)returned no rows, amapValuesindex dropped a matching granule for a constant storing a different representation of the indexed string type, and a valid predicate such asmap[k] = 1.0over aMap(String, UInt64)failed withBAD_GET.Description
Closes: #106924
Three defects in
MergeTreeIndexConditionBloomFilter::traverseTreeEquals, all reachable frommap[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 whendefault = const. The check compared the constant byte-wise against the constant's own type default: fortoFixedString('', 3)that is 3 NUL bytes against an emptyString, so every granule without the key was pruned although'' = toFixedString('', 3)is true at runtime. The realequalsnow runs on a default column of the map value type. A NULL result is not a match, so aNullablevalue type stays prunable.2.
mapValueshashed a constant storing a different representation. Equality ignores trailing NUL padding, and anEnumconstant 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 aLowCardinality(String)constant stores the sameString.3.
mapValueshashed the raw constant.hashWithFieldreads theFieldviaField::safeGet, which tolerates onlyUInt64 <-> Int64, so any other constant type threwBAD_GETand failed a valid query. It is converted first, as the ordinary column path and the siblingmapContainsValueandINpaths 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_USEDwhere it must decline.Measured carriers
BAD_GETon a valid predicate (defect 3), all on master before this change:mapValuestypeUInt64Float64,Int128,Decimal64Float64UInt64Date,Enum8StringInt128Int64A matching granule dropped (defect 2), against an indexed
String: aFixedStringof 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.
mapKeysneeds no conversion, sincearrayElementresolves the key constant to the map key type first. Heterogeneous integers were already sound: both signednesses share oneFieldslot andgetNumberTypeHashcasts to the indexed type.