Skip to content

Keep trailing zero bytes when converting FixedString to String - #122086

Open
alexey-milovidov wants to merge 120 commits into
masterfrom
cast-fixed-string-keep-trailing-zeros
Open

alexey-milovidov wants to merge 120 commits into
masterfrom
cast-fixed-string-keep-trailing-zeros

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes: #120986
Closes: #129837
Related: #117293

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The conversion of FixedString to String (CAST, toString, and implicit conversions) no longer removes trailing zero bytes: CAST(toFixedString('a', 2) AS String) is now 'a\0' instead of 'a'. The old behavior can be restored with the setting cast_fixed_string_to_string_strip_trailing_zeros = 1, which is also enabled by compatibility set to a version before 26.12.

Description

The conversion of FixedString(N) to String removed the trailing zero bytes of each value. That makes it lossy: toFixedString('a', 2) and a FixedString(2) value holding the bytes 'a\0' on purpose both become 'a', and a binary FixedString (a hash, an IPv6 address, a packed structure) that ends in a zero byte comes out shorter than N. It also disagrees with other conversions that keep the bytes as is, such as the conversion of constant IN set elements to the left-hand type. That mismatch came up in #117293 (comment).

Now the bytes are copied as is. The new setting cast_fixed_string_to_string_strip_trailing_zeros restores the old behavior. It is false by default and true with compatibility before 26.12. castColumn without a query context gets the new behavior as well.

This PR changes only the conversion. equals between String and FixedString still compares zero-padded, so 'a' = toFixedString('a', 2) stays true while toFixedString('a', 2)::String = 'a' is now false.

The new default is on deliberately, to see in CI which tests and internal code paths depend on the old behavior. Test 05256_cast_fixed_string_to_string_trailing_zeros covers both modes, Nullable, LowCardinality, and compatibility.

Internal code that emulated the old conversion follows the new one: the bloom_filter and text index analysis no longer strip a FixedString constant for has/hasAny/hasAll and the map functions (they returned different rows with and without the index), groupConcat over FixedString keeps the padding, and KeyCondition declines a FixedString constant pushed through a key transform over String. equals between a FixedString and an Enum now compares zero-padded, like with a String, and the primary key pads the constant to the key width for it. Arrays with FixedString elements are compared with arrays of another element type element by element, like the scalars, so [toFixedString('a', 2)] = ['a'] stays true. The other elements of such arrays (for example, the other fields of a tuple) are compared as in arrays of the same type, by compareAt. CASE with a FixedString mixed with another type in its keys, also inside a Tuple or an Array, goes through multiIf. The primary key analysis does not rewrite coalesce comparisons when a branch with a FixedString is converted to the result type. multiIf and transform (and CASE through them) convert their arguments without the query context, but read cast_fixed_string_to_string_strip_trailing_zeros themselves and pass it to the cast. if kept the padding before this change as well. A FixedString entry of transform looked up by a String value is converted without its trailing zero bytes, whatever the setting is, so transform('ab', [toFixedString('ab', 4)], [1], 0) finds the entry, as 'ab' = toFixedString('ab', 4) is true (05815_transform_fixedstring_shorter_entry). The join keys (ON, USING, both analyzers, the runtime filters and their index analysis, the shuffle hashing of a distributed JOIN, and the predicates pushed across the join) keep removing the trailing zero bytes in the conversion of a FixedString key to String, whatever the setting is, so JOIN ... ON fs = s matches the same rows as fs = s. A comparison of arrays with FixedString elements with arrays of another element type is not used as a join key: it compares zero-padded element by element, which the converted keys cannot reproduce, so it stays a filter over the joined rows. The primary key uses order comparisons of a FixedString key with an Enum too, with the constant padded to the key width, unless the Enum name ends with a zero byte. A FixedString constant compared with an Enum is normalized without its trailing zero bytes by the logical expression optimizer, and equality chains with such constants are not rewritten to IN. Note that has/hasAny/mapContainsKey between String and FixedString elements, and array with elements of both types, now see the padding, and they convert without the query context, so cast_fixed_string_to_string_strip_trailing_zeros does not restore them.

groupConcat over a sparse column now keeps the order of the rows: it added the default rows after all the others.

A NULL of a nullable Parquet FIXED_LEN_BYTE_ARRAY column read as String with input_format_null_as_default is the default FixedString(N) converted to String, so it is now N zero bytes instead of an empty string (05813_parquet_fixed_string_null_as_default).

A cast keeps its FixedString conversion mode when the query plan is serialized (two new bits of the node flags in the serialized ActionsDAG, ignored by older receivers), so the forced stripping of the join keys survives a distributed plan. The partition and primary key analysis declines conditions where a FixedString nested in a composite type (such as Array(FixedString(N))) would be converted to another type.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/122086]

`CAST(toFixedString('a', 2) AS String)` used to return `'a'`: the conversion
removed the zero bytes that pad a `FixedString` value to its length. This is a
lossy conversion, and it disagrees with other paths that keep the bytes as is,
such as the conversion of constant `IN` set elements, which made
`'a' IN (toFixedString('a', 2))` false while `'a' = toFixedString('a', 2)` is true.

Now the bytes are copied as is. The new setting
`cast_fixed_string_to_string_strip_trailing_zeros` (default `false`,
`true` with `compatibility` before 26.10) restores the old behavior.

Related: #117293 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ee5d7f2]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
05820_json_conversion_value_independent_of_skip_policy FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL
Code Review DROPPED
Build (amd_asan_ubsan) DROPPED
Build (arm_asan_ubsan) DROPPED
Integration tests (amd_asan_ubsan, db disk, targeted) DROPPED
Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) DROPPED

@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... labels Sep 24, 2026
alexey-milovidov and others added 7 commits September 26, 2026 03:24
The array-search functions coerce the constant with `castColumn`, which has no query
context and now keeps the trailing zero bytes of a `FixedString`. The index kept
stripping them, so it hashed a value the function never compares and pruned granules
with matching rows (`04654_bloom_filter_array_fixed_string_constant`).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Their cast to `String` now keeps the trailing zero bytes, so the needle must not be
stripped before the lookup, and on a `FixedString(N)` column only a needle of exactly
`N` bytes can match. Before, `hasAny(arr, [toFixedString('hello', 10)])` returned
different rows with and without the index (`05223_text_index_fixed_string_padded_needle`).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… transform over `String`

The constant is compared zero-padded, so it matches a family of `String` values, while
the cast to `String` now keeps all its bytes and gives one of them. With
`ORDER BY reverse(tuple(bin(p), reverse(p)))`, `toFixedString('abc', 257) = p`
selected no rows (`04612_fixedstring_const_string_key_condition`).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…cial case

`groupConcat` cut trailing zero bytes to match `CAST(FixedString AS String)`, which
no longer does that (`03235_groupArray_string_consistency`). `castForIf` existed only to
keep the padding that `castColumn` used to cut, so it is now the same as `castColumn`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ey sound for it

`equals` between a `FixedString` and an `Enum` casts both to `String`, which now keeps
the padding, so `toFixedString('7', 4) = CAST('7' AS Enum8('7' = 3))` became false while
the same comparison with the `String` constant `'7'` stays true. Compare the `FixedString`
side as is with the other side cast to `String`, as for a `String` argument.

`KeyCondition` wrapped such a key into a cast to `String` and pruned the matching granule.
For `equals`/`notEquals`, pad the constant to the key width instead, which keeps it a point;
decline other comparisons (`04652_enum_constant_vs_string_column`).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…the conversion to `String`

Where the output of the conversion is the point of the test, the references change. Where the
test is about something else, it avoids the padding (`toStringCutToZero`, exact
`FixedString` widths). The `bloom_filter` and `text` index tests keep comparing the indexed
answer with the unindexed one; their pinned rows and comments follow the new semantics, and
their pruning cells use constants that can still match: a constant wider than a `FixedString`
element now matches nothing, and the index declines it.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=8bf6d1d7432a06a04da8923840a560c45fd4ac00&name_0=PR&name_1=Fast%20test

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/Functions/if.cpp Resolved
…eep-trailing-zeros

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/Functions/FunctionsComparison.h Resolved
alexey-milovidov and others added 9 commits October 3, 2026 08:23
…lement by element

The cast of both arrays to their least supertype keeps the zero padding of
the `FixedString` elements, while the scalar comparison of `FixedString`
with `String` or `Enum` is zero-padded. So `[toFixedString('a', 2)] = ['a']`
was false while `toFixedString('a', 2) = 'a'` is true. Such arrays now go
through the element-wise lexicographic comparison, which reuses the scalar one.

Address review: #122086 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rip_trailing_zeros`

`multiIf` and `transform` (and `CASE`, which uses them) convert their
arguments with `castColumn`, which runs without a query context, so the
setting did not restore the old conversion of `FixedString` to `String`
in them. They now read the setting when they are created and pass it to the
cast: `castColumn` and `createInternalCast` take it as a flag that stands
for the setting when there is no context.

`if` is left as is: both its constant and non-constant paths kept the
padding before 26.10 as well, so `SELECT hex(if(1, toFixedString('a', 2), 'x'))`
was `6100` then too.

`optimize_if_transform_strings_to_enum` no longer rewrites `transform`
with a `FixedString` array of results: the rewrite took the values of the
array as they are, regardless of how `transform` converts them.

Address review: #122086 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The inherited `addBatchSparseSinglePlace` adds all non-default values first
and the default rows after them, which reorders the result of an
order-dependent function. Iterate row by row instead, as `groupFormat` does.

This made `03235_groupArray_string_consistency` fail with
`ratio_of_defaults_for_sparse_serialization = 0`: `groupConcat` over a sparse
`FixedString` column was reordered, while its cast to `String`, which now keeps
the zero padding, is no longer sparse and was not.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=5e3b4d8fa4b1729d36b1c8c802a322c3ceecb0c2&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29
PR: #122086

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…version to `String`

`multiIf`/`CASE` with a `FixedString` branch, and `Arrow`/`Parquet` fixed-size
binary data inserted into `String` columns keep the trailing zero bytes now.

`02764_csv_trim_whitespaces` is marked `long`: it runs hundreds of
`clickhouse-local` processes and takes more than 180 seconds in the flaky check
under ASan.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=5e3b4d8fa4b1729d36b1c8c802a322c3ceecb0c2&name_0=PR
PR: #122086

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test was added on master and converts `Nullable(FixedString(24))` to
`String` with `toString`, which now keeps the zero padding. Use
`toStringCutToZero` like `02764_csv_trim_whitespaces` does, so the test
checks the whitespace handling rather than the padding.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=cd6696d96f345cec52a8a777e5c7d45602bb44f7&name_0=PR&name_1=Fast%20test
PR: #122086

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Functions/FunctionsConversion.h Resolved
Comment thread src/Functions/multiIf.cpp Resolved
alexey-milovidov and others added 4 commits October 6, 2026 15:03
…eep-trailing-zeros

Resolve the conflict in `MergeTreeIndexBloomFilter.cpp`: keep the `Enum` name handling from
`master` and call `coerceStringFieldLikeSearchFunction` with the signature of this branch. The
comment of `tryConvertEnumNameConstant` is updated: the cast to `String` now keeps the padding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g` padding

`has`, `indexOf`, `hasAny` and `hasAll` compare an `Enum` with a `FixedString` after the cast
of both to `String`, which keeps the zero padding now, so a padded `FixedString` needle no longer
matches the name of the enum value. Add needles without padding to keep covering the match, and keep
the padded ones with the new expected results; the results with and without the index still agree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s` in `updateHash`

`FunctionConvertSettings::updateHash`, `FunctionMultiIf` and `FunctionTransform` captured the setting
but did not hash it, so expressions that differ only in it could share `query_condition_cache` entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…to_string_strip_trailing_zeros`

Without hashing the setting in `updateHash`, the second query of each pair was served the "no
matching rows" verdict of the first one and returned 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master. That brought in a semantic conflict with tests added there (05059_has_enum_array_by_name, 05062_has_enum_array_bloom_filter, 05257_has_enum_array_index_fixed_string). Those tests expected has/indexOf/hasAny/hasAll over Enum elements to match a padded FixedString needle such as toFixedString('a', 2) by name. These functions cast to the common type String, and with this PR that cast keeps the padding, so a padded needle no longer matches. I updated the references (716d5e3) and added unpadded needles so the match is still covered. Results with and without the skip index still agree. The bloom filter tryConvertEnumNameConstant still strips the padding: that is exact for equals, which this PR compares zero-padded, and at worst keeps extra granules for the search functions. If padded needles should keep matching Enum names in has, that is a design decision for a human.

Comment thread src/Functions/FunctionsComparison.h Resolved
alexey-milovidov and others added 4 commits November 13, 2026 16:59
…FixedString` constant

An `Enum` is ordered against a `FixedString` constant by its name, while
the folds of `optimize_redundant_comparisons` compare the `Enum` ordinals.
The two orders differ in general, e.g. for `Enum8('a' = 2, 'b' = 1)`, so
only an equality or inequality keeps the converted bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…side as a join key

Like arrays, maps with a `FixedString` key or value are compared with maps
of another type element by element, zero-padded, while the join keys convert
a `FixedString` to `String` without its trailing zero bytes. Add a test for
this and for the ordered `Enum` comparison folds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… like at execution

The adaptors for `Dynamic` and `Variant` arguments build the function again
during the execution, when the context of the scope that created the
resolver (e.g. a subquery with `SETTINGS`) may have expired. This threw
`Context has expired` from `arrayReduceInRanges` in the test
`05616_fixed_string_enum_single_name_and_const_array_comparison`.
Parse the name and parameters of the aggregate once, during the analysis,
and reuse them. `FunctionInitializeAggregation` did not use its context.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=8420b3e782dcb289512d1606401636ec9dbc92cb&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
PR: #122086

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed fd05e68 (merged master, plus three commits):

  • Addressed the two new review blockers: ordered Enum vs FixedString folds, and Map join keys (new test 05632_fixed_string_enum_order_fold_and_map_join_keys).
  • Fixed the Logical error: Context has expired exception in Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel). The Dynamic adaptor rebuilt arrayReduceInRanges during execution, after the context of the scope that created the resolver (the subquery with SETTINGS in 05616_…) had expired. arrayReduce, arrayReduceInRanges and initializeAggregation now parse the aggregate name and parameters during analysis and reuse the result.
  • 04502_distributed_plan_one_bucket_exchange was fixed on master by Do not shard a join by primary-key ranges over bucketed distributed reads #130887, which this merge brings in.
  • Performance Comparison did not run: test selection hit a GitHub API rate limit (infrastructure).

@groeneai, investigate the failure: Cannot start clickhouse-server in Stress test (amd_msan) (https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=8420b3e782dcb289512d1606401636ec9dbc92cb&name_0=PR&name_1=Stress%20test%20%28amd_msan%29), and provide a fix in a separate PR. In the last 10 days it failed the same way in about 40 stress-test runs across many unrelated PRs. If the fix is already in progress, link it here.

The two older threads (persisted key expressions on upgrade, groupConcat scope settings) still need a design decision from the author.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #130670, merged 2026-11-11 19:06 UTC. The run you linked was created at 13:27 UTC that day, so its build did not include it. This PR did not cause the failure. The tables in question come from 05496_dynamic_disk_wrapper_of_server_credentials_disk (added by #129044): either AST-fuzzer copies of its tables, or its own tables whose DROP the stress test ignored. They name disks and storage policies that exist only in memory, so the server cannot load them after a restart.

CIDB, last 10 days, Stress test (*) / Cannot start clickhouse-server: 48 rows. 39 of them come from this test, all since 2026-11-10 14:03 UTC, and the other 9 have different causes. The 39 break down as:

@groeneai

Copy link
Copy Markdown
Collaborator

The separate PR for the remaining case is #131426. It also sets memory_tracker_fault_probability=0 in 05496_dynamic_disk_wrapper_of_server_credentials_disk, so an injected client-side memory fault can no longer skip one of its cleanup DROPs. Locally, with the unpatched test, 2 of 20 runs left a table and the restart failed with the CI error. With the patch, 20 of 20 runs passed and the restart succeeded.

alexey-milovidov and others added 3 commits November 15, 2026 09:07
# Conflicts:
#	src/Interpreters/ActionsDAG.cpp
#	src/Interpreters/ActionsDAG.h
#	src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp
…of `optimize_and_compare_chain`

An `Enum` is ordered against a `FixedString` constant by its name, while
`tryNormalizeConstEdge` converted the constant to an `Enum` ordinal and put
the edge into the ordinal order domain, so transitive inference derived
wrong conjuncts for e.g. `Enum8('a' = 2, 'b' = 1)`. Only an equality or
inequality is normalized now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…very row

`gatherAlignedArrayElements` deferred a constant side only when its element
type contained `Array` or `Map`, so a long `FixedString` leaf or a `Dynamic`
holding an array was still copied once per input row. Decide by the size of
the elements of the constant instead, whatever carries the payload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 2d23af9 (merged master, resolved conflicts in ActionsDAG.h/ActionsDAG.cpp/MergeTreeIndexBloomFilter.cpp, plus two commits):

  • optimize_and_compare_chain no longer puts an ordered Enum vs FixedString comparison into the ordinal chain (8f2ad1d).
  • A constant array side is deferred by the size of its elements, so a long FixedString leaf or a Dynamic carrier is no longer copied once per row (2d23af9).
  • New test 05770_fixed_string_large_constant_elements_and_enum_order_chain.

@groeneai, thanks: the Stress test (amd_msan) failure is fixed by #130670, which this merge brings in. The remaining case is in #131426.

Two threads still need a decision from the author: persisted key expressions after upgrade, and groupConcat reading the query-level setting instead of the subquery scope.

alexey-milovidov and others added 5 commits November 18, 2026 18:10
…eep-trailing-zeros

Conflicts were with the `[[nodiscard]]` annotations added on master: kept the
PR's members and added `[[nodiscard]]` to them. In `castOrDefault.cpp` the
local `getSourceNullMap` was replaced on master by `getOuterNullMap`, which the
PR code already uses. In `if.cpp` the PR's removal of `castForIf` is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g` conversion mode

#118561 added a cast of the keys to the common type in
`preCalculateKeys` (used by the runtime filters). It was built without a context, which now keeps the
trailing zero bytes of a `FixedString`, so `JOIN ... USING` with runtime filters dropped all rows
(`05334_cast_fixed_string_to_string_join_keys`). Convert the keys as `predicateOperandsToCommonType`
does: without the trailing zero bytes and under the distinct name `_CAST_strip_trailing_zeros`.

Update the tests from master that pin the old conversion:
- `05136_join_fixed_string_zero_bytes`: arrays with `FixedString` elements are now compared element by
  element, zero-padded like the scalars, so the operator and the join both give 8 instead of 4.
- `05137_join_fixed_string_zero_bytes_runtime_filter`: the new name of the key cast in `EXPLAIN`.
- `05813_parquet_fixed_string_null_as_default`: a NULL read as `String` is the default `FixedString(2)`
  converted to `String`, which now keeps its two zero bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…c` in a serialized plan

`ConcatOverloadResolver` delegates a single argument to the `toString` it created from the context, but
`getFixedStringToStringStripTrailingZeros` only looked into `FunctionToOverloadResolverAdaptor`, so the
`FunctionBaseDynamicAdaptor` around `concat` reported no mode and the deserialized plan used the outer
scope's one. A resolver may now implement `IFunctionWithFixedStringToStringMode` itself, and
`ConcatOverloadResolver` reports the mode of its `toString`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The decision to defer a constant side in `gatherAlignedArrayElements` averaged the element sizes over the
whole constant, so one large element among many small ones was still copied for every input row (a 1 MB
first element next to 20000 empty strings needed a 953 MiB allocation). Sum the sizes of exactly the
positions that gathering would copy - the common prefix of the constant row for each input row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onstant arrays, and null-safe join keys

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 4 commits November 21, 2026 13:20
…settings history

The 26.11 release branch was created without this change, so the new default belongs to 26.12:
`compatibility` set to 26.11 or earlier keeps removing the trailing zero bytes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…lue zero-padded

Test `05815_transform_fixedstring_shorter_entry`, added in master for
#132103, expects
`transform('ab', [toFixedString('ab', 4)], [1], 0)` to find the entry, like `equals` does.
The fix in master relied on the conversion of the entries to `String` removing the trailing
zero bytes, which this branch no longer does by default. Convert such entries without the
trailing zero bytes whatever the setting is, as the join keys do.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Mark `getFixedStringToStringStripTrailingZeros` and `serializeNestedColumn` as `[[nodiscard]]`
(`modernize-use-nodiscard`) and allow the short-lived `std::vector` in `FunctionsComparison.h`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122086&sha=c4f5e9b5de261c818b7ccc499dad3b813fe11607&name_0=PR
#122086

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Comment thread src/Functions/concat.cpp Resolved
Comment thread src/Functions/FunctionsNullSafeCmp.h Resolved
alexey-milovidov and others added 4 commits November 24, 2026 14:01
…eep-trailing-zeros

Conflicts:
- `FunctionsConversion.cpp`, `FunctionsConversion.h`: both sides added includes and a member of
  `FunctionConvertSettings` (`cast_fixed_string_to_string_strip_trailing_zeros` here,
  `json_use_optimized_type_conversion` on master), both are kept. The new copy constructor for a nested
  JSON `CAST` takes `cast_fixed_string_to_string_strip_trailing_zeros` from the base settings.
- `RuntimeFilterLookup.cpp`: master applies the `CAST` function recorded from the probe-side filter,
  which was built with the `FixedString` to `String` conversion of the join keys, so the separate
  `addCast` with the override is not needed.
- `MergeTreeIndexBloomFilter.cpp`: master only rewrote the trimming of a `FixedString` constant with
  `trimRight`, while this branch removed the trimming; the removal is kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ring` in the logical expression optimizer

A `FixedString` inside an `Array` or a `Tuple` constant is compared with a `String` zero-padded element by
element, so the constant converted to the type of the column is only one of the values it matches. The chain
`k = [toFixedString('a', 2)] OR ...` over an `Array(String)` was rewritten to `IN` and lost the row `['a']`,
and `k = [toFixedString('a', 2)] AND k = ['a']` was folded to false. `tryConvertToColumnType` now declines
such constants, as it does for a top-level `FixedString` compared with a `String`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…esolver

The adaptors for `Dynamic` and `Variant` arguments hash the overload resolver instead of the function it builds.
`ConcatOverloadResolver` did not override `updateHash`, so single-argument `concat` over a `Dynamic` or
a `Variant` had the same query condition cache key with different values of
`cast_fixed_string_to_string_strip_trailing_zeros`. It now hashes the `toString` it delegates to.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…th a `FixedString`

`executeNullableWithoutSupertype` and `executeNotDistinctWithFixedString` converted constant operands to full
columns, so `isNotDistinctFrom` of a `Nullable(Enum)` column with a `Nullable` constant `FixedString` of 1 MB
replicated the constant for every row and exceeded the memory limit. The nested value of a constant, and the
elements of a constant tuple, are now passed on as constants.

Test `05873_fixed_string_composite_constant_chain_concat_hash_null_safe_constant` covers this and the two
previous commits.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

3 participants