Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
65385ee
Parquet v3: materialize constant column chunks from statistics
UnamedRus Aug 5, 2026
349e1ee
Parquet v3: fix constant-column detection gates (never fired)
UnamedRus Aug 6, 2026
d0d384b
Parquet v3: materialize all-null column chunks from statistics
UnamedRus Aug 6, 2026
48cb87d
Parquet v3: materialize constant column chunks as ColumnConst
UnamedRus Aug 7, 2026
3c79bb3
Parquet v3: per-subgroup (page-level) constant-column detection [tier 2]
UnamedRus Aug 7, 2026
1c770fa
Parquet v3: skip prefetch of constant subgroup pages [tier 2 phase 3]
UnamedRus Aug 7, 2026
1f32c8f
Parquet v3: optional force-load of column index for constant detection
UnamedRus Aug 7, 2026
856e23f
Parquet v3: mixed-topology constant-page fill [experimental, default …
UnamedRus Aug 7, 2026
bfd6f7a
Parquet v3: skip prefetch of filled constant pages (mixed topology)
UnamedRus Aug 7, 2026
c173818
Parquet v3: allow string constants (drop min==max truncation guard)
UnamedRus Aug 7, 2026
25b664a
Parquet v3: handle all-null pages in mixed-topology fill (lift gate 1)
UnamedRus Aug 7, 2026
8537304
Parquet v3: allow page-pruned columns in mixed fill (lift gate 3)
UnamedRus Aug 7, 2026
b9c0a89
Parquet v3: filter-aware mixed fill under prewhere (lift gate 4)
UnamedRus Aug 7, 2026
634300e
Parquet v3: cast the materialized constant (future-proof needs_cast)
UnamedRus Aug 7, 2026
5ba632f
Parquet v3: fix tier-2 constant detection for non-nullable columns
UnamedRus Aug 7, 2026
26e75a1
Parquet v3: record constant-column settings in the settings history
ianton-ru Nov 30, 2026
6281ea1
Parquet v3: give the constant-column tests free numbers
ianton-ru Nov 30, 2026
e706314
Parquet v3: remove the old names of the constant-column tests
ianton-ru Nov 30, 2026
d35eca0
Parquet v3: decode constant candidates without a cast only
ianton-ru Nov 30, 2026
816b6c2
Parquet v3: skip constant-column optimization when checksums are veri…
ianton-ru Nov 30, 2026
d618973
Parquet v3: do not materialize float columns as constants from min ==…
ianton-ru Nov 30, 2026
9ef6e3f
Parquet v3: don't trust an all-null Column Index page when the footer…
ianton-ru Nov 30, 2026
c7d9f93
Parquet v3: name the right setting when a force-loaded Column Index i…
ianton-ru Dec 1, 2026
b502638
Parquet v3: find the pages of a subgroup by binary search in constant…
ianton-ru Dec 1, 2026
28ff5f6
Parquet v3: add tests for tier-2 constant subchunks and the mixed fill
ianton-ru Dec 1, 2026
b171508
Parquet v3: fix stale comments and the design doc for the constant-co…
ianton-ru Dec 1, 2026
2b32cc0
Parquet v3: stop the page scan in constant detection after the subgroup
ianton-ru Dec 1, 2026
b42f57f
Parquet v3: document that the constant-column Column Index setting ne…
ianton-ru Dec 1, 2026
d59d687
Parquet v3: simplify the constant-column fixes
ianton-ru Dec 1, 2026
6005f3c
Parquet v3: expand an all-null constant column before applying null_a…
ianton-ru Dec 1, 2026
c47986f
Parquet v3: keep NULLs of a Nullable constant column with input_forma…
ianton-ru Dec 1, 2026
7220b4b
Parquet v3: do not count constant columns in the decoded-block memory…
ianton-ru Dec 1, 2026
b4b8276
Parquet v3: count constant columns when they are served, not when det…
ianton-ru Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions docs/design/parquet-v3-page-level-constant-column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
description: 'Design of the per-subgroup (page-level) constant-column optimization in the Parquet v3 reader.'
sidebarTitle: 'Parquet v3 page-level constants'
slug: /design/parquet-v3-page-level-constant-column
title: 'Parquet v3: page-level constant-column detection'
doc_type: 'reference'
---

# Parquet v3: per-subgroup (page-level) constant-column detection {#parquet-v3-per-subgroup-page-level-constant-column-detection}

## Motivation {#motivation}

The current constant-column optimization (`detectConstantColumn`) fires only when a whole
Parquet **column chunk** is single-valued (footer `min == max`, no nulls). Data that is sorted or
clustered on a column is often constant over long **runs of pages** without the whole row group
being constant, so chunk-level detection misses it.

Parquet's **Column Index** stores per-page `min_values` / `max_values` / `null_pages` /
`null_counts`. The v3 reader already loads and parses it (`applyColumnIndex`) for predicate
push-down, so per-page "is this page constant?" is available at zero extra I/O. This lets us mark a
column constant for the row range of an individual **row subgroup** (the unit that becomes one
output `Chunk`) and materialize it as a `ColumnConst`, skipping the covered pages' reads and decode.

## Tiers (both kept) {#tiers-both-kept}

| Tier | Source | Always present? | Exact flag? | Granularity |
|------|--------|-----------------|-------------|-------------|
| 1 (existing) | footer `ColumnMetaData.statistics` | yes | yes (`is_min_value_exact`) | whole chunk |
| 2 (this doc) | Column Index (per page) | no (optional) | no (not needed, see Guardrails) | per subgroup |

Tier 1 stays the always-on baseline. Tier 2 is opportunistic: only when the Column Index is already
loaded (or force-loaded, see below), only for chunks tier 1 did not already mark constant. Both tiers
cover `BYTE_ARRAY` / `FIXED_LEN_BYTE_ARRAY` strings, but neither applies `min == max` to floating-point
types (see Guardrails).

## Key decision: do NOT change subgroup sizing {#key-decision-do-not-change-subgroup-sizing}

Aligning subgroups to page boundaries would fragment the block stream into many tiny chunks
(pages are far smaller than a row group), and a subgroup carries all columns so its size is bounded
by the non-constant columns anyway. Instead, keep subgroup boundaries exactly as today and do
**per-subgroup, per-column** detection: a column is constant for a subgroup iff every Column-Index
page overlapping the subgroup's row range is constant with the *same* value (or every such page is
`null_pages`). Chunk count is unchanged; we just catch subgroups that sit inside a constant run.

## Phases {#phases}

- **Phase 0** — retain per-page constant info. `applyColumnIndex` currently discards the parsed
`parq::ColumnIndex`. Keep a compact per-page summary on `ColumnChunk` (value + `is_const` +
`all_null`), plus the page→`first_row_index` map already in the Offset Index. Populate only for
eligible types.
- **Phase 1** — `detectConstantSubchunk(column, column_info, [start_row, end_row))`: scan the pages
overlapping the range; return constant + value when all are `is_const` and share one value;
all-null when all are `null_pages`.
- **Phase 2** — call it in `intersectColumnIndexResultsAndInitSubgroups` for each subgroup /
primitive column that tier 1 didn't already mark constant; set `subchunk.is_constant` /
`is_all_null` / `constant_value` (the same fields `decodePrimitiveColumn` propagates).
`formOutputColumn` needs no change (already emits `ColumnConst`).
- **Phase 3** — skip work for constant subchunks: `decodePrimitiveColumn` skips decode on
`subchunk.is_constant`; `determinePagesToPrefetch` skips fetching a page only when it is constant
in **every** subgroup that overlaps it.
- **Phase 4** — stateless tests (page-run constant, all-null-per-page, string truncation guard,
`GROUP BY` correctness), with a new `ParquetConstantColumnSubchunks` ProfileEvent to prove tier 2
fired.
- **Phase 5** — ProfileEvents comparison on clustered data: expect further `S3GetObject` /
`ParquetFetchWaitTimeMicroseconds` drops with chunk count unchanged.

## Optional force-load {#optional-force-load}

By default tier 2 only uses the Column Index when it is already loaded (columns with a predicate
push-down). `input_format_parquet_use_column_index_for_constant_columns` (default off) extends it:
the Column Index (+ Offset Index) is force-loaded for eligible read columns that have no predicate,
so tier 2 can also fire on them. Cost is a small extra read of the (tiny, tail-contiguous, coalesced)
index; worthwhile mainly for sorted / low-cardinality columns. `applyColumnIndex` records per-page
constant info but skips predicate pruning when the column has no condition. A future `auto` mode
could gate this on footer signals (row-group `sorting_columns`, low compressed-bytes-per-value,
dictionary encoding stats) instead of an all-or-nothing switch.

The force-load is an explicit opt-in, so it does not honor `input_format_parquet_use_offset_index` or
`input_format_parquet_page_filter_push_down`: the Offset Index and Column Index are read for eligible
columns even when those are disabled. A malformed Column Index then fails the query even for a column
with no predicate; the error message names both `input_format_parquet_page_filter_push_down` and
`input_format_parquet_use_column_index_for_constant_columns` as the settings to turn off.

## Cast safety (future-proofing) {#cast-safety-future-proofing}

The optimization only fires when the stats decoder needs no value-transforming conversion
(`SchemaConverter` sets `allow_stats` accordingly), so today `input_type == output_type` for every
constant column and no cast is applied. To keep the constant path correct if `allow_stats` is ever
generalized to allow transforming casts, `formOutputColumn` builds the single-value constant in
`input_type` and runs the same `castColumn` the per-row decode uses when `needs_cast` is set - a
no-op today, O(1) on the `ColumnConst`, and it preserves const-ness. The all-null constant is
synthesized directly in the output domain (Null / output default), so it is not cast. The mixed fill
already goes through the normal `formOutputColumn` cast, so it is future-safe too. This does not
touch the `allow_stats` decision itself.

## Guardrails {#guardrails}

- All types with a total order, including `BYTE_ARRAY` / `FIXED_LEN_BYTE_ARRAY` strings. No
truncation guard is needed for the `min == max` case: statistics/Column-Index bounds are always
valid (`min <= every value <= max`) and truncation only widens them, so `min == max` proves a
single exact value (a truncated or multi-valued page yields `min < max`). This holds at both the
chunk level (tier 1) and per page (tier 2), so neither needs the `is_*_value_exact` flag.
- Not applied to `Float32` / `Float64` by `min == max`: floating-point has no total order. NaN is
excluded from the statistics (a chunk of `[1.0, NaN]` has `min == max == 1.0`), and `+0.0` and
`-0.0` compare equal (a page of `+0.0` values has `min = -0.0`, `max = +0.0` per the Parquet
spec, but would materialize as `-0.0`). Float columns are decoded normally unless the chunk or
page is all-null, which does not depend on `min` / `max`.
- Gate on the existing `input_format_parquet_use_constant_column_optimization` setting; the
force-load above is additionally gated by
`input_format_parquet_use_column_index_for_constant_columns`.
- Not applied when `input_format_parquet_verify_checksums` is enabled (its default). A constant
chunk or subchunk is materialized without reading its data pages, so their page checksums would
never be verified. With verification requested, such chunks are decoded normally, and the
optimization applies only when verification is turned off.
- Partial-page subgroup boundaries are fine: a partial overlap of a constant page still yields that
value, as long as every overlapping page is constant with the shared value.

## Mixed-topology fill (Approach B) — implemented, default off {#mixed-topology-fill-approach-b-implemented-default-off}

`input_format_parquet_fill_constant_pages` handles constant runs *shorter* than / straddling a
subgroup: `fillConstantPagesAndDecodeRest` fills single-value pages from the Column Index and decodes
only the varying ones, and `determinePagesToPrefetch` skips prefetching the filled pages (a page
shared with a subgroup that decodes it normally is still fetched — `willFillConstantPages` is
deterministic so both paths agree). The fill walks the rows that pass the filter (`row_subgroup.filter`), so it works under PREWHERE /
row-level filters and page-pruning predicates too - it produces exactly `rows_pass` values for any
filter, and because the decision no longer depends on `rows_pass` it is identical at prefetch time
and decode time (so the prefetch-skip can never drop a page the decode needs). All-null pages are
filled (nulls via the compact values + null map + `expand` path, or the output default under
`null_as_default`); a subgroup with an all-null page falls back only when the output can represent
neither null nor a default. The one remaining gate is `needs_cast`: the fill writes the Column Index
value into the `decoded_type` column, valid only when no post-decode cast applies. An all-null page is
filled only when the footer statistics allow nulls (a null map exists); a Column Index that contradicts
the footer (`null_count = 0` but an all-null page) is not trusted, and the page goes through the normal
decode path, which reports the inconsistency. Experimental, off by default.
2 changes: 2 additions & 0 deletions src/Common/ProfileEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,8 @@ The server successfully detected this situation and will download merged part fr
M(ParquetPrunedRowGroups, "The total number of row groups pruned from parquet data", ValueType::Number) \
M(ParquetReadPages, "The total number of Parquet data pages read", ValueType::Number) \
M(ParquetPrunedPages, "The total number of pages pruned from parquet data via column index", ValueType::Number) \
M(ParquetConstantColumnChunks, "The total number of parquet column chunks materialized from a single value in their min/max statistics, without reading their data pages", ValueType::Number) \
M(ParquetConstantColumnSubchunks, "The total number of parquet column subchunks (per row subgroup) materialized from a single value in their per-page column-index statistics, without decoding their data pages", ValueType::Number) \
M(ParquetDecodingTasks, "Tasks issued by parquet reader", ValueType::Number) \
M(ParquetDecodingTaskBatches, "Task groups sent to a thread pool by parquet reader", ValueType::Number) \
M(ParquetPrefetcherReadRandomRead, "The total number of reads with ReadMode::RandomRead by DB::Parquet::Prefetcher", ValueType::Number) \
Expand Down
9 changes: 9 additions & 0 deletions src/Core/FormatFactorySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ When reading GeoParquet files, skip whole row groups and, together with `input_f
)", 0) \
DECLARE(Bool, input_format_parquet_use_offset_index, true, R"(
Minor tweak to how pages are read from parquet file when no page filtering is used.
)", 0) \
DECLARE(Bool, input_format_parquet_use_constant_column_optimization, true, R"(
When a Parquet column chunk provably holds a single value in every row (according to its min/max statistics), materialize that value directly instead of reading and decoding the column's data pages. Not applied when `input_format_parquet_verify_checksums` is enabled, because the data pages of such chunks are not read and their checksums would not be verified.
)", 0) \
DECLARE(Bool, input_format_parquet_use_column_index_for_constant_columns, false, R"(
Load the Parquet Column Index for read columns that have no predicate of their own, so the constant-column optimization can also skip data pages that are single-valued over a row subgroup (not just over a whole column chunk). Costs a small extra read of the (tiny) Column Index; only worthwhile when columns are sorted or low-cardinality. The Column Index and the Offset Index are read for these columns even if `input_format_parquet_use_offset_index` or `input_format_parquet_page_filter_push_down` is disabled, and a malformed Column Index then fails the query; disable this setting to ignore it. Applies only when `input_format_parquet_use_constant_column_optimization` is enabled and `input_format_parquet_verify_checksums` is disabled.
)", 0) \
DECLARE(Bool, input_format_parquet_fill_constant_pages, false, R"(
Experimental. When a Parquet column is single-valued over some data pages but not the whole row subgroup, fill those pages' rows from the per-page Column Index statistics instead of reading and decoding them (mixed-topology subgroups). Extends the constant-column optimization below the subgroup granularity. Requires `input_format_parquet_use_constant_column_optimization`; disabled by default.
)", 0) \
DECLARE(Bool, input_format_parquet_verify_checksums, true, R"(
Verify page checksums when reading parquet files.
Expand Down
3 changes: 3 additions & 0 deletions src/Core/SettingsChangesHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
{
{"export_merge_tree_part_check_destination_schema_staleness_ms", 0, 5000, "New setting: how stale the latest Iceberg destination metadata version may be when each part export task checks that the destination schema and partition spec did not change since the export was scheduled."},
{"export_merge_tree_part_allow_lossy_cast", false, false, "The setting is obsolete. `EXPORT PART` and `EXPORT PARTITION` cast values the way `INSERT ... SELECT` does."},
{"input_format_parquet_use_constant_column_optimization", false, true, "New setting: when a Parquet column chunk provably holds a single value in every row (per its min/max statistics), materialize that value directly instead of reading and decoding the column's data pages."},
{"input_format_parquet_use_column_index_for_constant_columns", false, false, "New setting: load the Parquet Column Index for read columns without a predicate so the constant-column optimization can also skip data pages that are single-valued over a row subgroup."},
{"input_format_parquet_fill_constant_pages", false, false, "New experimental setting: when a Parquet column is single-valued over some data pages of a row subgroup, fill those pages from the Column Index statistics instead of reading and decoding them."},
});
addSettingsChanges(settings_changes_history, "26.8.35.20001.altinityantalya",
{
Expand Down
3 changes: 3 additions & 0 deletions src/Formats/FormatFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ FormatSettings getFormatSettings(const ContextPtr & context, const Settings & se
format_settings.parquet.page_filter_push_down = settings[Setting::input_format_parquet_page_filter_push_down];
format_settings.parquet.spatial_filter_push_down = settings[Setting::input_format_parquet_spatial_filter_push_down];
format_settings.parquet.use_offset_index = settings[Setting::input_format_parquet_use_offset_index];
format_settings.parquet.use_constant_column_optimization = settings[Setting::input_format_parquet_use_constant_column_optimization];
format_settings.parquet.use_column_index_for_constant_columns = settings[Setting::input_format_parquet_use_column_index_for_constant_columns];
format_settings.parquet.fill_constant_pages = settings[Setting::input_format_parquet_fill_constant_pages];

format_settings.parquet.enable_json_parsing = settings[Setting::input_format_parquet_enable_json_parsing];
format_settings.parquet.memory_low_watermark = settings[Setting::input_format_parquet_memory_low_watermark];
Expand Down
3 changes: 3 additions & 0 deletions src/Formats/FormatSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ struct FormatSettings
size_t footer_read_size = 0;
bool page_filter_push_down = true;
bool use_offset_index = true;
bool use_constant_column_optimization = true;
bool use_column_index_for_constant_columns = false;
bool fill_constant_pages = false;

bool enable_json_parsing = true;
bool preserve_order = false;
Expand Down
9 changes: 7 additions & 2 deletions src/Processors/Formats/Impl/Parquet/ReadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ void ReadManager::scheduleTask(Task task, bool is_first_in_group, MemoryUsageDif
/// Queue this subgroup's data-page reads; startPrefetch (below) issues them and charges
/// compressed bytes to the ColumnDataPrefetch budget, separate from the decode budget,
/// so many row groups prefetch ahead while only a few decode at once.
reader.determinePagesToPrefetch(column, row_subgroup, row_group, prefetches);
reader.determinePagesToPrefetch(column, row_subgroup.columns.at(task.column_idx), reader.primitive_columns.at(task.column_idx), row_subgroup, row_group, prefetches);

/// Side note: would be nice to avoid reading the dictionary if all dictionary-encoded
/// pages were filtered out (e.g. if it's a 100 MB column chunk with unique long strings,
Expand All @@ -798,7 +798,12 @@ void ReadManager::scheduleTask(Task task, bool is_first_in_group, MemoryUsageDif
break;
/// Reads already issued in ColumnDataPrefetch; here just reserve estimated decoded-output
/// memory against the ColumnData budget (runTask decodes from those buffers).
double bytes_per_row = reader.estimateColumnMemoryBytesPerRow(column, row_group, reader.primitive_columns.at(task.column_idx));
/// A constant subchunk (tier 2; tier 1 is accounted for by the estimate itself) is a single
/// value and allocates nothing per row.
const auto & column_info = reader.primitive_columns.at(task.column_idx);
const bool single_value_subchunk = subchunk.is_constant
&& Reader::constantIsSingleValueColumn(subchunk.is_all_null, column_info);
double bytes_per_row = single_value_subchunk ? 0. : reader.estimateColumnMemoryBytesPerRow(column, row_group, column_info);
size_t column_memory = static_cast<size_t>(bytes_per_row * static_cast<double>(row_subgroup.filter.rows_pass));
subchunk.column_and_offsets_memory = MemoryUsageToken(column_memory, &diff);
break;
Expand Down
Loading
Loading