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>
…e file
`ReadManager::init` reads the footer again when the `FileMetaData` that it was given has an empty `schema`. With the tail retained by the first read, the second call of `retainTail` violated its "at most once" precondition: `chassert(retained_tail_end == retained_tail_start)` aborted debug and sanitizer builds, instead of the regular `INCORRECT_DATA` ("Parquet file has no columns") that `SchemaConverter` throws.
`retainTail` now keeps the first retained chunk and ignores a repeated call: the bytes at the same offsets of the same file are the same.
Found by the audit of #2950
Related: #2950
Co-authored-by: Cursor <cursoragent@cursor.com>
…that use it `Reader::readFileMetaData` copied the part of the footer read that precedes the footer into `Prefetcher::retained_tail` on every call, while the whole read buffer was still alive: the peak memory was the buffer plus the copy, up to the size of the initial read (2 MiB by default, up to 16 MiB with the footer-size hint, up to the file size with a large explicit `input_format_parquet_footer_read_size`). The copy was also made for callers that never register ranges in the prefetcher and so never use it: `NativeParquetSchemaReader`, the count-only read of `ParquetV3BlockInputFormat` and `ParquetBucketSplitter`. - `readFileMetaData` takes an explicit `retain_tail` argument. Only `ReadManager::init` and the reader path of `ParquetV3BlockInputFormat` (through `getFileMetadata`) pass `true`. - The footer buffer is now a `PaddedPODArray<char>`, and `Prefetcher::retainTail` takes it by rvalue reference. It cuts off everything after the retained part with `shrink_to_fit` and moves the buffer in, so the bytes are not copied and the raw footer is not kept. The retained chunk is still padded, as the data of a task is. Found by the audit of #2950 Related: #2950 Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 29099698fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (retain_tail && buf_offset > 0) | ||
| prefetcher.retainTail(std::move(buf), buf_offset, file_size - initial_read_size); |
There was a problem hiding this comment.
Cap the tail retained after an explicit footer read
When input_format_parquet_footer_read_size is explicitly large, buf_offset is nearly that entire value, so this move retains it for the reader's full lifetime rather than releasing the temporary footer buffer after parsing. For example, a 1 GiB setting on a large file keeps roughly 1 GiB per active reader while column data is also decoded, even though the advertised 2/16 MiB bounds apply only to the adaptive/hinted paths; concurrent readers can therefore exhaust query memory. Retain only a bounded suffix needed for indexes, independently of the initial footer-read size.
Useful? React with 👍 / 👎.
`Reader::readFileMetaData` retained the whole part of the initial read that precedes the footer. The initial read is the explicit `input_format_parquet_footer_read_size` when it is set, so a large setting kept that many bytes for the lifetime of the reader, not only during the footer read. The bounds of 2 MiB by default and 16 MiB with the footer-size hint did not apply to an explicit setting. Only the last `Prefetcher::max_retained_tail_size` (2 MiB) bytes before the footer are retained now. The Column Index and the Offset Index are just below the footer, so these are the bytes that matter. Ranges that lie before the retained part are read from the file, as they were before the retained tail was introduced. The part is moved to the start of the buffer before it is handed to the prefetcher, so the buffer shrinks to it. The new test `05819_parquet_retained_tail_cap` reads a file of about 8 MiB with a footer read of 16 MiB, so the retained part starts in the middle of the file, and checks the results. Found by the audit of #2950, the comment of Codex on #2950 (`Reader.cpp`, the retained tail after an explicit footer read) Related: #2950 Co-authored-by: Cursor <cursoragent@cursor.com>
The PR head `feature/antalya-26.8/parquet-footer-hint-and-tail` contains the Parquet commits and a merge of `antalya-26.8`. Merge it here, so that the branch can be pushed as a fast-forward of that head. Related: #2950
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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: