Skip to content

Read a 64 KiB Parquet footer tail for local files - #124883

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:parquet-local-footer-tail-64k
Oct 11, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:parquet-local-footer-tail-64k

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124673
Related: #115686

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Opening a local Parquet file reads a 64 KiB tail for its footer again instead of 1% of the file, so short queries over many local Parquet files are faster.

Description

Since #115686, the Parquet reader with input_format_parquet_footer_read_size = 0 (the default) reads clamp(file_size / 100, 128 KiB, 2 MiB) bytes from the end of every file. That saves a second round trip on object storage. For a local file a second read is cheap, so the larger tail only adds bytes to every open. SELECT count() over ClickBench's 100 hits_N.parquet files (footers 23-57 KB) reads 140.7 MB of tails to parse 3.7 MB of footers.

Prefetcher now records ReadBufferFromFileBase::isRegularLocalFile of the buffer it reads, and readFileMetaData uses 64 KiB (the size before #115686) for a regular local file and the adaptive size otherwise. The decision uses the buffer, not the factory's is_remote_fs, because Hive over HDFS and Context::getInputFormat leave that flag at false. S3, Azure, HDFS and HTTP buffers and the cache wrappers keep isRegularLocalFile() = false, so their reads do not change, and neither does an explicit non-zero setting.

Category: #115686 is in no release yet (26.9 still reads 64 KiB), so nothing changes between releases.

Validation, Release build, clickhouse local, 4 threads, paired runs, fix/base with 95% CI, identical results:

  • Tail bytes for count() over the 100 files: 140,741,630 -> 6,553,600. A url() read requests the same adaptive tail on both builds.
  • Cached: q1 0.64 [0.60, 0.68], count() with all row groups pruned 0.63 [0.60, 0.66], q41 0.82 [0.67, 0.99]. Controls q3, q21, q24 unchanged or faster.
  • Not cached (NVMe RAID): q1 0.72 [0.64, 0.80], q41 0.76 [0.62, 0.92].

05025_parquet_footer_read_size now checks that the default reads 65536 bytes from a local file (131072 before).

The footer prefetch proposed in #124673 is not included.

🤖 Generated with Claude Code


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

Version info

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

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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-issue PR origin: picked up an external GitHub issue labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings) plus my own review (4 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ Wrappers around a local file (blob-log, page cache, reader executor, async prefetch) hide isRegularLocalFile, so those reads keep the adaptive tail DISAGREE Default IcebergLocal/DeltaLakeLocal reads get the plain local buffer and read 64 KiB; the wrappers need non-default settings, where the size equals master's. Forwarding the flag would let DWARF/SQLite bypass decryption and cache layers.
2 💡 The 26.10 SettingsChangesHistory reason still says 0 keeps the adaptive behavior AGREE, noted Text only, same unreleased entry.
3 💡 The test checks the local arm only AGREE, noted The remote arm is master's code; a url() read requests the same adaptive range on both builds.
4 💡 File(Parquet, fd)/stdin keep the adaptive tail; NFS/FUSE mounts count as local AGREE, noted fd buffers do not override isRegularLocalFile, so an fd/stdin read requests the same tail as on master (one file per query); mounts read 64 KiB, as before #115686.
5 💡 No tests/performance XML DISAGREE ParquetMetadataCache makes repeated StorageFile reads read 0 footer bytes; 05025 asserts the bytes.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261009-102500

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dd9a6b1]

Summary: ✅


AI Review

Summary

This PR changes the Parquet v3 footer-read default so path-based local files use a 64 KiB tail instead of the adaptive 1% tail, updates the setting/history text, and adds a stateless regression test. The main path looks reasonable, but the new locality check still misses regular local inputs that arrive through fd-backed buffers, so the promised local-file fast path is not applied consistently.

Findings

⚠️ Majors

  • [src/Processors/Formats/Impl/Parquet/Prefetcher.cpp:83] The new 64 KiB default is gated on ReadBufferFromFileBase::isRegularLocalFile(), which means “safe to reopen or mmap by path”, not simply “cheap second read from a regular local file”. Regular fd-backed local inputs (ReadBufferFromFileDescriptorPRead, MMapReadBufferFromFileDescriptor) never report true, so those Parquet reads still take the old adaptive clamp(file_size / 100, 128 KiB, 2 MiB) path even though they are seekable regular files. Suggested fix: plumb a separate “cheap local second read” capability (or regular-local-fd bit) instead of reusing isRegularLocalFile() here, and cover that entrypoint with a focused regression test.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: make the local-file fast path cover regular fd-backed local buffers too, or narrow the contract to path-backed local files only and add a regression test that locks down the intended boundary.

The setting description 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, as on master. The 26.10 settings history
reason no longer says that 0 keeps the adaptive behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-parquet-reader-v3 Issues related to the native Parquet reader. label Oct 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing dd9a6b169 with master a61252e3c (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4915e63c4; 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

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

Median compile-time ratio to the baselines is ×1.13 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +22.4 s (+10%) in total before that adjustment.

Job report

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6fbb4e7

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05316_secret_arguments_declared_by_engines test regression from merged #123364, not from this PR: under DatabaseReplicated the CREATE DICTIONARY row is counted twice in system.query_log (0 2 instead of 0 1, the password stays hidden). 22/22 reruns pass; 82 PRs show it in this lane since 2026-10-09 09:47Z #124928 (external, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05233_string_filters_fixed_string_constant flaky, not from this PR: the last query_log ProfileEvents check reads 0 instead of 1; under parallel replicas the scan events can land only in a remote replica's row, which the current_database = currentDatabase() filter drops. 145/145 reruns pass; 14 PRs in this lane #124911 (mine, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore flaky, not from this PR: Code: 60 Unknown table expression identifier '_materialized_cte_c_...' for a MATERIALIZED CTE read twice inside an IN subquery, sent to the replicas before the initiator's local plan wrote it (#112642). 140/140 reruns pass; 17 PRs in this lane #123121 (mine, open)
Mergeable Check, PR praktika rollups of the three rows above #124928 (external, open), #124911 (mine, open), #123121 (mine, open)

The changed test 05025_parquet_footer_read_size passed 50/50 in all five flaky checks.

Session id: cron:our-pr-ci-monitor:20261009-163012

@grantholly-clickhouse grantholly-clickhouse self-assigned this Oct 9, 2026
@grantholly-clickhouse

Copy link
Copy Markdown
Contributor

This makes a lot of sense for local reads. I'm taking a look now

if (auto * file_buf = dynamic_cast<ReadBufferFromFileBase *>(seekable))
{
size_t view_offset = 0;
is_local_file = file_buf->isRegularLocalFile(&view_offset);

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 seems like the key part of the PR. Now we take the ReadBuffer reader_, make it seekable with auto * seekable = dynamic_cast<SeekableReadBuffer *>(reader_); https://github.com/ClickHouse/ClickHouse/pull/124883/changes#diff-ff4e4f13a4e700303b228ac78bb907e5150adc20d96a533b499a20c6e6cb0edaR63 , and then we callisRegularLocalFile through ReadBufferFromFileBase which makes sense.

If we are using object storage, isRegularLocalFile should return false because the buffer isn't a file-based buffer, the cast returns nullptr, the block is skipped, and is_local_file stays at its default of false

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review. One detail on the object-storage path: there the cast usually succeeds, because s3() and the object-storage engines read through ReadPipeline::build(), which returns a ReadBufferFromFileBase (ReadBufferFromS3, AsynchronousBoundedReadBuffer, CachedOnDiskReadBufferFromFile all derive from it). is_local_file stays false because the base ReadBufferFromFileBase::isRegularLocalFile returns false and only the local-file buffers (ReadBufferFromFile, AsynchronousReadBufferFromFile, the mmap ones) override it. The cast returns nullptr only for buffers outside that hierarchy, such as url()'s ReadWriteBufferFromHTTP.

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.

Thanks for the clarification. That makes sense to me.

@grantholly-clickhouse

Copy link
Copy Markdown
Contributor

@groeneai

Copy link
Copy Markdown
Collaborator Author

I looked into it. 05233_constraint_graph_negated_ordered_comparison is flaky and not related to this PR. The job's diagnosis pins it on the randomized optimize_trivial_count_query=0: the count() then reads a session temporary MergeTree table through parallel replicas, which do not have that table and log There is no table _temporary_and_external_tables._tmp_... to stderr (stdout matches the reference). It is already fixed on master by #124934, which merged after this PR's CI was built (the failing run was a re-run of that old build). #124987 fixes the underlying parallel replicas behavior.

The other failures on this commit are covered too: 05233_string_filters_fixed_string_constant by #124911 and 05316_secret_arguments_declared_by_engines by #124928 (both merged), and 05210_lightweight_update_materialized_cte_in_ignore by #112642 (fix in #123121). So I did not open new issues. I merged master (dd9a6b1) so CI re-runs with these fixes.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - dd9a6b1

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) / 05239_written_rows_quota_interval_rollover flaky, not from this PR (the diff is the Parquet footer read only): in the AsyncInsert lane an insert is accounted to the quota when its async batch is flushed, so the second insert lands in the next interval and the 1 1 line is missing. 6/6 reruns pass; 19 PRs show it in this lane in 7 days #124935 (mine, open)
Mergeable Check, PR praktika rollups of the row above #124935 (mine, open)

The four NOT_FAILED rows in the AsyncInsert job are tests listed in tests/async_insert_blacklist.txt that passed (stale entries, same rows on 300+ PRs), not failures.

Session id: cron:our-pr-ci-monitor:20261010-063008

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 11, 2026
Merged via the queue into ClickHouse:master with commit 4104287 Oct 11, 2026
322 of 323 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 11, 2026
ianton-ru added a commit to Altinity/ClickHouse that referenced this pull request Nov 23, 2026
…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
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. groeneai-origin-issue PR origin: picked up an external GitHub issue pr-not-for-changelog This PR should not be mentioned in the changelog 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.

4 participants