Repository navigation
Conversation
With `apply_string_filters_during_scan`, the readers materialize the values that do not match a substring condition of PREWHERE as empty strings. AutoPR estimates input bytes from the in-memory size of the read columns, so these values, which were read from disk all the same, were missing from the estimate. On hits 100M, `SELECT count() FROM hits WHERE URL LIKE '%google%'` was estimated at 9.3 MB against ~1.55 GiB read, so AutoPR kept it local although parallel replicas are 1.9x faster. `SerializationString` now reports the size of the values it replaces through `DeserializeBinaryBulkSettings::string_value_filter_bytes_skipped`, the readers accumulate it per column, and `recordInputColumns` adds it to the read bytes. For parts with per-column sizes, the column's compression ratio applies; for compact parts, where the ratio is sampled, the part-wide ratio is used for such columns, because a sample of empty strings says nothing about the values read. Before (staging, 26.11.1.1) vs after (local), compressed bytes read against `RuntimeDataflowStatisticsInputBytes` for the new test: - wide part: 12.3 MB vs 0.40 MB -> 11.5 MB - compact part: 12.6 MB vs 0.05 MB -> 11.0 MB - wide part, two columns: 12.6 MB vs 1.0 MB -> 11.8 MB Co-Authored-By: Claude Opus 5.5 <[email protected]>
…atio Review: for a compact part, the restored bytes of a filtered column were compressed with the ratio of the whole part, which includes the columns the query does not read. With an unread column that compresses much better or much worse than the read one, the estimate was 40x too low or 145x too high. A compact part has no per-column sizes, so the ratio comes from a sample of the read blocks. Now the decision whether a block is sampled is taken before reading it (`RuntimeDataflowStatisticsCacheUpdater::shouldSampleInputBlock`), and a sampled block is read with the string value filters off, so the sample consists of the real values. At most five blocks of a query are sampled, so the filters stay on for practically all of the read. Wide parts keep using the per-column ratio and are read with the filters on. The test gets the two fixtures from the review. They pin `compress_per_column_in_compact_parts=1`: otherwise all columns of a granule are compressed together, and reading one of them reads the others as well, which no per-column estimate models (with or without the filter). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading the sampled blocks of compact parts without the string value filters materialized whole blocks of values that the filter would have dropped. With long values this made queries exceed their memory limit: a compact part with 4096 distinct values of about 64 KiB, filtered by `LIKE '%needle%'`, took 183 KiB without AutoPR and failed with `MEMORY_LIMIT_EXCEEDED` (97.28 MiB against `max_memory_usage=64MiB`) with it. Also, the decision to sample was taken before reading, so a read task fully rejected by the skip indexes used up a sampling opportunity without recording anything: with 31 rejected compact parts followed by a matching one, the query had zero `RuntimeDataflowStatisticsInputBytes`. Now the filters always stay on. For compact parts, the reader keeps the first 64 KiB of the values replaced with empty strings, and the sampled block estimates how the replaced values compress from that sample. The sampling decision is taken in `recordInputColumns` again, as before, only for the blocks actually read. Locally (estimate / `ReadCompressedBytes`): wide 0.93, compact 0.90, wide with two columns 0.94, compact with a compressible unread column 0.90, with an incompressible one 0.89. A compact part with 1 MiB values reads with 9.5 MiB of memory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test profile sets `max_rows_to_read`, which is checked before reading, so the skip indexes were applied before reading as well and no read task was rejected: the case passed before the fix too. With `max_rows_to_read=0` all 32 parts reach the read, and the case fails on `1c0cc58e5645` (zero `RuntimeDataflowStatisticsInputBytes`), as does the case with 1 MiB values (`MEMORY_LIMIT_EXCEEDED`, 49.18 MiB against 32 MiB). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [147ad21] Summary: ❌
AI ReviewSummaryReplaces sampled AutoPR input estimates with unique compressed-file ranges loaded by The previously reported text-index and patch-part accounting omissions are explicitly tracked in the author's stacked follow-ups: text-index reads and patch-part reads. The range-memory limit is also a documented follow-up. These remain separate changes in the intended merge and backport stack. The current-head Fast test report passes all three added regressions: Final VerdictStatus: ✅ Approve |
The sample of the values replaced with empty strings was taken once per read task and kept,
so blocks sampled later used the compression of the first 64 KiB: with a compact part whose
first 8192 rows compress well and the rest do not, the estimate was 4.5x too low. And it
sampled only the characters, while the serialized column also carries the sizes: with values
of `repeat('x', 1 + cityHash64(number) % 64)` the estimate was 20.7x too low.
Now the reader hands over the sample with each block and starts a new one, and the sample keeps
every replaced value, including an empty one, with its size. Every empty string of a filtered
column is a replaced value (a matching value is never empty), so the first rows of the block are
restored from the sample in order, and the restored rows are estimated like any other column.
Locally, estimate with the filter / estimate without it: compact 0.99, with a compressible unread
column 0.99, with an incompressible one 1.00, compressibility changing along the part 0.99,
varying lengths 0.98.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review findings on `e4e490d680e8`: - the restored rows copied every matching value: with 16 matching 1 MiB values in 32 rows, the query failed with `MEMORY_LIMIT_EXCEEDED` (81.25 MiB against 64 MiB) with AutoPR statistics; - the sample was reset only for blocks with skipped bytes, so after five granules of empty values the sample of their zero lengths stayed full: 3137 estimated bytes against 823654 read; - a value longer than the sample was cut, and its prefix priced as the whole value: with a compressible 64 KiB prefix and a 128 KiB high-entropy tail, 148x too low. Now the restored rows take at most 64 KiB, matching values included, and a value that does not fit is sampled as pieces spread along it (`appendSampleOfStringValue`), both when the replaced values are sampled and when the matching ones are restored. The restored rows give only the compression ratio; the weight of the column is the size of the read rows with the replaced values. The sample is reset with every block. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d values Granules of empty values alone make the filter turn itself off (checking short values one by one does not pay off), so their values now either match or are empty. The table also pins the serialization: with the sizes inline every value is checked one by one again, and the `Sparse` serialization, which the many empty values get under a randomized `ratio_of_defaults_for_sparse_serialization`, is not filtered at all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It passed before `af887a437943` too: restoring the matching values of a block takes less memory than reading them, so the restore never raised the peak of the query, with compressible values or not, and with large or default granules. The restore is bounded by construction now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The case from the review of `e4e490d680e8`: one compact granule with 16 distinct matching values of 1 MiB and 16 short values that do not match. `e4e490d680e8` copies all the matching values into the restored rows: here the query took 43.29 MiB with AutoPR statistics and 27.24 MiB without them (the review saw `MEMORY_LIMIT_EXCEEDED`, 81.25 MiB against 64 MiB, where the current code takes 49.3 MiB). The memory of reading differs between builds, so the test compares the query with the statistics against the same query without them instead of setting `max_memory_usage`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review finding on `0ae16d715ffc`: a matching value of at least 64 KiB took the whole budget of the restored rows, so their compression ratio was that of the matching value alone, applied to the replaced values too. With one compressible matching 1 MiB value followed by 8191 distinct high-entropy 80-byte values in a compact granule, the estimate was 85x too small. Now the filtered column is estimated as it is, which copies nothing, and the replaced values are estimated from their sample, each weighted by its own size: the in-memory size of the column, and the size of the replaced values. The offsets of the empty strings, which are the replaced values, count with the replaced values. Restoring the rows is gone, and with it the copies of the matching values. Locally, estimate with the filter / without it: this case 1.000, compact 0.92-0.99, with a compressible unread column 0.91, with an incompressible one 0.96, compressibility changing along the part 0.98, varying lengths 0.96, empty granules 0.94, long values 1.000. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A long replaced value filled the 64 KiB sample of the replaced values, so the values replaced after it in the block were not in the sample, and the compression ratio of the long value was applied to all of them. For a granule with a repetitive 1 MiB replaced value followed by 8190 incompressible 80-byte ones, the estimate was 10708 bytes with the filter against 680862 without it. Now half of the sample is for the short values, sampled whole, and the other half is for the first 8 long values (longer than 4 KiB), each sampled along its length by itself. Each sample is weighted by the size of the values it represents: the short sample by the total size of the short values, the long samples by the total size of the long values in proportion to the sizes of the sampled ones. The same granule is now estimated at 659832 bytes with the filter against 652449 without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A sample of a long replaced value was compressed by itself, and its compression ratio, framing and codec overhead included, was applied to the whole value. A repetitive value compresses much better as a whole than a 4 KiB sample of it does, so it was overestimated: for 64 distinct repetitive 1 MiB values with one matching row, the estimate with the filter was 1179281 bytes against 267999 without it with `LZ4`, and 1030395 against 10710 with `ZSTD(3)`. Now the compressed size of the value is the compressed size of the sample plus the rest of the value times how much the compressed sample grows per byte from a shorter sample of the same pieces (a quarter of each). The estimates are now 265869 against 267999 with `LZ4`, and 25669 against 10710 with `ZSTD(3)`: `ZSTD` stores such a value in about 167 bytes, and one compressed byte of difference between the two samples already extrapolates to about 340 bytes per MiB, so the test allows 3x for it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sampling them
The compressed size of the values replaced by a string value filter was extrapolated from samples of them, and every
way to extrapolate had a counterexample: a sample of a repetitive value compresses much worse by itself than the
whole value, and a shorter sample of the same pieces can have a different mix of entropy. For 16 distinct 1 MiB
values of records of 256 pseudo-random bytes and 768 bytes of padding with `ZSTD(3)`, the estimate was 389952 bytes
with the filter against 4261214 without it.
Now the reader writes the replaced values, and their sizes as the part has them (varints before the values, or
`UInt64` in a stream of their own), into compressors with the codec of the column, over a `NullWriteBuffer`, and
takes the compressed size at the end of each block. This is done only while the statistics may still sample
blocks, so the cost is bounded, and only for parts without the sizes of their columns. The memory is bounded by the
buffers of the compressors, created only when needed.
The estimate without the filter serializes the sampled columns as they are sent over the network, where a `String`
column has offsets instead of the sizes of the values, so it is not close to what a part has when the sizes matter.
Two cases of the test are compared with the size of the column in a wide part with the same data instead:
varying_lengths, LZ4: with filter 275573, without 378412, on disk 315226
varying_lengths, ZSTD(3): with filter 71218, without 117902, on disk 82872
repetitive values, ZSTD(3): with filter 9400, without 10710, on disk 9744
The other cases still compare the estimates with and without the filter, within 1.2 now: the worst over 60 runs with
randomized settings is 1.104.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The compressed size of the values replaced by a string value filter was measured in every block while the statistics could still sample one, and the check looked at both counters of the input statistics, one of which the reads from disk never advance, so the measurement never stopped. Even within the window, all replaced values of up to 25 blocks were compressed, while the statistics sample 5 of them, and only the first `numRowsToSample` rows of each. Now the reads of compact parts without the sizes of their columns decide whether to sample a block before reading it, from the counter of the blocks read from disk, and the readers measure the replaced values only in the rows that the statistics sample from the other columns. A block without rows gives its turn back, so that the read tasks rejected by a skip index while reading do not use up the blocks to sample. A scan of 4M rows with `ZSTD(19)` and AutoPR statistics took 90 s, now 1.1 s, as with the filter disabled. The compressors were created for every filtered column of every reader, two buffers of 1 MiB each, even for the columns of the steps of PREWHERE that are never read: 32 string conditions on a table of two rows exceeded 64 MiB. Now they are created when the column is read in a measured block and released after it, and the buffer for the sizes is as large as a granule of them. The same query uses 2.9 MiB now. Also fixes `readability-make-member-function-const` reported by clang-tidy. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127586&sha=38e912d41adaedb67df7adf6b2a9eb30159e39f8&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 PR: #127586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The measurement was capped at `numRowsToSample(max_rows)` before reading, while the statistics sampled the column as it was read. A compact part is read in whole granules, so with `max_block_size=1` only the first row of an 8192-row granule was measured, and the estimate was 3005 bytes instead of 653526. The reader now reports how many rows it measured (at most `maxRowsToSample(max_rows)`, which is at least a granule), and the column is sampled in the same rows, weighted as a sample of the usual size. With `enable_multiple_prewhere_read_steps=0`, all the filtered columns of the step are measured at once, and the compressors of 32 columns took 17 MiB. They now share a fixed budget of 4 MiB for their blocks. A block given back because it had no rows decremented the counter of blocks, which another stream could have already advanced: the sampled slot was then lost, and a read that has few blocks after the granules dropped by a runtime filter never sampled one (`05243_autopr_reordering_wrapper_is_looked_through`). The block is now given back with its decision, which the next read takes over. `05443` also failed with the randomized `index_granularity_bytes`: the reads with and without the filter make blocks of a different number of granules (the filtered read does not update the value size hints), so they sample different rows. The case that depends on the blocks now has non-adaptive granules. Filter on vs off over 4M rows with `ZSTD(19)`: 1083 ms vs 1144 ms. CI: #127586 (comment) PR: #127586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g values `05243_autopr_reordering_wrapper_is_looked_through` still failed on `arm_asan_ubsan, targeted`: the join recorded `input bytes=0`. The runtime filter's index reader dropped 32 of the 36 granules of the left table at read time, so three of the four streams read blocks with no rows. Each of them had taken a sampling decision before reading and gave it back, but under ASan the only stream with data could take its decisions for both of its blocks before a sampled one was given back, and then nothing took it over. The decision is only needed for the measurement of the values replaced by a string value filter, so it is now taken right before the first reader that has such values to measure, and not taken at all for a block with no rows left. Without string value filters, the blocks are sampled as before this change, when they are recorded. Deciding after the read and measuring every block that may still be sampled was also tried: it measures up to 25 blocks instead of 5, and the filtered scan over 4M rows with `ZSTD(19)` took 4835 ms instead of 1150 ms. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127586&sha=de8a22e7b3d54d1b11f704f2c49c1f7a82e3c3ed&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 PR: #127586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The analyzer turns `length(s)` and `s <> ''` into reads of the subcolumn `s.size`. `RuntimeDataflowStatisticsCacheUpdater::recordInputColumns` counted the bytes of such a column in `bytes`, but found no compression ratio for it: the wide-part branch looks columns up in `getColumnSizes`, keyed by storage column, and the compact-part branch checked membership in the part's `NamesAndTypesList`. The subcolumn then silently inherited the ratio of the other columns of the block. On ClickBench Q27 (`hits_4p`, 100M rows) the key compresses 1:1279, so the recorded input was 0.94 MB against ~97 MB actually read for `URL.size`, and AutoPR could never switch to parallel replicas there. On Q31 the other columns compress poorly, so the same bug inflated the input by 48% instead. - Wide parts: the read task resolves the sizes of the subcolumns it reads once, through `getSubcolumnSize`, and they are priced by the compressed bytes of their streams per row. Not by a ratio: their in-memory bytes need not match those streams - a `single_stream` `String` keeps its sizes inside its only stream, so reading `s.size` reads all of `s`. - Compact parts: subcolumns are matched through the part's `ColumnsDescription`, so they are sampled like any other column, with the `CODEC` of their storage column. - A column the part has but which still cannot be priced marks the case unsupported instead of borrowing another column's ratio. Known limitation: a compact part with a `single_stream` `String` still prices `s.size` by the sizes column alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The callback that records input bytes receives the columns under the names the readers give them, which are the names in the part, while the size and codec maps were keyed by the read task's current-schema names. Fixes found in review: - A column renamed by a mutation not yet applied to the part is read as `s.size` but was looked up as `renamed.size`, so the statistics of the whole query were dropped as unsupported (0 bytes instead of 2.99 MB). - `length(n.a)` reads the offsets `n.size0` shared by the arrays of a `Nested`. That name was in no map and unknown to the flattened part description, so it borrowed the other columns' ratio (72 KB recorded against 2.47 MB read). - Several columns reading the one stream `n.size0` charged it once each (9.79 MB recorded against 2.47 MB read for four of them). - After a pending rename, a compact part was sampled with the part's default codec instead of the column's `CODEC` (3.2 MB vs 14.1 MB). `MergeTreeReaderWide::getCompressedBytesOfColumnsToRead` lists, for each column it reads, the streams it opens and their compressed bytes, under the names the read uses. The read task builds the size and codec maps from each main and PREWHERE reader, pairing the requested column (for the metadata lookup) with the column in the part (for the key). A stream is charged once per block, while every column's in-memory bytes still count in the sample, as they do in `read_bytes`. The membership check uses the part description with collected `Nested` columns. Columns with a dynamic structure, or a bucketed `Map`, list their data streams only after their prefixes are read; they keep using the part's `getSubcolumnSize`. A random `map_serialization_version_for_zero_level_parts = 'with_buckets'` used to make the reader treat every column that way. Known gap: compact parts still charge a stream shared by several columns once per column. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CVmLtoabe9AeMvcwV5SBnf
The compact tables of `05443` and `05452` are created from their wide counterparts, keeping only the settings that make them compact. The assertions of `05452` and `05838` take their aliases from `WITH` instead of a subquery. Comments that repeated the accounting are shortened, and the comment on the columns cache in `05443` says why it is still disabled: a reader writing to it reads the values without the string filter. `Readers::countCompressedBytesRead` had one caller and is inlined into it, and `RuntimeDataflowStatistics.h` no longer includes headers for the removed input sampling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g-filters # Conflicts: # src/Processors/QueryPlan/Optimizations/RuntimeDataflowStatistics.h
AI review of a later commit does not approve the PR, see the AI Review comment.
`CountedCompressedBlocks` is `ReadRangesRegistry`, its `CountedRanges` are `ReadRanges`, united by `unite` into `united_ranges`. A reader gets the registry by `setReadRangesRegistry` and registers what it read by `registerReadRanges`, and the buffers append to `ranges_read`, set by `setRangesReadSink`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ReadRangesRegistry::count` is `registerRanges` and `ReadRanges::unite` is `add`, and the readers keep the `ReadRanges` of their files in `read_ranges`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
left a comment
There was a problem hiding this comment.
I reviewed the diff at 6830bd0 and tested a debug build of it merged into master 13091b1, against a debug build of master 9f7ed31. I found no defect.
Accuracy. 11 reads over 8 column types, each on a wide and on a compact part (2M rows, SELECT k % 10 AS g, <agg> FROM t GROUP BY g, automatic_parallel_replicas_mode = 2, uncompressed, columns and query condition caches off, second run so the marks are cached). Ratio of RuntimeDataflowStatisticsInputBytes to ReadCompressedBytes:
| Read | master | PR |
|---|---|---|
compact Array(String), sum(length(v)) |
0.263 | 1.000 |
compact Nullable(String), countIf(v IS NULL) |
0.265 | 1.000 |
compact Tuple(a String, b UInt64), max(v.a) |
0.560 | 1.000 |
compact Map(String, UInt64), sum(v['k1']) |
1.738 | 1.000 |
wide Array(String), sum(length(v)) |
1.271 | 1.000 |
wide UInt64, WHERE k % 8192 < 100 (PREWHERE) |
0.341 | 1.000 |
| all 22 queries | 0.263 to 1.738 | 0.977 to 1.000 |
The others were UInt64, LowCardinality(String), JSON (v.a), sparse UInt64, and Nullable/Array read whole.
Tests. 05443, 05452 and 05838 fail on the master build and pass on this one (3/3). At this head CI ran them 1250 times in the flaky checks and 1299 times elsewhere, with no failure.
Code paths I checked. No stream that gets a sink is uncompressed: only the text index postings and positions are, and they never enter a wide or compact reader. The only decompression off the reading thread in the wide reader, the Object prefixes on the prefix pool, is waited for before readRows returns, so nothing appends during registerReadRanges. ReadRanges::add keeps the ranges disjoint and charges only the uncovered bytes. Two coordinated reads can't share a registry, since collectCoordinatedReads rejects a second one.
Performance Comparison reds at this head. All 8 slower queries use optimize_aggregation_in_order: aggregation_in_order #3 +222%, aggregation_in_order_2 #2 575 -> 1538 ms, aggregation_in_order_if_null_map #10 238 -> 293 ms (the 11:03 UTC re-run of shard 1/8 reproduced it). The previous head 052e58f differs from this one only by the three renaming commits, and measured the same queries at 467 -> 467 ms and 240 -> 242 ms. Master's own runs of aggregation_in_order_2 #2 on 11-23 stayed at 439-601 ms. Without AutoPR the diff adds a null check per loaded block and an early-returning virtual call per read step. Locally that query on 100M rows in 30 parts takes 1093 ms here against 1053 ms on master (debug, median of 6). So I don't see a cost in the diff that explains these reds.
…noseconds` The timer covered only the merge of the ranges into the counted ones. Now it also covers the lookup of the counted ranges by path and the loop over the streams of a reader. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g-filters # Conflicts: # src/Storages/MergeTree/MergeTreeReadTask.h
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Automatic parallel replicas now measure input bytes as the compressed blocks the readers actually load, instead of estimating them by sampling. Queries that read subcolumns such as
length(URL), skewed ranges of rows, or string columns filtered during the scan (apply_string_filters_during_scan) are no longer under-priced.This PR now also contains #127835, which was stacked on it; the two overlapped too much to review separately.
AutoPR estimated input bytes from the in-memory size of the read columns times a compression ratio, taken from
getColumnSizesor from sampling. That missed data in several ways:apply_string_filters_during_scan, the readers materialize the values that do not match a substring condition ofPREWHEREas empty strings, although they were read from disk all the same. On hits 100M,SELECT count() FROM hits WHERE URL LIKE '%google%'was estimated at 9.3 MB against ~1.55 GiB read, so AutoPR kept it local although parallel replicas are 1.9x faster.length(s)ands <> ''into reads of the subcolumns.size, which found no ratio of its own and inherited the ratio of the other columns of the block. On ClickBench Q27 (hits_4p, 100M rows) the recorded input was 0.94 MB against ~97 MB read forURL.size; on Q31 the same bug inflated the input by 48%.PREWHEREor primary-key range that selects rows with long strings was priced at the part average.Instead, the readers now report the compressed blocks they load, and input sampling is removed:
CompressedReadBufferFromFileandCachedCompressedReadBufferappend the file range of every block they load, including those taken from the uncompressed cache, to the sink set bysetRangesReadSink.ReadRangesRegistryof its statistics, given to them bysetReadRangesRegistrywhen the read task is created. After each step,MergeTreeReadersChaincallsregisterReadRanges, which unites the ranges a reader loaded with theReadRangesalready registered for the same file and adds only the new bytes to the input (or duplicated) bytes. So a stream shared by several columns (n.size0,sands.sizeof asingle_streamString), a block shared by the columns of a compact part, and a block loaded by several granules or readers are charged once.registerReadRangesis pure virtual: every reader states what it loads.MergeTreeReaderIndexloads nothing from the part, andMergeTreeReaderTextIndexregisters what its fallback reader loads.estimateCompressedColumnSize, codec resolution per column, the ratio lookups, and the in-memory sizing of read columns inMergeTreeReadersChain. Output sampling stays.A granule served from the columns cache loads nothing from the part and can't be measured, so a reader that collects the statistics doesn't read from the columns cache (it still writes to it). The columns cache is experimental and off by default, and this change is meant for a backport to 26.10, where it stays off; pricing cache hits can lift this in a follow-up.
Results on a local server, recorded input against
ReadCompressedByteswith a string filter: wide part 12,463,758 against 12,463,758 (0.40 MB before), compact part 12,490,572 against 12,490,939 (0.05 MB before), wide part with two columns 12,777,620 against 12,777,620. The two halves of a lazily materialized duplicated read share one registry, so the blocks both load are counted once.Tests:
05443_autopr_input_bytes_estimation_string_filters_during_scan,05452_autopr_subcolumn_input_bytes,05838_autopr_duplicated_lazy_read_counted_once.Stacked on this PR, each on the previous one, to be merged and backported with it:
automatic_parallel_replicas_max_counted_ranges); past the limit the input is not measured.Workflow [PR]
Sync PR [sync-upstream/pr/127586]