Skip to content

Fix CAST into SimpleAggregateFunction(f, Bool) keeping values other than 0 and 1 - #129731

Merged
Blargian merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/cast-to-simple-aggregate-function-bool
Nov 17, 2026
Merged

Blargian merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/cast-to-simple-aggregate-function-bool

Conversation

@groeneai

@groeneai groeneai commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124074
Related: #129664
Related: #129683
Related: #129894
Related: #129892
Related: #116656

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 into CHANGELOG.md):

Fixed CAST into SimpleAggregateFunction(f, Bool) for f returning Bool (any, anyLast, min, max) keeping the source value: CAST(300 AS SimpleAggregateFunction(any, Bool)) was printed as true but did not compare equal to true, and 0.5 became false. Such a column filled from a DEFAULT, an INSERT ... SELECT of another numeric type or VALUES now gets 0 and 1, as Bool does, and so does JSONExtract into it or into LowCardinality(Bool). Also fixed wrong rows from optimize_read_in_order, optimize_distinct_in_order and a minmax skip index over a CAST into Bool.

Description

On 26.3.60.2, 26.8.18.2 and 26.10.2.103, SELECT CAST(300 AS SimpleAggregateFunction(any, Bool)) AS x, toUInt8(x), x = true returns true 44 0 (CAST(300 AS Bool) gives true 1 1), and an AggregatingMergeTree column v SimpleAggregateFunction(any, Bool) DEFAULT 2 filled by DEFAULT, INSERT ... SELECT toInt32(2) or VALUES (3, 300) makes WHERE v = true return no rows.

SimpleAggregateFunction(f, Bool) is the Bool storage type under its own name, and the Bool conversions recognize Bool by name. isSimpleAggregateFunctionOfBool (argument and result are Bool, so not sumWithOverflow or groupBit*) is now checked next to isBool in CAST (interpreted and JIT), convertFieldToType and JSONExtract, and where results must agree: the native IN set fast paths, the correlated subquery substitution guard, the Bool JOIN key comparison of #129894, the CAST monotonicity and index analysis. The last two also cover Bool itself (as #129683 and #116656 do): the cast was reported as strict, so in-order reading returned wrong rows, and index analysis kept the raw value for a granule range, so a minmax index pruned [2, 2] against CAST(u, 'Bool') = true (the AST fuzzer's debug abort here).

Behaviour change: subquery IN into this type now follows Bool, so number IN (SELECT anySimpleState(true)) changes from [1] to [1,2,3], as number IN (SELECT true) gives (#129892 fixes that for Bool).

Not changed, as for Bool: nested casts of a UInt8 (#129664) and INSERT ... SELECT of a UInt8, which adds no CAST.

Validation: the test fails on master and passes with the fix; reverting any changed site fails its part; 50/50 randomized runs.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/129731]

Version info

  • Merged into: 26.11.1.2600-master (included in 26.11 and later)

groeneai and others added 2 commits November 6, 2026 12:15
…han 0 and 1

SimpleAggregateFunction(f, Bool) is the Bool storage type under its own custom
name, while the Bool branches of CAST and convertFieldToType recognize Bool by
name (isBool). So a CAST into it took the plain UInt8 path: a UInt8 source was
reused as is, wider integers were truncated (300 -> 44, -1 -> 255), 0.5 became 0,
accurate casts failed on values that Bool accepts, and the JIT emitted an integer
truncation. The value is printed as `true` but `= true` is false.

isSimpleAggregateFunctionOfBool() recognizes the type when both the argument and
the aggregate result are Bool (any, anyLast, min, max). sumWithOverflow and
groupBitOr/And/Xor over Bool are accepted by the type because their UInt8 result
equals the Bool storage, but their state legitimately exceeds 1, so they keep the
UInt8 semantics.

It is checked next to isBool in prepareImpl, ConvertImpl, FunctionCast::compile
and convertFieldToType, and in the places that must agree with the new
conversion:
- createFunctionBaseCast: the cast is not injective, so it must not get the
  strict UInt8 monotonicity (read-in-order / DISTINCT-in-order would trust it);
- tryConvertNumericColumnNative and nativeBatchApplicable: castColumnAccurateOrNull
  now maps an IN member 2 to 1, so these sets use the strict per-element
  conversion, as for Bool;
- classifySubstitutionConversion: a non-Bool member must not reconstruct the
  correlated column, as for Bool (an outer value stored as 2 otherwise matched
  only with correlated_subqueries_substitute_equivalent_expressions = 0).

tryConvertNativeNumberMembersBatch needs no change: it calls
nativeBatchApplicable before converting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The correlated subquery substitution guard accepted any Bool-valued member for
a Bool or SimpleAggregateFunction(f, Bool) correlated column. A member with a
different type name (SimpleAggregateFunction(max, Bool) for a
SimpleAggregateFunction(any, Bool) column, Bool for such a column, or the
reverse) then took the cross-base branch and was reconstructed through a CAST
that now normalizes the value, so with a raw 2 stored on both sides (an
INSERT ... SELECT of a UInt8 adds no CAST) EXISTS returned 0 with the
substitution and 1 with correlated_subqueries_substitute_equivalent_expressions
= 0. Only a member of the same type name may reconstruct such a column now; for
plain Bool this is the same check as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Gate B (cold, independent model, codex): 2 findings on 92ec23464a3, 1 on 75194d794cf. Own review: 3 nits, then none.

Finding Verdict
❌ The correlated-subquery guard accepted a member of another Bool-valued type (SimpleAggregateFunction(max, Bool) for a SimpleAggregateFunction(any, Bool) column); its reconstructing CAST now maps a stored 2 to 1, so EXISTS depended on correlated_subqueries_substitute_equivalent_expressions. AGREE, fixed: only a member of the same type name may reconstruct a Bool-valued correlated column (for plain Bool this is the master rule); regression cases added.
❌ Within one query, the constant IN set built for a SimpleAggregateFunction(any, Bool) column is reused for a UInt8-storage column (SimpleAggregateFunction(sumWithOverflow, Bool)) with the same literal, so the result depends on the predicate order. DISAGREE, separate PR: prepared sets are identified by the literal and IDataType::equals, which ignores custom names, so Bool and UInt8 columns already share one set on master (Bool drops 2, UInt8 keeps it). This PR gives SimpleAggregateFunction(f, Bool) the Bool behaviour; the set identity belongs in PreparedSets.
⚠️ Result-only checks may not prove the JIT, monotonicity and substitution paths run. DISAGREE: reverting only the JIT site, only the monotonicity site or only the substitution guard turns its own rows red (JIT 2 3 instead of 1 1, which an interpreted fallback cannot give).
💡 Declaration comment of isSimpleAggregateFunctionOfBool did not state the result-type condition. AGREE, fixed.
💡 isBool(t) || isSimpleAggregateFunctionOfBool(*t) is spelled out at several sites. noted, not blocking

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: CAST(toUInt8(2) AS SimpleAggregateFunction(any, Bool)) gives true 2 0 (value, toUInt8, = true) on master and on 26.3.60.2 / 26.8.18.2 / 26.10.2.103, every run.
b Root cause explained? SimpleAggregateFunction(f, Bool) is the Bool storage under its own name, and the Bool branches of CAST and convertFieldToType test the name, so the conversion took the plain UInt8 path (2 kept, 300 -> 44, 0.5 -> 0).
c Fix matches root cause? Yes: the type is recognized where Bool is; no setting, no guard at the symptom.
d Test intent preserved / new tests added? New test 05556_cast_to_simple_aggregate_function_bool; reverting any one changed site fails its own part of it.
e Both directions demonstrated? tests/clickhouse-test: FAIL on the master binary, OK with the fix; 50/50 randomized runs OK.
f Fix is general across code paths? Interpreted and JIT CAST, convertFieldToType, plus the places that must agree with the conversion: CAST monotonicity, the native IN set fast paths and the correlated subquery substitution guard.
g Fix generalizes across inputs (params/datatypes/wrappers)? Integer, float, decimal and DateTime64 sources, accurateCast/accurateCastOrNull, Array/Tuple elements, DEFAULT, VALUES, values(). SimpleAggregateFunction(any, Nullable(Bool)) was already correct; SimpleAggregateFunction(f, UInt8), sumWithOverflow and groupBit* over Bool keep UInt8 semantics (tested).
h Backward compatible? (maintainer-approved exception only) No setting or format change; stored data is untouched. Results now match Bool.
i Invariants and contracts preserved? The cast is no longer reported strictly monotonic, so in-order reading does not rely on it; IN sets drop out-of-range members as for Bool; a correlated column of either type is reconstructed only from a member of the same type name, as for Bool.

Session id: cron:clickhouse-impl-self-slot-57:20261106-124200

@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b667e67]

Summary: ✅


AI Review

Summary

The PR makes conversions into SimpleAggregateFunction(f, Bool) normalize values like Bool and adjusts dependent optimizations. One additional wrong-result case remains: index analysis removes a normalizing same-type cast before the new range guard runs. One new inline blocker was posted; previously dismissed findings remain recorded below.

Findings

❌ Blockers

  • src/Storages/MergeTree/KeyCondition.cpp:7378: Same-type casts still cause incorrect index pruning. isTrivialCast at line 715 removes a cast when source and target names match, although this PR makes that cast normalize stored bytes. Create a MergeTree table with v SimpleAggregateFunction(any, Bool), ORDER BY toUInt8(v), and index_granularity = 1, then insert toUInt8(number) from numbers(4). countIf(CAST(v, 'SimpleAggregateFunction(any, Bool)') = true) returns 3, but the equivalent WHERE returns 1, including with implicit projections and PREWHERE movement disabled. The reference rows are [1,2,3]; the filtered rows are [1]. A minmax index on toUInt8(v) has the same failure. Preserve normalizing casts in isTrivialCast and add focused regression coverage for this source type and numeric index expression.

Previously dismissed findings, retained as deferred concerns:

  • [dismissed by author -- https://github.com/Fix CAST into SimpleAggregateFunction(f, Bool) keeping values other than 0 and 1 #129731#discussion_r4528177211] Subquery IN still changes numeric membership. number IN (SELECT anySimpleState(true)) matches [1,2,3], while equality with true matches only 1. This remains a real comparison inconsistency, deliberately accepted here to match existing Bool behavior; the description links the follow-up PR #129892. The thread remains resolved.
  • [dismissed by author -- https://github.com/Fix CAST into SimpleAggregateFunction(f, Bool) keeping values other than 0 and 1 #129731#discussion_r4584690237] Boolean JOIN keys with differing nullable wrappers still change stored values. Two Boolean-valued keys containing raw 2 compare equal, but a normalizing wrapper conversion can make their JOIN return no match and make correlated results depend on substitution. The relevant code remains unchanged. The author deliberately deferred this existing Bool behavior to issue #130894 / PR #131433. The thread remains resolved.
Missing context / blind spots
  • ⚠️ Builds and functional tests for head b667e67b5e2f14e45d868984a972c3200add002e are pending. Runtime reproductions used the ARM release artifact for 213163be514263b92005da2cde046d432234eb8d; the faulty cast-removal path was verified against the exact current-head source and executes before the latest guard. The preceding targeted CI run passed all 50 runs of 05556_cast_to_simple_aggregate_function_bool.
Final Verdict

❌ Block — preserve normalizing same-type casts during index analysis and add the regression above. The previously dismissed concerns remain deferred to their existing follow-ups.

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @nihalzp @Manerone, could you review this and add the can be tested label so CI runs? SimpleAggregateFunction(f, Bool) stores Bool under its own name, so the name-based Bool branches of CAST (interpreted and JIT) and convertFieldToType skipped it and kept raw values like 2 or 300; the PR recognizes it there and in the places that must agree with the cast (monotonicity, native IN set paths, correlated subquery substitution).

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 6, 2026
@Manerone Manerone self-assigned this Nov 6, 2026
@Manerone Manerone added the can be tested Allows running workflows for external contributors label Nov 6, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... label Nov 6, 2026
Comment thread src/Functions/FunctionsConversion.h Resolved
Comment thread src/Functions/FunctionsConversion.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b667e67b5 with master 20786f02a (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.

Object file sizes

12 object files changed (+117.56 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Functions/FunctionsConversion.cpp.o 25.35 MiB 25.46 MiB +112.17 KiB (+0.43%)

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

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

Job report

@Manerone Manerone left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, the root cause is clear, and making SimpleAggregateFunction(f, Bool) behave exactly like Bool looks like the right contract to me. The CAST / convertFieldToType part is correct, and the test covers each changed site well.

One thing before merge: the monotonicity override misses SimpleAggregateFunction(any, Nullable(Bool)) (inline comment below). It is a one-condition fix, and it also covers plain Bool, which keeps the "same as Bool" contract consistent there too.

About the two P1 comments from the AI review (subquery IN and JOIN keys): I checked them against plain Bool on 26.6.1, and Bool behaves the same way:

SELECT true IN (2);          -- 0
SELECT 2 IN (SELECT true);   -- 1 (Set::execute casts the probe into Bool, so 2 becomes 1)
SELECT groupArray(number) FROM numbers(4) WHERE number IN (SELECT true);  -- [1,2,3]

For JOINs, Nullable(Bool) vs a UInt8 key also gives 1 or 0 depending on table order (with join_algorithm = 'partial_merge' or enable_join_runtime_filters = 0), because getLeastSupertype keeps whichever custom-named UInt8 type comes first. So with this PR the SAF type simply matches Bool here, and I don't think it should be fixed in this PR. Two small asks:

  • Mention in the description that subquery IN and JOIN keys into this type now follow Bool. For example, number IN (SELECT anySimpleState(true)) changes from [1] to [1,2,3].
  • Optionally, add a couple of queries to the test that show the SAF type and Bool give the same results there, so the two don't drift apart later.

The underlying problem is in Bool itself: implicit conversions and = disagree. = compares numerically (2 ≠ true), but the subquery IN probe and a JOIN key whose common type is Bool go through the cast into Bool, which turns any nonzero value into 1, so 2 matches true. For JOINs, the result also depends on table order. Could you open a separate issue for this, with the queries above, and link it here with Related:?

Minor follow-up, not blocking: JSONExtract('{"a":2}', 'a', 'SimpleAggregateFunction(any, Bool)') still returns 2 (JSONExtractTree.cpp also checks for Bool by name), while 'Bool' returns 1. This is another spot where the SAF type doesn't yet behave like Bool.

Comment thread src/Functions/FunctionsConversion.cpp Resolved
groeneai and others added 2 commits November 10, 2026 16:08
…IN keys and JSONExtract like Bool

Review feedback on ClickHouse#129731:

- The monotonicity override is checked after `removeNullable`, so for
  `SimpleAggregateFunction(any, Nullable(Bool))` (custom name on the Nullable
  wrapper) it saw plain `Bool`, which, like `Bool` and `Nullable(Bool)` themselves,
  fell into the `UInt8` branch that reports the cast as strict. Match plain `Bool`
  as well, so `optimize_read_in_order` / `optimize_distinct_in_order` over such a
  CAST no longer return wrong rows (the DISTINCT case aborted a debug build).

- ClickHouse#129894 (merged into master) compares a `Bool` JOIN key with an integer key in
  `UInt8`, but checks for `Bool` by name. With the CAST into
  `SimpleAggregateFunction(any, Bool)` now mapping 2 to 1, a
  `Nullable(SimpleAggregateFunction(any, Bool))` key joined with an `UInt8` key 2
  matched `true` in one table order only. `compareBoolKeysAsUInt8` now treats the
  SAF type as `Bool`.

- `JSONExtract(..., 'SimpleAggregateFunction(any, Bool)')` kept 2 instead of 1, and so did
  `LowCardinality(Bool)`, whose branch checked the `LowCardinality` type instead of its
  dictionary type.

The test gains `Bool` and `SimpleAggregateFunction(any, Nullable(Bool))` in the
in-order section, and queries that show subquery `IN`, JOIN keys and
`JSONExtract` give the same results for the SAF type and `Bool`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Changes in 435e3ad, plus a master merge (see the JOIN point):

  • Monotonicity: applied your suggestion, and the in-order section now also has Bool and SimpleAggregateFunction(any, Nullable(Bool)) (details in the thread).
  • Description: added that subquery IN into this type now follows Bool, with the [1] -> [1,2,3] example.
  • Parity queries: the new same as bool section compares the SAF type with Bool for subquery IN, JOIN keys in both table orders and JSONExtract.
  • JOIN keys: I merged master because Compare a Bool JOIN key with an integer key by value #129894 (merged 2026-11-07) compares a Bool JOIN key with an integer key as UInt8, but recognizes Bool by name. On the merged tree, this PR made Nullable(SimpleAggregateFunction(any, Bool)) JOIN UInt8 2 return 1 in one table order and 0 in the other, while Nullable(Bool) gives 0 both ways. compareBoolKeysAsUInt8 now treats the SAF type as Bool.
  • JSONExtract: fixed here too, together with LowCardinality(Bool), whose branch checked the LowCardinality wrapper instead of the dictionary type and so also kept 2.
  • The Bool problem itself: I didn't open a new issue because both halves already have fixes of mine, now linked with Related:: Compare a Bool JOIN key with an integer key by value #129894 for JOIN keys (merged) and Fix IN with a Bool subquery matching every nonzero number #129892 for subquery IN (open). If Fix IN with a Bool subquery matching every nonzero number #129892 lands after this PR, the IN parity query here will show that it needs to cover this type as well.

@clickhouse-gh clickhouse-gh Bot added comp-data-types Type system & core datatypes used across query planning/execution. and removed comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... labels Nov 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 435e3ad

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log not from this PR: background mutation of the empty DETACH PART part of 04653 retries UNKNOWN_IDENTIFIER b (MutatePlainMergeTreeTask, all_1_1_1_2) after the restart, seen on 51 PRs in 30 days (#120975) #125293 (external, open)
Mergeable Check, PR rollups of the row above #125293 (external, open)

CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261110-220011

clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 213163b

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted, old_compatibility) / Logical error: 'exact_ranges[i].end <= range.end' (STID: 2508-46d3) pre-existing for Bool: on master the same assertion fires for a plain CAST(u, 'Bool') filter on a minmax-indexed key under this job's compatibility = '24.3' (use_skip_indexes_on_data_read = 0), because the minmax index skips applying the UInt8 to Bool cast and prunes a granule inside an exact primary-key range. This PR makes SimpleAggregateFunction(any, Bool) behave as Bool, so the fuzzer reached it through this type. #116656 fixes the index condition for Bool; whichever of the two PRs lands second extends it to this type (report) #116656 (mine, open)
PR praktika rollup of the row above #116656 (mine, open)

CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261116-213021

@Manerone

Copy link
Copy Markdown
Contributor

@groeneai check the failing tests in the CI, if they are caused by this PR fix them

`functionIsCastPreservingFieldRepresentation` lets `KeyCondition` skip
applying a cast to the analyzed range when both types share a Field
representation. `Bool` and `SimpleAggregateFunction(f, Bool)` are `UInt8`
with a custom name, so a cast from `UInt8` into them passed the width test,
yet it maps every nonzero value to 1. A minmax skip index then kept the
granule [2, 2] as 2 and pruned it against `CAST(u, 'Bool') = true`.

With `use_skip_indexes_on_data_read = 0` that is a wrong count in release
(1 instead of 3 over 0..3), and in debug the aggregate-projection count path
aborts on `exact_ranges[i].end <= range.end` (AST fuzzer, STID 2508-46d3,
`compatibility = '24.3'`). Plain `Bool` has this on master; this PR made
`SimpleAggregateFunction(any, Bool)` reach it because its cast now
normalizes like a cast into `Bool`.

Never skip a cast into either type. Rows added to 05556 for both types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

The only failing check was AST fuzzer (amd_debug, targeted, old_compatibility) (exact_ranges[i].end <= range.end). Its query filters on CAST(u, 'SimpleAggregateFunction(any, Bool)'), which does not abort on master, so for this type it is caused by this PR. Index analysis skips applying a cast between UInt8-stored types to the granule range, and a cast into this type now maps 2 to 1 like a cast into Bool. So a minmax index on u pruned the granule [2, 2] against = true: over 0..3 the filter returned [1] instead of [1,2,3] with default settings, and with use_skip_indexes_on_data_read = 0 (set by the job's compatibility = '24.3') the count path hit that abort in debug.

Fixed in b667e67: functionIsCastPreservingFieldRepresentation no longer skips a cast into Bool or SimpleAggregateFunction(f, Bool). As with the monotonicity change, the condition also covers plain Bool, which returns the same [1] on master (my #116656 has the same Bool guard). 05556 has new rows for both types that fail on the previous head, and the fuzzed query now returns its row. I updated the description.

Comment thread src/Storages/MergeTree/KeyCondition.cpp Resolved
@clickhouse-gh
clickhouse-gh Bot dismissed their stale review November 17, 2026 11:54

AI review of a later commit does not approve the PR, see the AI Review comment.

@Manerone
Manerone added this pull request to the merge queue Nov 17, 2026
@Blargian
Blargian removed this pull request from the merge queue due to a manual request Nov 17, 2026
@Blargian
Blargian added this pull request to the merge queue Nov 17, 2026
Merged via the queue into ClickHouse:master with commit 9c1dc0f Nov 17, 2026
379 of 380 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 17, 2026
ClickHouse#129731 made a CAST into `SimpleAggregateFunction(f, Bool)` (with `f`
returning `Bool`) map every nonzero value to 1, as a CAST into `Bool` does,
and added `isSimpleAggregateFunctionOfBool`. `convertsToBool` matched only
the `Bool` custom name, so `UInt8` into such a column still counted as an
identity conversion: INSERT SELECT, MODIFY COLUMN and the other gates kept
the raw byte (2 stayed 2), and `WHERE CAST(v, 'Bool') = true` over a key on
`toUInt8(v)` then disagreed with a full scan.

`05556_cast_to_simple_aggregate_function_bool` inserted `toUInt8(2)` into
`Bool` and `SimpleAggregateFunction(any, Bool)` columns and expected it to be
stored as is. Both now store 1, so its correlated comparisons with the
`UInt8` value 2 count 0, with and without the substitution.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 20, 2026
…RT SELECT`

Since ClickHouse#129731, `VALUES` into a `SimpleAggregateFunction(f, Bool)` column
stores 0 and 1, so `t_saf` and `t_array_saf` no longer held the byte 2 the
test is about. `INSERT SELECT` of a `UInt8` still stores it, for this type
and for a plain `Bool`, so fill both tables that way. The reference is
unchanged: 17 of the 25 lines fail on the merge base and on 26.8.37.168,
26.9.25.15 and 26.10.5.57, and all pass with the fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 21, 2026
…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.
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 24, 2026
…Bool)

Since ClickHouse#129731, a CAST into `SimpleAggregateFunction(f, Bool)` normalizes the
value like a CAST into `Bool`. `needsConvertingCast` kept only a node named
`Bool` out of the relabelling casts, so `UInt8 -> SimpleAggregateFunction(any, Bool)`
counted as a relabel and got a `_CAST`: an INSERT ... SELECT toUInt8(2) and a view
over a `UInt8` column now stored/returned 1 for that type while `Bool` kept 2.
That is what made `05556_cast_to_simple_aggregate_function_bool` fail after the
master merge (its correlated block relies on the raw value).

Keep the full name of such a node, so it is relabelled neither from `UInt8` nor
from `Bool`, exactly as on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-data-types Type system & core datatypes used across query planning/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.

4 participants