pingcap / pingcap/tidb

Inconsistent Behavior When Comparing CHAR Column with Binary Values

Open
#58,810 5 comments 0 reactions 0 assignees View on GitHub
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
drop table if exists t;
create table t (a char(20) charset utf8mb4, b char(20) charset gbk, c binary(20));
insert into t values ('一', '一', 0xe4b880);
insert into t values ('一', '一', 0xd2bb);
insert into t values ('一', '一', 0xe4ba8c);
insert into t values ('一', '一', 0xb6fe);
select * from t where a >= 0xb6fe and a <= 0xb6fe; -- error
select * from t where a between 0xb6fe and 0xb6fe; -- empty set
```

### 2. What did you expect to see? (Required)
Both sql statements return the same result.
### 3. What did you see instead (Required)
```sql
tidb> select * from t where a >= 0xb6fe and a <= 0xb6fe;
ERROR 1105 (HY000): Cannot convert string '\xB6\xFE' from binary to utf8mb4
tidb> select * from t where a between 0xb6fe and 0xb6fe;
Empty set, 2 warnings (0.00 sec)

tidb> show warnings;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 3854 | Cannot convert string '\xB6\xFE' from binary to utf8mb4 |
| Warning | 3854 | Cannot convert string '\xB6\xFE' from binary to utf8mb4 |
+---------+------+---------------------------------------------------------+
2 rows in set (0.00 sec)
```

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

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.