Repository navigation
A value that does not fit the set's key type is not a member, not an error - #117606
Conversation
…error
`IN` against a set converts the probe column into the set's declared key type.
When the accurate-or-null conversion is not taken - `transform_null_in` makes
`NULL` an ordinary matchable value, and a table-backed `ENGINE = Set` always
sets it - the conversion was strict, so a value outside the key type's range
raised `CANNOT_CONVERT_TYPE` instead of simply not matching:
CREATE TABLE s (k UInt64) ENGINE = Set;
INSERT INTO s VALUES (1);
CREATE TABLE t (v Int64) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t VALUES (1), (-1);
SELECT count() FROM t WHERE v IN (1); -- 1
SELECT count() FROM t WHERE v IN s;
-- Code: 70. Value in column Int64 cannot be safely converted into type UInt64
The literal list computes a common supertype for the comparison and concludes
that `-1` is not a member, which is the answer the set form must give too. And
because the exception is raised per row read, the same query succeeded or
failed depending on how much the plan pruned.
The conversion is now lenient and the values that did not fit are marked as
non-members, using the mask the neighbouring `transform_null_in` branch
already uses for that purpose. Their `NULL` never reaches the key column: with
a `Nullable` key the set may hold a `NULL`, and a value that merely does not
fit is not that `NULL`, so the key column keeps each row's original nullness.
Key types that cannot be wrapped in `Nullable`, and `Tuple` keys - which the
accurate-or-null path already excludes because it would change the key
structure - keep the strict conversion.
Three tests pinned the old exception; they now check that the result matches
the same query at the default `transform_null_in = 0`.
Closes: #113854
|
Workflow [PR], commit [2e8c17f] Summary: ✅
AI ReviewSummaryThis PR makes Final Verdict
LLVM Coverage ReportMeasured on commit 2e8c17f.
Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code |
…t-out-of-range-113854
`nullIn` (and `IN` with `transform_null_in = 1`, which is renamed to
`nullIn`) reaches `Set::execute` with the `Nullable` argument still in
place, unlike plain `IN`, whose `Nullable` wrapper is stripped before the
set is probed. That path cast the nested column strictly, so a value the
set's key type cannot represent still raised `CANNOT_CONVERT_TYPE`:
CREATE TABLE s (k UInt64) ENGINE = Set;
INSERT INTO s VALUES (1);
SELECT nullIn(CAST(-1 AS Nullable(Int64)), s);
Convert leniently there too. When the key column is not `Nullable`,
neither a source NULL nor a value that does not fit can be a member, and
together they are exactly the NULLs the lenient cast produces, so that
cast's null map is the non-member mask. The strict nested-column cast
remains only for key types that cannot be lenient at all - a `Tuple`, or
a type that cannot be inside `Nullable`.
Also fix the `clang-tidy` `performance-move-const-arg` error by taking the
mask by value in `add_non_member_rows`, and renumber the test, whose
number was taken on `master` meanwhile.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A review asked whether a genuine `NULL` of a wrapped probe survives the lenient conversion. It does - the `LowCardinality` wrapper is removed before `Set::execute` sees the argument - so pin that at the query level: a `NULL` still matches the `NULL` of a `Nullable` set key, while the value that does not fit the key type is a non-member. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ColumnNullable::create` takes the null map by const reference, so the `std::move` of `original_null_map` moved nothing and `clang-tidy` rejects it. Verified with `clang-tidy` on `Set.cpp`, which is now clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
…t-out-of-range-113854
…ll_in = 0` The review suggested that an out-of-range probe against a `Nullable` set key is compared as the nested default value when `transform_null_in = 0`, because the final `extractNestedColumnsAndNullMap` would drop the non-member mask. That branch is unreachable there: `Set::setHeader` strips `Nullable` from the key types when `transform_null_in = 0`, so the probe takes the `castColumnAccurateOrNull` path, whose NULLs are exactly the non-members that the final extraction turns into the null map. Pin the behaviour with the suggested queries, including `NOT IN` and a `Nullable` probe column. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…t-out-of-range-113854
… conversion The test landed on `master` after this branch was last tested and pinned `CANNOT_PARSE_TEXT` for `IN` under `transform_null_in = 1` with a String probe the set key type cannot represent. With this change such a probe is not a member of the set - it matches neither a value nor the NULL in the set - which is the answer `transform_null_in = 0` already gives. The guarded defect (the unparseable key becoming NULL and matching the NULL in the set) stays fixed: the first query still returns 0. Merge queue failure: https://github.com/ClickHouse/ClickHouse/actions/runs/35809514335/job/107017968820 PR: #117606 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…t-out-of-range-113854
When the probe already has the set key type (up to `Nullable`), no value can fail to fit, so skip the lenient `castColumnAccurateOrNull` conversion and the non-member mask. The common `x IN set_table` case with `ENGINE = Set` (which always has `transform_null_in`) again takes the no-op `castColumnAccurate` path instead of materializing a `Nullable` column and an all-zero mask. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the merge, the set is reported inexact by master's value-level round trip instead of this branch's type-level flag, so the cases that existed only to pin that flag go: the bare-literal granularity case, the `has`-caller relaxation case and the emptiness-ordering case. The cross-type `'1'` case and the three liveness controls now prune exactly under `NOT IN`, so they assert `Parts: 2/3`. The narrower-`FixedString` arm asserts an empty result again, because a key that does not fit the set's type is no longer an error (ClickHouse#117606). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed
INagainst a table-backed set (ENGINE = Set), or withtransform_null_in = 1, throwingCANNOT_CONVERT_TYPEfor probe values outside the set key type's range instead of evaluating them to false, which also made the query succeed or fail depending on how much the plan pruned.Documentation entry for user-facing changes
INagainst a set converts the probe column into the set's declared key type. When the accurate-or-null conversion is not taken —transform_null_inmakesNULLan ordinary matchable value, and a table-backedENGINE = Setalways sets it — the conversion was strict, so a value outside the key type's range raisedCANNOT_CONVERT_TYPEinstead of simply not matching:The literal list computes a common supertype for the comparison and concludes that
-1is not a member, which is the answer the set form must give too. And because the exception is raised per row read, the same query succeeded or failed depending on how much the plan pruned.The conversion is now lenient and the values that did not fit are marked as non-members, using the same mask the neighbouring
transform_null_inbranch already uses for that purpose. It covers aNullableprobe against a non-Nullablekey as well, whichnullInandIN ... SETTINGS transform_null_in = 1reach with theNullablewrapper still in place, unlike plainIN: there a sourceNULLand a value that does not fit are both non-members, and together they are exactly theNULLs of the lenient conversion. With aNullablekey the inventedNULLnever reaches the key column, because the set may hold aNULLand a value that merely does not fit is not thatNULL, so the key column keeps each row's original nullness. Only key types that cannot be wrapped inNullable, andTuplekeys — which the accurate-or-null path already excludes because it would change the key structure — keep the strict conversion.Three tests pinned the old exception; they now check that the result matches the same query at the default
transform_null_in = 0.Closes: #113854
Workflow [PR]
Sync PR [sync-upstream/pr/117606]
Version info
26.10.1.1353-master(included in26.10and later)