Skip to content

Do not prune Parquet row groups and pages by integer statistics above 1 read as Bool - #123864

Merged
PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:parquet-bool-hint-no-minmax-pruning
Oct 6, 2026
Merged

PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:parquet-bool-hint-no-minmax-pruning

Conversation

@groeneai

@groeneai groeneai commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121033
Related: #121077

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 Parquet row group and page pruning silently dropping rows of an integer column read with a Bool type hint (also inside Nullable or LowCardinality) 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 plain Bool (x IN (true)):

INSERT INTO FUNCTION file('u8two.parquet', Parquet, 'x UInt8') SELECT toUInt8(2) FROM numbers(10);
SELECT count() FROM file('u8two.parquet', Parquet, 'x LowCardinality(Bool)') WHERE x = true
SETTINGS allow_suspicious_low_cardinality_types = 1,
    input_format_parquet_bloom_filter_push_down = 0, input_format_parquet_dictionary_filter_push_down = 0;
-- 0 before, 10 here (10 with every push-down off); `'x Bool' ... WHERE x IN (true)` is the same

Root cause. The integer statistics allowlist sees Bool as UInt8, so a UINT_8 column passes the width and signedness check and its min/max [2, 2] is used as is. A Bool reader can see 2 as 1: the LowCardinality(Bool) cast maps every nonzero value to 1, and IN (true) matches a stored 2 under plain Bool. So true is outside [2, 2] and the row group or page is skipped.

Change. For a Bool output, a statistic above 1 bounds nothing. 0 and 1 read the same either way, so 0/1 and BOOLEAN columns 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 Bool hint over a non-BOOLEAN column, 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, a Tuple element, plain Bool / Nullable(Bool) IN (true), and ParquetPrunedRowGroups / ParquetPrunedPages controls showing that statistics of 0 and of 1, BOOLEAN and plain UInt8 keep pruning. It fails on master and passes 50/50 randomized; the Parquet and Bool stateless tests give the same results as master.


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

Version info

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

groeneai and others added 2 commits October 4, 2026 13:11
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-self PR origin: self-found defect (impact-bar validated) labels Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, 1 finding, fixed)
  • ⚠️ page-leg-live (test): the page-pruning arm had no positive control for the page path. AGREE, fixed in this PR: a plain UInt8 read of the same file asserts ParquetPrunedPages > 0, and the Bool arm asserts that no pages are pruned.

Re-review of the published head: no findings.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A UINT_8 file of 2s read as LowCardinality(Bool), x = true, bloom and dictionary push-downs off: 0 on master, every time (the new test fails 20/20 randomized runs on master with the same diff).
b Root cause explained? The integer statistics allowlist treats Bool as UInt8 (8 unsigned bits to 8 unsigned bits), so the endpoints [2, 2] are kept, while the LowCardinality(Bool) cast maps every nonzero value to 1. 1 is outside [2, 2], so the row group or page is pruned.
c Fix matches root cause? Yes. The allowlist now refuses a Bool output over a non-BOOLEAN physical type, at the same place the other order-changing hints are refused. No setting, no guard at the read site.
d Test intent preserved / new tests added? New test 05321_parquet_bool_hint_no_minmax_pruning: row group and page legs, LowCardinality(Nullable(Bool)), x <= true, a Tuple element, plus two pruning controls.
e Both directions demonstrated? Master and an in-tree revert: FAIL with the same diff (0, 0, 1000, 0, 600 instead of 1000, 1000, 2000, 10, 1000). With the fix: OK, 50/50 randomized. Dropping only the BOOLEAN exemption reddens only the BOOLEAN control (2 row groups read, 0 pruned).
f Fix is general across code paths? One flag gates every min/max consumer (row groups, pages, TopK), and the changed lambda serves every integer site. The bloom and dictionary filters are a separate hash comparison with no type gate on master; the same rule is owed in #121077.
g Fix generalizes across inputs (params/datatypes/wrappers)? Bool, Nullable(Bool), LowCardinality(Bool) and LowCardinality(Nullable(Bool)) all reach the lambda as Bool; nested Tuple elements take the same path (tested). Signed or wider stored types were already refused by the width check.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; the only effect is no min/max pruning for a Bool hint over a non-BOOLEAN column.
i Invariants and contracts preserved? A pruning endpoint bounds the output column again for this hint. allow_stats = false is the existing conservative state; the converter fields the early return leaves at their defaults are read only when statistics are used.

Session id: cron:clickhouse-impl-self-slot-57:20261004-122600

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a62e5da]

Summary: ✅


AI Review

Summary

This PR tightens the Parquet min/max-statistics soundness check for Bool hints so row-group and page pruning stop treating UINT_8 endpoints above 1 as bounds, while still keeping the safe 0/1 cases prunable. I reviewed the current diff together with the existing discussion threads and the shared stats consumers (row-group, page index, and TopK), and I did not find any unresolved correctness, safety, or contract issues in the current head.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit a62e5da.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 9/11 (81.82%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-parquet-reader-v3 Issues related to the native Parquet reader. labels Oct 4, 2026
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]>
@groeneai groeneai changed the title Do not prune Parquet row groups and pages by integer statistics read as Bool Do not prune Parquet row groups and pages by integer statistics above 1 read as Bool Oct 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit a62e5da761716907d80be971be4656b74053cee5 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

@PedroTadim PedroTadim self-assigned this Oct 5, 2026
return std::nullopt;
if (!input_signed && field_signed && val > UInt64(INT64_MAX))
return std::nullopt;
if (field_bool && val > 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🕵️ The fix looks right and conservative. Two points:

  1. On its own this doesn't change what users see: on master, WHERE x = true over 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 the Bool-hint extension. Please merge them together, or say so in the changelog.

  2. Separate bug: plain Bool keeps the raw value. toUInt8(x) is 2 (LowCardinality(Bool) normalises to 1), so with all pruning off x = true matches 0 rows while x IN (true) and x match 10. Normalising non-zero integers to 1 under a Bool hint would fix that, and would let these statistics map to 1 instead of being dropped. Worth an issue.

Nit: isBool() rather than comparing the type name to "Bool".

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.

Thanks, done:

  1. 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). The Bool rule 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.
  2. Opened A Bool type hint over an integer column keeps the stored value: x = true misses rows that x IN (true) and WHERE x return #124074. Parquet, Arrow, RowBinary and Native all keep the 2; ORC maps it to 1.
  3. 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).

groeneai and others added 2 commits October 5, 2026 18:06
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]>
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 6, 2026
Merged via the queue into ClickHouse:master with commit 799048c Oct 6, 2026
149 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 6, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 6, 2026
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]>
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-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.

3 participants