Incorrect results with LIKE operator on BOOL column due to inconsistent binary/string conversion behavior
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
When using the `LIKE` operator on boolean columns with mixed binary and non-binary comparisons, TiDB returns unexpected results due to inconsistent type handling.
### 1. Minimal reproduce step
```sql
CREATE TABLE t0(c0 BOOL);
CREATE TABLE t1 LIKE t0;
INSERT INTO t0 VALUES (false);
INSERT INTO t1 VALUES (false);
SELECT * FROM t0 JOIN t1 ON t0.c0 LIKE t1.c0 AND BINARY(t0.c0) NOT LIKE t1.c0 AND t0.c0 NOT LIKE t1.c0; -- expect: empty set
+------+------+
| c0 | c0 |
+------+------+
| 0 | 0 |
+------+------+
1 row in set (0.00 sec)
SELECT * FROM t0 JOIN t1 ON t0.c0 LIKE t1.c0 AND t0.c0 NOT LIKE t1.c0 AND BINARY(t0.c0) NOT LIKE t1.c0;
Empty set (0.00 sec)
```
### 2. What did you expect to see?
The expression `t0.c0 LIKE t1.c0 AND t0.c0 NOT LIKE t1.c0` should always evaluate to `FALSE`, making the entire result set empty.
```sql
SELECT * FROM t0 JOIN t1 ON t0.c0 LIKE t1.c0 AND BINARY(t0.c0) NOT LIKE t1.c0 AND t0.c0 NOT LIKE t1.c0;
Empty set (0.00 sec)
```
### 3. What did you see instead
However, TiDB incorrectly returns a row.
```sql
SELECT * FROM t0 JOIN t1 ON t0.c0 LIKE t1.c0 AND BINARY(t0.c0) NOT LIKE t1.c0 AND t0.c0 NOT LIKE t1.c0;
+------+------+
| c0 | c0 |
+------+------+
| 0 | 0 |
+------+------+
Empty set (0.00 sec)
```
### 4. What is your TiDB version?
v8.5.0, v8.5.1, v8.5.2
| Release Version: v8.5.2
Edition: Community
Git Commit Hash: f43a13324440f92209e2a9f04c0bbe9cf763978d
Git Branch: HEAD
UTC Build Time: 2025-05-29 03:30:55
GoVersion: go1.23.8
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
Contributor guide
Research direction
Start by running the reported CREATE TABLE, INSERT, and JOIN queries against TiDB v8.5.2 to reproduce the inconsistent LIKE and NOT LIKE results. Trace the SQL expression handling for BOOL columns and mixed binary/non-binary comparisons, then add regression coverage showing that contradictory LIKE predicates return an empty set.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100