Repository navigation
Conversation
…m` state type `argMinState(map(1, 2))(...)`, and the same call on `argMax`, on the aliases `argAndMin`, `argAndMax`, `min_by`, `max_by`, and on `intervalLengthSum`, produced a state type printed as `AggregateFunction(argMin([(1, 2)]), UInt64, UInt64)`. A table created from such a state is accepted and queryable, and its own metadata then fails to parse, so the table does not load on `ATTACH` or at server start and recovery needs hand-editing the metadata `.sql`. Root cause: ClickHouse#110143 changed both constructors to forward the caller's parameters to the base class, which it must do because `AggregateFunctionArray` throws `LOGICAL_ERROR` when `parameters != nested_func->getParameters()`. `IAggregateFunction::getStateType` then puts those parameters into `DataTypeAggregateFunction`, whose name renders each one with `FieldVisitorToString`, under which a `Map` becomes `[(1, 2)]`. On reload `parseFieldFromCastedLiteral` accepts only an `ASTLiteral` or a two-argument `CAST` of a literal, so that spelling is rejected with `Code: 36`. Both classes already dropped the parameters in `getNormalizedStateType`; `getStateType` was never given the same treatment, and that inconsistency is the defect. Neither function ever reads a parameter, so `getStateType` is overridden in both classes to build the state type with an empty parameter list, mirroring each class's existing `getNormalizedStateType`. `getParameters` is untouched, so the wrapper-vs-nested parameter equality that `AggregateFunctionArray` asserts, and that ClickHouse#110143 exists for, keeps holding. The printed state type returns to exactly what master printed before ClickHouse#110143, a name the parser already accepts. Test 04368 pinned the two parameterized state-type names that this changes, so its reference is updated and three comments that became false are corrected. New test 05076 covers the printed state type for both families and a `DETACH`/`ATTACH` reload. Combinator- and adapter-wrapped state types (`-If`, `-OrNull`, `-Distinct`, `-ForEach`, `-Array`, and the implicit null adapter used when an argument is `Nullable`) build their state type from the wrapper's own parameters and still carry the `Map`. That is unchanged here: it is measured byte-identical on a pre-ClickHouse#110143 build, so it is not this regression, and it is not fixable by propagating through `getNestedFunction` because `AggregateFunctionResample`'s own parameters determine its state size. Related: ClickHouse#118006 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewAn independent cold review and a second-model gate ran against this diff over two rounds before it ❌ "The state-type policy is bypassed for
An earlier round raised the column-vs-type name divergence: it was measured on pre-fix and post-fix |
|
Workflow [PR], commit [0d5173b] Summary: ✅
AI ReviewSummaryReviewed #118156 at State-name consumers traced: metadata parsing and binary type decoding preserve legacy declarations; Final VerdictStatus: ✅ Approve |
|
cc @Algunenano @rschu1ze, could you review this? |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionsArgMinArgMax… |
17.38 MiB | 16.80 MiB | -596.93 KiB (-3.35%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniq.cpp.o |
14.67 MiB | 14.73 MiB | +62.86 KiB (+0.42%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionCovar.cpp.o |
7.52 MiB | 7.56 MiB | +47.23 KiB (+0.61%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionCorr.cpp.o |
7.73 MiB | 7.78 MiB | +46.94 KiB (+0.59%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupArrayMov… |
6.38 MiB | 6.42 MiB | +42.29 KiB (+0.65%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupNumericI… |
6.09 MiB | 6.12 MiB | +31.64 KiB (+0.51%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSum.cpp.o |
4.28 MiB | 4.31 MiB | +29.25 KiB (+0.67%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionIntervalLengt… |
1.01 MiB | 1008.43 KiB | -28.23 KiB (-2.72%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.36 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.36 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.36 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.35 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.35 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.35 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.52 MiB | 3.54 MiB | +24.35 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined2… |
3.51 MiB | 3.54 MiB | +24.35 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.51 MiB | 3.54 MiB | +24.35 KiB (+0.68%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionAvgWeighted.c… |
14.82 MiB | 14.85 MiB | +22.33 KiB (+0.15%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionQuantileExact… |
3.45 MiB | 3.47 MiB | +20.39 KiB (+0.58%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/Combinators/AggregateFunctionR… |
265.18 KiB | 284.83 KiB | +19.66 KiB (+7.41%) |
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.78 (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&) |
7.3 s | 15.2 s | +9.4 s (+165%) |
Compile time of recompiled translation units
336 translation units recompiled, 3304 s compile time in total, 336 of them have a recent master baseline.
|
The combinator- and |
|
Thanks, that is the right split. I added Two in-tree constraints, since the issue offers rejecting the ignored parameters as one of the two ways out. #110143's own test records why they are accepted rather than rejected: hard-rejecting them would make legacy |
`argMin`, `argMax` and `intervalLengthSum` accept parameters but never read them. ClickHouse#110143 started preserving them in `getParameters()` (the -Array combinator requires the wrapper's parameters to equal the nested function's), and this PR kept them out of the state type. The name that travels with a state serialized into a `Field` is built separately, in `ColumnAggregateFunction::getTypeString()`, straight from `getParameters()`, so it still spelled them out and disagreed with the state type: CREATE TABLE t (s AggregateFunction(argMin, UInt8, UInt8)) ENGINE = Memory; INSERT INTO t VALUES (arrayReduce('argMinState(map(1, 2))', [1, 2], [1, 2])); -- Code: 43, Cannot insert field with type AggregateFunction(argMin([(1, 2)]), UInt8, UInt8) -- into column with type AggregateFunction(argMin, UInt8, UInt8) SELECT dynamicType(x) FROM VALUES('x Dynamic', (arrayReduce('argMinState(map(1, 2))', [1, 2], [1, 2]))); -- Code: 36, Expected a literal or a CAST of a literal, got '[(1, 2)]' A `Map` parameter renders as `[(1, 2)]`, which the `AggregateFunction` type parser rejects, so every consumer that re-derives a type from that name fails: `ColumnAggregateFunction::insert`, `convertFieldToType`, and `FieldToDataType` when `Dynamic`/`Variant` discovers the variant type. State a single property instead of duplicating the parameter list: `areParametersPartOfState()` replaces the two per-function `getStateType()`/`getNormalizedStateType()` overrides and also decides what the column prints, so both carriers agree by construction. `getParameters()` keeps returning the real parameters, so the -Array invariant is untouched. Combinator-wrapped shapes (`argMinIfState`, `argMinArrayState`, ...) build their state type from the wrapper's own parameters, fail the same way on master, and are unchanged here; they are tracked in ClickHouse#118168. A name that still spells those parameters (declared metadata, a binary encoded type, an older server) denotes the same state, and `nameMatchesState` cannot recognise it because it starts by parsing the name, so `acceptsStateTypeName` compares that spelling verbatim as well.
`ColumnAggregateFunction::insert`/`tryInsert` and `convertFieldToType` both answer the same question - does the state name carried by a `Field` denote this function's state - and each had its own answer. The column additionally accepted a name that still spells parameters the function never reads, `convertFieldToType` accepted an exact name or `nameMatchesState` only, so the two rules could drift apart. Move that tolerance into `nameMatchesState`, which both call. The spelling compared verbatim is now the one `DataTypeAggregateFunction` renders rather than the column's own, which matters because the only producer of such a name is a type whose parameters the factory kept (a type decoded from the binary encoding), and that type renders its name through `shouldPrintParametersWithTypes`. Measured on every reachable shape (a `Dynamic` MergeTree part written by a build that carries the regression and read back, a state Field converted to its state type, `VALUES`, `IN`, `CAST`, merge): identical results before and after, so this is a consolidation, not a behaviour change.
The rule accepts a state name that spells parameters the function never reads, which is how a `Field` taken from a type decoded with those parameters still matches the state type that drops them. No SQL construct produces such a name (a `Map`-parameterized `AggregateFunction` type cannot be declared, and the column stamps the parameterless spelling into every `Field`), so a unit test is the only way to pin it. Verified live: with the verbatim comparison in `nameMatchesState` removed, the test fails on `tryInsert`. Both carriers are asserted, `ColumnAggregateFunction::tryInsert` and `convertFieldToType`, plus a negative control naming a different function's state.
`.claude/CLAUDE.md` asks for literal class and function names inside inline code blocks, and for a function to be named `f` rather than `f()`.
The mechanism it narrated is in the commit that added the test.
…type A combinator and the adapter for `Nullable` arguments are constructed with the caller's parameters, so `argMinIfState(map(1, 2))(a, b, cond)` and `argMinState(map(1, 2))(toNullable(a), b)` kept writing `AggregateFunction(argMinIf([(1, 2)]), ...)` into the table metadata - a type the parser rejects, so the table could not be attached and did not load after a restart, while the bare call was already clean. The wrappers now answer for the function they wrap, as they do for `shouldPrintParametersWithTypes`. `-Resample`, the one combinator that takes parameters of its own, answers for those itself. Closes: ClickHouse#118168
|
📊 Cloud Performance Report 🟢 AI verdict: This PR changes which parameters appear in aggregate function state type names: argMin, argMax and intervalLengthSum now leave out parameters they never read, and combinators follow the function they wrap. It does not change how aggregation itself runs, and no ClickBench or TPC-H query builds or names -State types. ClickBench Q20 shows a large, consistent -43.6% with CPU time roughly halved, so its verdict stands under the hard trust rule, but this diff gives no explanation for it. Check the baseline build or rerun before crediting this PR. Q33 and Q34 (about -7%) fall inside master's normal variance band and correctly show no change, and Q28 is borderline. None of the three can be linked to this diff. clickbench🟢 1 improved · Flagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
`-Resample` is constructed with the wrapped function's parameters followed by its own `(begin, end, step)`, and `transformParameters` strips just the last three before building the nested aggregate; `-Tuple` builds one nested function per tuple element and answers for none of them. Both therefore kept a parameter the wrapped function never reads: `argMinResampleState(map(1, 2), 0, 2, 1)(...)` and `argMinTupleState(map(1, 2))(...)` announced `AggregateFunction(argMinResample([(1, 2)], 0, 2, 1), ...)` and `AggregateFunction(argMinTuple([(1, 2)]), ...)`, types the parser rejects, so a table holding such a state could not be attached and did not load after a restart - the shape the bare call and the other wrappers no longer write. A boolean cannot express which parameters those are, so the property is now the set itself: all of them by default, none for a function that ignores them, for `-Resample` its own three plus whatever the wrapped function answers for, and for `-Tuple` the answer of an element that has a state. Both carriers of a state name read the same set, and `begin`, `end` and `step` still belong to it, so states over different resample ranges keep different types. A tuple whose every element is only-null keeps its parameters as before: each element is then the placeholder that deliberately carries the caller's list, as `04057_aggregate_function_nothing_with_parameters` pins, and no element is left to say that the parameters go unread.
|
@groeneai, fix conflicts. |
Two conflicts, both in the state-name printer this branch shares with ClickHouse#119810 (merged as d9c814e), which took the DataTypeAggregateFunction::formatParameters helper out of this branch: - src/Columns/ColumnAggregateFunction.cpp: master now calls the shared helper with getParameters(). This branch exists to print getStateParameters() there instead, so the argument is kept and the rest of master's hunk (the SipHashingWriteBuffer change to updateHashWithValue) is taken as is. - src/Columns/tests/gtest_column_aggregate_function.cpp: both sides appended a test at the end of the file. Both are kept; they cover different printers, quantile with a Decimal level from master and an argMin state name carrying a Map parameter here. Nothing else conflicted: the formatParameters consolidation and its comments are already on master in identical form, so the merge drops this branch's copy of them and keeps only the getStateParameters mechanism plus the parameter-tolerant nameMatchesState. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Conflicts resolved in 750e956 (merge of master, no force-push). Both were in the state-name printer this branch shares with #119810, which took
The merge drops this branch's now-redundant copy of |
Picks up the revert of the 05147 granule assertions (ClickHouse#121135), which broke Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) on master and on every PR whose merge ref predated it.
CI finish ledger - 750e956Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260920-123139 |
CI finish ledger - 07c65e6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260920-160237 |
|
🕵 @groeneai, investigate the failure: |
|
The fix in progress is #123926 (yours, lazy On #123926's own CI, #123926 does not touch |
# Conflicts: # src/AggregateFunctions/IAggregateFunction.h # src/Columns/ColumnAggregateFunction.cpp
Master added `getStateTypeWithVersionOf` (and the same logic in `AggregateFunctionTuple::getStateType`), which built the state type of pass-through combinators from the raw `parameters`. That bypassed `getStateParameters`, so `argMinIfState(map(1, 2))(...)` and other wrapped states again carried the unread `Map` parameter, failing `05180_wrapped_aggregate_state_map_parameter` in Fast test. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118156&sha=latest&name_0=PR&name_1=Fast%20test PR: ClickHouse#118156 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Fast test failed on |
`AcceptsStateNameSpellingUnreadParameters` asserted that `DataTypeFactory` cannot parse the decoded type's name, `AggregateFunction(argMin([(1, 2)]), UInt8, UInt8)`. Since ClickHouse#121725 taught `parseFieldFromCastedLiteral` to read `array`/`tuple` parameters, that name parses, so the precondition fails in all unit test jobs once master is merged. The precondition only documented which branch of `nameMatchesState` accepts the Field. The behaviour the test pins does not depend on it: the state type still drops the unread parameter, both carriers still accept the decoded Field, and the `argMax` name is still rejected. On master the acceptance now goes through the parse branch; on a branch without ClickHouse#121725 it goes through the verbatim comparison. The headers of 05076 and 05180 no longer claim the parser rejects the name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 6880b4dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The five builds started at 22:43Z on 2026-10-13, in the 22:30-23:00Z wave in which Session id: cron:our-pr-ci-monitor:20261014-053008 |
# Conflicts: # src/AggregateFunctions/Combinators/AggregateFunctionTuple.h
CI finish ledger - 223b870Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261108-193008 |
…pe-parameters Resolved conflicts by keeping the `getStateParameters` overrides of this PR and adopting the `[[nodiscard]]` annotations from master. Master removed `forEachNestedFunction`, so it is dropped from `AggregateFunctionTuple.h` too.
Closes: #118168
Related: #118006
Related: #110143
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
argMin,argMaxandintervalLengthSumno longer put their unread parameters into the state they produce, neither into the state type nor into the name a serialized state carries, so aMapparameter no longer creates a table that cannot load or a state that cannot be inserted back. This also covers such a state behind a combinator (argMinIfState(map(1, 2))(...)) or behind the adapter forNullablearguments, which is a bug of released versions.Description
argMinState(map(1, 2))(...), and the same call onargMax, its aliases andintervalLengthSum, producedAggregateFunction(argMin([(1, 2)]), UInt64, UInt64). On 26.9 a table built from such a state is accepted and queryable, then fails to load onATTACHand at server start. The same name breaks two more user-reachable paths. Since #121725 such names parse, so master no longer fails on these, bare or wrapped; there this PR only drops the unread parameter from the state type and the state name.The two other carriers
Root cause: #110143 forwards the caller's parameters to the base class in both constructors, and a
Maprenders as[(1, 2)], whichparseFieldFromCastedLiteralrejected before #121725. That name is built twice - once for the type, once for the column that stamps it into every state serialized into aField- so both spellings had to change.Neither function reads a parameter, so
getStateParametersnames what a state depends on - nothing here - and both spellings follow it.getParametersis untouched, so the equalityAggregateFunctionArrayasserts, which #110143 exists for, keeps holding.Combinator- and adapter-wrapped states (
-If,-OrNull,-Distinct,-ForEach,-Array, the null adapter for aNullableargument) had the same defect for another reason: each is constructed with the caller's parameters, so it carried theMapeven where the function it wraps does not. That leg fails on a pre-#110143 build too (reported in #118168) and is fixed here: a wrapper answers for the function it wraps.-Resampleand-Tupledo not pass the caller's list on unchanged:-Resamplekeeps its trailing(begin, end, step),-Tuplefollows the elements that have a state. A tuple of only-null elements keeps them: every element is then the placeholder that deliberately carries them.Workflow [PR]
Sync PR [sync-upstream/pr/118156]