Repository navigation
Fix exceptions and wrong results of IN when the keys and the set have different types - #119183
Conversation
|
Workflow [PR], commit [e8dfcea] Summary: ✅
AI ReviewSummaryThe PR fixes tuple-key NULL handling and tuple-field conversion failures, rejects lossy timestamp membership conversions, and restricts Nullable-result consumers traced: The previous review's outstanding aggregate-state rewrite concern is now tracked in #132301, satisfying the requested follow-up option. Previously discussed numeric enum, timestamp range, boolean index, and composite boolean cases are tracked separately in #132250, #132251, #132252, and #132253. These accepted follow-ups do not require reopening the resolved threads. Validation with the head's Fast test binary: all 12 targeted regression files matched their references, and all 13 separately executed expected-error cases produced the expected exception codes. The PR head remained unchanged throughout the review. Final Verdict✅ Approve |
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/Functions/FunctionsConversion.cpp.o |
25.35 MiB | 24.96 MiB | -397.56 KiB (-1.53%) |
src/CMakeFiles/dbms.dir/Interpreters/getDateTime64CastLossMap.cpp.o |
new | 71.74 KiB | +71.74 KiB |
src/CMakeFiles/dbms.dir/Functions/CastOverloadResolver.cpp.o |
359.46 KiB | 403.57 KiB | +44.11 KiB (+12.27%) |
src/CMakeFiles/dbms.dir/DataTypes/NullableUtils.cpp.o |
60.65 KiB | 79.01 KiB | +18.36 KiB (+30.27%) |
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.
Compile time of recompiled translation units
3010 translation units recompiled, 21643 s compile time in total, 3009 of them have a recent master baseline.
…g-point key type
…and pass the column
…ull_in = 0`, as primary-key analysis keeps the bytes
|
@groeneai The review raised four bugs that are also on master, so they are out of scope for this PR. Open one issue for each, with its reproducer, and say in it that it reproduces on master. Then reply here with the links.
|
…of tuple elements, so that array and map elements convert to their declared types
|
@groeneai Open an issue for the remaining case of the AI review, and say in it that it reproduces on master: SELECT accurateCastOrNull(tuple(materialize([toUInt16(1)])), 'Nullable(Tuple(Array(UInt8)))')
SETTINGS enable_nullable_tuple_type = 1;The same holds for numeric map values, numeric tuples inside arrays and numeric |
|
It reproduces on master ( |
IN with Nullable(Tuple) and DateTime64 keysIN when the keys and the set have different types
…t-numbers-by-value ClickHouse#119183 moved the conversion of `IN` keys into `Set::castToKeyType`, so the exact-value conversion of a number for a `Bool` key moves there: such a probe converts into `UInt8` instead of `Bool`, and the number alternatives of a `Variant` probe are converted again after the cast of the whole column. ClickHouse#129731 made `SimpleAggregateFunction(f, Bool)` keep `Bool` values, so a key of that type gets the same exact-value conversion, and a probe of that type keeps the `Bool` one. Expectations that encoded the collapse of a number into `true` change: 05168 (`materialize(toUInt8(2)) IN (SELECT true)` with `transform_null_in = 0` is now 0, as it already was with `transform_null_in = 1`), 05556 `same as bool` (`[1]` for both sets) and the `u` lines of 05406. 04871 keeps its expectations: its `Bool` byte 2 is now a `Bool` from `reinterpret` instead of a `UInt8`, which the set compares by value.
Closes: #104942
Related: #119081
Related: #117606
Related: #117245
Related: #61982
Related: #67230
Fix conversion exceptions and incorrect
IN/NOT INresults for tuple keys, includingNullable(Tuple). Skip outer NULL payloads, report failed tuple-field conversions consistently, and reject timestamp conversions that create false matches through truncation or range overflow.Bug 1: Outer NULL keys raise conversion exceptions.
An outer NULL cannot match a non-nullable set key. Its hidden payload must not be converted before the row is excluded.
The same problem affects NULL tuples with a
Stringfield whentransform_null_in = 1: parsing the hidden empty string raises an exception even though the row cannot match.Bug 2: Failed tuple-field conversions throw instead of returning NULL or a non-match.
Tuple keys supported by
accurateCastOrNullshould treat failed conversions as non-matching rows, as scalar keys do.The underlying
accurateCastOrNullcall must return a NULL tuple when a field fails to convert. Numeric and enum parsers both need to honor this policy.Bug 3: Reducing timestamp precision creates false matches.
Non-NULL
Nullable(DateTime64)values used as scalar components of multi-columnINkeys skipped the sub-second check. The half-second timestamp below must not match a whole-secondDateTimekey.The check must also reach fields inside composite keys. Here,
.123and.12differ; casting the left key to the set’s lower precision must not make them match.Bug 4: Out-of-range timestamps match the destination boundary.
The input is one second beyond the largest
DateTimevalue. A cast that clamps it to that boundary must not make it equal to the boundary key.The following two fixes affect scalar conversions independently of
Nullable(Tuple). They are included in the shared parsing and timestamp-conversion changes.Bug 5: Decimal parsing rejects valid zero-padded
FixedStringvalues.Trailing zero bytes are padding, so
1.25remains valid decimal text.Bug 6: Fractional timestamps fail to match equivalent floating-point keys.
The value
0.5is exactly representable asFloat64. Precision-loss checks must allow this conversion to match.Bug 7: Floating-point keys match every timestamp within their resolution.
A float holds a timestamp only to its own resolution, so the cast maps distinct
DateTime64values to one float: about 240 nanosecond ticks forFloat64in 2026, and 128 seconds forFloat32. Only the timestamp that the float converts back to matches it.Bug 8: A
NULLfield inside aNullable(Tuple)key never matched a constant set member.A
NULLfield of a non-NULLtuple is part of the key value, as it already is when the set comes from a subquery. Constant sets skipped such members and the row-wiseIN arrrewrite guarded against such keys withtransform_null_in = 0. Only a plain tuple with several elements is a multi-column key, where aNULLelement never matches.JOIN keys with
LowCardinality(Nullable)tuple elements take the common-subtype fallback like plainNullableelements, sinceaccurateCastOrNullreports their NULLs through the tuple's null map;JoinCommon::tryGetCommonSubtypeForJoinKeysno longer rejects them withNO_COMMON_TYPE.The implementation shares null-map combination and tuple field mapping, including named fields, and keeps rejected timestamp conversions separate from genuine SQL NULLs. Ordinary
CASTretains its existing truncation behavior.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
INandNOT INno longer fail with an exception when a tuple left-hand column with NULL rows or NULL fields, such as aNullable(Tuple)column, has to be converted to the set's key type, and no longer report false matches when aDateTime64value loses sub-second precision or exceeds theDateTimerange in that conversion; a fractionalDateTime64value now matches an equalFloat64value.accurateCastOrNullto a tuple type returns NULL instead of throwing when one of the fields cannot be converted, andtoDecimal*OrNullandtoDecimal*OrZeroaccept zero-paddedFixedStringinput. ADateTime64value matches a floating-point set key only when the key converts back to the same timestamp, and JOIN keys whose tuple elements areLowCardinality(Nullable)take the common-subtype fallback instead of failing withNO_COMMON_TYPE.Workflow [PR]
Sync PR [sync-upstream/pr/119183]
Version info
26.11.1.2570-master(included in26.11and later)