Repository navigation
Do not prune Parquet row groups and pages by integer statistics above 1 read as Bool - #123864
Conversation
…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]>
…max_pruning With the fix the `LowCardinality(Bool)` page arm returns 1000 whether or not the page index is used, so the count alone did not prove that the fixture has a usable page index. The same file read as plain `UInt8` must prune pages (`ParquetPrunedPages > 0`), and the `Bool` read must prune none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds, 1 finding, fixed)
Re-review of the published head: no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261004-122600 |
|
Workflow [PR], commit [a62e5da] Summary: ✅
AI ReviewSummaryThis PR tightens the Parquet min/max-statistics soundness check for Final Verdict
LLVM Coverage ReportMeasured on commit a62e5da.
Changed lines: Changed C/C++ lines covered: 9/11 (81.82%) · Uncovered code |
The previous commit dropped every min/max statistic of a non-BOOLEAN column read as `Bool`, which also stopped pruning for integer columns that hold only 0 and 1, with any wrapper, including plain `Bool`. Withhold only the endpoints above 1 instead. An endpoint of 0 or 1 is the same value whether the column keeps the stored byte (plain `Bool`) or maps nonzero to 1 (`LowCardinality(Bool)`), so it still bounds the chunk; an endpoint above 1 bounds nothing, because both readings occur: a plain `Bool` keeps 2 for `x = true` and `toUInt8(x)`, but `x IN (true)` matches it. On master that `IN` lost rows to pruning for plain `Bool` and `Nullable(Bool)` too (0 instead of 1000), so the gate cannot be narrowed to the `LowCardinality` wrappers. All three statistics consumers treat a missing endpoint as unbounded: the row group hyperrectangle and the page index start from the whole universe, and TopK gives up on a row group when either bound is missing. The BOOLEAN exemption is no longer needed, as its endpoints are always 0 or 1. The test gains plain `Bool` / `Nullable(Bool)` `IN (true)` arms and `ParquetPrunedRowGroups` controls showing that the [0, 0] row group is still pruned under both `LowCardinality(Bool)` and plain `Bool`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
BoolBool
Build profile diff (arm_release)Commit See the job log for details. |
| return std::nullopt; | ||
| if (!input_signed && field_signed && val > UInt64(INT64_MAX)) | ||
| return std::nullopt; | ||
| if (field_bool && val > 1) |
There was a problem hiding this comment.
🕵️ The fix looks right and conservative. Two points:
-
On its own this doesn't change what users see: on master,
WHERE x = trueover the ten stored 2s returns 0 with only row-group min/max on, with only page min/max on, and with bloom/dictionary on — each layer drops the rows. So at defaults it stays 0 until Do not use Parquet bloom or dictionary filters when the requested type changes what a value hashes to #121077 lands with theBool-hint extension. Please merge them together, or say so in the changelog. -
Separate bug: plain
Boolkeeps the raw value.toUInt8(x)is2(LowCardinality(Bool)normalises to1), so with all pruning offx = truematches 0 rows whilex IN (true)andxmatch 10. Normalising non-zero integers to1under aBoolhint would fix that, and would let these statistics map to1instead of being dropped. Worth an issue.
Nit: isBool() rather than comparing the type name to "Bool".
There was a problem hiding this comment.
Thanks, done:
- Said so in the changelog entry. It does change the default-settings result for a file without bloom filters and dictionary pages (written with
output_format_parquet_write_bloom_filter = 0, output_format_parquet_max_dictionary_size = 0: 0 on master, 10 here). TheBoolrule for the bloom and dictionary filters goes into whichever of this and Do not use Parquet bloom or dictionary filters when the requested type changes what a value hashes to #121077 merges second. - Opened A
Booltype hint over an integer column keeps the stored value:x = truemisses rows thatx IN (true)andWHERE xreturn #124074. Parquet, Arrow, RowBinary and Native all keep the 2; ORC maps it to 1. isBool()in e3df5f8. I also added a test arm with [0, 0] and [1, 1] row groups checking that a statistic of 1 still prunes (a62e5da).
Review nit on ClickHouse#123864: check the requested type with isBool() instead of comparing its name to "Bool". Co-Authored-By: Claude Opus 5.5 <[email protected]>
…int_no_minmax_pruning A UInt8 file with row groups [0, 0] and [1, 1] read as LowCardinality(Bool) with `x = false` must prune the [1, 1] group. Without this arm, changing the bound check from `val > 1` to `val > 0` passed the whole test; with it, that mutant gives `05321prune_one 2 0`. 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]>
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: #121033
Related: #121077
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Parquet row group and page pruning silently dropping rows of an integer column read with a
Booltype hint (also insideNullableorLowCardinality) when the column holds values other than 0 and 1. A statistic above 1 no longer bounds such a column; statistics of 0 and 1 still prune. Bloom filters and dictionary pages, where the file has them, still drop these rows until #121077 is merged.Description
On 26.8 and 26.9, an integer column holding 2 loses rows to min/max pruning when read as
LowCardinality(Bool)(x = true) or as plainBool(x IN (true)):Root cause. The integer statistics allowlist sees
BoolasUInt8, so aUINT_8column passes the width and signedness check and its min/max[2, 2]is used as is. ABoolreader can see 2 as 1: theLowCardinality(Bool)cast maps every nonzero value to 1, andIN (true)matches a stored 2 under plainBool. Sotrueis outside[2, 2]and the row group or page is skipped.Change. For a
Booloutput, a statistic above 1 bounds nothing. 0 and 1 read the same either way, so 0/1 andBOOLEANcolumns keep pruning.Scope. At default settings the query still returns 0 for a file with bloom filters or dictionary pages: those filters drop these rows by hash and have no type gate on master. #121077 adds that gate; it also needs to skip a
Boolhint over a non-BOOLEANcolumn, which I add to whichever of the two PRs merges second.Validation. New stateless test: row group and page legs,
LowCardinality(Nullable(Bool)),x <= true, aTupleelement, plainBool/Nullable(Bool)IN (true), andParquetPrunedRowGroups/ParquetPrunedPagescontrols showing that statistics of 0 and of 1,BOOLEANand plainUInt8keep pruning. It fails on master and passes 50/50 randomized; the Parquet andBoolstateless tests give the same results as master.Workflow [PR]
Sync PR [sync-upstream/pr/123864]
Version info
26.10.1.1663-master(included in26.10and later)