Repository navigation
Columns cache for Parquet - #124531
Columns cache for Parquet#124531
Conversation
Use the columns cache (`use_columns_cache`) for `Parquet` files read from the local filesystem (`file`, `File`), from object storages (`s3`, `azureBlobStorage` and their engines) and by data lake tables. An entry holds a whole output column of one row group; the row group index is its stripe. The key is made of the path of the file, its version (the ETag of an object, or the version token of a local file once it has settled) and size, the format settings that change the decoded values, the columns of the file the column is read from and the types it is decoded into and converted to. The entries share the cache with `MergeTree`, its size limit, `system.columns_cache` and `SYSTEM DROP COLUMNS CACHE`. A column found in the cache is neither prefetched nor decoded: every row subgroup takes its rows from the cached column, filtered as the subgroup is. A column is written only when every row subgroup of the row group reads all its rows before any filter, so with `PREWHERE` the columns of the filter are written. The per-query write budgets are respected. `use_parquet_metadata_cache` is now honored by the format itself, as `StorageObjectStorageSource` now passes the object metadata also when only the columns cache needs it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dictionary filter prunes row groups for all columns, so a column found in the cache still reads its dictionary page when the filter is used for it. Pin `use_columns_cache = 0` where `05055_string_filters_during_scan_parquet` checks that the string filters are applied: a column that can be written to the columns cache is decoded without them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [08059a4] Summary: ✅
AI ReviewSummaryThis PR extends Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Correct the time-zone identity, bound in-flight cache-write memory, size cached-copy reservations from decoded data, and preserve the parser-depth limit; cover these cases with focused regressions. |
Build profile diff (arm_release)Commit See the job log for details. |
…che` `DatabaseCatalog::tryGetByUUID` requires a non-nil UUID, and the entries of `Parquet` files have the nil one, so reading `system.columns_cache` threw a logical error exception in debug and sanitizer builds. Also pin `use_columns_cache = 0` in tests that check the reads themselves: `04342_reader_executor_s3_long_connections` writes the same object with the same ETag in every run, so a rerun was served from the cache without opening a connection, and `05321_parquet_bool_hint_no_minmax_pruning` checks `ParquetReadPages`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124531&sha=7b7a1351da28112ad0428c6f960ffddc75fedbc1&name_0=PR PR: #124531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts to the columns cache The check consulted only `block_missing_values`, which is allocated only for the columns of the sample block and only with `input_format_defaults_for_omitted_fields`. Decide from the null map of the column instead, so that a column whose nulls were replaced with defaults (`input_format_null_as_default`) is never written, whether or not the query reports them in the block missing values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ue path, check the source grant in `system.columns_cache` The relative path of an object does not identify it: another bucket, container or endpoint can have an object with the same key and version token. `StorageObjectStorageSource` now passes `getUniqueStoragePathIdentifier` (with the namespace, the connection and `read_source_index`) as `RelativePathWithMetadata::path_for_content_cache`, and `StorageFile` passes the absolute path. The columns cache is not used for an object without it. An entry of a file now records its source (`FILE`, `S3`, `AZURE`, `HDFS`, `URL`), and `system.columns_cache` shows it only to a user holding an unrestricted `READ` grant on that source besides `SHOW COLUMNS` globally, so the paths of the files do not leak across privilege boundaries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_cache_access` The style check requires queries to `system.columns` (which also matches `system.columns_cache`) to have a `database` condition. The entries of `Parquet` files have an empty `database`, so filter by `database = ''`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Measurements of this PR (CI build of 74a3564) on ClickBench Setup. r7g.xlarge (4 vCPU, 30 GiB).
Each arm and repetition starts a fresh server; 4 paired repetitions in rotated order. Ratios are cache on / cache off, geometric mean with a 95% t-interval. The write budgets are raised because with the defaults the 13 GiB cache stores nothing for the
The run that fills the cache. For Q20, query memory goes from 0.31 to 9.3 GiB, system time from 3.8 to 7.2 s and minor page faults from 1.0M to 3.6M. Disabling Memory pressure.
Counting the evictable part of the cache as available in Queries and run order-- Q2
SELECT SUM(AdvEngineID), COUNT(*), AVG(ResolutionWidth) FROM hits;
-- Q20
SELECT COUNT(*) FROM hits WHERE URL LIKE '%google%';
-- Q21
SELECT SearchPhrase, MIN(URL), COUNT(*) AS c FROM hits WHERE URL LIKE '%google%' AND SearchPhrase <> '' GROUP BY SearchPhrase ORDER BY c DESC LIMIT 10;
-- Q27
SELECT CounterID, AVG(length(URL)) AS l, COUNT(*) AS c FROM hits WHERE URL <> '' GROUP BY CounterID HAVING COUNT(*) > 100000 ORDER BY l DESC LIMIT 25;
-- Q33
SELECT URL, COUNT(*) AS c FROM hits GROUP BY URL ORDER BY c DESC LIMIT 10;Rerun table: each repetition runs Q20 × 6, Q21 × 6, Q27 × 6, waits until 95 s after server start, then runs Q20 and Q2 × 12, with |
…ies read by tables The entries of a `Parquet` file read by a table (`ENGINE = File`, `S3`, `AzureBlobStorage`, `Iceberg`, ...) had the nil UUID, so `system.columns_cache` showed them to any user with global `SHOW COLUMNS` and `READ` on the source, regardless of their access to the table. Now such entries carry the UUID of the table and are shown under the same rules as the entries of `MergeTree` tables; the nil-UUID, source-grant path is kept only for table functions. A table without a UUID (e.g. in an `Ordinary` database) does not use the columns cache, since the provenance of its entries cannot be kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks for the measurements, @snelheidai. Pushed c489c79, which addresses the AI-review blocker: The three costs you found change how the cache is accounted and admitted, so they need a decision from the author. I have not changed them in this pass:
All of the remaining CI failures are unrelated to this PR:
|
… cache key The key of a `Parquet` columns cache entry was built with the nil UUID even for reads by tables, so a read by a table function (`file`, `s3`) and a read by a table (`ENGINE = File`, `S3`, data lakes) of the same file shared one entry. Whichever path wrote it decided which access check `system.columns_cache` applies. Now the identity includes the UUID of the owning table, so the entries of the two paths are separate. The test `05355_parquet_columns_cache_table_access` now warms the file through the table function first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Processors/Formats/Impl/Parquet/Reader.cpp
The admission control of `ColumnsCache` lowers the probability of writes (down to 1/64) when other tests load the cache with entries that are never read, so `05340_parquet_columns_cache_access` and `05355_parquet_columns_cache_table_access` could not populate the cache in 20 attempts in the targeted ASan runs. Mark them `no-parallel`, as the other columns cache tests are, and drop the cache at the start, which resets the admission probability. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124531&sha=91b302b267c0d25015f3389a985ed8e451c88562&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 PR: #124531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed tables The columns cache entries of a file read by a table (`File`, `S3`, `AzureBlobStorage`, data lakes) are not removed when the table is dropped, so they fall into the branch of `system.columns_cache` for unresolvable table UUIDs, which only required the global `SHOW COLUMNS`. Keep the source of the file in every `Parquet` entry, and require the unrestricted `READ` grant on it in that branch too, as for the entries of table functions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124531&sha=91b302b267c0d25015f3389a985ed8e451c88562&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 ( |
|
The fix is already in progress: #123121 (mine, open). This is the race from #112642: query 26 of |
The `DatabaseReplicated` test configuration sets `distributed_ddl_output_mode = none`, so `DROP TABLE` returns before the table is dropped and its UUID still resolves. Wait until the entries of the table no longer show its name. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124531&sha=a5029b4afdb55339526ebaa8bd74b2e982d38a23&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20sequential%29 #124531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uery The copy of a column written to the columns cache goes to the shared cache, so allocate and release it outside the memory tracker of the query, like the marks in the mark cache. Otherwise warming the cache could exceed `max_memory_usage` of a query that fits without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stem.columns_cache` Entries of a file read by a table carry the table UUID and show its name; only entries of table functions have the nil UUID, and the entries of a dropped table also require the `READ` grant on the source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pushed three commits:
Thanks @groeneai. #123121 is merged now. This branch will pick it up with the next merge of master. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124531&sha=726f6f75887f99e327e188e8dffd2fd2401cf985&name_0=PR&name_1=Build%20(arm_release) ( |
|
Acknowledged. I am investigating the |
|
Fix: #126296 (when no readiness probe gets any HTTP answer, the hook reports a workflow warning and exits 0; any answer from the cluster still fails it). The cause itself is outside the repo: the CI logs cluster writer endpoint has not answered since this morning and is still down at 13:00 UTC, which is also why these runs carry |
…ters_during_scan_parquet_short_dictionary_values` The test was added on `master` after this branch pinned the same setting in `05055_string_filters_during_scan_parquet`. A `Parquet` column that can be written to the columns cache is decoded without `apply_string_filters_during_scan`, so that the cache gets its values. With the randomized `use_columns_cache = 1`, `StringValueFilterValuesReplaced` is `0` and the check fails. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124531&sha=1303eb3b1b6beafeb084da62ae0e5a576291bac3&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20distributed%20plan%2C%20targeted%29 PR: #124531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master added reading of dictionary-encoded `PREWHERE` columns as `ColumnReplicated` (`decode_dictionary_as_replicated`), materialized after the last step. Such a column can reach `addToColumnsCacheWrite` before that, so it is converted with `convertToFullColumnIfReplicated` before being copied into the columns cache write. In `ReadManager::read` keep both the new `getOrFormOutputColumn` signature and master's `convertToFullColumnIfReplicated`. In `05055_string_filters_during_scan_parquet.sh` take master's queries and keep `use_columns_cache = 0`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master reverted #124131, so the Parquet reader no longer produces `ColumnReplicated`: dropped the `convertToFullColumnIfReplicated` calls after `getOrFormOutputColumn` in `ReadManager::read` and in `Reader::addToColumnsCacheWrite`, and the `ParquetRowsDecodedAsDictionaryIndexes` declaration. In `05055_string_filters_during_scan_parquet.sh`, took master's queries and kept `use_columns_cache = 0`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Very good implementation. Love all of it.
…age-column-data-read-ahead Resolves the conflict with ClickHouse#124531 (columns cache for Parquet) in ReadCommon.h: ReadOptions keeps both is_remote_fs and columns_cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test runner randomizes use_columns_cache since ClickHouse#124531. A row group column served from the columns cache has no column data to read, so with the cache enabled for reads and writes the second read of the same file (e_s3_limit_1gb, g_s3_16_decoders) reads nothing ahead and prints 0. Measured: forcing use_columns_cache = 1 with reads and writes fails exactly those two lines; with the pin the test passes, and 50/50 randomized runs pass (7 of them drew that combination). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A column served from the columns cache (ClickHouse#124531) has no column data to read, so a reader whose row groups are all served from it can start no read-ahead, yet each ColumnData admission round still took the shared lock and ran an exclusive pass over the schedulable row groups. The init gate now also requires a row group with a column that is not served from the cache. Measured (debug build, 3963 row groups of one UInt32 column in MinIO, every column served from the cache, 5 runs): max_download_threads 16 median 185 ms before vs 92 ms after (max_download_threads 1: 95 / 93 ms). With one of two columns cached the reader still reads ahead (15 row groups). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extends the columns cache (#96844) to
Parquetfiles: local files (file,File), object storages (s3,azureBlobStorageand their engines) and data lake tables, i.e. every read that goes through the metadata-awareParquetcreator. Repeated queries over hot Parquet data no longer pay for reading, decompressing and decoding the column chunks.How it works:
ColumnsCacheasMergeTree(the row group index is the stripe). So it shares the size limit, admission control,system.columns_cacheandSYSTEM DROP COLUMNS CACHE.getUniqueStoragePathIdentifier; the absolute path of a local file), its version (ETag of an object, or the version token of a local file) and its size; the format settings that change decoded values; the file columns the output column is read from; and the decoded and output types. A local file is cached only once its version token has settled, the same rule the query condition cache uses (ObjectMetadata::etag_is_strongis set accordingly).PREWHERE, the filter columns are cached; columns read only for the rows that pass are not. A column that may be written is decoded withoutapply_string_filters_during_scan, so the cache gets its real values.columns_cache_max_estimated_bytes_to_write_to_cacheandcolumns_cache_max_bytes_to_write_to_cacheapply. The estimate is the uncompressed size of the column chunks to be written.system.columns_cache, an entry of a file is shown only to a user holding globalSHOW COLUMNSand an unrestrictedREADgrant on the source of the file (FILE,S3,AZURE,HDFS,URL).use_parquet_metadata_cacheis now checked by the format creator itself, becauseStorageObjectStorageSourcenow passes the object metadata when either cache needs it.Local check (1M rows, 4 columns, 8 row groups,
max_threads = 1): CPU time per query went from about 60 ms to 6-7 ms once the columns were cached. All existing statelessParquettests were also run withuse_columns_cache = 1forced through the default profile. Results are unchanged; the only differences were counters in05055_string_filters_during_scan_parquet, which now pinsuse_columns_cache = 0for those checks.Related: #96844
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The columns cache (
use_columns_cache) now also applies toParquetfiles read from the local filesystem, from object storages such as S3 and Azure, and by data lake tables. Repeated reads of the same row groups skip reading and decoding the column chunks.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124531]
Version info
26.11.1.136-master(included in26.11and later)