Skip to content

A value that does not fit the set's key type is not a member, not an error - #117606

Merged
alexey-milovidov merged 12 commits into
masterfrom
fix-table-backed-set-out-of-range-113854
Oct 2, 2026
Merged

alexey-milovidov merged 12 commits into
masterfrom
fix-table-backed-set-out-of-range-113854

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed IN against a table-backed set (ENGINE = Set), or with transform_null_in = 1, throwing CANNOT_CONVERT_TYPE for 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

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 same mask the neighbouring transform_null_in branch already uses for that purpose. It covers a Nullable probe against a non-Nullable key as well, which nullIn and IN ... SETTINGS transform_null_in = 1 reach with the Nullable wrapper still in place, unlike plain IN: there a source NULL and a value that does not fit are both non-members, and together they are exactly the NULLs of the lenient conversion. With a Nullable key the invented NULL never reaches the key column, because 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. Only 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]
Sync PR [sync-upstream/pr/117606]

Version info

  • Merged into: 26.10.1.1353-master (included in 26.10 and later)

…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
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2e8c17f]

Summary: ✅


AI Review

Summary

This PR makes Set::execute treat out-of-range probe values as non-members instead of raising CANNOT_CONVERT_TYPE along the ENGINE = Set / transform_null_in = 1 paths, keeps the exact-type fast path for the common x IN set_table case, and adds focused regression coverage for Nullable, LowCardinality, bloom-filter pruning, and the default transform_null_in = 0 control cases. I re-checked the current code and every existing review thread; the previously reported correctness and hot-path concerns are addressed in the current head, and I did not find any remaining blockers or major issues.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 2e8c17f.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 2, 2026
Comment thread src/Interpreters/Set.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026
Comment thread src/Interpreters/Set.cpp Resolved
alexey-milovidov and others added 3 commits September 10, 2026 11:00
`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]>
Comment thread src/Interpreters/Set.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2e8c17f5e with master d046101ce (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline.

Job report

alexey-milovidov and others added 2 commits September 17, 2026 17:09
…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]>
Comment thread src/Interpreters/Set.cpp Resolved

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 23, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 23, 2026
alexey-milovidov and others added 2 commits September 24, 2026 01:38
… 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]>
alexey-milovidov and others added 2 commits October 2, 2026 12:15
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]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into master with commit 19de9fd Oct 2, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-table-backed-set-out-of-range-113854 branch October 2, 2026 23:36
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 9, 2026
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]>
leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IN with a table-backed Set (ENGINE = Set) throws CANNOT_CONVERT_TYPE for out-of-range values where a literal IN list returns false

2 participants