Repository navigation
Decode Parquet columns densely after a scattered PREWHERE when the file has a page index or NULLs - #128139
Decode Parquet columns densely after a scattered PREWHERE when the file has a page index or NULLs#128139groeneai wants to merge 7 commits into
Conversation
When a column chunk has an offset index or needs a null map, the filter is not applied inside the page decoders, and `decodePrimitiveColumn` seeks and decodes once per run of passing rows. With a PREWHERE that keeps 10-90% of scattered rows that is thousands of tiny decodes per row subgroup. Count the runs with one pass over the mask. When seeking to each run costs more than decoding the failing rows between them, decode the pages that hold passing rows as whole ranges and remove the failing rows with `IColumn::filter`; for nullable columns the mask is mapped to the non-null values. Pages without passing rows are still skipped, so a range never covers a page whose prefetch was reset or which the offset index does not list. Arrays, strings, values wider than 16 bytes and sparse masks keep the current path. The filtered values column is reserved for exactly the passing non-null values, and the page scan starts at the first page that can overlap the subgroup. The patch is from @ snelheidai in ClickHouse#123483. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dense path decodes and filters every row from the first to the last passing one, so compare the cost of seeking to each run with that, not only with decoding the failing rows. With 99% of rows passing, the old rule chose the dense path and was about 9% slower than reading run by run. Masks whose runs and gaps together average more than 16 rows keep the current path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alue The dense path converts every decoded row, also the rows an earlier PREWHERE step removed, and the run loop never converts those. A value that the read type cannot hold, such as a DATE before 1970 read as Date or an INT96 timestamp after 2262, made a query fail although its row is filtered out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A geometry column read as Point decodes to a 16-byte tuple, so the dense path took it and converted the rows an earlier PREWHERE step removed too. Converting a geometry of another kind throws, so a mixed column read as Point failed although only points pass the filter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the design notes on the dense Parquet decode path to one line each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261029-103200 |
|
cc @scanhex12 @grantholly-clickhouse, could you review this and add the |
|
Workflow [PR], commit [3d7080d] Summary: ✅
AI Review
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units19 translation units recompiled, 228 s compile time in total, 19 of them have a recent master baseline. |
CI finish ledger - e3d8ff7Every 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:20261029-160007 |
…nse-decode-page-index # Conflicts: # src/Processors/Formats/Impl/Parquet/Decoding.h
Master now enforces clang-tidy `modernize-use-nodiscard` (ClickHouse#126158), so the `canRejectValues` overrides get `[[nodiscard]]` like the neighbouring `isTrivial` overrides, and bans plain `std::vector` in `src/Processors/Formats` (ClickHouse#126530), so the decode ranges use `VectorWithMemoryTracking`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #123483
Related: #123618
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reading Parquet files with a
PREWHEREthat keeps a scattered part of the rows is up to 3x faster when the column chunks have a page index (written by default by ClickHouse, Spark and parquet-mr) or can contain NULLs.Description
Patch by @ snelheidai in #123483, cost rule re-tuned.
Root cause. #123618 applies the mask in the page decoders only to chunks without an offset index or null map. Others take the run loop of
Reader::decodePrimitiveColumn: a seek and decode per run of passing rows, thousands per row subgroup when 10-90% of scattered rows pass.Change. When runs of passing rows plus gaps average at most 16 rows (
runs * 16 >= last - first), rows from the first to the last passing row are decoded, except pages without passing rows (an unfetched page is never read), then filtered once withIColumn::filter; a null map maps the mask to non-null values. Arrays, strings, values wider than 16 bytes, types whose conversion can reject a value (DATE,INT96, wide decimals, geometries) and sparser or denser masks keep the current path, so a row filtered out is never converted.Performance (Xeon 6975P-C, Release, 4 threads, geomean of 12 paired ratios, 95% CI):
At 5% or 99% pass: current path, +0.3-0.5% instructions. Results are identical; peak memory within 6 MiB at default settings.
Tests.
05457_parquet_prewhere_page_index_nullablecomparesPREWHEREreads of files with and without a page index (NULLs, all-NULL pages, small pages) with the source table, incl. a value the read type cannot hold in filtered-out rows only; seven mutations of the new code fail it.parquet_prewhere_plain_columns.xmlgains four page-index queries.Workflow [PR]
Sync PR [sync-upstream/pr/128139]