Repository navigation
Conversation
…; r8 test cases Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 04711: the two push-down rows pin serialize_query_plan = 0. The distributed plan CI suites set serialize_query_plan = 1 in the server profile (tests/config/users.d/distributed_plan.xml), and the push-down is off for plans that can be shipped, so the okv row printed 0 there. - ReadFromMergeTree part guard: compare the types of the read columns only, instead of iterating every column of every part (parts x table columns). - tryPushDownSubcolumnsToReading: return before cloning the DAG when no node of the step is a subcolumn read of an input (a necessary condition of collectSubcolumnReads). - 05507: forced partition-key and set/text index checks through a subquery for k3, k3w, k5s, k5w. - 05337: say why the last query disables the push-down. Co-Authored-By: Claude Opus 5.5 <[email protected]>
05507: the K3 (partition key over the whole tuple) and K5 (set index over the whole tuple and over a Nullable) refusals get a plan check of the prewhere filter column, which keeps getSubcolumn over the whole column when the plain read is refused. The Output lines cannot show it, since the filter moves to PREWHERE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove three comments in pushDownVolumeReducingFunctions.cpp that restate the code below them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 1-3 of this PR's review)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261104-194200 |
|
cc @KochetovNicolai @vdimir, could you review this and add the |
|
Workflow [PR], commit [bbdd89c] Summary: ❌
AI ReviewSummaryReviewed commit Final VerdictStatus: ✅ Approve. |
The byte limit checks read `min(length(s))` above the join so that the 1 KB column stays in the rows the join emits. With the subcolumn push-down `length(s)` reads only `s.size` through the non-padded side of the join, so the rows are 8 bytes and the padded blocks are no longer cut by `max_joined_block_size_bytes` (Fast test: `unmatched probe rows, bytes` and `unmatched build rows, bytes` print 0). The checks now compare the whole column, which brings it back to the join (max block 9 rows, as on master). The reference is unchanged. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129422&sha=0ca909af4598d2dce65eefd65d0065d54e1c3ea8&name_0=PR Co-Authored-By: Claude Opus 5.5 <[email protected]>
`FunctionToSubcolumnsPass` reads `vec.N` for `tupleElement(vec, N)` (and `vec.N`) over a `QBit` column read directly from a table, but through a subquery the read still took the whole column. The plan-level matcher now accepts that form too, with the same element name check (`getElementSubcolumnName` for `QBit`) and the same storage substream check as the direct rewrite. It is a function form, so the existing guards for keys, skip indexes (including vector similarity ones), projections and `FINAL` apply. `05507` gets a case that reads `vec.1, vec.9` instead of `vec` with identical results; the binary without this change prints `vec`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `skip_empty_columns_on_insert = 1` and `serialization_info_version = 'with_missing_columns'`, a column whose values are all defaults is not written to the part; `serialization.json` records it in `missing_columns` with the type it had at write time, and `IMergeTreeReader` fills it with that type's default and then converts it to the current type. After a metadata-only type change (`MODIFY COLUMN data JSON(a String)` with `enable_json_lazy_type_hints = 1` over a `JSON(a UInt32)` part) the whole column reads `a = '0'`, while a subcolumn read takes `data.a.size` from the frozen default and returns 0. The part guard skipped columns absent from the part, so `length(data.a)` through a subquery returned 0 with the push-down and 1 without it. The guard now also compares the recorded type of an omitted column with the metadata type, as it already does for a column the part stores. Case N11b in 05507 is the reproducer (the binary before this change reads `data.a.size` and prints `[(0),(0)]`). Found by the clickhouse-gh review on ClickHouse#129422. 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 sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/pushDownVolumeReducingFunctions.cpp.o |
129.35 KiB | 607.27 KiB | +477.91 KiB (+369.47%) |
src/CMakeFiles/dbms.dir/Analyzer/Passes/getSubcolumnOfFunction.cpp.o |
new | 99.93 KiB | +99.93 KiB |
src/CMakeFiles/dbms.dir/Processors/QueryPlan/ReadFromMergeTree.cpp.o |
2.57 MiB | 2.62 MiB | +45.89 KiB (+1.74%) |
src/CMakeFiles/dbms.dir/Analyzer/Passes/FunctionToSubcolumnsPass.cpp.o |
466.76 KiB | 421.27 KiB | -45.49 KiB (-9.75%) |
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Slowest function optimization changes (ThinLTO)
Median per-function time ratio to the master baseline: programs/clickhouse ×0.58, programs/clickhouse-keeper ×0.59 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.
| Binary | Function | Master | PR | Δ vs median |
|---|---|---|---|---|
programs/clickhouse |
DB::registerFunctionConversion(DB::FunctionFactory&) |
6.4 s | 10.5 s | +6.8 s (+181%) |
programs/clickhouse |
_ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… |
3.5 s | 7.2 s | +5.1 s (+250%) |
Compile time of recompiled translation units
232 translation units recompiled, 2330 s compile time in total, 231 of them have a recent master baseline.
| Translation unit | Master | PR | Δ vs median |
|---|---|---|---|
src/Processors/QueryPlan/Optimizations/pushDownVolumeReducingFunctions.cpp |
4.3 s | 13.8 s | +9.6 s (+228%) |
The flaky check runs each changed test in 8 parallel copies with the thread fuzzer on, and 05507 took 187-217 s per run in the amd_debug, amd_binary and amd_asan_ubsan flaky checks, over the 180 s limit. Its 617 statements are evenly cheap (the job's query_log shows no dominant query), so the cost is the statement count. The cases are moved, not changed, into three files along their fixtures: plan cases on the basic shapes (P1-N-ADD, N-ADD2), on-the-fly changes, part formats, projections and read in order (N9-N31), and keys, indexes and projections (K1-K8, P36-P39). Every statement of the old file appears exactly once, and the three references reassemble into the old reference; the only new line is a label for the K8 projection check, which moved next to K8. Locally, at 8 concurrent copies with the thread fuzzer's sleeps, the old file took 27.1 s (median of 8) and the new ones 11.2, 6.6 and 9.2 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Map key of type LowCardinality(FixedString(N)) passed the width check,
so `m['ab']` over `Map(LowCardinality(FixedString(4)), V)` read through a
subquery was rewritten to the subcolumn `m.key_ab\0\0`: the constant is
padded to the key width, and a key 'ab\0\0' then matched although
`arrayElement` returns the default for it (99 instead of 0). The same for
a FixedString constant of another width (`m[toFixedString('ab', 3)]`).
Reported by the AI review on ClickHouse#129422. Test cases N19b (refused short key)
and P41 (a full-width key is still read as the key subcolumn).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The part check of `canReadSubcolumnsOfColumn` looks only at the parts of the planning snapshot, but a `STREAM` read also reads the parts committed later. A compact part without substream marks inserted into a running stream cannot read `s.null` of a sparse `Nullable` alone, so `SELECT s.null FROM (SELECT * FROM t STREAM)` failed with NOT_IMPLEMENTED while the same query with the push-down off returned all rows. Refuse the rewrite for every stream read. 05509 inserts such a part after the stream has read the first one: it fails with the error on the previous commit and returns the rows now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The push-down of subcolumn reads is off when parallel replicas are used, so in the ParallelReplicas CI job (parallel replicas on in the server profile) the row that expects `arr.size0` in the plan of a read through `okv` printed 0. Pin the setting on that row and on its negative pair for `vw`, like `serialize_query_plan = 0` is already pinned for the distributed plan jobs. Reproduced locally with the job's settings at both `parallel_replicas_local_plan` values: the old rows fail with the same diff, the pinned rows pass (also 50/50 randomized with and without parallel replicas), and dropping the pin fails again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-to-reading Needed for the bucketed-only gate of ClickHouse#124553 (`IStorage::hasBucketedMapSerialization`), which the push-down of `m['key']` to a key subcolumn has to apply as well: with it merged, a basic `Map` read through the push-down gets the key-subcolumn rewrite again (Fast test 03989 and 05340). Co-Authored-By: Claude Opus 5.5 <[email protected]>
ClickHouse#124553 rewrites `m['key']` to the key subcolumn `m.key_<key>` only when the table writes Maps with buckets: with the basic serialization the key subcolumn reads the whole Map anyway. The push-down matched `m['key']` regardless, so on a basic Map it brought the rewrite back, both for a read through a subquery and for a direct read whose rewrite FunctionToSubcolumnsPass had just declined (Fast test 03989 and 05340 on the merge with master). Refuse the key-subcolumn form unless `MergeTreeData::hasBucketedMapSerialization`. 05507: the tables whose cases expect `m.key_*` pin both Map serialization settings to `with_buckets` (clickhouse-test randomizes them), and a new case N32 reads `m['k1']` of a basic Map through a subquery. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The filter push-down can move `WHERE s.tup.a` below a join as a filter whose filter column is the subcolumn read `getSubcolumn(__table1.tup, 'a')` itself, removed after filtering, while the step above the join reads the same subcolumn again. The rewrite turned both reads into one carried column and made the join return it, but the filter still removed it, so the join's input had no column for its DAG input: `The header [__table1.id] has a column for only 1 of the DAG's 2 inputs` (AST fuzzer, STID 2728-49fe), and NOT_FOUND_COLUMN_IN_BLOCK when building the join pipeline. Refuse the rewrite when a filter on the path removes a filter column that a step above reads as a carried column. Other columns of the same read are still pushed down (N33: `n` is read whole, `tup.a` as a subcolumn). Co-Authored-By: Claude Opus 5.5 <[email protected]>
`SELECT tup.a FROM (SELECT * FROM t PREWHERE tup.a < 3)` aborted in `tryPushDownSubcolumnsToReading` with `std::out_of_range` (`unordered_map::at: key not found`), AST fuzzer STID 2508-34fb. PREWHERE `tup.a < 3` makes `ReadFromMergeTree` read the subcolumn `tup.a` itself and drop it after the filter, so its output has `tup` but not `tup.a`. `addReadColumn` returns early for a column the read already reads, so it does not pass `tup.a` through the PREWHERE actions, and after `readSubcolumnsInsteadOfColumn` the output still lacks it. A row policy on the subcolumn (`row_level_filter`) does the same. Refuse the push-down when a subcolumn it would read is already read but missing from the read's output. The query then reads the whole column, as master does. Cases that read the subcolumn for the first time are unchanged. New cases in 05507: N34 (PREWHERE on `tup.a` two subqueries down) and N35 (row policy on `t2` using `tup.a`). Both abort the pre-fix server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`tryPushDownSubcolumnsToReading` rewrote one column per call and returned, so a query reading subcolumns of N columns through a subquery applied the optimization N times, and each time cloned and re-analysed every step of the path for each column: planning time grew quadratically with the projection width. With 1000 `String` columns, `EXPLAIN SELECT length(s0), ..., length(s999) FROM (SELECT * FROM t)` took 11.0 s instead of 0.08 s (debug build), and a query with enough such columns failed with TOO_MANY_QUERY_PLAN_OPTIMIZATIONS. The columns are now followed down the plan together and grouped by the read and the path they come from. A group is analysed in one pass over the steps of the path: a column that fails a check is dropped and the others are analysed again, and the rest are rewritten at once, with one `Read subcolumns` step and one pruning of the read (`ReadFromMergeTree::readSubcolumnsInsteadOfColumns`). If the steps take each column alone but not all of them together, the columns are tried one by one, as before. Planning time on vs off (debug, EXPLAIN): 1000 String columns 0.085 s vs 0.072 s, 2000 columns 0.182 s vs 0.153 s, `.a` of 1000 Tuple columns 0.103 s vs 0.097 s. 05507 P42: all 40 columns are pushed down with `query_plan_max_optimizations_to_apply = 10`; before, EXPLAIN pushed 4 of them and the query failed with TOO_MANY_QUERY_PLAN_OPTIMIZATIONS. P31 now has one `Read subcolumns` step for its two columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The table that this PR added to push_down_volume_reducing_functions.xml has a `JSON` column, which the Iceberg rewrite of the perf runner cannot map, so all six `Performance Comparison (..., iceberg_local|iceberg_s3, k/3)` jobs failed with `IcebergRewriteError: Column data of type JSON has no Iceberg equivalent`. Skipping push_down_volume_reducing_functions.xml would also stop the Iceberg configuration from measuring its existing queries, which it runs today. So the new table and its four queries move unchanged into push_down_subcolumns_to_reading.xml, which is added to iceberg_skip_list.txt with the reason `JSON column`, and push_down_volume_reducing_functions.xml is back to its master content. The push-down reads subcolumns only from MergeTree, so nothing of it is measurable on Iceberg tables anyway. The new file does not inherit `optimize_functions_to_subcolumns = 0` from the old one. The three plain subcolumn reads do not depend on it (`getSubcolumn` is matched before the function-form check, and their query trees are identical with 0 and 1), and the `length(arr)` query keeps its own `optimize_functions_to_subcolumns = 1`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - bf32767Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261106-150005 |
# Conflicts: # src/Processors/QueryPlan/Optimizations/pushDownVolumeReducingFunctions.cpp
… APIs changed in ClickHouse#129617 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
|
🕵 Merged |
Closes: #75538
Closes: #92455
Closes: #107038
Related: #112688
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Read only the requested subcolumns of columns returned by subqueries, CTEs, views,
UNION ALLbranches and the non-padded sides of aJOIN: for example,SELECT data.a FROM (SELECT * FROM t)andSELECT length(arr) FROM (SELECT * FROM t)now read onlydata.aandarr.size0from aMergeTreetable, and skip indexes and the primary key over a subcolumn are used through a view. It is controlled byquery_plan_push_down_volume_reducing_functions.Description
A re-implementation of #112688 as a query plan optimization, the design @ novikd proposed there.
FunctionToSubcolumnsPassstill rewrites direct reads.Through a subquery,
x.pisgetSubcolumn(x, 'p')over the whole column, andFunctionToSubcolumnsPassrewriteslength(arr),isNull(n),m['k'], ... only for direct reads, soReadFromMergeTreereads the whole column (forJSON, all paths).tryPushDownVolumeReducingFunctionnow first follows a column that only subcolumn reads use from the topExpression/Filterdown throughExpression,Filter,Sorting,Limit,Offsetand the non-padded side ofJoinStepLogicaltoReadFromMergeTree, which then reads the subcolumns. The whole path is rewritten at once, so no other optimization sees an intermediate state. Residual functions (empty(arr)isarr.size0 = 0) stay in their step, and the top header is unchanged.UNION ALLbranches are handled byliftUpUnion.It is not applied (whole column read as before) to plans shipped to other servers,
FINALof engines that combine values, tables with changes applied on the fly (pending mutations withapply_mutations_on_fly, unmerged patch parts) or masking policies, parts whose stored type differs from the table's, compact parts without substream marks, paddedJOINsides, non-MergeTreesources, function forms over columns used by keys, skip indexes or projections, and plain reads over columns of the partition key, aggregate projections orsetindexes.Validation:
05507compares the read columns and results with the setting off for each case;05508checks read bytes drop 10x. The tests of #112688 and #94105 give the same results with the setting on and off. Locally,SELECT data.k0 FROM (SELECT * FROM t WHERE key % 2 = 0)reads 63 MB instead of 507 MB.Workflow [PR]
Sync PR [sync-upstream/pr/129422]