pingcap / pingcap/tidb

Wrong result when comparing `BOOL UNSIGNED` column with `TAN()` result

Open
#69,151 4 comments 0 reactions 0 assignees View on GitHub
affects-8.1 affects-8.5 contribution severity/critical sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Comparing a floating-point expression with a `BOOL UNSIGNED` column produces a different result than comparing with `CAST(c1 AS SIGNED)`, even though both comparisons should evaluate the same boolean expression.

### 1. Minimal reproduce step (Required)

```sql
DROP DATABASE IF EXISTS testdb;
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE t0(c1 BOOL UNSIGNED NOT NULL);
INSERT INTO t0 VALUES (false), (true);

SELECT
TAN(-0.15),
c1,
TAN(-0.15) < c1,
TAN(-0.15) < CAST(c1 AS SIGNED)
FROM t0;
```

### 2. What did you expect to see? (Required)

`TAN(-0.15) < c1` and `TAN(-0.15) < CAST(c1 AS SIGNED)` should produce the same result for each row, since comparing a float with a BOOL value should be semantically equivalent to comparing the same float with the integer representation of that BOOL value.

Expected result:

```
+-------------------------+----+------------------+-----------------------------------+
| TAN(-0.15) | c1 | TAN(-0.15) < c1 | TAN(-0.15) < CAST(c1 AS SIGNED) |
+-------------------------+----+------------------+-----------------------------------+
| -0.15113521805829508 | 0 | 1 | 1 |
| -0.15113521805829508 | 1 | 1 | 1 |
+-------------------------+----+------------------+-----------------------------------+
```

### 3. What did you see instead (Required)

```sql
mysql> SELECT TAN(-0.15), c1, TAN(-0.15) < c1, TAN(-0.15) < CAST(c1 AS SIGNED) FROM t0;
+-------------------------+----+------------------+-----------------------------------+
| TAN(-0.15) | c1 | TAN(-0.15) < c1 | TAN(-0.15) < CAST(c1 AS SIGNED) |
+-------------------------+----+------------------+-----------------------------------+
| -0.15113521805829508 | 0 | 0 | 1 |
| -0.15113521805829508 | 1 | 0 | 1 |
+-------------------------+----+------------------+-----------------------------------+
```

`TAN(-0.15) < c1` incorrectly returns `0` for both rows, while `TAN(-0.15) < CAST(c1 AS SIGNED)` correctly returns `1`. The comparison with the `BOOL UNSIGNED` column gives wrong results.

### 4. What is your TiDB version? (Required)

```
Release Version: v8.5.6
Edition: Community
Git Commit Hash: ae18096e023780bb56bfce33698abec0d4640d0a
Git Branch: HEAD
UTC Build Time: 2026-06-04 05:49:11
GoVersion: go1.25.8
Race Enabled: false
Check Table Before Drop: false
Store: unistore
```

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.