Skip to content

Fix if function type mismatch between UInt64 and Int32 - #96012

Merged
Avogar merged 1 commit into
masterfrom
fix-issue-70017-if-uint64-int32-type-mismatch
Feb 6, 2026
Merged

Avogar merged 1 commit into
masterfrom
fix-issue-70017-if-uint64-int32-type-mismatch

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

When combining UInt64 (from floor of a large literal that fits in Int64) with Int32 in an if expression, the result type should be Int64. The canUnsignedBeSigned flag on DataTypeUInt64 indicates this, but it can be lost during distributed query plan transformations. When the flag is lost, the execution produces Int128 instead of the expected Int64.

This fix adds a check: when the expected result_type is Int64 but arguments are UInt64 and another integer type (and the flag is not present), use a new executeGenericWithType function to properly cast both columns to the expected result type.

Closes #70017

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):

Fix if function type mismatch between UInt64 and Int32 in an unusual case of distributed queries and PREWHERE, with type inference. Closes #70017.

@Avogar, I'm surprised we have such weird code. But as long as we have a bug fix, I'm ready to take it.

Version info

  • Merged into: 26.2.1.316

When combining UInt64 (from floor of a large literal that fits in Int64)
with Int32 in an if expression, the result type should be Int64. The
`canUnsignedBeSigned` flag on DataTypeUInt64 indicates this, but it can
be lost during distributed query plan transformations. When the flag is
lost, the execution produces Int128 instead of the expected Int64.

This fix adds a check: when the expected result_type is Int64 but
arguments are UInt64 and another integer type (and the flag is not
present), use a new `executeGenericWithType` function to properly cast
both columns to the expected result type.

Closes #70017

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [afe5926]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_binary, 4/5) failure
test_server_overload/test.py::test_drop_connections FAIL cidb, issue ISSUE CREATED
Stress test (amd_tsan) failure
Logical error: Unexpected return type from A. Expected B. Got C. Action: (STID: 1611-3d19) FAIL cidb, issue ISSUE EXISTS
Stress test (arm_asan, s3) failure
Logical error: Cannot modify size limits to A in size and B in elements: not enough space freed. Current size: C/D, elements: E/F (G) (STID: 4012-44fe) FAIL cidb, issue ISSUE EXISTS
Stress test (amd_ubsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue ISSUE EXISTS
BuzzHouse (amd_tsan) error IGNORED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Feb 5, 2026
@Avogar Avogar self-assigned this Feb 6, 2026
@Avogar
Avogar added this pull request to the merge queue Feb 6, 2026
Merged via the queue into master with commit 8674d12 Feb 6, 2026
124 of 129 checks passed
@Avogar
Avogar deleted the fix-issue-70017-if-uint64-int32-type-mismatch branch February 6, 2026 13:26
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Server throws exception: Logical error: 'Unexpected return type from if. Expected Int64. Got Int128.

3 participants