tidb
tidb copied to clipboard
Behavior on VARBINARY data type of comparison operator 'LIKE' is different from mysql
Please answer these questions before submitting your issue. Thanks!
- What did you do? If possible, provide a recipe for reproducing the error.
check the behavior of 'LIKE' on different data types.
create table t (a char(10), b varchar(10), c binary(10), d varbinary(10));
insert into t values ('text','text','text','text');
mysql> desc t;
+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| a | char(10) | YES | | NULL | |
| b | varchar(10) | YES | | NULL | |
| c | binary(10) | YES | | NULL | |
| d | varbinary(10) | YES | | NULL | |
+-------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from t;
+------+------+------------+------+
| a | b | c | d |
+------+------+------------+------+
| text | text | text | text |
+------+------+------------+------+
1 row in set (0.00 sec)
- What did you expect to see?
MySQL
mysql> select * from t where a like 'TEXT';
+------+------+------------+------+
| a | b | c | d |
+------+------+------------+------+
| text | text | text | text |
+------+------+------------+------+
1 row in set (0.00 sec)
mysql> select * from t where b like 'TEXT';
+------+------+------------+------+
| a | b | c | d |
+------+------+------------+------+
| text | text | text | text |
+------+------+------------+------+
1 row in set (0.00 sec)
mysql> select * from t where c like 'TEXT';
Empty set (0.00 sec)
mysql> select * from t where d like 'TEXT';
Empty set (0.00 sec)
- What did you see instead?
TiDB
MySQL [gin]> select * from t where a like 'TEXT';
+------+------+------------+------+
| a | b | c | d |
+------+------+------------+------+
| text | text | text | text |
+------+------+------------+------+
1 row in set (0.01 sec)
MySQL [gin]> select * from t where b like 'TEXT';
+------+------+------------+------+
| a | b | c | d |
+------+------+------------+------+
| text | text | text | text |
+------+------+------------+------+
1 row in set (0.00 sec)
MySQL [gin]> select * from t where c like 'TEXT';
Empty set (0.00 sec)
MySQL [gin]> select * from t where d like 'TEXT';
+------+------+------------+------+
| a | b | c | d |
+------+------+------------+------+
| text | text | text | text |
+------+------+------------+------+
1 row in set (0.00 sec)
- What version of TiDB are you using (
tidb-server -V)? Git Commit Hash: 365e4ab491b683a69c2004f30b1ae4f86256e2ad Git Commit Branch: master UTC Build Time: 2017-08-16 01:24:27
thanks for your feed back ! to #4080
TiDB defaults to, and only supports binary collation (documented here). Support for a case insensitive collation is on the ROADMAP.
This now works in TiDB when the server is bootstrapped with collations enabled, and the table is created with an insensitive collation (tidb defaults to binary collation). Here is a pastable testcase:
drop table if exists t;
create table t (a char(10), b varchar(10), c binary(10), d varbinary(10)) collate utf8mb4_general_ci;
insert into t values ('text','text','text','text');
desc t;
select * from t;
select * from t where a like 'TEXT';
select * from t where b like 'TEXT';
select * from t where c like 'TEXT';
select * from t where d like 'TEXT';
select * from t where a = 'TEXT';
select * from t where b = 'TEXT';
select * from t where c = 'TEXT';
select * from t where d = 'TEXT';
..
mysql> select * from t;
+------+------+------------------------+------------+
| a | b | c | d |
+------+------+------------------------+------------+
| text | text | 0x74657874000000000000 | 0x74657874 |
+------+------+------------------------+------------+
1 row in set (0.00 sec)
mysql> select * from t where a like 'TEXT';
+------+------+------------------------+------------+
| a | b | c | d |
+------+------+------------------------+------------+
| text | text | 0x74657874000000000000 | 0x74657874 |
+------+------+------------------------+------------+
1 row in set (0.00 sec)
mysql> select * from t where b like 'TEXT';
+------+------+------------------------+------------+
| a | b | c | d |
+------+------+------------------------+------------+
| text | text | 0x74657874000000000000 | 0x74657874 |
+------+------+------------------------+------------+
1 row in set (0.00 sec)
mysql> select * from t where c like 'TEXT';
Empty set (0.00 sec)
mysql> select * from t where d like 'TEXT';
Empty set (0.01 sec)
mysql> select * from t where a = 'TEXT';
+------+------+------------------------+------------+
| a | b | c | d |
+------+------+------------------------+------------+
| text | text | 0x74657874000000000000 | 0x74657874 |
+------+------+------------------------+------------+
1 row in set (0.00 sec)
mysql> select * from t where b = 'TEXT';
+------+------+------------------------+------------+
| a | b | c | d |
+------+------+------------------------+------------+
| text | text | 0x74657874000000000000 | 0x74657874 |
+------+------+------------------------+------------+
1 row in set (0.00 sec)
mysql> select * from t where c = 'TEXT';
Empty set (0.00 sec)
mysql> select * from t where d = 'TEXT';
Empty set (0.00 sec)
I am going to close this issue now. Thanks!