1
drop table if exists t1,t2;
2
create table t1 (name char(20) not null, primary key (name));
3
create table t2 (name char(20) binary not null, primary key (name));
4
insert into t1 values ("�");
5
insert into t1 values ("�");
6
insert into t1 values ("�");
7
insert into t2 select * from t1;
8
select * from t1 order by name;
13
select concat("*",name,"*") from t1 order by 1;
18
select min(name),min(concat("*",name,"*")),max(name),max(concat("*",name,"*")) from t1;
19
min(name) min(concat("*",name,"*")) max(name) max(concat("*",name,"*"))
21
select * from t2 order by name;
26
select concat("*",name,"*") from t2 order by 1;
31
select min(name),min(concat("*",name,"*")),max(name),max(concat("*",name,"*")) from t2;
32
min(name) min(concat("*",name,"*")) max(name) max(concat("*",name,"*"))
34
select name from t1 where name between '�' and '�';
38
select name from t2 where name between '�' and '�';
43
select name from t2 where name between '�' and '�';
46
create table t1 (a char(10) not null, b char(10) binary not null,key (a), key(b));
47
insert into t1 values ("hello ","hello "),("hello2 ","hello2 ");
48
select concat("-",a,"-",b,"-") from t1 where a="hello";
49
concat("-",a,"-",b,"-")
51
select concat("-",a,"-",b,"-") from t1 where a="hello ";
52
concat("-",a,"-",b,"-")
54
select concat("-",a,"-",b,"-") from t1 ignore index (a) where a="hello ";
55
concat("-",a,"-",b,"-")
57
select concat("-",a,"-",b,"-") from t1 where b="hello";
58
concat("-",a,"-",b,"-")
60
select concat("-",a,"-",b,"-") from t1 where b="hello ";
61
concat("-",a,"-",b,"-")
63
select concat("-",a,"-",b,"-") from t1 ignore index (b) where b="hello ";
64
concat("-",a,"-",b,"-")
66
alter table t1 modify b tinytext not null, drop key b, add key (b(100));
67
select concat("-",a,"-",b,"-") from t1;
68
concat("-",a,"-",b,"-")
71
select concat("-",a,"-",b,"-") from t1 where b="hello ";
72
concat("-",a,"-",b,"-")
74
select concat("-",a,"-",b,"-") from t1 ignore index (b) where b="hello ";
75
concat("-",a,"-",b,"-")
78
create table t1 (b char(8));
79
insert into t1 values(NULL);
80
select b from t1 where binary b like '';
82
select b from t1 group by binary b like '';
85
select b from t1 having binary b like '';
88
create table t1 (a char(3) binary, b binary(3));
89
insert into t1 values ('aaa','bbb'),('AAA','BBB');
90
select upper(a),upper(b) from t1;
94
select lower(a),lower(b) from t1;
98
select * from t1 where upper(a)='AAA';
102
select * from t1 where lower(a)='aaa';
106
select * from t1 where upper(b)='BBB';
109
select * from t1 where lower(b)='bbb';
112
select charset(a), charset(b), charset(binary 'ccc') from t1 limit 1;
113
charset(a) charset(b) charset(binary 'ccc')
115
select collation(a), collation(b), collation(binary 'ccc') from t1 limit 1;
116
collation(a) collation(b) collation(binary 'ccc')
117
latin1_bin binary binary
119
create table t1( firstname char(20), lastname char(20));
120
insert into t1 values ("john","doe"),("John","Doe");
121
select * from t1 where firstname='john' and firstname like binary 'john';
124
select * from t1 where firstname='john' and binary 'john' = firstname;
127
select * from t1 where firstname='john' and firstname = binary 'john';
130
select * from t1 where firstname='John' and firstname like binary 'john';
133
select * from t1 where firstname='john' and firstname like binary 'John';
137
create table t1 (a binary);
138
show create table t1;
140
t1 CREATE TABLE "t1" (
142
) ENGINE=MyISAM DEFAULT CHARSET=latin1
144
create table t1 (col1 binary(4));
145
insert into t1 values ('a'),('a ');
146
select hex(col1) from t1;
150
alter table t1 modify col1 binary(10);
151
select hex(col1) from t1;
155
insert into t1 values ('b'),('b ');
156
select hex(col1) from t1;
164
a binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
167
INSERT INTO t1 SET a=unhex('1F9480179366F2BF567E1C4B964C1EF029087575');
168
INSERT INTO t1 SET a=unhex('1F9480179366F2BF567E1C4B964C1EF029082020');
169
INSERT INTO t1 SET a=unhex('1F9480179366F2BF567E1C4B964C1EF029080707');
170
SELECT hex(a) FROM t1 order by a;
172
1F9480179366F2BF567E1C4B964C1EF029080707
173
1F9480179366F2BF567E1C4B964C1EF029082020
174
1F9480179366F2BF567E1C4B964C1EF029087575
175
EXPLAIN SELECT hex(a) FROM t1 order by a;
176
id select_type table type possible_keys key key_len ref rows Extra
177
1 SIMPLE t1 index NULL idx 20 NULL 3 Using index
178
SELECT hex(a) from t1 WHERE a=unhex('1F9480179366F2BF567E1C4B964C1EF029082020');
180
1F9480179366F2BF567E1C4B964C1EF029082020
182
SELECT hex(a) from t1 WHERE a=unhex('1F9480179366F2BF567E1C4B964C1EF029082020');
183
id select_type table type possible_keys key key_len ref rows Extra
184
1 SIMPLE t1 ref idx idx 20 const 1 Using where; Using index
185
SELECT hex(a) from t1 WHERE a=unhex('1F9480179366F2BF567E1C4B964C1EF02908');
189
id numeric(20) NOT NULL,
190
lang varchar(8) NOT NULL,
191
msg varchar(32) NOT NULL,
192
PRIMARY KEY (id,lang)
194
INSERT INTO t1 VALUES (33, 'en', 'zzzzzzz');
195
INSERT INTO t1 VALUES (31, 'en', 'xxxxxxx');
196
INSERT INTO t1 VALUES (32, 'en', 'yyyyyyy');
197
SELECT * FROM t1 WHERE id=32;