pingcap / pingcap/tidb

Inconsistent query result when using `IF` function with mixed types in NOT IN clause

Open
#66,344 4 comments 0 reactions 1 assignee Claimed by @guo-shaoge View on GitHub
contribution may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major severity/minor sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)
```SQL
mysql> CREATE TABLE t1 (c0 VARCHAR(10), c1 FLOAT);
Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE t0 (c2 FLOAT);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO t1 VALUES (NULL, 0.15635101107120514);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO t0 VALUES (0.15635101107120514);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT t1.c0, t1.c1, t0.c2 FROM t1, t0 WHERE t1.c1 = t0.c2;
+------+------------+------------+
| c0 | c1 | c2 |
+------+------------+------------+
| NULL | 0.15635101 | 0.15635101 |
+------+------------+------------+
1 row in set (0.00 sec)

mysql> SELECT t1.c0, t1.c1, t0.c2 FROM t1, t0 WHERE t1.c1 IN (t0.c2);
+------+------------+------------+
| c0 | c1 | c2 |
+------+------------+------------+
| NULL | 0.15635101 | 0.15635101 |
+------+------------+------------+
1 row in set (0.00 sec)

-- Problematic Query:
mysql> SELECT t1.c0, t1.c1, t0.c2
-> FROM t1, t0
-> WHERE NOT ((IF(0.02324252233242134, t1.c1, t1.c0)) NOT IN (t0.c2));
Empty set (0.00 sec)
```

### 2. What did you expect to see? (Required)
```SQL
mysql> SELECT t1.c0, t1.c1, t0.c2
-> FROM t1, t0
-> WHERE NOT ((IF(0.02324252233242134, t1.c1, t1.c0)) NOT IN (t0.c2));
+------+----------+----------+
| c0 | c1 | c2 |
+------+----------+----------+
| NULL | 0.156351 | 0.156351 |
+------+----------+----------+
1 row in set (0.01 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.45 |
+-----------+
1 row in set (0.01 sec)
```

### 3. What did you see instead (Required)
```SQL
mysql> SELECT t1.c0, t1.c1, t0.c2
-> FROM t1, t0
-> WHERE NOT ((IF(0.02324252233242134, t1.c1, t1.c0)) NOT IN (t0.c2));
Empty set (0.00 sec)
```

### 4. What is your TiDB version? (Required)
```SQL
mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-1250-g8bee66cb56
Edition: Community
Git Commit Hash: 8bee66cb5678a723ed89dd5b97907d7ebae388f1
Git Branch: master
UTC Build Time: 2026-02-24 01:55:46
GoVersion: go1.25.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Kernel Type: Classic |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.