pingcap / pingcap/tidb

Selecting INT column with COLLATE utf8mb4_general_ci throws an error

Open
#34,349 3 comments 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
affects-5.4 affects-6.1 affects-6.5 affects-7.1 affects-7.5 report/customer severity/moderate sig/sql-infra 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
set names utf8mb4;
select 'TEST' collate utf8mb4_general_ci;
select 1 collate utf8mb4_general_ci;
```

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

in MySQL, we can get this,
```sql
(root@127.1) [(none)] 09:17:46> select version();
+-----------+
| version() |
+-----------+
| 5.7.38 |
+-----------+
1 row in set (0.001 sec)

(root@127.1) [(none)] 09:17:50> create schema test;
Query OK, 1 row affected (0.002 sec)

(root@127.1) [(none)] 09:17:53> use test;
Database changed
(root@127.1) [test] 09:17:56> set names utf8mb4;
Query OK, 0 rows affected (0.001 sec)

(root@127.1) [test] 09:21:30> SELECT VARIABLE_NAME, VARIABLE_VALUE FROM performance_schema.session_variables WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%';
+--------------------------+--------------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_results | utf8mb4 |
| collation_connection | utf8mb4_general_ci |
+--------------------------+--------------------+
4 rows in set (0.004 sec)

(root@127.1) [performance_schema] 09:22:09> select 'TEST' collate utf8mb4_general_ci;
+-----------------------------------+
| 'TEST' collate utf8mb4_general_ci |
+-----------------------------------+
| TEST |
+-----------------------------------+
1 row in set (0.001 sec)

(root@127.1) [performance_schema] 09:22:28> select 1 collate utf8mb4_general_ci;
+------------------------------+
| 1 collate utf8mb4_general_ci |
+------------------------------+
| 1 |
+------------------------------+
1 row in set (0.001 sec)
```

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

but in TiDB, got this one,
```sql
TiDB [(none)] 08:37:17> select version();
+--------------------+
| version() |
+--------------------+
| 5.7.25-TiDB-v6.0.0 |
+--------------------+
1 row in set (0.001 sec)

TiDB [test] 08:37:35> set names utf8mb4;
Query OK, 0 rows affected (0.000 sec)

TiDB [test] 08:37:41> SELECT VARIABLE_NAME, VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME LIKE 'character_set_c%' OR VARIABLE_NAME LIKE 'character_set_re%' OR VARIABLE_NAME LIKE 'collation_c%';
+--------------------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+--------------------------+----------------+
| character_set_connection | utf8mb4 |
| character_set_client | utf8mb4 |
| collation_connection | utf8mb4_bin |
| character_set_results | utf8mb4 |
+--------------------------+----------------+
4 rows in set (0.018 sec)

TiDB [test] 08:37:51> select 'TEST' collate utf8mb4_general_ci;
+-----------------------------------+
| 'TEST' collate utf8mb4_general_ci |
+-----------------------------------+
| TEST |
+-----------------------------------+
1 row in set (0.001 sec)

TiDB [test] 08:37:56> select 1 collate utf8mb4_general_ci;
ERROR 1253 (42000): COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'binary'
```

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

```c
tidb_version(): Release Version: v6.0.0
Edition: Community
Git Commit Hash: 36a9810441ca0e496cbd22064af274b3be771081
Git Branch: heads/refs/tags/v6.0.0
UTC Build Time: 2022-03-31 10:33:28
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
```

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.