Repository navigation
Do not use Parquet bloom or dictionary filters when the requested type changes what a value hashes to - #121077
Conversation
…e changes what a value hashes to The bloom-filter and dictionary-filter row-group legs compare hashes computed in two different value spaces. The stored side is hashed in physical space: hashDictionaryValues materializes the dictionary as decoded_type and parquetTryHashColumn casts every value to the parquet physical type, and the file's own bloom filter holds digests of the physical values by definition. The query side is hashed from a KeyCondition constant, which is a value of the requested (output-block) type. Nothing checked that the conversion between the two preserves static_cast<physical>, and a structure hint can break it four ways: a narrowing drops bits (a UInt32 column read as UInt16 compares 70000 against 4464), a signedness flip below the physical width changes the sign-extended 32-bit pattern (UInt8 200 read as Int8 -56), a Date/Date32 hint over a source wider than 16 bits is a unit change because the cast reads a Unix timestamp rather than a day number, and a String/FixedString(N) mismatch changes the hashed byte count. A matching constant then hashes to a digest the filter has never seen, the leg reports "no match", and the row group holding the match is pruned, so count() returns 0 where the answer is 1. The min/max legs never had this hole: they are gated by PageDecoderInfo::allow_stats, which SchemaConverter sets only where the stored endpoints are meaningful in the requested type, and they have cast_stats_to_output_type to move endpoints into the output space. The hash legs were given neither, and they are not gated by allow_stats either, so the min/max signedness fix does not help them. Give them the gate they never had: parquetHashFilterOutputTypeIsExact, checked once per column in Reader::prepareBloomFilterCondition. A column that fails it is never made eligible, so no constants are hashed for it and both legs stay off (use_dictionary_filter requires use_bloom_filter). The legs are withheld rather than reconciled, deliberately. Recovering a match would mean mapping a requested-type constant back into physical space, which is one-to-many exactly in the broken cases - 65536 physical values per UInt16 value, 86400 seconds per Date32 day - so the bloom leg cannot be reconciled at all; given that, the dictionary leg is withheld at the same gate rather than given a second, divergent predicate. Pruning is preserved wherever the two spaces agree: every widening hint, same-width signedness flips (which wrap, leaving the hashed low bits intact), DateTime/IPv4/IPv6, the date family over a column of at most 16 bits, and Nullable/LowCardinality wrappers. Reading the requested type from extended_sample_block_data_types rather than from PrimitiveColumnInfo is load-bearing: SchemaConverter assigns decoded_type to the latter, so comparing against it would have compared a type with itself. The wrapper strip is load-bearing too, which is why it uses removeLowCardinalityAndNullable and not removeNullable after removeLowCardinality: the latter order leaves the Nullable inside LowCardinality(Nullable(T)). Pruning is given up only where soundness came from the data rather than from the types: String and FixedString(N) where every value happens to be exactly N bytes, and a 64-bit column read into a 32-bit space. The new test asserts 16 shapes that returned the wrong count, 30 controls that check via read_rows that each leg still skips three of four row groups, and two no-pruning baselines so that no control can pass vacuously. Its Date32 arms compare against toDate32(toDateTime(...)) rather than a date literal because the integer to date cast of a timestamp is time-zone dependent and the test runner randomizes session_timezone.
Delete the comments narrating the new predicate's own design (the call-site rationale, the two disjunct derivations, the wrapper-stripping justification) and shorten the surviving property comments to one line each. The retained ones state pre-existing semantics a reader cannot derive at that spot: what the integer CAST does to Date/DateTime/Enum/IPv4 targets, the 16-bit day-number window, why the type enumeration and the switch default are exhaustive, and that a 16-byte FLBA is decoded as FixedString(16) for an IPv6 request.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus a separate cold read of the
The admitting clauses were checked by walking the pass set rather than sampling it: Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260919-180100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260919-153700 |
|
Workflow [PR], commit [b4a6455] Summary: ✅
AI ReviewSummaryThis PR correctly moves the Parquet hash-filter eligibility decision into Findings
Final Verdict
LLVM Coverage ReportMeasured on commit b4a6455.
Changed lines: Changed C/C++ lines covered: 71/71 (100.00%) · Uncovered code |
CI finish ledger - 04127a7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260920-080106 |
al13n321
left a comment
There was a problem hiding this comment.
This seems similar to PageDecoderInfo::allow_stats, I would've thought this belongs next to it, in the main type dispatch in SchemaConverter. Would that work? What are the advantages of this PR's approach over that?
|
Yes, it would work, and I think it is the better home.
It is also a small part of the dispatch, not all of it: The advantages of this PR's placement are narrower than I would like: it is purely subtractive (one One asymmetry worth naming, since it is the reason this needs no I will move it there and push; the tests stay as they are. I will re-request your review on the new head. |
Master now has 05231_ast_json_storage_argumentless_function_dialect, 05231_deltalake_write_unparsable_value_into_nullable and 05231_timeseries_to_grid_timestamp_scale_conversion. The lowest free prefix is 05241. Only the file names and the in-file fixture names change; no assertion and no reference line is touched.
The previous commit answered "does a query constant of the output type hash to
the digest of the stored value it must match?" with a predicate in
parquetBloomFilterHash.cpp, called once per column from
Reader::prepareBloomFilterCondition. Michael Kolupaev asked in review whether
the decision belongs next to PageDecoderInfo::allow_stats, in the main type
dispatch in SchemaConverter, and it does.
The triple that decides the question is (physical type, decoded type, output
type), and processPrimitiveColumn is the function that chooses two of the three:
it is handed the physical type in element.type and the output type in type_hint,
and it picks out_decoded_type itself. The read-time predicate therefore had to
re-derive which decode branch had run from (decoded_type, physical_type) after
the fact, and it re-enumerated the output-type list that
dispatch_int_stats_converter already enumerates thirty lines from where the
branch decided everything. Two independent enumerations of the same set, in two
files, that must not drift.
So: one default-false PageDecoderInfo::allow_hash_filters, set in the six
dispatch branches whose values can be hashed at all, and one continue on it in
Reader::prepareBloomFilterCondition, exactly as Reader.cpp already does for
allow_stats. parquetBloomFilterHash.{h,cpp} go back to being what they were
before this PR; RequestedIntegerSpace and getRequestedIntegerSpace move
verbatim, and the three legs of the rule (a 16-bit-source check,
value_preserving, reinterpretation) move unchanged into an
allow_int_hash_filters lambda beside the dispatch they must stay in step with.
The default is false, so a branch added later is ineligible until someone
decides otherwise, which is the fail-closed behaviour allow_stats already has.
The requested type is available at the dispatch by construction, not by
coincidence: Reader::init constructs SchemaConverter with
&extended_sample_block, processSubtree reads node.type_hint out of that same
block, and processSubtreePrimitive strips LowCardinality and then Nullable
before passing it in, which is the strip the read-time predicate performed by
hand. A column absent from the sample block is never requested, so in the read
pass the hint is never null.
Three of the six sites are one expression each rather than a call, because what
they encode is a fact about their own branch that no shared helper could know.
The FixedString escape hatch deliberately does not copy the annotation condition
on the allow_stats line above it: min/max needs the annotations absent, hashing
does not, because both sides hash the raw bytes, and a UTF8-annotated fixed
array read as FixedString(n) prunes correctly today. The BYTE_ARRAY assignment
sits after the json block rather than on the allow_stats line, because that
block reassigns the inferred type. The FIXED_LEN_BYTE_ARRAY fallback admits
IPv6 only: a FixedString request whose width equals the array's is served by the
escape hatch and never reaches it, and the remaining hint that the old predicate
admitted there, a legacy [U]Int128 or [U]Int256 of matching width, is unhashable
because such a constant is a Field::Int128 for which parquetTryHashField returns
nullopt.
Behaviour is unchanged. The test's forty-six existing assertions were measured
on the previous head and not one of them moved; the base binary still returns
the wrong count on all sixteen arms and the fixed binary the truth, with every
control row byte-identical, so the diff between the two full outputs is a single
sixteen-line hunk. Each of the six sites was reverted on its own and reddens
only its own controls, which is what makes six assignments six independent facts
rather than one rule copied six times.
Two controls are added because two branches had none: ClickHouse writes Int32,
Int64 and FixedString(N) without any parquet annotation, so a forgotten flag at
either the unannotated-INT64 branch or the escape hatch would have given up
pruning with the whole suite green. One of them reads the file with no structure
hint, which is what pins that the hint is never null in the read pass.
Delete the two lines restating the PR's root cause on the new PageDecoderInfo field, and drop the sentence tying the integer lambda to the min/max one above it. The survivors state pre-existing semantics a reader cannot derive at that spot: what the integer CAST does to Date/DateTime/Enum/IPv4 targets, the 16-bit day-number window, why the requested-type enumeration is exhaustive, that only 64-bit physical types decode at the physical width, that hashing ignores the annotations min/max depend on, the json block's reassignment ordering, and that a 16-byte fixed array decodes as FixedString(16) for an IPv6 request.
|
@al13n321 you were right, and it is moved. Re-requesting your review on the new head The exactness decision is now one default-false Six branches assign the flag, which is fewer sites than it sounds: only six dispatch branches can reach Two things about the tests, where I said they would not change:
Internal second-model review: adjudication log (click to expand)Independent cold read of the resulting tree plus a second-model gate (engine: codex), bounded: 1 full
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260923-053425 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units17 translation units recompiled, 148 s compile time in total, 17 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - 116b8eeEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260923-190314 |
| out_decoder.allow_hash_filters = WhichDataType(get_output_type_index()).isIPv6() | ||
| && size_t(element.type_length) == sizeof(IPv6); |
There was a problem hiding this comment.
Wait, doesn't this code path also happen in the normal simple FIXED_LEN_BYTE_ARRAY -> FixedString trivial conversion case, which can (?) use bloom filter? (And FIXED_LEN_BYTE_ARRAY -> String?) I'm probably missing something because I also don't understand why the preexisting line above doesn't allow FixedString. Please explain how this works.
There was a problem hiding this comment.
Answering the three parts.
1. FIXED_LEN_BYTE_ARRAY -> FixedString(N) never reaches this line. An explicit FixedString(N) hint whose N equals element.type_length is taken by the escape hatch at SchemaConverter.cpp:1124-1152 and returns there, and that hatch is where I enabled hash filters for it (:1149, allow_hash_filters = type == FIXED_LEN_BYTE_ARRAY). The no-hint read measures identically, and since this line would have disabled the filters, the read pass must be arriving with the inferred FixedString(N) as its hint. Both legs still prune 3 of 4 row groups, same as master; controls hfilter_d_17_fs8_fs8 and hfilter_d_18_fs8_inferred in the test assert it.
What does reach this line with a FixedString output is only a hint of a different width, since the hatch requires size == getN(). That read raises TOO_LARGE_STRING_SIZE while decoding, so there is no pruning to preserve. On master the hash filter ruled out every row group first, so the query returned 0 instead of raising; now it raises.
2. FIXED_LEN_BYTE_ARRAY -> String does reach it, and turning the filters off there is the fix. The output value is not the stored value: FixedString(N) -> String strips trailing zero bytes (FunctionsConversion.h:4780). Both hash sides work in the stored space. The dictionary leg materializes column_info.decoded_type, i.e. FixedString(N) (Reader.cpp:1779-1782), and a bloom filter was written over the same N bytes, while a query constant goes through tryHashFLBA -> tryHashStringWithoutCompatibilityCheck, which hashes the Field's own byte length (parquetBloomFilterHash.cpp:77). So for a stored 'ab\0\0' read as String, the row really is 'ab' and really matches x = 'ab', but xxh64('ab') gets looked up in a filter built from xxh64('ab\0\0'), the row group is ruled out and the row is gone. It looks exact only when the stored bytes happen to carry no padding, which is why x = '00000200' over an 8-byte column matched on master too.
3. Why the pre-existing line does not mention FixedString. Same reason as (1): with a matching-width hint the FixedString case has already returned, so allow_stats here never sees it. WhichDataType::isString() is TypeIndex::String exactly, so that line reads as "allow min/max when the output is String". The two flags are also different guarantees, hence the different shapes: min/max needs the conversion to preserve order, and zero-stripping does (FunctionsConversion.h:4778-4784), while hashing needs identity of the exact bytes.
One thing worth flagging since it is the line you asked about: allow_stats is too permissive for -> String in the same way. With both hash legs off, the min/max legs alone still drop that padded row, on master and on this head alike, and #121033 is integer-scoped so it does not cover this. Out of scope here (the Part 1 assertions turn those legs off for exactly this reason), but it is a live wrong-results path if you want it fixed.
Measured on debug builds of this head and of master. Fixture for the first three rows is a FixedString(4) file holding toFixedString('ab', 4) read as String with WHERE x = 'ab'; the rest is a 256-row FixedString(8) file in 4 row groups with a bloom filter, where ParquetReadPages is the pruning oracle.
| arm | master | this head |
|---|---|---|
FLBA(4) -> String, hash legs only |
0 rows | 1 row |
FLBA(4) -> String, min/max legs only |
0 rows | 0 rows |
FLBA(4) -> String, all legs off |
1 row | 1 row |
FLBA(8) -> FixedString(8), dictionary leg |
1 of 4 pages | 1 of 4 pages |
FLBA(8) -> FixedString(8), bloom leg |
1 of 4 pages | 1 of 4 pages |
FLBA(8), no structure hint, dictionary leg |
1 of 4 pages | 1 of 4 pages |
FLBA(8), no structure hint, bloom leg |
1 of 4 pages | 1 of 4 pages |
FLBA(8) -> String, dictionary leg |
1 of 4 pages | 4 of 4 pages |
FLBA(8) -> String, bloom leg |
1 of 4 pages | 4 of 4 pages |
FLBA(8) -> FixedString(8), no legs |
4 of 4 pages | 4 of 4 pages |
If it would have saved you the question, I can add a line here noting that the matching-width FixedString case returns at :1142.
| converter->output_size = 2; | ||
|
|
||
| out_decoder.allow_stats = dispatch_int_stats_converter(/*allow_datetime_and_ipv4=*/ true, *converter); | ||
| out_decoder.allow_hash_filters = allow_int_hash_filters(physical_bits == 64 ? 64 : bits, is_signed, physical_bits); |
There was a problem hiding this comment.
This drops the logical INT(n, ...) bound exactly on the one carrier where Parquet often widens it. For a column stored as physical INT64 but annotated INT(16, false) or INT(16, true), the file can still contain only 16-bit values, so hashing a matching UInt32 / Date32 / Enum16 constant back to INT64 remains exact — the upper 48 bits are just zero/sign extension of the same value. Using 64 here disables both dictionary and bloom pruning for those exact cases, which is a real regression from the current behavior.
I think physical_bits only needs to control the native-integer reinterpretation branch; the value-preserving branch should still reason from the logical bits. Please also add a focused regression on an INT64-physical, logically narrow integer (for example INT(16, false) read as UInt32).
…as Bool The integer statistics allowlist in `dispatch_int_stats_converter` sees a `Bool` output type as `UInt8`, so a `UINT_8` column passes the width and signedness check and its stored min/max are used as is. Under a `LowCardinality(Bool)` hint the output column is a cast that maps every nonzero byte to 1, so a column holding only 2 has statistics [2, 2] while every row reads as `true`: `x = true` pruned the row group (and, on the page index leg, the page) and silently returned no rows. Released 26.8 and 26.9 behave the same. `Bool` holds only 0 and 1, so endpoints of any other stored integer do not bound it. A `Bool` output over a non-BOOLEAN physical column now gets no min/max statistics (row groups, pages and the TopK shortcut all key on `allow_stats`). BOOLEAN columns, which is what ClickHouse and Spark write, keep pruning. The bloom and dictionary filters lose the same rows through their own hash comparison and have no type gate on master; ClickHouse#121077 adds that gate and the same rule belongs there. The new test pins both of them off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A `Bool` hint reads a stored integer above 1 as `true`: through `LowCardinality` the cast maps 2 to 1, and a plain `Bool` keeps 2, which `IN (true)` matches. The bloom filter and the dictionary page still hold the stored 2 while the constant `true` hashes as 1, so each leg on its own skipped the row group holding the match (0 rows instead of 10, measured on master). ClickHouse#123864 stopped the min/max legs from bounding such a column, and its changelog says the hash legs keep dropping these rows until this PR merges. The value-space rule cannot express it (a `Bool` is an 8-bit unsigned integer to it), so the integer branches now leave `allow_hash_filters` off for a `Bool` output. The `BOOLEAN` branch never enables the hash filters. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lumns The requested-type list left out `Time` and `Interval*`, whose constants are `Int64` fields that `tryHashInt` hashes, so both legs were turned off for them although master pruned there. Measured on this binary: - An integer CAST to `Interval*` is a plain conversion to `Int64` (a `UInt64` wraps, `UInt32`/`Int8` keep their value), so it is treated as a 64-bit signed integer. - One to `Time` keeps a value of at most 16 bits and clamps a wider one at 999:59:59, independent of the time zone, so it gets the same 16-bit source rule as `Date32`. Test: one arm that loses its row on master (an `Int32` holding 2000000000 read as `Time`, i.e. the clamp) and controls for both legs over `Time` and `IntervalSecond`. Dropping the 16-bit rule for `Time` reddens only that arm; dropping both entries reddens only the four controls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Head branch was pushed to by a user without write access
|
Two commits on top of the master merge: |
|
@al13n321 @scanhex12 the CI is green. It's up to you |
|
OK, revert if you don't agree |
A Parquet UINT_8 column is stored as INT32; the reader narrows each value to its low byte and returns UInt8. Bool is a named UInt8, so the decoded type compares equal to the requested one, no cast runs, and a stored 2 reaches the query under type Bool: `x = true` matches nothing while `x IN (true)` and `WHERE x` match every row. When the output type is Bool, the narrowing now writes `x != 0`. The dictionary page is decoded through the same converter, so the dictionary filter stops dropping these rows. A min/max statistic above 1 is clamped to 1 instead of being dropped (as ClickHouse#123864 did), which is sound because `v -> v != 0` is monotone over the unsigned stored values that reach the statistics path, so `[2, 2]` prunes `x = false` again. The output element type stays UInt8. Arrow, Native and RowBinary have the same symptom through other paths and are not changed here; the bloom filter still hashes stored values (ClickHouse#121077). Related: ClickHouse#124074 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #118376
Related: #121033
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results when reading a
Parquetfile with a structure hint whose type differs from the stored one. Bloom-filter and dictionary-filter row-group pruning hashed the query constant in the requested type but the stored values in the Parquet physical type, so a row group holding a match was skipped andcount()could return0instead of the real count. Affected hints include narrowing (UInt32read asUInt16), a signedness flip below the physical width (UInt8read asInt8),Enum8/Enum16,Date/Date32/Timeover a column wider than 16 bits,Boolover an integer column holding a value above 1, andString/FixedString(N)length mismatches.Description
Same family as #118376; its min/max legs are #121033 and, for
Bool, #123864.Root cause. The two hashed sides live in different value spaces. The stored side is hashed in physical space (the dictionary is cast to it by
parquetTryHashColumn, and the file's bloom filter holds digests of physical values); the query side is aKeyConditionconstant of the requested type. Nothing checked that the conversion preservesstatic_cast<physical>, which each hint above breaks. The min/max legs are gated byallow_stats; the hash legs had no gate at all.Change. One fail-closed
PageDecoderInfo::allow_hash_filters, decided inSchemaConverter's type dispatch next toallow_statsand read by onecontinueinReader::prepareBloomFilterCondition: a branch leaving itfalsemakes the column ineligible, so both legs stay off. This is the placement asked for in review; only six branches can hash at all, and their shared rule is one helper beside theallow_statsdispatch.I withhold rather than reconcile: mapping a constant back into physical space is one-to-many in exactly the broken cases (65536 values per
UInt16). Pruning is kept wherever the two spaces agree, and given up where soundness came from the data rather than the types (e.g.Int32read asDateTime).Validation. New test
05241_parquet_hash_filter_output_type_value_space: 19 arms that returned the wrong count, 38 controls asserting viaread_rowsthat each leg still skips three of four row groups, and four no-pruning baselines so nothing passes vacuously. Each branch has a control that reddens when only it is reverted. Theparquetsuite's failure set is unchanged.Workflow [PR]
Sync PR [sync-upstream/pr/121077]
Version info
26.10.1.1848-master(included in26.10and later)