Repository navigation
Parquet: size the initial footer read to 1% of the file within [128 KiB...2 MiB] - #115686
grantholly-clickhouse merged 20 commits into
Conversation
…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]>
|
Workflow [PR], commit [b6e4119] Summary: ✅
AI ReviewSummaryThis PR makes the Findings
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit b6e4119.
Changed lines: Changed C/C++ lines covered: 47/48 (97.92%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: 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
|
Updated comment to clarify the purpose of the initial read size calculation.
Benchmark is already included as part of PR description.
|
…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]>
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]>
…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]>
|
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. So, current plan is to have some meaningful min...max value:
Between those set numbers have some "ladder", (1% is relatively arbitrary). |
grantholly-clickhouse
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
This is the heart of the changes. Looks like the rest of the PR is wiring this change into all the call sites
`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_); |
There was a problem hiding this comment.
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.
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]>
|
@UnamedRus for resolving the SettingsChangesHistory conflict, do we want to move this new setting to 26.10? |
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…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]>
…-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]>
6d87edd
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]>
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
More optimistic
Parquetfooter-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
26.10.1.1035-master(included in26.10and later)