Skip to content

Do not use Parquet bloom or dictionary filters when the requested type changes what a value hashes to - #121077

Merged
PedroTadim merged 8 commits into
ClickHouse:masterfrom
groeneai:parquet-hash-filter-output-type-value-space
Oct 8, 2026
Merged

PedroTadim merged 8 commits into
ClickHouse:masterfrom
groeneai:parquet-hash-filter-output-type-value-space

Conversation

@groeneai

@groeneai groeneai commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #118376
Related: #121033

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 results when reading a Parquet file 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 and count() could return 0 instead of the real count. Affected hints include narrowing (UInt32 read as UInt16), a signedness flip below the physical width (UInt8 read as Int8), Enum8/Enum16, Date/Date32/Time over a column wider than 16 bits, Bool over an integer column holding a value above 1, and String/FixedString(N) length mismatches.

Description

Same family as #118376; its min/max legs are #121033 and, for Bool, #123864.

INSERT INTO FUNCTION file('u32.parquet', Parquet, 'x UInt32') SELECT toUInt32(70000);
SELECT count() FROM file('u32.parquet', Parquet, 'x UInt16') WHERE x = 4464; -- 0 since 25.11, should be 1

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 a KeyCondition constant of the requested type. Nothing checked that the conversion preserves static_cast<physical>, which each hint above breaks. The min/max legs are gated by allow_stats; the hash legs had no gate at all.

Change. One fail-closed PageDecoderInfo::allow_hash_filters, decided in SchemaConverter's type dispatch next to allow_stats and read by one continue in Reader::prepareBloomFilterCondition: a branch leaving it false makes 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 the allow_stats dispatch.

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. Int32 read as DateTime).

Validation. New test 05241_parquet_hash_filter_output_type_value_space: 19 arms that returned the wrong count, 38 controls asserting via read_rows that 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. The parquet suite's failure set is unchanged.


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

Version info

  • Merged into: 26.10.1.1848-master (included in 26.10 and later)

…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.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-self PR origin: self-found defect (impact-bar validated) labels Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
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
resulting tree; bounded: 1 full pass, 0 fix rounds. Four findings adjudicated: one DISAGREE with
recorded evidence, one note, and two defects in this description itself, fixed before publication.

# Sev Finding Verdict Evidence / action
1 ❌ Enum8/Enum16 targets are admitted as value-preserving even though a numeric-to-enum cast throws for an undeclared value, so a hash leg can skip a row group whose read would have raised UNKNOWN_ELEMENT_OF_ENUM DISAGREE Scenario: an Int8 column holding 2 in one row group and 1 in another, read as Enum8('a' = 1). The predicate answers its own question correctly: 1 and 2 hash identically on both sides, so the skipped row group holds no matching row and count() stays correct. What is lost is a conversion error on a non-matching row, which no value-space rule governs. The prescribed remedy would not restore it either: dispatch_int_stats_converter (SchemaConverter.cpp:994-997) makes enum output types statistics-eligible and the integer path does not set cast_stats_to_output_type, so the min/max legs already compare the raw bound 2 against [1,1] and skip that row group themselves, with or without this change. Behaviour is identical to master. Whether Parquet pruning may skip a conversion error on a row the predicate excludes is a design question I leave to you rather than answering inside this change: if it may not, refusing Enum in getRequestedIntegerSpace plus one control is the whole fix
2 💡 source_must_fit_in_16_bits states the 16-bit rule as the cast's semantics for the whole date family AGREE, noted Exact for Date, whose day-number/timestamp switch is DATE_LUT_MAX_DAY_NUM = 0xFFFF (FunctionsConversion.h:339); for Date32 the window ends at DATE_LUT_MAX_EXTEND_DAY_NUM = 2932896, so the rule is conservative rather than descriptive. Also the real reason Int16 and UInt16 read as Date32 are admitted: Date32's window [-719528, 2932896] strictly contains the whole 16-bit range, so neither the timestamp switch nor the lower clamp can fire. Sound either way: the predicate withholds at least as much as soundness needs

The admitting clauses were checked by walking the pass set rather than sampling it: reinterpretation
admits a native-integer target at or above the physical width, where the cast is modulo 2^bits and so
preserves the only bits either side hashes; value_preserving admits a numerically identical conversion
and refuses every signedness change out of a signed source. The one candidate hole I chased was Int16
read as Date32, where ToDate32TransformFromSecondsOrDays clamps a signed source below its lower
bound; it is unreachable, per finding 2. The change is purely subtractive (one continue before the
eligibility emplace), so it can only give up pruning, never introduce a skip, which is what the 30
read_rows controls assert.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-self-slot-58:20260919-180100

@clickhouse-gh clickhouse-gh Bot closed this Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, on demand, 16 single-count() arms. INSERT INTO FUNCTION file('u32.parquet', Parquet, 'x UInt32') SELECT toUInt32(70000) then SELECT count() FROM file('u32.parquet', Parquet, 'x UInt16') WHERE x = 4464 returns 0; 1 is correct.
b Root cause explained? Yes. The stored side is hashed in physical space (the dictionary is materialized as decoded_type and cast to the physical type; the bloom filter holds physical digests) while query constants are hashed in the requested type. Nothing checked that the conversion preserves static_cast<physical>, which narrowing, a signedness flip below the physical width, a unit change (an integer wider than 16 bits read as Date32 is a timestamp, not a day number) and a byte-length mismatch each break.
c Fix matches root cause? Yes. One predicate expressing exactly the "same value space" condition, at the single point where a column becomes eligible for the hash legs. Not a widened bound, a no-random-* tag, a dataset reduction, or a guard at the symptom site.
d Test intent preserved / new tests added? New test 05231_parquet_hash_filter_output_type_value_space: 16 wrong-result arms, 30 pruning-preservation controls (one per predicate clause, per leg), 2 no-pruning baselines. No existing test weakened; the parquet suite's failure set is unchanged.
e Both directions demonstrated? Yes. Base binary (bfbaf3b1): sixteen 0s. Fix binary (b115b7e7, differing from the published tree in comments only): the truth values. diff is a single hunk 1,16c1,16, so all 64 control lines are byte-identical. 4 of 4 mutations redden the committed test, each on the expected line.
f Fix is general across code paths? Yes. One gate covers both legs (use_dictionary_filter requires use_bloom_filter, Reader.cpp:1019-1020); the null_as_default default-value hash and the IN-set hash_many path sit behind the same gate. Reader v0 no longer exists, so Reader.cpp is the only consumer of parquetTryHash*. The min/max and page-index legs are untouched (already gated by allow_stats); bbox pruning uses endpoints, not digests, on physical DOUBLE columns that were never hashable.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Both physical widths (INT32, INT64), both signedness directions, all four integer widths, Enum8/Enum16/Date/Date32/DateTime/IPv4/IPv6, String/FixedString. The wrapper strip is load-bearing, not defensive: it is what lets UInt32->Nullable(UInt16) be refused while UInt32->Nullable(UInt32) and String->LowCardinality(String) keep pruning. Boundaries covered: UInt8 200 -> Int8 -56, Int8 -1 -> UInt8 255 and UInt16 65535, Int64 2^32+5 -> Int32 5.
h Backward compatible? (maintainer-approved exception only) Yes. No setting added, removed or re-defaulted, so no SettingsChangesHistory.cpp entry is owed; no format or on-disk change. The only observable difference is that some row groups are read instead of wrongly skipped.
i Invariants and contracts preserved? Yes. The gate only continues before bf_eligible_columns[...].emplace(...), leaving the slot nullopt; hash_one/hash_many then return nullopt and use_bloom_filter stays false, which is the state a column with no bloom filter and no dictionary page already produces. No lock, allocation, ownership or error-path change, and hashDictionaryValues's exactly-budgeted pruning-memory reservation is untouched because nothing new is hashed. The .at() cannot throw: SchemaConverter.cpp:106 asserts idx_in_output_block != UINT64_MAX for every primitive column.

Session id: cron:clickhouse-impl-self-slot-57:20260919-153700

@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b4a6455]

Summary: ✅


AI Review

Summary

This PR correctly moves the Parquet hash-filter eligibility decision into SchemaConverter and fixes the wrong-results cases it targets, but one performance regression is still present on the current head: physically INT64 columns with a narrower logical INT(n, ...) annotation now lose exact bloom/dictionary pruning even when the requested type still lives in the same value space. Because that regression is still in the live code, I would not merge this as-is.

Findings

⚠️ Majors

  • [src/Processors/Formats/Impl/Parquet/SchemaConverter.cpp:1300] allow_int_hash_filters forces decoded_bits = 64 for every logical integer carried in a physical INT64, so the value_preserving check rejects exact cases like logical INT(16, false/true) read as UInt32, Enum16, Date, Date32, Time, DateTime, or IPv4. On those files the read path still only exposes the narrow logical value space, and hashing the query constant back to the physical INT64 remains exact because the upper bits are just sign/zero extension. This change therefore turns off both dictionary and bloom pruning on a class of files that master still prunes correctly.
  • Suggested fix: keep using physical_bits only for the native-integer reinterpretation branch, but let the value_preserving branch reason from the logical bits that Parquet declares. Please also add a focused stateless regression for a physical INT64 column annotated as logical INT(16, ...) and read through one of the exact requested types above.
Final Verdict

⚠️ Needs changes before merge: fix the physical-INT64 / narrow-logical-integer regression in src/Processors/Formats/Impl/Parquet/SchemaConverter.cpp:1300.

LLVM Coverage Report

Measured on commit b4a6455.

Metric Baseline Current Δ
Lines 88.30% 88.20% -0.10%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 71/71 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-parquet-reader-v3 Issues related to the native Parquet reader. label Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 04127a7

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
Build profile diff infra, not reachable from this diff: the CI logs cluster read timed out three times (urllib3.exceptions.ReadTimeoutError at 03:51:18, 03:52:48 and 03:54:23 against the staging endpoint), after which query() raised RuntimeError: CI logs cluster query failed at ci/jobs/build_profile_diff_job.py:234, reached through compare_symbols. No test-level failure was reported anywhere on this head; the diff is Parquet reader code plus two stateless tests. #118708 (mine, open), which reports the cluster's error and skips the check when the cluster is unavailable
CH Inc sync - CH Inc sync (private, not actionable by me)
PR aggregator row: mirrors the two rows above, and no other check failed on this head #118708 (mine, open)

Session id: cron:our-pr-ci-monitor:20260920-080106

@al13n321 al13n321 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes, it would work, and I think it is the better home.

SchemaConverter is constructed with extended_sample_block (Reader.cpp:576-580) and node.type_hint is taken from it (SchemaConverter.cpp:259), so processPrimitiveColumn already has the exact requested type this predicate needs, with LowCardinality/Nullable stripped for it (:388-402) rather than by hand. PageDecoderInfo already carries physical_type (:962), and Reader already consults that struct for the parallel min/max decision (if (!column_info.decoder.allow_stats) continue;, Reader.cpp:311). So the shape is one bool next to allow_stats, set in the dispatch, and the read side becomes a continue on that flag.

It is also a small part of the dispatch, not all of it: parquetTryHashField hashes only INT32/INT64 annotated INT or nothing, and BYTE_ARRAY/FIXED_LEN_BYTE_ARRAY annotated String/JSON/BSON or nothing, so every other branch can leave the flag false and lose no pruning.

The advantages of this PR's placement are narrower than I would like: it is purely subtractive (one continue before the eligibility emplace), so it cannot make a column newly eligible anywhere, and it adds no field that each branch has to remember to set. Against that, getRequestedIntegerSpace re-enumerates the requested-type list dispatch_int_stats_converter already enumerates (native integer, IPv4, Date, DateTime, Enum8, Enum16, Date32), which will drift, and the predicate has to re-derive which branch decoded the column from (decoded_type, physical_type) instead of being told by the branch that ran. Your placement also gets the fail-closed default that allow_stats has, so a newly supported logical type is ineligible until someone decides otherwise.

One asymmetry worth naming, since it is the reason this needs no cast_stats_to_output_type counterpart: a hash is not order preserving, and a constant of the requested type cannot be mapped back into physical space one-to-one (65536 UInt32 values hash where one UInt16 constant does), so withholding is the only available answer and the entire decision is type-level. That is a further argument for deciding it where the type-level decisions are made.

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.
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Sep 23, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@al13n321 you were right, and it is moved. Re-requesting your review on the new head 116b8ee6dadd5.

The exactness decision is now one default-false PageDecoderInfo::allow_hash_filters, set in
processPrimitiveColumn's dispatch next to allow_stats, and Reader::prepareBloomFilterCondition
reads it with a single continue. parquetBloomFilterHash.{h,cpp} are byte-identical to master again
(git diff master -- <those two files> is empty), and the rule moved verbatim, so it is the same rule
you approved, now told its inputs instead of re-deriving them from decoded_type.

Six branches assign the flag, which is fewer sites than it sounds: only six dispatch branches can reach
a hash at all, because parquetTryHashField hashes INT32/INT64 behind the logical and converted
integer gate and BYTE_ARRAY/FIXED_LEN_BYTE_ARRAY behind the string one, plus IPv6 at length 16,
and returns nullopt everywhere else. The integer rule lives in one helper that three of them call; the
other three are one-expression facts about their own branch. Each site has a control that fails when
only that site is left out.

Two things about the tests, where I said they would not change:

  • Renumbered 05231 to 05241, master had taken the prefix.
  • Six control rows and two fixtures added. Int32, Int64 and FixedString(N) are written with no
    parquet annotation, so the escape-hatch branch and the two no-annotation branches had no
    surviving-pruning control, and a flag forgotten at one of them would have lost pruning with the whole
    suite still green. Nothing was weakened and nothing was changed: all 46 assertions from the approved
    head are byte-identical and the new binary reproduces their reference exactly, which is what pins the
    behaviour as unchanged.
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
pass, 0 fix rounds. The gate returned no findings. Three items adjudicated from my own read.

# Sev Finding Verdict Evidence / action
1 ❌ The fixed-array fallback branch admits only IPv6, while the approved head allowed the hash legs for a FIXED_LEN_BYTE_ARRAY read as FixedString(n) through requested->equals(*decoded). Since FixedString is written as an unannotated fixed array by default and tryHashFLBA hashes a String field for one, that shape prunes today, so this looked like silently lost pruning on the commonest fixed-width read DISAGREE The case cannot reach that branch. In the read pass the requested type is always set, because node.requested = true and node.type_hint = sample_block->getByPosition(pos).type are assigned in the same block and processSubtreePrimitive returns early when the node is not requested. So a FixedString(n) whose width equals the physical width is taken by the escape hatch above, which does set the flag, and the fallback is reached only by a non-matching width, where false is required for correctness rather than merely equivalent. Measured, not argued: the control that reads that fixture with no structure hint at all asserts read_rows 64 of 256, and its expected value was derived before the run rather than read out of the binary
2 ⚠️ The new site set is narrower than the old predicate in several branches: a legacy [U]Int128/[U]Int256 fixed-array hint, UUID, FLOAT16, DECIMAL, GeoParquet and INTERVAL all satisfied requested->equals(*decoded) and now leave the flag false AGREE, no change No observable difference: a constant of each of those types is a Field that parquetTryHashField rejects (tryHashInt takes only Int64/UInt64/IPv4, tryHashFLBA only IPv6 at length 16 or a String field), and the annotated ones fail the logical and converted gates before that, so no constant was ever hashed for such a column. Disclosed because it is the one place the move is not literally type for type
3 💡 A comment in the new control block calls Int64 and FixedString the only types written without a parquet annotation AGREE, noted Int32 is one too, and the pre-existing unannotated INT32 control is hfilter_*_05. No behavioural effect

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding.

Session id: cron:clickhouse-review-slot-9:20260923-053425

@groeneai
groeneai requested a review from al13n321 September 23, 2026 06:24
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b4a6455a7 with master 5d00df722 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 2788f1048; 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.

Compile time of recompiled translation units

17 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.
The matched translation units cost -10.8 s (-7%) in total before that adjustment.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 116b8ee

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
Performance Comparison (arm_release, master_head, 2/6) / dashboard verdict job summary 1 confirmed regression(s) on the performance dashboard #121090 (mine, open), with #121189 (mine, open)
Performance Comparison (arm_release, master_head, 2/6) / index_bulk_filtering #2 the shard's own 1 slower: 46 ms old -> 73 ms new on a bimodal fixture; 230 distinct PRs and 51 master commits hit it in 14 days #121260 (mine, open)
Mergeable Check praktika rollup of the rows above #121090 (mine, open)
PR praktika rollup of the rows above #121090 (mine, open)

index_bulk_filtering is a pure ENGINE = MergeTree skip-index benchmark, while this diff
touches only src/Processors/Formats/Impl/Parquet/{Decoding.h,Reader.cpp,SchemaConverter.cpp}
plus one stateless test, so the diff cannot reach that query. Shards 1/6 and 3/6 to 6/6 all
passed on this head.

Session id: cron:our-pr-ci-monitor:20260923-190314

Comment on lines +1723 to +1724
out_decoder.allow_hash_filters = WhichDataType(get_output_type_index()).isIPv6()
&& size_t(element.type_length) == sizeof(IPv6);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

CurtizJ pushed a commit to CurtizJ/ClickHouse that referenced this pull request Oct 6, 2026
…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]>
groeneai and others added 2 commits October 6, 2026 13:54
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]>
auto-merge was automatically disabled October 6, 2026 14:49

Head branch was pushed to by a user without write access

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Two commits on top of the master merge: a5e9f29 turns the hash filters off for a Bool hint over an integer column, the half that #123864 (merged first) left to this PR, and b4a6455 adds Time and Interval* hints to the allowlist, which master pruned and the previous head did not. The test gains the matching arms and controls; nothing else changed.

@PedroTadim

Copy link
Copy Markdown
Member

@al13n321 @scanhex12 the CI is green. It's up to you

@PedroTadim
PedroTadim added this pull request to the merge queue Oct 8, 2026
@PedroTadim

Copy link
Copy Markdown
Member

OK, revert if you don't agree

Merged via the queue into ClickHouse:master with commit fbff0c6 Oct 8, 2026
149 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 8, 2026
jh0x pushed a commit to jh0x/ClickHouse that referenced this pull request Oct 8, 2026
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]>
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-parquet-reader-v3 Issues related to the native Parquet reader. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai groeneai-origin-self PR origin: self-found defect (impact-bar validated) pr-bugfix Pull request with bugfix, not backported by default 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.

4 participants