Repository navigation
Fix an element added to a named Tuple getting 0 instead of the default of its type - #131186
Conversation
`FunctionCast::createTupleWrapper` matches the elements of named tuples by name. A target element without a source element was filled with `createColumn()->cloneResized(n)`, which appends the column zero and bypasses `IDataType::insertDefaultInto`, the place where an `Enum` gets its first value (and a `Tuple` or a typed `JSON` path containing one gets the same). So `CAST`, `ALTER TABLE ... MODIFY COLUMN` (the mutation, and the reads and merges of old parts after a metadata-only ALTER with `allow_metadata_only_named_tuple_alter = 1`), `INSERT ... SELECT` from the narrower tuple and `Memory` tables gave the new `Enum` element 0, which is either not a value of the `Enum` (the ALTER then stored it and `SELECT *` threw UNKNOWN_ELEMENT_OF_ENUM) or not its default. For a type whose default insertion is not trivial the element is now filled with `insertManyDefaultsInto`, as the hash join does for the key of a not-matched row. Trivial types keep `cloneResized`: it is one resize, and `Nothing` (trivial) has no `insertDefaultInto`. Closes ClickHouse#130899 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review.
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261113-021600 |
|
Workflow [PR], commit [9acd7ef] Summary: ✅
AI ReviewSummaryReviewed #131186 at Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 57 s compile time in total, 7 of them have a recent master baseline. |
2dd7ee4
Closes: #130899
Related: #131124
Related: #130259
Related: #130898
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an element added to a named
TuplebyALTER TABLE ... MODIFY COLUMN,INSERT ... SELECTorCASTgetting 0 in existing rows instead of the default of its type. For anEnumwhose first value is not 0 this is the wrong value, and often not a value of theEnumat all: after such anALTER,SELECT *failed withUNKNOWN_ELEMENT_OF_ENUM.Description
On 26.10.2.103 (also 26.8.21.12),
ALTER TABLE t MODIFY COLUMN attrs Tuple(a UInt8, status Enum8('x' = 1, 'y' = 2))on a table withattrs Tuple(a UInt8)stores 0 inattrs.statusof existing rows, which is not a value of theEnum:SELECT * FROM tthen throwsUNKNOWN_ELEMENT_OF_ENUMwhileCHECK TABLEpasses.INSERT ... SELECTfrom the narrowerTuple,CAST,Array(Tuple(...))andMap(K, Tuple(...))columns, theMemoryengine and the metadata-onlyALTER(allow_metadata_only_named_tuple_alter = 1, old parts converted on read and on merge) do the same. WithEnum8('m' = -3, 'n' = 0, 'o' = 4)the new element isninstead ofm.FunctionCast::createTupleWrappermatches the elements of named tuples by name and filled a target element without a source withcreateColumn()->cloneResized(n), the column zero, bypassingIDataType::insertDefaultInto, which gives anEnum(or aTupleor typedJSONpath containing one) its type default. All the paths above convert through it. Such an element is now filled withinsertManyDefaultsIntowhen the default insertion of its type is not trivial; other types keepcloneResized.ALTER TABLE ... ADD COLUMNwas already correct. Values stored by earlier mutations are not rewritten (ALTER TABLE ... UPDATErepairs them).The new test covers
CAST, the mutation withArray/Map, the metadata-onlyALTER,INSERT ... SELECTandMemory. It fails on master and passes with the fix.The cause was first found by @ Marouane-elfadli in #131124. My #130259 changes the same line inside a larger rework of the format readers and will take this version.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131186]
Version info
26.11.1.2199-master(included in26.11and later)