Repository navigation
Conversation
`Set::execute` converts each probe key column into the set's key type before the
hash lookup. For a `Bool` key that is `castColumnAccurateOrNull(probe, Bool)`, and a
conversion into `Bool` turns every nonzero number into `true`, so 2, 300, -1, 0.5
and NaN all hit the element `true`:
SELECT groupArray(number) FROM numbers(4) WHERE number IN (SELECT true); -- was [1,2,3]
SELECT groupArray(number) FROM numbers(4) WHERE number NOT IN (SELECT true); -- was [0]
while `number IN (true)`, `number = true`, the documented `IN` semantics
(`accurateCastOrNull` of the right side to the left side's type) and the
primary-key read all give [1] / [0,2,3].
`Bool` is stored as `UInt8`, so when the set key is `Bool` (or `Nullable(Bool)`) and
the probe is a non-`Bool` integer or floating-point number, convert the probe into
`UInt8` instead: an accurate conversion into `UInt8` keeps the value or yields NULL
(a non-member), so only 0 and 1 can match. This mirrors the exact-value semantics of
ClickHouse#93115, which covered the opposite direction (a `Bool` probe against numbers).
Covers every `IN` flavour that reaches `Set::execute` (`in`, `notIn`, `nullIn`,
`globalIn`), multi-column keys, `Nullable`/`LowCardinality` probes and set columns,
`transform_null_in`, `ENGINE = Set` tables, `GLOBAL IN`, and the spilled `DiskSet`.
Composite keys (`Tuple`/`Array`/`Map` holding a `Bool`) and `Decimal` probes are left
unchanged: the former are converted strictly, where an `UInt8` element would throw for
values above 255, and an accurate `Decimal` -> `UInt8` conversion truncates.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the getTypeToConvertKeyTo comment to the cast invariant. 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; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261107-055200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261107-051500 |
|
Workflow [PR], commit [52629125] Summary: ❌
AI ReviewSummaryThe PR makes integer and floating-point probes compare by value against Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Make indexed and full-scan results agree for the reproduction above and add regression coverage. |
|
cc @nihalzp @yariks5s, could you review this and add the |
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. |
`05406_vortex_pushdown_probe_conversion` used `UInt8` `2 IN (SELECT k FROM bool_keys)` with the key `true` as an example of a non-injective row conversion: `Set::execute` cast the row to `Bool`, so `2` became `true` and matched. With this PR the row is compared with the `Bool` key by its value, so `2` matches no key: the `u` lines become 0 / 1 with the pushdown both on and off, which still agree. The Vortex converter keeps refusing to push a `Bool` key for a non-`Bool` column; only the comments that cited this example are updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A `Variant` probe reaches `Set::execute` as a whole in a multi-column key (`(v, 1) IN (SELECT true, 1)`) and in the null-aware membership (`nullIn`, `IN` with `transform_null_in = 1`), which do not use the default `Variant` adaptor. Its cast into the `Bool` key converts every alternative into `Bool`, so a number alternative other than 0 or 1 still became `true` and matched. After that cast, the number alternatives are converted again into `UInt8`, the same conversion a probe of their own type gets, and only their rows are replaced. `String`, `Bool`, NULL and unconvertible alternatives keep the result of the `Bool` cast. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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.
A `Bool` key converts a probe of its own type with `transform_null_in = 0`, so a `Bool` value holding a byte other than 0 and 1 is `true`. The check used `isBool`, which is false for `SimpleAggregateFunction(any, Bool)`, while `equals` holds between that type and `Bool`, so the conversion was skipped as a no-op: `b IN (SELECT anySimpleState(true))` returned 0 for a `Bool` byte 2 where `b IN (SELECT true)` returns 1, and a `Variant` probe in a multi-column key, which is always converted, returned 1 again. Use `holdsBool`, which the number-probe path already uses for such keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| /// can hold such a byte, e.g. from `reinterpret`. With `transform_null_in = 1` the probe keeps its bytes, | ||
| /// as primary-key analysis does, which matches a `Bool` member only against the byte 1 (see | ||
| /// `KeyCondition::tryPrepareSetColumnsForIndex`). | ||
| const bool converts_bool_key = !transform_null_in && holdsBool(target_type); |
There was a problem hiding this comment.
[Blocker] Keep primary-key pruning consistent with boolean normalization
Extending this exception to SimpleAggregateFunction(f, Bool) makes the lookup accept stored boolean bytes 2 and 3, but KeyCondition::tryPrepareSetColumnsForIndex still treats the set as the single key point 1. Consequently, enabling the primary key silently removes matching rows:
CREATE TABLE t (b Bool) ENGINE = MergeTree ORDER BY b
SETTINGS index_granularity = 1;
INSERT INTO t SELECT toUInt8(number) FROM numbers(4);
SELECT arraySort(groupArray(toUInt8(b))) FROM t
WHERE b IN (SELECT anySimpleState(true))
SETTINGS use_primary_key = 0, optimize_use_implicit_projections = 0;
SELECT arraySort(groupArray(toUInt8(b))) FROM t
WHERE b IN (SELECT anySimpleState(true))
SETTINGS use_primary_key = 1, optimize_use_implicit_projections = 0;Reproduced with the 526291255098 fast-test binary: the results are [1,2,3] and [1], respectively. Both queries return [1] with the previous 95e7b2e5c872 binary. The ordinary INSERT ... SELECT preserves these bytes, so this affects existing data as well as the newly added boolean-byte test case.
Please make index analysis account for the normalization, or decline unsafe pruning, and add a regression comparing indexed and full-scan execution. The new Memory test cannot exercise this boundary.
There was a problem hiding this comment.
A plain Bool key already splits this way: b IN (SELECT true) and b IN (true) give [1,2,3] without and [1] with the primary key on 26.8.37.168, 26.10.5.57 and master 573bbb2, and with this PR the anySimpleState(true) set gives the same results as true in both modes (also for NOT IN). The root cause is the stored bytes 2 and 3, which #131433 stops INSERT ... SELECT from writing, so I am leaving primary-key analysis unchanged here.
AI review of a later commit does not approve the PR, see the AI Review comment.
Related: #93115
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
INwith a subquery, aSettable orGLOBAL INwhose column isBoolmatching every nonzero number on the left side.number IN (SELECT true)now matches only1, likenumber IN (true)andnumber = true.Description
On 26.3.42.3, 26.8.18.2 and 26.10.3.7,
SELECT groupArray(number) FROM numbers(4) WHERE number IN (SELECT true)returns[1,2,3]and theNOT INform returns[0], whileIN (true),= trueand the documentedINsemantics give[1]. Also matched:-1,0.5,256,nan,inf. Master gives the same after #119183. No related open issue found.Set::castToKeyTypeconverts the left side into the set's key type before the lookup, and a conversion intoBoolturns every nonzero number intotrue. Now, when the set key isBool,Nullable(Bool)orSimpleAggregateFunction(f, Bool)(#129731) and the left side is a non-Boolinteger or floating-point number, it is converted intoUInt8, which storesBool: the value is kept, or it does not fit and is not a member. This is the exact-value semantics #93115 introduced for the opposite direction. It coversin,notIn,nullIn,GLOBAL IN, multi-column keys,Settables,transform_null_in, spilled sets and the number alternatives of aVariantleft side. ABoolleft side still converts, so aBoolbyte 2 istrue.Not changed: a
Boolinside a composite key (Tuple/Array/Map) andDecimalleft sides.Existing expectations of the old matching change:
toUInt8(2) IN (SELECT true)in05168_nullable_in_key_cast_null_rows(now 0 in bothtransform_null_inmodes),same as boolin05556_cast_to_simple_aggregate_function_bool([1]) and theulines of05406_vortex_pushdown_probe_conversion.04871_in_tuple_single_key_rewrite_in_to_joinnow takes its byte 2 from aBool, so its results stay.Validation: new test
05567_in_subquery_bool_set_compares_numbers_by_value(25 results, each wrong on master), 30 randomized runs of every touched test, and 543 related stateless tests (IN, sets,Bool,Variant) with the same verdicts as on master apart from the four above.Workflow [PR]
Sync PR [sync-upstream/pr/129892]