Incorrect SUM() result on constant IF expression with BLOB column (returns 48 instead of 0)
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
drop table if exists t1;
create table t1
(
c0 tinyblob not null
);
INSERT INTO t1 (c0) VALUES (0x31343936393730313331);
SELECT SUM((IF(t1.c0 IS NULL, t1.c0, 0)))
FROM t1;
### 2. What did you expect to see? (Required)
0
Reason:
The column c0 is defined as NOT NULL, so the condition:
t1.c0 IS NULL
is always FALSE.
Therefore, the expression:
IF(t1.c0 IS NULL, t1.c0, 0)
always evaluates to:
0
So the query is equivalent to:
SELECT SUM(0) FROM t1;
which should return:
0
### 3. What did you see instead (Required)
48
### 4. What is your TiDB version? (Required)
Release Version: v8.5.5
Edition: Community
Git Commit Hash: 1fa258b833ff113883beeba40bc130be7ce66610
Git Branch: HEAD
UTC Build Time: 2026-01-14 22:19:19
GoVersion: go1.25.5
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Contributor guide
Assessment
This issue has not been assessed yet.