Skip to content

Initialize parquet reader a bit earlier - #128607

Merged
scanhex12 merged 3 commits into
masterfrom
parquet-prefetch-footer-in-reader-creation
Nov 2, 2026
Merged

scanhex12 merged 3 commits into
masterfrom
parquet-prefetch-footer-in-reader-creation

Conversation

@scanhex12

@scanhex12 scanhex12 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Initialize parquet reader a bit earlier


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

Version info

  • Merged into: 26.11.1.1146-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6804acf]

Summary: ✅


AI Review

Summary

The PR prefetches the next object-storage file's Parquet footer while processing the current file, deferring column decoding until consumption. At head 6804acfea9c1edfe7c9662370900d231dc8d40bb, two previously reported issues remain: concurrent whole-file buffering can exceed query memory limits, and prefetched footer errors lose the offending filename. ❌ Block pending fixes. No additional inline code findings were identified; the existing threads remain open.

PR Metadata

Improvement is acceptable and requires a changelog entry. The current entry, “Initialize parquet reader a bit earlier”, does not explain the affected operation or benefit. Suggested replacement:

Overlap Parquet footer reads with processing of the current file when querying multiple files in object storage.

Findings

❌ Blockers

  • ParquetV3BlockInputFormat.cpp:216: Footer prefetch is not bounded to metadata reads. Prefetcher::init copies the entire input into entire_file when input_format_allow_seeks = 0 or the buffer cannot seek, including externally compressed files. With one source reading two large files, the active reader and reader_future can retain both complete files simultaneously, before the metadata-cache lookup even on a cache hit. This introduces memory-limit failures for queries that previously fit. Check eligibility for bounded range reads before initialization and keep other inputs lazy.

⚠️ Majors

  • StorageObjectStorageSource.cpp:1932: Calling prefetch outside IInputFormat::generate bypasses its filename annotation. A valid 0.parquet followed by a corrupt 1.parquet now reports the footer's wrong-magic exception without identifying the bad object, making failures in multi-file reads difficult to repair. Annotate and rethrow prefetch exceptions with the input filename.
Tests
  • ⚠️ Add a two-file read with max_threads = 1, input_format_allow_seeks = 0, and a memory limit permitting one buffered file but not two; verify that prefetch preserves that bound.
  • ⚠️ Extend the malformed-file assertion to require the offending filename. Checking only INCORRECT_DATA misses the diagnostic regression.
  • ⚠️ The output and cache-hit assertions also pass without footer prefetch. A focused before/after multi-file measurement would establish the intended reduction in footer waits.
Final Verdict

❌ Block. Keep whole-file inputs lazy, preserve filenames on prefetch exceptions, and add focused regression coverage. Both code findings already have open inline threads; no duplicate comments were posted.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 2, 2026
…f a source

Address the review of the previous commit:

- `ObjectStorageQueueSource` also calls `StorageObjectStorageSource::createReader`,
  before it registers the file. Initializing the format there moved a footer error
  out of its per-file error handling. Now `createReader` initializes the format in
  advance only when asked, and only `createReaderAsync` of `StorageObjectStorageSource`
  asks, so the queue and the first file of a source stay lazy.
- Initializing the reader in advance also started reading and decoding the column
  chunks, so a source had two readers, each entitled to the whole memory allowance
  of a stream. Now `prefetch` only reads the footer (`readFileFooterIfNeeded`), and
  the reader is initialized on the first `read`.

#128607

Co-Authored-By: Claude Opus 5.5 <[email protected]>
});

auto new_reader = std::make_unique<Parquet::ReadManager>();
new_reader->reader.prefetcher.init(in, read_options, parser_shared_resources);

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.

[P1] Keep whole-file buffering out of footer prefetch

readFileFooterIfNeeded is not limited to metadata I/O: Prefetcher::init calls determineReadModeAndFileSize, which copies the entire input into entire_file when input_format_allow_seeks = 0 or the input cannot seek (including externally compressed .parquet.gz files). This happens before the metadata-cache lookup, even on a cache hit.

StorageObjectStorageSource starts this work for reader_future while its current reader is still alive. A single source reading two large files can therefore retain both complete files simultaneously, in addition to the current decoder's memory. Previously only the active file was buffered this way, so queries that fit max_memory_usage can now fail; the Parquet decoding watermarks do not bound entire_file.

Please keep these inputs lazy by checking that footer initialization can use bounded range reads before calling Prefetcher::init. Cover a two-file read with max_threads = 1, input_format_allow_seeks = 0, and a memory limit that permits one buffered file but not two.

input_format->needOnlyCount();

if (prefetch_input_format)
input_format->prefetch();

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.

[P2] Preserve the offending filename on prefetched footer errors

Previously footer parsing ran through IInputFormat::generate, whose exception handler adds (in file/uri ...). This call runs outside that handler, and the background scheduler passes the exception unchanged to reader_future.get.

For example, with a valid 0.parquet followed by a corrupt 1.parquet, the footer now raises Not a Parquet file (wrong magic bytes at the end of file) without identifying the bad object. A glob containing many files consequently gives users no filename to repair or exclude. The new malformed-file test only checks INCORRECT_DATA, so it misses this regression.

Please annotate and rethrow prefetch exceptions with the input filename, as IInputFormat::generate does, and extend the malformed-file assertion to require that filename.

@clickhouse-gh clickhouse-gh Bot added the comp-parquet-reader-v3 Issues related to the native Parquet reader. label Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6804acfea with master 0f8ede73b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

161 translation units recompiled, 1324 s compile time in total, 161 of them have a recent master baseline.

Job report

…icas

With parallel replicas `s3` is rewritten to `s3Cluster`, and the Parquet
metadata cache hits are counted by secondary queries, which run in the
`default` database. Sum `ParquetMetadataCacheHits` over `initial_query_id`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128607&sha=ecd7c592358da0b17407b87655b03e625da673d9&name_0=PR
PR: #128607

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scanhex12
scanhex12 added this pull request to the merge queue Nov 2, 2026
@scanhex12 scanhex12 self-assigned this Nov 2, 2026
Merged via the queue into master with commit a13fd81 Nov 2, 2026
179 checks passed
@scanhex12
scanhex12 deleted the parquet-prefetch-footer-in-reader-creation branch November 2, 2026 22:08
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 2, 2026
@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 3, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 3, 2026
PedroTadim added a commit that referenced this pull request Nov 4, 2026
Cherry pick #128607 to 26.10: Initialize parquet reader a bit earlier
PedroTadim added a commit that referenced this pull request Nov 4, 2026
Cherry pick #128607 to 26.9: Initialize parquet reader a bit earlier
PedroTadim added a commit that referenced this pull request Nov 4, 2026
Cherry pick #128607 to 26.8: Initialize parquet reader a bit earlier
PedroTadim added a commit that referenced this pull request Nov 4, 2026
Cherry pick #128607 to 26.3: Initialize parquet reader a bit earlier
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 4, 2026
Backport #128607 to 26.8: Initialize parquet reader a bit earlier
clickhouse-gh Bot added a commit that referenced this pull request Nov 4, 2026
Backport #128607 to 26.10: Initialize parquet reader a bit earlier
PedroTadim added a commit that referenced this pull request Nov 5, 2026
Backport #128607 to 26.9: Initialize parquet reader a bit earlier
PedroTadim added a commit that referenced this pull request Nov 5, 2026
Backport #128607 to 26.3: Initialize parquet reader a bit earlier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parquet-reader-v3 Issues related to the native Parquet reader. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

3 participants