Skip to content

Parquet: size the initial footer read to 1% of the file within [128 KiB...2 MiB] - #115686

Merged
grantholly-clickhouse merged 20 commits into
ClickHouse:masterfrom
UnamedRus:parquet-footer-read-size
Sep 30, 2026
Merged

grantholly-clickhouse merged 20 commits into
ClickHouse:masterfrom
UnamedRus:parquet-footer-read-size

Conversation

@UnamedRus

@UnamedRus UnamedRus commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

64 KIB cap is not enough for wide parquet files (hundreds of columns).
S3 have high TTFB penalty, between 30-40ms and in some cases up to 100ms. (if bad backend)
But, there is very small latency difference, if you read between 128KiB and 2MiB slice of object.
So, it's better if we be more optimistic with estimating footer size.

Table 1 — Footer (metadata_size) distribution, (301-col, 58 files, ~68 MiB each)

┌───────────────────────────────────┬─────────┬──────────┐
│              metric               │  bytes  │    ≈     │
├───────────────────────────────────┼─────────┼──────────┤
│ min                               │  42,989 │ 42 KiB   │
├───────────────────────────────────┼─────────┼──────────┤
│ avg                               │  78,928 │ 77 KiB   │
├───────────────────────────────────┼─────────┼──────────┤
│ p50 / p95 / max                   │  81,590 │ 79.7 KiB │
├───────────────────────────────────┼─────────┼──────────┤
│ files > 64 KiB (old floor missed) │ 54 / 58 │ 93%      │
├───────────────────────────────────┼─────────┼──────────┤
│ files > 128 KiB (new floor)       │  0 / 58 │ 0%       │
├───────────────────────────────────┼─────────┼──────────┤
│ files > 2 MiB (cap)               │  0 / 58 │ 0%       │
└───────────────────────────────────┴─────────┴──────────┘

Table 2 — Tail Range GET, WARM (440 reqs, 58 files ×7.6 hits, same-region us-east-1)

┌────────────────┬──────────┬──────────┬───────────┬──────────┬───────────┐
│      tail      │ TTFB p50 │ TTFB p95 │ total p50 │ xfer p50 │ speed p50 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│         64 KiB │       45 │      121 │        47 │        2 │   1 MiB/s │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│ 81590 (footer) │       41 │      133 │        44 │        2 │         1 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│         100003 │       41 │      125 │        44 │        2 │         2 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│        128 KiB │       49 │      160 │        52 │        3 │         2 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│        256 KiB │       42 │      140 │        45 │        4 │         5 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│         300007 │       43 │      118 │        48 │        4 │         5 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│        512 KiB │       42 │      153 │        48 │        5 │         9 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│         700001 │       41 │      150 │        47 │        7 │        12 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│          1 MiB │       41 │      139 │        47 │        6 │        18 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│        1500001 │       41 │      131 │        50 │        9 │        24 │
├────────────────┼──────────┼──────────┼───────────┼──────────┼───────────┤
│          2 MiB │       43 │      136 │        55 │       11 │        31 │
└────────────────┴──────────┴──────────┴───────────┴──────────┴───────────┘

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

More optimistic Parquet footer-size estimate instead of fixed 64 KiB, fetching the footer in one read instead of two and reducing footer-read latency.


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

Version info

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

…2 MiB)

The reader always read a fixed 64 KiB tail to get FileMetaData; files whose
metadata (or metadata + Column/Offset index) exceed that pay a second read. On
wide-schema tables that is the common case: on a 301-column Iceberg table
(~68 MiB files) the FileMetaData is 42-82 KiB, so 93% of files exceeded the
64 KiB tail and did a second metadata read.

Size the initial tail to 1% of the file, clamped to [128 KiB, 2 MiB], so the
first read usually covers the whole footer - including the Column/Offset index
just before FileMetaData - in one read. The 128 KiB floor covers the observed
footers even for small files; the 2 MiB cap avoids over-reading a large tail.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: UnamedRus <[email protected]>
@thevar1able thevar1able added the can be tested Allows running workflows for external contributors label Aug 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b6e4119]

Summary: ✅


AI Review

Summary

This PR makes the Parquet v3 reader size its initial footer read adaptively and adds input_format_parquet_footer_read_size to override it, wiring that through the main reader, schema reader, count path, and bucket splitter. The compatibility plumbing looks consistent, but two regressions remain: the new 128 KiB floor turns small files into full-file metadata reads, and the splitter path still ignores input_format_allow_seeks = 0.

Findings

⚠️ Majors

  • [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/115686#discussion_r3826311487] [src/Processors/Formats/Impl/Parquet/Reader.cpp:239] The original dead-overread concern is still real in a sharper form: std::clamp(file_size / 100, 128 KiB, 2 MiB) makes every file up to 128 KiB read the whole object just to parse FileMetaData, and those bytes are discarded immediately afterwards. The test_storage_delta change in this PR already has to pin input_format_parquet_footer_read_size = 64 * 1024 because the default otherwise destroys the column-pruning byte-count signal, so the default now regresses small-file reads, need_only_count, and schema inference. Suggested fix: keep the old 64 KiB floor (or otherwise avoid a whole-file tail read until those extra bytes are actually reused by later footer/index consumers).
  • [src/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp:28,305] convertReadOptions still never copies format_settings.seekable_read, so the bucket-splitter code added here builds Prefetcher with ReadOptions::seekable_read = true even when input_format_allow_seeks = 0. That regresses cluster_table_function_split_granularity = 'bucket': on seekable Parquet sources it can still issue tail range reads during splitting despite the explicit no-seeks contract. Suggested fix: set options.seekable_read = format_settings.seekable_read inside convertReadOptions before any Prefetcher::init call.
Tests
  • ⚠️ The new stateless test only proves result equivalence for several explicit input_format_parquet_footer_read_size values, and the Delta integration test now pins the old 64 KiB behavior. There is still no regression coverage for the default 0 on sub-128 KiB files, which is exactly the case that over-reads the whole object.
Final Verdict

⚠️ Request changes before merge: the default footer heuristic still regresses small-file workloads, and the new bucket-splitter path still bypasses the input_format_allow_seeks = 0 contract.

LLVM Coverage Report

Measured on commit b6e4119.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 47/48 (97.92%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit b6e41192716aad9cfb775320a7385f32fc491477 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 6cb5a1d9-1305-4cbe-b694-3eab46a593de
  • MIRAI run: 533219ec-1707-46c2-abd8-bf05b85c0966
  • PR check IDs:
    • clickbench_2023975_1790476804
    • clickbench_2023981_1790476804
    • clickbench_2023987_1790476804
    • tpch_adapted_1_official_2023998_1790476804
    • tpch_adapted_1_official_2024009_1790476804
    • tpch_adapted_1_official_2024046_1790476804

Updated comment to clarify the purpose of the initial read size calculation.
@UnamedRus

Copy link
Copy Markdown
Contributor Author

⚠️ The PR description measures one wide-schema S3 workload, but there is no focused before/after measurement for the opposite side of the rollout: large files whose FileMetaData already fit in 64 KiB. If the file-size-based heuristic stays, a small benchmark on that shape is needed to prove it does not regress latency or bytes read.

Benchmark is already included as part of PR description.
Still few points:

  1. It target AWS S3, (other cloulds probably have similar ~ behavior, but still worth mentioning)
  2. It probably doesn't make sense to target via test using minio/whatever in CI
  3. Local "production" s3 distribution, might have different behavior.

UnamedRus and others added 4 commits August 24, 2026 14:01
…aptive footer read

The initial footer read is sized adaptively (1% of the file, clamped to
`[128 KiB, 2 MiB]`) so it usually covers the whole `FileMetaData` in one read.
This adds `input_format_parquet_footer_read_size` to override that: `0` (default)
keeps the adaptive "ladder", a non-zero value forces a fixed initial read size.
Useful for very high-latency object storage where reading a larger tail up front
avoids a second round trip. The value is clamped to the file size and floored at
the 8-byte trailer so a tiny explicit value can't underflow the offsets.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
readFileMetaData is a static member function and cannot access the Reader's
`options`, so the footer read size is passed in as an argument from each caller
instead. Fixes the build error introduced by reading `options` inside it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ry block

Master opened the 26.9 version block; the new setting must be recorded there
rather than in 26.8, as the style check requires.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
The setting is new in 26.9; its SettingsChangesHistory row records the pre-26.9
behavior as the fixed 64 KiB footer read (65536). Add an assertion that
SET compatibility = '26.8' restores getSetting to 65536, so a future wrong
history row can't silently leak the new adaptive default (0) through the
compatibility path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Core/FormatFactorySettings.h Resolved
UnamedRus and others added 3 commits August 26, 2026 15:17
…litter

`ParquetBucketSplitter::splitToBuckets` - the initiator-side metadata read
used by `cluster_table_function_split_granularity = 'bucket'` - called
`parquet::ReadMetaData`, which has no properties parameter and therefore
always used arrow's fixed `kDefaultFooterReadSize` of 64 KiB. The setting
never reached that path, so on object storage a footer larger than 64 KiB
(wide schemas, many row groups) still cost a second round trip there.

Extract the footer sizing into `parquetFooterReadSize` in `ReadCommon.h`
(shared with `Reader::readFileMetaData`, so the two cannot drift) and open
the file through `parquet::ParquetFileReader::Open` with a
`parquet::ReaderProperties` whose `footer_read_size` is set from it.
`ReadMetaData` is exactly `Open(source)->metadata()`, so behavior is
otherwise unchanged; arrow clamps the size to the file size internally.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ParquetBucketSplitter::splitToBuckets` - the initiator-side metadata read
behind `cluster_table_function_split_granularity = 'bucket'` - was the last
place in `ParquetV3BlockInputFormat` still going through arrow. It wrapped the
buffer in `asArrowFile` and called `parquet::ReadMetaData`, which takes no
properties and so always used arrow's fixed 64 KiB `kDefaultFooterReadSize`:
`input_format_parquet_footer_read_size` never reached this path, and a footer
wider than 64 KiB cost an extra round trip on object storage.

Use `Parquet::Prefetcher` plus `Reader::readFileMetaData` instead, exactly as
`NativeParquetSchemaReader` and the `need_only_count` path already do. The
footer sizing (adaptive by default, overridable by the setting) now comes from
the one implementation in `readFileMetaData`, so the two paths cannot drift,
and row-group sizes are read straight from the thrift `FileMetaData` without
building arrow's wrapper objects. This also drops the last uses of
`ArrowBufferedStreams.h` and `parquet/file_reader.h` from this file.

This supersedes the `parquet::ReaderProperties` workaround from the previous
commit, whose `parquetFooterReadSize` helper is reverted as unneeded.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@grantholly-clickhouse

Copy link
Copy Markdown
Contributor

This seems like a pretty cool optimization. Did you generate a bunch of wide parquet files for testing? I am curious how you calculated the avg sizes.

@grantholly-clickhouse grantholly-clickhouse self-assigned this Aug 29, 2026
@UnamedRus

Copy link
Copy Markdown
Contributor Author

This seems like a pretty cool optimization. Did you generate a bunch of wide parquet files for testing? I am curious how you calculated the avg sizes.

Well, initially it was idea to estimate it from number of rows/object size/ number/types of column using iceberg metadata.
But, it was more complicated to pass values around.
If we look at latency of global S3 (AWS, may be some others clouds), for small requests (under 2-4MiB), majority of time is taken by TTFB.

So, current plan is to have some meaningful min...max value:

  1. 128 KiB is almost indistinguishable from 64 KiB both by size and latencies)
  2. 2 MiB is still within boundaries when added latency for fetching bytes relatively small

Between those set numbers have some "ladder", (1% is relatively arbitrary).
Also, allow to return old behavior via setting: input_format_parquet_footer_read_size.

@grantholly-clickhouse grantholly-clickhouse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. This seems like an exciting improvement

/// footer - FileMetaData for wider range of layouts - in one read. A non-zero
/// `footer_read_size` overrides this adaptive size with a fixed read size.
if (footer_read_size == 0)
footer_read_size = std::clamp<size_t>(file_size / 100, 128ul << 10, 2ul << 20);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the heart of the changes. Looks like the rest of the PR is wiring this change into all the call sites

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is

@clickhouse-gh clickhouse-gh Bot added the comp-parquet-reader-v3 Issues related to the native Parquet reader. label Sep 4, 2026
`test_storage_delta/test.py::test_column_pruning` asserts the exact number
of bytes read from S3 for a query that touches one column. With the adaptive
footer read size the initial tail read is at least 128 KiB, which is larger
than the ~90 KiB Parquet file the test writes, so the whole file is read and
the assertion fails (`assert 132273 <= 107232`).

Pin `input_format_parquet_footer_read_size` to the previous fixed 64 KiB in
both queries: the byte counts then measure column pruning again, instead of
the size of the footer heuristic's initial read.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115686&sha=437d9962d8b8b416b3b4e53c5e8b88181135ec28&name_0=PR
PR: ClickHouse#115686

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
std::atomic<int> is_stopped = false;
auto arrow_file = asArrowFile(buf, format_settings_, is_stopped, "Parquet", PARQUET_MAGIC_BYTES, /* avoid_buffering */ true, nullptr);
auto metadata = parquet::ReadMetaData(arrow_file);
Parquet::ReadOptions read_options = convertReadOptions(format_settings_);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

splitToBuckets used to go through asArrowFile(..., format_settings_, ...), which respected input_format_allow_seeks = 0 by refusing the random-access wrappers when format_settings_.seekable_read was false. This new Prefetcher path builds a fresh ReadOptions through convertReadOptions, but that helper never copies format_settings.seekable_read, so ReadOptions::seekable_read stays at its default true here. The result is a user-visible regression: cluster_table_function_split_granularity = 'bucket' on seekable Parquet sources will still issue a tail range read during bucket splitting even when seeks are explicitly disabled. Please propagate seekable_read into ReadOptions (ideally in convertReadOptions) before calling prefetcher.init.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should be addressed as part of #115681

UnamedRus added a commit to UnamedRus/ClickHouse that referenced this pull request Sep 4, 2026
The gate added here keys the from-start read-ahead off the format alone:
`Parquet` reads its footer at the tail, so the read-ahead is dropped. That
premise only holds while the reader is allowed to seek. With
`input_format_allow_seeks = 0` the reader is supposed to read the object
sequentially from the start, which is exactly what the read-ahead serves, so
gating it off there is a pessimization.

The setting never reached the v3 reader either: `Parquet::ReadOptions::seekable_read`
is read by `Prefetcher` but `convertReadOptions` never assigned it, so the v3
reader seeked regardless of `input_format_allow_seeks`. Wire the flag through and
`AND` the prefetch hint with it, so one notion of "this reader seeks" drives both
the read-ahead gate and the reader itself.

This also makes `input_format_allow_seeks` effective on the bucket-splitter path
that reads the footer through `Prefetcher`, raised in review of
ClickHouse#115686 (comment)

Extend `05024_parquet_s3_no_footer_prefetch` with the seeks-disabled case: the
same big object must still get the from-start prefetch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@grantholly-clickhouse

Copy link
Copy Markdown
Contributor

@UnamedRus for resolving the SettingsChangesHistory conflict, do we want to move this new setting to 26.10?

UnamedRus and others added 3 commits September 23, 2026 14:28
…ory block

Master has opened the `26.10` block, so an entry still sitting under `26.9`
would make `compatibility` below 26.9 restore a default that the setting never
had in a released version.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The remote branch had moved on (a `master` merge and the Delta column-pruning
test pin) while this bump was prepared locally. Keep both; the settings-history
entry stays in the `26.10` block, where the bump moved it, rather than in the
`26.9` block the remote side still had it in.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
UnamedRus and others added 2 commits September 23, 2026 16:15
…-size

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@grantholly-clickhouse
grantholly-clickhouse added this pull request to the merge queue Sep 30, 2026
Merged via the queue into ClickHouse:master with commit 6d87edd Sep 30, 2026
340 of 341 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 30, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 11, 2026
Since ClickHouse#115686 the v3 reader reads clamp(file_size / 100, 128 KiB, 2 MiB)
bytes from the end of every file when input_format_parquet_footer_read_size
is 0. That saves a round trip on object storage, but for a local file a
second read is cheap and the larger tail only costs bytes on every open.

Resolve the default from the buffer being read: Prefetcher records
ReadBufferFromFileBase::isRegularLocalFile, and readFileMetaData uses 64 KiB
(the size before ClickHouse#115686) for a regular local file and the adaptive size
otherwise. S3, Azure, HDFS and HTTP buffers and the cache wrappers do not
override isRegularLocalFile, so their reads are unchanged, as is an explicit
non-zero setting. The factory's is_remote_fs flag is not used: Hive over HDFS
and Context::getInputFormat leave it at its false default.

SELECT count() over ClickBench's 100 hits_N.parquet files now reads 6.55 MB of
footer tails instead of 140.7 MB. clickhouse-local, 4 threads: warm q1 0.64x,
cold q1 0.72x.

Analysis by @ snelheidai in ClickHouse#124673.

Related: ClickHouse#124673

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. pr-performance Pull request with some performance improvements 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.

5 participants