Repository navigation
Conversation
… exclude the filter On a warm server the footers of local Parquet files are in the Parquet metadata cache, but a filtered read of a glob still opened every file, built a reader and converted the min/max statistics of every row group, only to find that no row group can match. The decision depends only on the file version, the column, its type and a few format settings, so it is now kept: after a read of a settled file version (the query condition cache's write gate), the format keeps the converted statistics ranges of the key condition columns with the file's cache cell, per column key. Later reads of the same version, also with other constants, look the ranges up before opening the file and skip it when no row group can satisfy the key condition, which is exactly a file the reader would have pruned completely by the same statistics. - `ParquetKeptStatistics`: one shared sub-object of the cache cell (mutex, ranges per column key, byte count), counted in the cell weight and capped at a quarter of the footer size (at least 4 KiB). The re-weight is atomic (`CacheBase::replaceIfMatches`), so a dropped or evicted cell is never re-inserted. - `ParquetCachedStatisticsFilter`: built once per source; refuses filter push-down off, a column mapper, an undecidable key condition and headers the format factory would change. The token is re-checked right before a skip. - A skipped file counts `ParquetPrunedRowGroups` and `ParquetMetadataCacheHits` like the reader would, plus the new `ParquetFilesSkippedByCachedStatistics`. - `use_parquet_metadata_cache = 0` disables both the recording and the skip. Object storage is not changed here. Based on the analysis and patch by @ snelheidai in ClickHouse#125423. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten API docs to one-line invariants and drop comments that narrate the new code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck), plus my own cold review (4 nits, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261012-221300 |
|
Workflow [PR], commit [9b0d293] Summary: ✅
AI ReviewSummaryPR #125528 retains converted Final VerdictStatus: ✅ Approve. No new inline findings. |
`updateWeight` re-set the file's cell right after the read that kept the statistics. With the default SLRU policy, both the `get` and the `set` of `replaceIfMatches` move a probationary cell to the protected segment, so one filtered query promoted every file it read for the first time, which master leaves probationary until a second access. A one-off filtered query over many files then demoted and evicted the entries that are actually reused. Now the kept bytes are counted at the next hit of the cell (`getOrSetMetadataCell` or the skip check), which moves the cell anyway; until then they are not counted. Measured with a 4-entry SLRU cache: two hot files read twice, then two one-off filtered queries over four cold files, then the hot files read again. Master and this commit: both hot files hit. Before this commit: both miss. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📊 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
|
The previous commit counted kept statistics in the cache weight only at the next hit of the cell, so a file read once by a filtered query held them uncounted for as long as it stayed in the cache. Now a read keeps statistics only in a cell it found in the cache, and counts them at once with `updateWeight`. Re-setting the cell moves it like the hit already did, so a cell that a read inserts is not moved after the insertion, and one-off filtered scans still leave cold files probationary under SLRU. The skip starts from the third read of a file version instead of the second. The reader collects the ranges only when it can keep them: for a cached cell it hit, and only if the caller asked with `FormatFilterInfo::keep_filter_column_statistics`, which only `StorageFile` sets. Object storage, archive, file descriptor and metadata-cache-off reads no longer copy them. `AggregateFunctionStatesFromValuesInputFormat` now forwards `cacheFilterColumnStatistics`, so reads through it keep the ranges they collect. Measured (debug build, `clickhouse local`): the cache weight includes the kept statistics right after the read that keeps them (2848 bytes after the first read, 3263 after the second, which keeps 415 bytes). With a 4-entry SLRU cache, two hot files read twice, then one-off filtered reads of four cold files: both hot files still hit, as on master. The test checks the weight with `clickhouse-local`; it fails without the `updateWeight` call and on both previous versions of this change, and without the forwarding in the wrapper. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test started three client processes per checked query (the query, SYSTEM FLUSH LOGS and the query_log lookup), about 90 in total, plus two clickhouse-local runs. Under ASan that took 60 s for a single run, and the flaky check of `amd_asan_ubsan` stopped it at the 180 s limit. Queries now run in one client call per state of the files, tagged with a log_comment, and their profile events are read with one flush at the end; the two clickhouse-local runs are merged. The assertions are unchanged; only the row-group line of the reference changes its format. Measured with 16 parallel runs: ASan 60.7 s -> 10.2 s, debug 12.1 s -> 2.5 s. 50 parallel random-settings runs and 8 DatabaseReplicated runs pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes62 object files changed (+178.77 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units
|
| Translation unit | Master | PR | Δ vs median |
|---|---|---|---|
src/Storages/StorageFile.cpp |
13.8 s | 19.5 s | +5.4 s (+38%) |
Translation units without a recent master baseline:
src/Formats/FormatFactory.cpp: 47.9 ssrc/Server/GRPCServer.cpp: 10.2 ssrc/Interpreters/AsynchronousInsertQueue.cpp: 9.8 ssrc/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockInputFormat.cpp: 9.8 sprograms/keeper-bench/LogRunner.cpp: 9.4 sprograms/keeper/Keeper.cpp (clickhouse-keeper): 7.8 ssrc/Storages/StorageXDBC.cpp: 7.6 ssrc/Storages/ObjectStorage/Web/Configuration.cpp: 7.6 ssrc/Processors/Formats/Impl/DWARFBlockInputFormat.cpp: 7.3 ssrc/Storages/YTsaurus/StorageYTsaurus.cpp: 7.2 ssrc/Databases/DatabaseURL.cpp: 7.1 ssrc/Databases/DataLake/HiveCatalog.cpp: 7.0 ssrc/TableFunctions/TableFunctionFile.cpp: 7.0 ssrc/Storages/prepareReadingFromFormat.cpp: 6.9 ssrc/TableFunctions/ITableFunctionXDBC.cpp: 6.8 ssrc/Dictionaries/YTsaurusDictionarySource.cpp: 6.5 ssrc/Processors/Formats/Impl/FreeformRowInputFormat.cpp: 6.5 sprograms/obfuscator/Obfuscator.cpp: 6.5 ssrc/Functions/UserDefined/UserDefinedWebAssembly.cpp: 6.4 ssrc/Processors/Formats/Impl/PuffinBlockInputFormat.cpp: 6.3 s- ... and 24 more
`kept_statistics->add` changed a resident cell before `updateWeight` took the cache lock to recompute its weight, so an insertion or eviction in between saw the cell with its old weight. `CacheBase::updateIfMatches` runs the change and the weight recomputation under one lock acquisition; it replaces the `replaceIfMatches` added earlier in this PR. The ranges are copied and their bytes counted by `ParquetKeptStatistics::prepare` before the cache lock is taken, so the lock only covers the map insertion. `prepare` also returns nothing for a column already kept or over the cap, and then the cache lock is not taken at all. 05390 now also checks that a read of a file whose version token has not settled keeps nothing, even though its metadata is cached: the two unsettled reads in the client part were followed by a new token, so they could not tell. Without the settled check before `cacheFilterColumnStatistics` the new line fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 9ce9ca0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261013-113003 |
|
how do we make sure the statistics we read are not stale? |
|
The kept ranges are part of the file's entry in the Parquet metadata cache, and that entry is keyed by the path and the file's version token ( On top of that, ranges are kept and used only after the token has settled (mtime at least 3 s in the past, the same gate the query condition cache uses for files), because only then does every later write have to change the mtime. The read that keeps them re-checks the token after reading, and the skip re-checks it right before skipping, so a rewrite during either one is caught. The one case it can't detect is a rewrite that keeps the inode, the size and the mtime, but master's footer cache and the query condition cache trust the same token there too. |
|
performance review doesn't show any improvements. Possible reason is:
I don't like the idea of adding a sleep() call, is there another way we can test this? |
The fill query wrote the files right before the measured runs, but a file is skipped only once its version has settled (mtime at least 3 s in the past), so the CI runs measured the unskipped path. The lineitem files of the `tpch_ice_sf10` dataset are unpacked before the tests and keep the archive's mtime, so they need no fill and no sleep. They are split by `l_shipdate` month, so a date filter skips all files but the matching one. `max_threads = 1` keeps the cost of the skipped files from hiding behind the read of the matching file. The `l_orderkey` query skips nothing and is the control. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Right, that was the cause: the fill finishes a few seconds before the measured runs, and a file is skipped only once its mtime is 3 s old, so CI measured the unskipped path. Running perf.py here with the CI release builds of this PR and of master, the query that happened to run first skipped files only in its last 8 of 31 runs. Instead of a sleep, the test now reads the
The test sets |
CI finish ledger - d8b6fd4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The build failure dropped 110 dependent jobs, so no functional or performance test has run on this head yet, including the changed Session id: cron:our-pr-ci-monitor:20261016-133003 |
|
Fixing PR for the targeted-job test-selection |
|
some nits:
Also, please fix the merge conflicts and merge the latest master |
…by-cached-statistics # Conflicts: # src/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp # src/Processors/Formats/Impl/ParquetV3BlockInputFormat.h
…tatistics invariants The setting description now says that it also controls keeping filter column statistics and skipping files with them, and that open-time errors of a skipped file depend on the cache contents. Comments state the per-cell budget of kept statistics and why the push into `key_condition_column_ranges` must come before any query-dependent `continue`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The kept ranges live in the shared metadata cache, so allocate them outside the memory tracker of the query and user, like the uncompressed cache and the columns cache. Measured on 300 files whose filter column has 500-byte min/max: the read that keeps them peaked at 2279487 bytes before and 1463183 after. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. I merged master (the only conflicts were the new columns cache include and declaration next to ours in
Also in 6db3834: the kept ranges belong to the shared cache, so they are now allocated outside the memory tracker of the query, like the columns cache entries. On 300 files with 500-byte min/max values, the read that keeps them peaked at 2.28 MB before and 1.46 MB after. 05390 passes 50/50 with random settings on the merged tree. |
…ry too The kept ranges were allocated outside the memory tracker of the query, but released by whichever query evicts the cell or drops the last reference to them, and that free lowered the usage of a query that holds live allocations. Allocate and release the kept statistics with `ServerOwnedCacheEntryAllocator` and a deleter that blocks the tracker, like the uncompressed cache. Measured with a 300-entry LRU cache: a query reading 300 new files evicts 300 cells whose 500-byte min/max ranges were kept. Its memory_usage was 15823303 bytes against 16613047 when the evicted cells kept nothing, and is now 16572791 against 16575927. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ot settled `StorageFile` keeps the ranges only for a settled version, so a hit read of a file written in the last 3 seconds copied them for nothing. Take the cell for keeping only when the version identifies the content, as the columns cache does. Measured on 150 files with an mtime in the future: the hit read peaked at 1258031 bytes instead of 1260847; settled files keep and skip as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
fix merge conflicts |
…by-cached-statistics # Conflicts: # src/Common/CacheBase.h # src/Processors/Formats/Impl/Parquet/Reader.cpp # src/Processors/Formats/Impl/Parquet/Reader.h # src/Processors/Formats/Impl/ParquetMetadataCache.cpp # src/Processors/Formats/Impl/ParquetMetadataCache.h # src/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp # src/Processors/Formats/Impl/ParquetV3BlockInputFormat.h
… cell Since ClickHouse#124364, a read that finds a file's footer in `ParquetMetadataCache` replaces the cell with one that also holds the column chunks it parsed (`addColumnChunks`). The new cell had fresh, empty kept statistics, and `keepStatistics` kept ranges only in the exact cell the read found. So after the master merge the read that replaced the cell kept nothing, a file was skipped one read later than before, and every later replacement (a read of other columns) dropped the ranges kept so far. 05390 fails on the merge commit alone. The replacing cell now shares the kept statistics of the cell it replaces (their byte cap stays a quarter of the footer of the first cell), and `keepStatistics` keeps ranges in the resident cell whenever it shares them, under the same cache lock that recomputes its weight. With column chunks added on a hit, the first hit also changes a cell's weight by the chunks it parses, so the clickhouse-local weight checks of 05390 first read x and s twice without a filter; the filtered read that follows changes the weight only by the ranges it keeps. Checked: dropping the kept bytes from the weight fails "weight counts the kept ranges", and dropping both settle gates (StorageFile and `isEtagUsableAsCacheKey`) fails the unsettled line.
|
Done: merged master in d8f99d0. The conflicts were with #124364, which replaces the metadata cache cell when it adds column chunks. 0f56d1f makes the new cell keep the statistics already kept with the old one; with the merge alone, 05390 fails because the third read of a file no longer skips it. It also makes the weight checks in 05390 read the column chunks first, so they still measure only the kept ranges. |
A read whose metadata cache cell keeps statistics copied the ranges of every key condition column for every row group, and only then found that a column was already kept or did not fit the cell's budget. For a file with long string bounds every warm read held all of them at once and discarded them: 1000 row groups with 3000-byte bounds of `s`, `WHERE s = 'zzzz'`, took 7.25 MiB instead of 1.23 MiB for the same read of an unsettled copy, and nothing was kept. Now the format asks the reader to collect only the columns the cell does not keep yet, with the bytes the cell can still take. The reader counts the bytes while collecting and, while all columns together take more, drops the column that takes the most. Only complete columns are left. The same read takes 2.86 MiB, the rest being the budget itself (a quarter of the footer); with two such columns 4.28 MiB instead of 13.30 MiB. A budget per column would not do: with four columns it collects as much as before. `ParquetKeptStatistics::prepare` takes the byte count from the reader instead of recounting the ranges under its lock. 05390 checks the extra memory of such a read of four columns against an unsettled copy: +1.6 MB, while the previous commit and a per-column budget both take +6.3 MB (threshold 3 MB). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-parallel-read Conflicts with the query condition cache for tables without a UUID (#122127) and with skipping Parquet files by the cached statistics (#125528): the split file now uses `query_condition_cache_table_id` (computed before splitting), the sources of a split file don't keep the statistics (each reads only some row groups) and count a skipped file once, and the reader of a bucket skips other buckets' row groups only after recording their ranges. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p-k-file-order Resolves the conflicts with the Parquet footer cache changes on master (ClickHouse#125528 and the lazy column chunks): - `getOrSetMetadata` now returns the cache cell, so the footer probe uses it and `getOrSetMetadataCell` is dropped; - the probe reads the footer with `readFileFooter` and `setFileFooter`; - `keep_filter_column_statistics` is set before the file order pass; - the includes master now has in `StorageFile.cpp` are not repeated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…file order pass Since ClickHouse#125528 a reader skips a local Parquet file without opening it when the statistics kept with its cached footer exclude the filter. The file order pass ran before that check and still analysed the footer of every such file, so a repeated query whose filter excludes most files paid for footers it never reads. The pass now uses the same `ParquetCachedStatisticsFilter` check and leaves such files without a bound, as it already does for the files the query condition cache excludes. Measured (debug build, 100 files x 100 row groups x 17 columns, the cached statistics exclude 99 files, warm, pass on vs off by `input_format_parquet_preserve_order`, 40 interleaved pairs, median wall): 1 thread 12.96 -> 9.34 ms (off: 7.6 ms), 4 threads 9.27 -> 8.47 ms (off: 7.5-8.0 ms). 05341 checks that the second read analyses only the footer of the file the statistics do not exclude. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…adata cache A warm read of a Parquet file from object storage or a data lake, whose footer is already in `ParquetMetadataCache`, still read the offset index of every column chunk it read before requesting the column data. ClickHouse writes the page index after the bloom filters, more than `remote_read_min_bytes_for_seek` from the data, so that was a separate, sequential request per file; since ClickHouse#128471 an Iceberg data file is one row group, so a warm `IcebergS3` scan paid one request latency per data file and stream. The offset indexes a read decodes and validates are now kept with the cached footer, like ClickHouse#125528 keeps statistics: a container shared by the cache cells of a file version, counted in the cell weight and limited to the footer size (at least 4 KiB). Only a read that found the footer in the cache adds to it, when it reaches the end of the file, so a file read once is not moved to SLRU's protected segment; the per-read collection stops at the bytes the container can still keep (master frees each offset index with its row group, so an unbounded collection would hold them all until the end of the file). The offset indexes come from beyond the footer bytes, so they are used and kept only when the cache key identifies the content (a strong ETag or an immutable content id), the gate of the columns cache and the page cache. A later read copies the kept offset index instead of registering its byte range, and the column-index stage decodes only an offset index it read. New counter `ParquetMetadataCacheOffsetIndexHits`. Measured (Release, 8 paired rounds, S3 behind a 20 ms first-byte delay): a warm `IcebergS3` scan of 100M rows in 110 files -32.6% (203 -> 110 GETs), the `s3()` glob of the same files -31.3%, 10M rows in 16 files -25.7%; `WHERE b = 5`, 1000 tiny files and 20 random-`UInt64` files unchanged (the last makes 40 requests instead of 20, with 21% fewer bytes). The metadata cache grows by about 640 B per 3-column file. Based on the analysis and patch by snelheidai in ClickHouse#129400. Closes ClickHouse#129400 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A filtered read of a glob of local Parquet files (
Fileengine,file()table function) no longer opens the files whose row groups the min/max statistics already excluded: an earlier read keeps those statistics with the cached file metadata, so later queries skip such files even with other constants.Description
Related: #125423
On a warm server the footers of local Parquet files are cached, but a filtered read of a glob still opens every file and converts the statistics of every row group, only to find that none can match. The query condition cache helps neither for other constants nor for
file().After a read of a settled file version (the query condition cache's gate) whose metadata was already cached, the converted min/max ranges of the key condition columns are kept in the file's cache cell, keyed by column, type and the format settings that affect the conversion, and counted in its weight at once. A read that inserts the cell keeps nothing, so one-off scans do not move cold files in the cache. A later read of that version evaluates the same key condition on them before opening the file and skips it if no row group can match. Skipped files count in
ParquetPrunedRowGroupsand in the newParquetFilesSkippedByCachedStatistics.use_parquet_metadata_cache = 0disables it. A file that is not skipped costs one more metadata cache lookup.On 100 files with the ClickBench
hitsschema (release, medians of 7 alternating rounds): Q37-Q43 matching 3 files take 8-10 ms instead of 11-13 ms (3 files opened instead of 100); Q1, Q2, Q3, Q8, Q20, Q24, Q30 and the cold first query are unchanged; the metadata cache grows by 2.2%.A differential oracle of 1000 random filters over 13 column types matched master; a mutant skipping on any excluded row group failed it.
Object storage is not changed: there the skip touches the read-ahead that #124950 changes. #124959 and #124364 touch the same
getOrSetMetadataCellandCacheBasecode; #115877 is complementary; #122127 brings the query condition cache tofile(), for the same condition only.Based on the analysis and patch by @ snelheidai.
Workflow [PR]
Sync PR [sync-upstream/pr/125528]
Version info
26.11.1.644-master(included in26.11and later)