Repository navigation
Conversation
The inversion check ran on the decoded range. Decoding leaves a bound at infinity when the requested type cannot hold it, so under a type hint the inverted polars statistics can stop looking inverted: a UInt64 chunk with min_value 2^63 and max_value 1 read as `DateTime` decodes to [-inf, 1], and row group and page pruning dropped the row that the read saturates to the `DateTime` maximum (`WHERE u64 > toDateTime(100)` returned nothing; it returns that row with the pruning disabled). 26.10 and master return no row; 26.9 and older fail the query with INCORRECT_DATA instead. `IntConverter` now compares the stored values in the column's sort order (signed or unsigned per the logical type), and the row group and column index paths ignore statistics that are inverted there. The TopN and min/max-from-statistics paths already give up when a bound does not decode. The check on the decoded range stays for the other converters. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nt in 05479
The two DateTime arms asserted only the returned row, so they would also
pass if every statistic were ignored under a DateTime hint. They now also
print ParquetPrunedRowGroups / ParquetPrunedPages, like the no-hint arms:
row group 1 / page 1 (valid statistics {10, 20}) must still be pruned.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; round 1: 1 finding, round 2 on
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261101-172500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261101-171700 |
|
cc @scanhex12 @grantholly-clickhouse, could you review this and add the |
|
Workflow [PR], commit [1e8630f] Summary: ❌
AI ReviewSummaryPR #128508, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
| return val; | ||
| } | ||
|
|
||
| bool IntConverter::statsInverted(std::span<const char> min, std::span<const char> max) const |
There was a problem hiding this comment.
@groeneai why do we need to cover the case when stats are inverted? seems a bit ridiculous
There was a problem hiding this comment.
I think that the user won't try to invert the stats
There was a problem hiding this comment.
The user doesn't produce them, the writer does: polars 0.20 writes UInt64/UInt32 min/max in signed order while declaring TYPE_ORDER (#128302), so a row group holding both 1 and 2^63 gets min = 2^63, max = 1. Until #128336, any filter on such a column failed with INCORRECT_DATA; @ fm4v asked in #128302 to ignore these statistics instead.
This PR covers the case where the decoded-range check (the old INCORRECT_DATA one and #128336's) cannot see the inversion: with a DateTime hint the min 2^63 is out of range and decodes to no bound, so the decoded range is [-inf, 1] and the row group is pruned. With the #128302 file:
SELECT count() FROM file('polars_u64.parquet', Parquet, 'u Nullable(DateTime)') WHERE u > toDateTime(100)
-- 26.10.2.103: 0 (1 with both Parquet filter pushdowns disabled); 26.9: INCORRECT_DATASo since 26.10 it is a silent wrong result instead of an error. Checking the stored values before the decode is the smallest fix I found. If you still think it isn't worth handling, I'll close the PR.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units20 translation units recompiled, 202 s compile time in total, 20 of them have a recent master baseline. |
CI finish ledger - 48650b6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261101-233003 |
…atistics-stored-order Conflict in Decoding.h: master added [[nodiscard]] to the converter declarations (clang-tidy modernize-use-nodiscard). Kept it and added it to the new statsInverted and loadValue declarations as well. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`query_plan_propagate_predicate_across_join` copied a filter conjunct onto the other side of an equi-join only when that side reads a MergeTree whose primary key contains the key. A `file`, `url` or plain object storage read of Parquet got nothing, although the same filter written by hand skips row groups by their min/max statistics. A read now says through `SourceStepWithFilterBase::canSkipDataByFilterOn` whether a filter on a column lets it skip data without dropping rows that pass the filter. `ReadFromFile`, `ReadFromURL` and `ReadFromObjectStorageStep` answer yes for a Parquet read with `input_format_parquet_filter_push_down` for a column the format reads from the file as it is (in `format_header` with the same type, no Hive partition or virtual column, no default expression) of a native integer, `Date`, `Date32` or `Decimal` type, also inside `Nullable` / `LowCardinality`. Left out on purpose: - floats: Parquet bounds leave out NaN, so `x != 1.5` would skip a row group of NaN and 1.5 that the join matches (ClickHouse#118110); - `String`: bounds of a FIXED_LEN_BYTE_ARRAY read as `String` keep the padding (ClickHouse#120986); - `DateTime`, `IPv4`: a narrowing conversion leaves a bound unset (ClickHouse#128508); - `UUID`, `DateTime64`, `FixedString`, containers and others: no usable statistics, so a copy would be a full-scan filter; - default expressions: the default replaces NULL after the reader skipped data (ClickHouse#125929); - data lakes: their `format` is only the write format, and Iceberg pruning still has open defects a join-side filter would reach (ClickHouse#128578, ClickHouse#119576, ClickHouse#122602). `use_primary_key` now only stops the copy onto a MergeTree read (read from that read's context) instead of disabling the whole pass. Release build, 30M-row Int64 Parquet files of 29 row groups, MergeTree source, 10-20 paired alternating runs, median change [95% CI]: point lookup -80.5%, narrow range -81.7%, IN of 6 keys -94.2%, unsorted with bloom filters -55.5%; costs of a copy that skips nothing (`k % 1000 = 0 AND k >= 1000`): hash join +3.2% [+0.3, +6.8] at 1 thread, +2.2% at 4, +1.1% at default threads; full_sorting_merge +7.8% [+6.5, +11.4] at 1 thread, +2.1% at 4; non-selective IN of 1000 keys -3.7%. Related: ClickHouse#129119 Related: ClickHouse#128374 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #128302
Related: #128336
Related: #121033
Related: #128494
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the native Parquet reader skipping matching rows when a
UInt64column with inverted statistics (min_value > max_value, as polars 0.20 writes them for values >= 2^63) is read asDateTimeand filtered. Such statistics are now detected in the column's stored order and ignored.Description
On 26.10.2.103,
SELECT count() FROM file('f.parquet', Parquet, 'u Nullable(DateTime)') WHERE u > toDateTime(100)over the #128302 reproducer (polars 0.20.31,pl.Series([1, 2**63], dtype=pl.UInt64), statisticsmin_value2^63,max_value1) returns 0. Withinput_format_parquet_filter_push_down = 0, input_format_parquet_page_filter_push_down = 0it returns 1: the read saturates 2^63 to theDateTimemaximum.#128336 ignores statistics whose decoded range is inverted. Since #121033, a
DateTimebound aboveUINT32_MAXdecodes to no bound, so this pair decodes to[-inf, 1]. That range is not inverted, and row group and page pruning use it to skip the row. 26.9 and older reject the query withINCORRECT_DATAinstead.IntConverter::statsInvertedcompares the two stored values in the column's sort order.getHyperrectangleForRowGroupandapplyColumnIndexignore statistics that are inverted there, before the type-dependent decode. The TopN andoptimize_min_max_from_filespaths already give up on a bound that does not decode.This re-lands c61dbb6, which was pushed to #128336 after it was enqueued and so did not merge with it. The test now also checks that the valid row group and page are still pruned.
Validation:
05479_parquet_inverted_statistics_ignoredgets twoDateTimearms (row group and page pruning). On master both rows are missing; with the fix it passes, 50/50 with random settings. The real polars file behaves the same forDateTime,Nullable(DateTime),LowCardinality(Nullable(DateTime))and timezone-qualified hints; other hints and valid statistics prune as before. The other Parquet stateless tests give the same results with and without the fix.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128508]