Repository navigation
Cherry pick #118988 to 26.9: Name a Dynamic constant's active member type in the shard-facing literal - #125066
Merged
robot-clickhouse-ci-2 merged 26 commits intoNov 3, 2026
Merged
Conversation
columnConstantToExactLiteralASTImpl's TypeIndex::Dynamic branch recursed into the
active member and emitted its bare literal without naming the member's type, so a
secondary server rebuilt the Dynamic from whatever the literal infers back to:
Enum8('7' = 3) became UInt8, Date32 became String, Array(UInt64) became
Array(UInt8). The Variant branch three cases above already names its member type,
which is why a Variant carrier survived the round trip and a Dynamic one did not.
Consequence on any Distributed / remote() / cluster() read: col = <Dynamic
constant> raised NO_COMMON_TYPE on the shard while the same predicate was correct
locally, because the comparison substitutes the active member's type
(FunctionDynamicAdaptor) and getLeastSupertype counts Enum as String-compatible
but not UInt8; and anything the shard computed from the value's own type saw a
type the initiator never held.
Name the member's own type and the Dynamic type at both value exits of the branch,
gating member naming on an allow-list, literalIdentifiesValue, whose default is
"do not name". Naming a type the literal does not determine would invent a value
rather than preserve one: a DateTime renders as local text shared by both instants
of a DST fold, an AggregateFunction state is re-read according to
aggregate_function_input_format, a JSON's dynamic paths are re-inferred from their
tokens, and a String source is re-parsed under
cast_string_to_dynamic_use_inference. Those families keep exactly today's
behaviour; an allow-list is closed under the classes nobody has audited yet,
whereas an exclusion list is not.
Naming the Dynamic type itself is required, not redundant: array and map resolve
their result type from their arguments, so a member that is itself a container of
Dynamic keeps that element type only if every element arrives named as Dynamic.
The declining comment this replaces was written deliberately, in a decimal-focused
PR; its stated reason (naming changes the stored subtype of values whose literal
infers back wider or narrower) is factually right and is precisely the intent, the
change being toward the initiator's own subtype.
Measured, remote versus a purely local read of the same constant, across 34 member
types and both code sites: 6/34 faithful before, 26/34 after, 20 rows repaired, no
new divergence, and every still-diverging row byte-identical to before. The IN leg
is NOT fixed here: it additionally needs the active-alternative hint in
convertColumnToType, so this change does not close it.
ConstantNode::toASTImpl's non-exact path needs no counterpart: typeMayContainDecimal
includes isDynamic() and is applied with forEachChild, so any type containing a
Dynamic takes the exact path first.
Co-Authored-By: Claude Opus 5 <[email protected]>
Follow-up to the previous commit on this branch, which named both the active member's type
and the Dynamic type itself, and named a member wherever it appeared. Two further rounds of
measurement narrowed that in three ways.
Stop naming the Dynamic type. Naming it at every node promotes an enclosing container's
element type to Dynamic, which routes an excluded member's bare text through the re-inferring
String -> Dynamic conversion in createColumnToDynamicWrapper. Measured: a DateTime at a DST
overlap came back at epoch 1698539400 where the initiator held 1698543000, an hour early and
with the same printed text, so a visible type mismatch became a silently different instant.
Dropping it also gives this branch the exact shape of the Variant branch three cases above,
which names its member type and not the Variant type. For a scalar constant the caller already
emits _CAST(..., 'Dynamic') and makeCastToTypeNameAST's identity dedupe collapses the pair.
Two types leave the allow-list, each because its text is not an injective carrier.
- Floats. Two distinct Float32 NaN payloads, 0x7FC00001 and 0x7FC01234, both reach a
secondary server as the canonical 0x7FC00000, because all four literals format as the
single text `nan`; formatFloat says so itself ("Roundtrip may lead to loss of precision",
FieldVisitorToString.cpp). isFloat() covers Float32, Float64 and BFloat16, so this also
correctly excludes Point, which is a Tuple(Float64, Float64).
- Date32. Its serializeText formats through writeDateText(ExtendedDayNum(...)), which
saturates at DATE_LUT_MAX_EXTEND_DAY_NUM, so day 2932996 and day 2932896 share the literal
`9999-12-31`; toDate32('9999-12-31') + 100 reaches that from plain SQL. ClickHouse already
classifies this: ToStringMonotonicity marks Date32 -> String non-injective and Date ->
String strict, because Date is a UInt16 whose whole domain the day LUT covers. Date stays.
A Dynamic nested inside array() or map() is no longer named at all. Those two resolve one
element type from all their arguments, so elements named as their own concrete types must
acquire a common type: Int64 and UInt64 siblings have none unless use_variant_as_common_type
builds a Variant for them, while master's unnamed literals simply widen. Measured on a mutant
without this rule: NO_COMMON_TYPE where master returns a row. tuple() is deliberately not
suppressed, because FunctionTuple keeps every argument's type independently and performs no
sibling conversion, and an IN list is serialized as a tuple.
Blast radius, measured as a value-and-type oracle over 34 member types at both code sites,
comparing a remote read against the purely local one: faithful round trips go from 6/34 to
21/34. Five families the previous commit repaired are no longer repaired, each for one of the
measured reasons above: Float32, BFloat16, Point, Date32, and the container-of-Dynamic shapes
(Array(Dynamic), Map(Dynamic, Dynamic)). All five are byte-identical to master, in value and
in reconstructed type, so nothing regresses relative to master. A Dynamic nested in a tuple
does move, from Tuple(UInt8) to Tuple(Int64), with its value unchanged.
The test grows to five cells. Cells 1 to 3 redden on pristine master. Cells 4 and 5 are
guards: each reads identically on master and here, and each fails a purpose-built mutant that
drops one of the two restrictions above, so neither restriction can be simplified away
unnoticed.
Co-Authored-By: Claude Opus 5 <[email protected]>
The previous commit stops naming a `Dynamic` member that sits inside `array()` or `map()`, and that restriction reaches the walker through three independently revertible call sites: array elements, map keys and map values. Only the array one was covered by a cell. The existing guard dies on a mutant that removes the restriction's single shared test, which disables all three at once, so it could not show that the two `map()` arguments still pass the flag: reverting just those two left the whole file green. Add one cell over a `Dynamic`-keyed, `Dynamic`-valued map. `map()` resolves one key type from all of its keys and one value type from all of its values, so the cell needs two entries; with a single entry there are no siblings to reconcile and the restriction is invisible. Measured on a mutant that reverts only the two `map()` call sites: the new cell raises `NO_COMMON_TYPE`, because the shard receives `map(_CAST(1, 'Int64'), _CAST(3, 'Int64'), _CAST(2, 'UInt64'), _CAST(4, 'UInt64'))` and `FunctionMap` then has to reconcile `Int64` with `UInt64` under `use_variant_as_common_type = 0`. That mutant fails this cell alone, while the mutant without the array rule fails the array cell alone, and the two die in different resolvers (`FunctionArray::getReturnTypeImpl` versus `FunctionMap::getReturnTypeImpl`), so the two arms are now pinned separately. The reference is taken from pristine master, which reads identically here: this cell is a guard, not a repair. Co-Authored-By: Claude Opus 5 <[email protected]>
The in-tree rulebook reached through the `AGENTS.md` symlink asks for ClickHouse names in comments to be written as inline code. The sibling comment on `nameDynamicMemberAST` and the pre-existing `Variant` comment further down already do, so this file disagreed with itself. Comment text only. The stripped token stream is identical to the previous commit's, and the recompiled object leaves the binary's build id unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
…cells `columnConstantToExactLiteralASTImpl` suppresses member naming inside `array` and `map`, whose element type is reconciled across all arguments, and deliberately does not suppress it inside `tuple`, which keeps each argument's type independently. Two shipped lines carried that distinction with no cell able to observe either: the `Tuple` case forwarding `inside_unifying_container` unchanged, and the shared binary variant's own value exit passing the flag separately from the regular member exit. Cell 6 is a repair cell for the `tuple` exception. An `Int64` and a `UInt64` member of a `tuple` both arrive named, so they coexist under `use_variant_as_common_type = 0`, where pristine master collapses both to `UInt8`. Cell 7 is a guard for the shared exit: a `Dynamic(max_types = 0)` inside an `array` has to stay unnamed, and its reference is taken from pristine master, which reads identically here. Measured on two further mutants, each one edit against this tree: - M4 forwards `true` from the `Tuple` case. Cell 6 alone reddens, reading `UInt8` for both members, and the shard receives `tuple(1, 2)` instead of `tuple(_CAST(1, 'Int64'), _CAST(2, 'UInt64'))`. - M5 hard-codes `false` at the shared exit's naming decision, leaving the inner recursion alone. Cell 7 alone reddens with `Code: 386 NO_COMMON_TYPE` from `FunctionArray::getReturnTypeImpl`, because the shard receives `array(_CAST(1, 'Int64'), _CAST(2, 'UInt64'))` where this tree sends `array(1, 2)`. The three earlier mutants keep their single cells: the one without the value-identifies test fails cell 8, the one without the container restriction fails cells 4, 5 and 7, and the one reverting only the two `map()` call sites fails cell 5 in `FunctionMap::getReturnTypeImpl`. Every arm returns the same values, `(1,2)` and `[1,2]`; only the member types differ. Co-Authored-By: Claude Opus 5 <[email protected]>
The in-tree rulebook reached through the `AGENTS.md` symlink asks for literal ClickHouse names in comments to be inline code spans, and the newest numbered stateless tests follow it, including the adjacent distributed sibling `05136_view_over_distributed_ships_filter_to_shards`. An earlier commit did this for `literalIdentifiesValue`'s comment and missed this file. Comment text only: type names, setting names, function names and `NO_COMMON_TYPE`. Wording and line breaks are otherwise unchanged, every executable line is byte-identical, and the `.reference` file is untouched. Co-Authored-By: Claude Opus 5 <[email protected]>
The comment enumerated only the value-carrying leaves, while the predicate also admits `String` and the wrappers `Nullable`, `Array`, `Tuple`, `Map` and `LowCardinality`. A reader comparing the two found `String` admitted here and string-like rejected a few lines below in `nameDynamicMemberAST`, with nothing connecting the two. Name the wrappers and point at where the top-level string-like case is decided. Comment text only: the token stream of this file, with string literals preserved, is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
…wn cell `nameDynamicMemberAST` declines to name a member on three independent conditions, and only two of them had a cell: the container restriction (cells 4, 5 and 7) and the value-identifies test (cell 8). Nothing caught the third, so a contributor collapsing three conditions to two by dropping the `isStringOrFixedString` disjunct would keep CI green while changing what a shard rebuilds, because `literalIdentifiesValue` accepts `FixedString(3)`. Cell 9 catches that deletion. Built against a tree with only that disjunct removed, the cell reports `FixedString(3)` where it reports `String` here, since with `cast_string_to_dynamic_use_inference` off the receiving cast keeps the name the initiator wrote. The cell reads identically on pristine master and on this branch, so it is a guard, not a repair. The `SETTINGS cast_string_to_dynamic_use_inference = 0` clause is what keeps that catch possible: measured with the setting on, the build missing the disjunct is indistinguishable from this one, because the receiving conversion re-parses the named `FixedString` back to the inferred type. A plain `String` member cannot serve here at all, since naming `String` changes nothing and such a cell reads the same on every build. The value fills the type exactly, so no padding reaches the reference. Cells 1 to 8 keep their numbers and their reference lines byte for byte. Co-Authored-By: Claude Opus 5 <[email protected]>
The comment gave one reason for skipping a string-like member: that the receiving cast re-parses it under `cast_string_to_dynamic_use_inference`. That holds only when the setting is on. With it off, which is the default, a named `FixedString` is not re-parsed, it sticks, so the sentence did not cover the case the new cell 9 measures. The property that does hold either way is that naming a string-like member would make the type arriving at the shard depend on a receiving-side setting, where leaving it unnamed gives `String` under both values. Comment text only. The comment-stripped, whitespace-collapsed token stream of this file is byte-identical across the edit, checked against two negative controls that do detect a one-token code change. Co-Authored-By: Claude Opus 5 <[email protected]>
…se AST
`getASTForExternalDatabaseFromQueryTree` lowers the query tree with `add_cast_for_constants = false`,
so a `Dynamic` constant reaches `ConstantNode::toASTImpl`'s exact-literal path and is returned as the
bare member AST that this branch now names. `ReplacingConstantExpressionsMatcherNumOrStr` then fires
on that `_CAST` function node, and for a member type `isNumber` rejects it re-serializes the folded
value as text: an `Enum8` becomes the enum's name, not its underlying value. Pushdown is only a
pre-filter, sound while the pushed predicate selects a superset of the one ClickHouse re-applies, so
pushing the name where the value was pushed before drops rows. Measured against a SQLite table
holding '7', '3' and 'x', with an `Enum8('7' = 3)` member: `IN (3)` returned row 3 and `IN ('7')`
returns nothing, `NOT IN (3)` returned 7 and x and `NOT IN ('7')` returns only x.
An external database has no `Dynamic` at all: it reads whatever literal arrives as text, so naming
the member is meaningless there by construction, the same way `_CAST` itself must not reach it. So
the external entry point is the one that declines, through a new `ConvertToASTOptions` flag threaded
into `columnConstantToExactLiteralAST`; every other caller keeps today's behaviour, `ReadFromRemote`
via the defaulted overload and the cross-replication lowering by not setting the flag.
The decimal, `DateTime64` and `Time64` carriers are deliberately left alone: master emits those on
the external path too, so suppressing them would change pre-existing decimal pushdown. The `=` shape
is restored to master's bytes as well, which means giving up an accidental repair: master's
`"field" = 3` is not a superset of `field = '7'` either, and fixing that is a separate question about
external pushdown for `Dynamic` constants, not about which literal this walker writes.
Co-Authored-By: Claude Opus 5 <[email protected]>
…e skip `literalIdentifiesValue`'s comment said naming a string-like member "cannot help", which is true of the value (the text is identical either way) and false of the type, which is exactly what `nameDynamicMemberAST`'s comment three lines below says naming would change. Only the parenthetical is rewritten, to point at the other block instead of pre-empting it. Comment text only. The comment-stripped, whitespace-collapsed token stream of this file is byte-identical across the edit, and a negative control that turns the same clause into one line of code does show a difference. Co-Authored-By: Claude Opus 5 <[email protected]>
…with its own case
`05138`'s `IN list` cell can only observe ROWS, and its local recheck repairs the fixture under every
mutation, so that cell reads `3` whether the pushed predicate is `IN (3, 4)`, `IN ('7', '3')`, or
absent altogether. The single-element cell is not blind (a named member pushes `IN ('7')`, SQLite
returns 7, the recheck rejects it and the cell goes empty), which is precisely why the multi-element
form needs an assertion of its own rather than inheriting confidence from its sibling. A
multi-element right-hand side travels as one constant `tuple`, so it is the only shape that observes
the member type being left unnamed inside `tuple` elements as well, and only the generated text can
show that.
Measured: the transformed query is `WHERE "field" IN (3, 4)`, the enum values. With the naming
opt-out ignored, the same list leaves as ONE quoted string holding the tuple's text,
`'(\'7\',\'3\')'`, which against a `TEXT` column matches no row at all; the three existing cells fail
differently, as `= '7'`, `IN ('7')` and `NOT IN ('7')`. The `TransformQueryForExternalDatabase` suite
is fully green with the new case, and red on that mutant alone.
Co-Authored-By: Claude Opus 5 <[email protected]>
`AGENTS.md` asks for `f` rather than `f()` in documentation, comments and commit messages, where the text names the function itself rather than its application. All four sites do: `materialize`, `dynamicType`, `array` and `map`. That is the complete set of parenthesised function names in this branch's whole diff; `05138`, the gtest and every `src/` comment were already clean. Comment text only. The comment-stripped, whitespace-collapsed token stream of the file is byte-identical across the edit, with a negative control changing one executable token to show the comparison does move, and a second control confirming a comment-text-only change does not. Co-Authored-By: Claude Opus 5 <[email protected]>
The `Dynamic` branch of the exact literal serializer has two value exits and each forwards `name_dynamic_member_types` on its own: the regular member exit and the shared-binary-variant exit that decodes `Dynamic(max_types = 0)` values. Every existing external-path case uses a default `Dynamic`, so all four of them traverse the regular exit only, and the one test that reaches the shared exit runs on the shard path where naming is enabled anyway. The whole suite therefore stays green if the shared exit stops honouring the opt-out, while an external database receives the enum's name `'7'` instead of its value `3` and the pushed predicate silently selects the wrong rows. The generated text was measured before the expected string was trusted: a temporary probe printed the transformed query for every case in the file, and the new one came out as `WHERE "field" = 3`. A single-exit mutant that hard-codes the shared exit's flag reddens this case alone.
A constant of type `Dynamic` whose active member is `Tuple(Dynamic, ...)` is only partly left alone. The `Tuple` branch recurses with the container flag unchanged, so the nested `Dynamic` elements are named one level down, and then the outer member type declines because a `Tuple` holding `Dynamic` is not a type whose literal identifies its value. The shard consequently rebuilds `Tuple(Int64, UInt64)` where master rebuilt `Tuple(UInt8, UInt8)`, while the initiator held `Tuple(Dynamic, Dynamic)`. Both arms carry the same values, so nothing a comparison can observe changes, but the rebuilt type moved and no cell was watching it. Both values are measured, not predicted: the statement was run on the shipped tree and on a pristine-master server, each with `buildId()` asserted first.
Master now carries the pieces a much smaller change needs: the `Variant` case of the exact literal serializer names both the member type and the whole `Variant`, and `date_time_as_numbers` already marks the one consumer (the external-database pushdown) that parses a literal itself instead of re-applying its declared type. So this reverts the six source files to the branch's merge base and drops the external-pushdown test. The `Dynamic` case is rewritten on top of current master in a following commit, which also rewrites `05137`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nt-active-member-type
… a shard
The exact literal serializer recursed into a `Dynamic` constant's active member
without naming its type, so the secondary server re-inferred it from the literal:
an `Enum8('7' = 3)` member arrived as `_CAST(3, 'Dynamic')` and was rebuilt as
`UInt8`, a `UInt64` as `UInt8`, an `IPv4` as `String`, a `Map` as an `Array` of
tuples. `IN` then compared against the wrong value, and `=` raised
`NO_COMMON_TYPE`.
Serialize the member the way the `Variant` case already does: name the member
type and then the `Dynamic` type, which also gives `array` and `map` siblings a
common type. The member is recursed with `date_time_as_numbers` forwarded, so a
`DateTime` member travels as its exact timestamp. When the flag is cleared (the
external-database pushdown, which parses the literal itself) the bare member
literal is kept, exactly as before.
This replaces the note added in #95055 that declined to name the member type.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erver Rewrites `05137` for the new serialization: one cell per face reported on #119745 (`=` and `IN` with an `Enum8` member, `Dynamic(max_types = 0)`, the `UInt64`, `IPv4` and `Map` members read through `dynamicType`), plus an `array` of two different member types, a `DateTime` from the repeated hour at the end of daylight saving time, a `DateTime` bound on a `Date` column, and the `=` cell read through parallel replicas. The reference is the fixed server's own output. Pristine master fails the file at the first cell with `NO_COMMON_TYPE`, and every other cell differs there too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…`05137` The `Dynamic` case forwards `date_time_as_numbers` separately at its regular and shared-variant exits, and only the regular one had a cell. Add the same `DateTime` from the repeated hour at the end of daylight saving time stored in a `Dynamic(max_types = 0)`: reverting the shared exit alone makes the secondary server read it one hour early. The parallel-replicas cell read locally whenever the runner drew `automatic_parallel_replicas_mode = 2`, which switches `enable_parallel_replicas` off for the query, so it passed without the fix in about a quarter of the runs. Pin `automatic_parallel_replicas_mode = 0` there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the local rows
An external database has no `Dynamic`, so the pushdown to it keeps the bare
member literal instead of naming the member type. Read an `IN` list of `Dynamic`
numbers from SQLite and locally: naming the members there folds the list into
one string, `IN ('(3,7)')`, and the external read loses both rows. Master and
this branch both push `IN (3, 7)`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…296` strict The parallel-replicas cell ran with `enable_parallel_replicas = 1`, under which the planner falls back to a local read when it declines parallel replicas, so the cell could pass without the fix. It already pins `automatic_parallel_replicas_mode = 0`, so nothing switches strict mode off: use `enable_parallel_replicas = 2`, where a declined plan raises. `05296` read SQLite with the default `external_table_strict_query = 0`, which drops a predicate that cannot be pushed and filters the fetched rows locally, so the file would pass if the `Dynamic` list stopped being pushed. The external read now sets `external_table_strict_query = 1`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the Dynamic member-naming comment to a two-line invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…TRICT so the filter is pushed down Without `STRICT`, `StorageSQLite` keeps the column local-only and `external_table_strict_query` rejects every filter on it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=gh-readonly-queue/master/pr-118988-b0918a446545249d7036492d6c3a601354532084&sha=5fdbd197e0eb9f485a48f617bbbf891288288bf1&name_0=MergeQueueCI&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29
…-member-type Name a `Dynamic` constant's active member type in the shard-facing literal
Resolve the cherry-pick of #118988 to 26.9. `src/Analyzer/Utils.cpp` merges cleanly. The only conflict is the doc comment above `columnConstantToExactLiteralAST` in `src/Analyzer/Utils.h`: on master #117831 rewrote it before #118988 edited it, and #117831 is not on 26.9. 26.9's comment is kept unchanged, so this commit carries #118988's code and tests and drops only its 5-line comment edit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
The only conflict is the doc comment above What I checked:
@fm4v, I have After that the robot merges this PR and opens the 26.9 backport PR itself. |
Contributor
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #118988
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job