Repository navigation
Columns cache for compact parts - #127287
Conversation
The columns cache was implemented only in `MergeTreeReaderWide`, so data in compact parts was never served from it or written to it. Compact parts are the format of every small part (fresh inserts, patch parts of lightweight updates, small tables), so whether a query was accelerated depended on the part format. Every granule of every column of a compact part is serialized on its own, with its own prefix, and is read after a seek to its mark. So a granule of a column can be served from the cache or read from the part independently of the other granules and columns, without any stream positions to restore. `MergeTreeReaderCompact` now does this: a column whose entry covers the granule is served from it, the others are read; a block that is a whole entry is shared with the cache without a copy, and the granules read from the part are accumulated per column into runs of a stripe and written. The part of the cache logic that does not depend on the part format (the identities of the columns, the admission, the write budget, the deferred writes, serving rows from an entry) is moved from `MergeTreeReaderWide` to `IMergeTreeReader`, and both readers use it. The entries of compact parts are removed when the part goes away, as for wide parts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [973a0a3] Summary: ✅
AI ReviewSummaryPR #127287, reviewed at Final Verdict✅ Approve — no required changes. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes22 object files changed (+47.33 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 units150 translation units recompiled, 1764 s compile time in total, 150 of them have a recent master baseline. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Good. The ideas are clear, the code meets the quality standard, and it is easy to follow.
Since the columns cache serves Compact parts (ClickHouse#127287, 2c9139d), the Compact reader returns a cached granule without reading the JSON structure prefix, the same way the Wide reader already did. Once the calibration scan has filled the cache, the cancelled scans can no longer land inside the prefix read, so "cancelled inside the reader at least once" reads 0. Measured on the merged head (debug, Build ID 052cbf4d): - use_columns_cache=1 with reads and writes on: 5/5 FAIL with that diff; use_columns_cache=0 with reads and writes on: 3/3 OK. - with the clamp, randomized, reads and writes forced on: 10/10 OK, and query_log shows use_columns_cache never set in any run. - negative control (clamp line made unparseable): use_columns_cache=1 in 5/10 runs and exactly those 5 FAIL. - compact + wide, randomized, 25 runs each, 4 jobs: 50/50 OK. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the columns cache After merging master, the readers of compact parts write to the columns cache too (#127287), so the condition `isWidePart` let the reader of a compact part apply the string filter and then cache the substituted empty strings: an unfiltered query served from the cache saw them. Drop the condition and check the compact part in the test the same way as the wide part. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#127287 the columns cache serves compact parts, so with a randomized `use_columns_cache = 1` the warm-up query caches the columns and the measured queries open no data files. That turns the FileOpen oracle blind: the in-range control fails (FileOpen 30, not > PARTS), and the selective and postings-cached arms pass vacuously (0 files opened). Pin `use_columns_cache = 0` in the settings every measured query and warm-up uses, next to the query cache pins. With the setting at 0 the cache is neither read nor written, so the `enable_reads_from_columns_cache` and `enable_writes_to_columns_cache` draws need no pin. Failing job: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127715&sha=9500cdadc54b2d1ef5c3825d11b4d749668a5fd2&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20sequential%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed disk tests Since #127287 the columns cache also covers compact parts, so with `use_columns_cache` on by default the repeated reads in these tests were served from it and never reached the filesystem cache, the page cache, or the (broken) underlying storage. Also drop the duplicate `use_columns_cache = 0` in `05218_text_index_substreams_opened_lazily`, which master already sets. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123890&sha=5501a1e6376dc3fce82c0fbb6fbbd9c6cfc6d3fa&name_0=PR PR: #123890 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#127287 the columns cache also serves compact parts. The runner randomizes `use_columns_cache` + `enable_reads_from_columns_cache` + `enable_writes_to_columns_cache`. When all three are on and the parts are compact, the read after ATTACH fills the cache (DETACH destroys the parts and removes their entries), and `SYSTEM CLEAR MARK CACHE` does not drop it. The next `SELECT ... WHERE NOT ignore(*)`, the test's positive control ("a read after clearing the mark cache loads marks"), is then served entirely from the columns cache and requests no marks. Only the speculative async marks load scheduled by the compact reader can still count `LoadedMarksCount`, and it is cancelled when the reader finishes first, so the reference `1` becomes `0` in a fraction of runs. Under the same settings the expected-0 "prewarm worked" rows are vacuous, since a cache-served read loads no marks either way. Disable the columns cache for the whole test, as 2376801 did for the sibling 03254_prewarm_mark_cache_columns. A session SET beats the runner's injected value and also holds where randomization is off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On 26.10 only MergeTreeReaderWide uses the columns cache; the Compact reader got it in #127287, which is master-only, so the Compact case's system.columns_cache probe returns no rows there. Test only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lation-compact-reader-mark-loop Conflicts resolved: - MergeTreeReaderCompactSingleBuffer.cpp: master (ClickHouse#127287) moved the mark loop out of readRows into MergeTreeReaderCompact::readGranules, and ClickHouse#128083 already guards the reportBroken catch with isQueryCancellation. Took master's file as is; the per-granule checkTimeLimit moves to both loops of MergeTreeReaderCompact (readGranules and readGranulesWithColumnsCache). - checkDataPart.{cpp,h}: ClickHouse#128083 added isQueryCancellation under the same name. Kept master's function and declaration; dropped ours. Master accepts only the three cancellation codes on a DB::Exception, so isCodeOfCancelledQuery stays as an extra clause in both catch branches: a killed query can rethrow the error it was cancelled with, of any code and any exception type. - MergeTreeSequentialSource.cpp: master's catch line is identical to ours. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#127287 the compact reader reads the granules of a block in one of two loops: the plain one, or the columns cache one when use_columns_cache is on. The cancellation check is in both, so the timeout arm now also runs with use_columns_cache = 1 and cache writes off, which keeps every granule a read from the part. ColumnsCacheMisses, counted only by that loop, proves the arm went through it. Disabling either loop's check fails exactly the arms of that loop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On 26.10 only MergeTreeReaderWide uses the columns cache; the Compact reader got it in #127287, which is master-only, so the Compact case's system.columns_cache probe returns no rows there. Test only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The columns cache was implemented only in
MergeTreeReaderWide, so data in compact parts was never served from it or written to it. Compact parts are the format of every small part - fresh inserts, patch parts of lightweight updates, small tables - so whether a query was accelerated depended on the part format, which is invisible to the user.Every granule of every column of a compact part is serialized on its own, with its own prefix, and is read after a seek to its mark. So a granule of a column can be served from the cache or read from the part independently of the other granules and columns, and there are no stream positions to restore, unlike in wide parts.
MergeTreeReaderCompactnow does this:getColumnsCacheStripeMarksandcanReadWholeColumnsCacheStripeare implemented, so the read tasks and blocks are aligned to the stripes as for wide parts.The format-independent part of the cache logic (column identities, admission, the write budget, deferred writes, serving rows from an entry) is moved from
MergeTreeReaderWidetoIMergeTreeReaderand shared by both readers.IMergeTreeDataPart::mayStoreColumnsInColumnsCache, the write estimate and the task alignment in the read pools now include compact parts, so their entries are removed when the part goes away.Columns that are not in the part, or read only for the offsets of a
Nestedsibling, or not a function of the granule (the distinct-paths subcolumn ofJSON) have no entries and are read from the part, as in the wide reader.Tested with the new test, the existing columns cache tests, and about 2800 stateless tests on
Dynamic,JSON,Variant,Nested, sparse columns, subcolumns,PREWHERE, lazy materialization and patch parts run withuse_columns_cache = 1forced on (with randomized MergeTree settings, which produce compact parts): no differences from the runs with the cache off.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 applies to compact parts ofMergeTreetables, not only to wide parts.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127287]
Version info
26.11.1.739-master(included in26.11and later)