Repository navigation
Conversation
The adaptive footer read (`clamp(file_size / 100, 128 KiB, 2 MiB)`, backported from 115686) 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. `Prefetcher` now records `ReadBufferFromFileBase::isRegularLocalFile`, and `Reader::readFileMetaData` reads 64 KiB when `input_format_parquet_footer_read_size` is 0 and the file is a regular local file. Other sources and an explicit non-zero setting are unchanged. Cherry-picked from 5a58f22; the setting description and the test follow the 26.8 layout (`05385_parquet_footer_read_size`). ClickHouse#124883 Related: ClickHouse#124673 Related: #2181
…m master. The setting description of `input_format_parquet_footer_read_size` now says the 64 KiB tail applies when the file is read directly from the local filesystem (the reader's buffer reports `isRegularLocalFile`). Reads through a file descriptor or a wrapping buffer keep the adaptive size. The `SettingsChangesHistory` reason no longer says that `0` keeps the adaptive behavior. Cherry-picked from 6fbb4e7; on 26.8 the history reason is in `SettingsChangesHistory.cpp`, so it is changed there. ClickHouse#124883 Related: #2181
…ter tail Two changes that make the footer and the page indexes of a Parquet file cost fewer reads on object storage. 1. Footer-size hint. The v3 reader reads a tail of the file to parse the footer (`FileMetaData`) and needs one more read when the footer is larger than the tail. On `antalya-26.8` the tail is 64 KiB for a local file and `clamp(file_size / 100, 128 KiB, 2 MiB)` otherwise, so the footer of a wide file or of a file with many row groups does not fit. An Iceberg manifest entry knows the number of columns, the file size, the record count and the min/max bounds of each column, which is enough to estimate the footer size. `IcebergDataObjectInfo` computes `estimateParquetFooterSize` for a Parquet data file and puts it in the new `RelativePathWithMetadata::footer_size_hint`. `ParquetV3BlockInputFormat` passes it to `ReadOptions::footer_size_hint`, and `Reader::readFileMetaData` takes the larger of its default tail and the hint when `input_format_parquet_footer_read_size` is 0. An explicit non-zero setting still wins. The hint can only widen the first read, so a wrong estimate costs the second read that happens today, or some extra bytes. It reaches the reader with the object's metadata, that is when `use_parquet_metadata_cache` is on and the ETag can be a cache key, and it is not serialized for `*Cluster` functions. 2. Retained tail. The Column Index and the Offset Index are just below the footer, so they are inside the tail that `readFileMetaData` reads. That read went to a local buffer, and the ranges registered later for the indexes were read again, which is another `GET` on object storage. `Prefetcher::retainTail` keeps the part of the tail that precedes the footer, and `pickRangesAndCreateTaskIfNotExists` attaches a range that lies fully inside it to a task that is already `Done` and refers to the retained bytes, with the existing zero-copy `cached_region`. Nothing is retained when the whole file is in memory, or when the footer did not fit into the first read. The tail is written once before the ranges are finalized and is read-only afterwards, so it needs no locking. A file smaller than the tail is read as one chunk and all of its ranges are served from memory, so `03723_parquet_prefetcher_read_big_at` now counts one `ParquetPrefetcherReadRandomRead` instead of two. New profile events: `ParquetFooterSecondRead` (the footer did not fit into the first read) and `ParquetPrefetcherServedFromRetainedTail` (ranges served from the retained tail). Tests: `05814_parquet_retained_footer_tail` checks the retained tail with and without a footer that fits. The integration test `test_parquet_footer_size_hint` writes an Iceberg table of 3000 columns with ClickHouse, whose footer is 378 KB, and checks that the default read needs no second read and that a read without the hint needs one, for local and S3 storage. Related: #2181 Co-authored-by: Cursor <cursoragent@cursor.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the split of #2181: the Parquet "footer-size hint, plus reuse of that tail" feature.
This is a draft that goes on top of #2949 (the backport of ClickHouse#124883), so the first two commits of this branch are the ones of that pull request. The files changed by this pull request alone are in the last commit. Merge #2949 first; this pull request then shrinks to one commit and can be marked ready.
The v3 reader reads a tail of the file to parse the footer, and the Column Index and Offset Index ranges are read again later, although they are in that tail. On object storage each of these is a separate
GET.estimateParquetFooterSizeestimates the footer. The estimate goes throughRelativePathWithMetadata::footer_size_hintandReadOptions::footer_size_hinttoReader::readFileMetaData, which reads the larger of its default tail and the hint wheninput_format_parquet_footer_read_sizeis 0. A wrong estimate costs the second read that is needed today, or some extra bytes.Prefetcher::retainTailkeeps the part of the tail that precedes the footer, and a range that lies fully inside it is served from memory with the existing zero-copycached_region, without a read.New profile events:
ParquetFooterSecondReadandParquetPrefetcherServedFromRetainedTail.Differences from the original commits of #2181, because
antalya-26.8already reads a footer tail sized to the file: the hint can only widen that tail (it does not replace it), and the retained part is the one before the footer, which is the part that holds the indexes. The estimator uses 96 bytes per column chunk instead of 64, because the footer of a file written by ClickHouse is about 126 bytes per column (378 KB for 3000Int32columns), twice as much as one written by Spark; the row group count is taken from the file size too (128 MiB by default in Iceberg).Limits:
use_parquet_metadata_cacheis on and the ETag can be a cache key. Otherwise the default tail is read, as before.*Clusterfunctions, so a worker does not have it. The retained tail works on the worker.Tests, run on a local aarch64 build in Praktika (PR CI has not run yet): the new
05814_parquet_retained_footer_tailand integration testtest_parquet_footer_size_hint(S3 and local) pass; all 205 stateless tests withparquetand 118 withicebergin the name pass, except02841_parquet_filter_pushdownthat failed once in the parallel run on a shared file name and passed alone, and03723_parquet_prefetcher_read_big_at, whose reference changed from 2 to 1 read because a file smaller than the tail is now read in one chunk.Related: #2181
Related: #2949
Related: ClickHouse#124883
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Reading Parquet data files of an Iceberg table fetches the footer in one request when its size can be estimated from the manifest, and serves the Column Index and the Offset Index from the footer tail that was already read.
Documentation entry for user-facing changes
Not needed.
CI/CD Options
Exclude tests:
Regression jobs to run: