~drizzle-trunk/drizzle/development

1 by brian
clean slate
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;
9
name
10
å
11
ä
12
ö
13
select concat("*",name,"*") from t1 order by 1;
14
concat("*",name,"*")
15
*å*
16
*ä*
17
*ö*
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,"*"))
20
å	*å*	ö	*ö*
21
select * from t2 order by name;
22
name
23
ä
24
å
25
ö
26
select concat("*",name,"*") from t2 order by 1;
27
concat("*",name,"*")
28
*ä*
29
*å*
30
*ö*
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,"*"))
33
ä	*ä*	ö	*ö*
34
select name from t1 where name between 'Ä' and 'Ö';
35
name
36
ä
37
ö
38
select name from t2 where name between 'ä' and 'ö';
39
name
40
ä
41
å
42
ö
43
select name from t2 where name between 'Ä' and 'Ö';
44
name
45
drop table t1,t2;
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,"-")
50
-hello-hello-
51
select concat("-",a,"-",b,"-") from t1 where a="hello ";
52
concat("-",a,"-",b,"-")
53
-hello-hello-
54
select concat("-",a,"-",b,"-") from t1 ignore index (a) where a="hello ";
55
concat("-",a,"-",b,"-")
56
-hello-hello-
57
select concat("-",a,"-",b,"-") from t1 where b="hello";
58
concat("-",a,"-",b,"-")
59
-hello-hello-
60
select concat("-",a,"-",b,"-") from t1 where b="hello ";
61
concat("-",a,"-",b,"-")
62
-hello-hello-
63
select concat("-",a,"-",b,"-") from t1 ignore index (b) where b="hello ";
64
concat("-",a,"-",b,"-")
65
-hello-hello-
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,"-")
69
-hello-hello-
70
-hello2-hello2-
71
select concat("-",a,"-",b,"-") from t1 where b="hello ";
72
concat("-",a,"-",b,"-")
73
-hello-hello-
74
select concat("-",a,"-",b,"-") from t1 ignore index (b) where b="hello ";
75
concat("-",a,"-",b,"-")
76
-hello-hello-
77
drop table t1;
78
create table t1 (b char(8));
79
insert into t1 values(NULL);
80
select b from t1 where binary b like '';
81
b
82
select b from t1 group by binary b like '';
83
b
84
NULL
85
select b from t1 having binary b like '';
86
b
87
drop table t1;
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;
91
upper(a)	upper(b)
92
AAA	bbb
93
AAA	BBB
94
select lower(a),lower(b) from t1;
95
lower(a)	lower(b)
96
aaa	bbb
97
aaa	BBB
98
select * from t1 where upper(a)='AAA';
99
a	b
100
aaa	bbb
101
AAA	BBB
102
select * from t1 where lower(a)='aaa';
103
a	b
104
aaa	bbb
105
AAA	BBB
106
select * from t1 where upper(b)='BBB';
107
a	b
108
AAA	BBB
109
select * from t1 where lower(b)='bbb';
110
a	b
111
aaa	bbb
112
select charset(a), charset(b), charset(binary 'ccc') from t1 limit 1;
113
charset(a)	charset(b)	charset(binary 'ccc')
114
latin1	binary	binary
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
118
drop table t1;
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';
122
firstname	lastname
123
john	doe
124
select * from t1 where firstname='john' and binary 'john' = firstname;
125
firstname	lastname
126
john	doe
127
select * from t1 where firstname='john' and firstname = binary 'john';
128
firstname	lastname
129
john	doe
130
select * from t1 where firstname='John' and firstname like binary 'john';
131
firstname	lastname
132
john	doe
133
select * from t1 where firstname='john' and firstname like binary 'John';
134
firstname	lastname
135
John	Doe
136
drop table t1;
137
create table t1 (a binary);
138
show create table t1;
139
Table	Create Table
140
t1	CREATE TABLE "t1" (
141
  "a" binary(1)
142
) ENGINE=MyISAM DEFAULT CHARSET=latin1
143
drop table t1;
144
create table t1 (col1 binary(4));
145
insert into t1 values ('a'),('a ');
146
select hex(col1) from t1;
147
hex(col1)
148
61000000
149
61200000
150
alter table t1 modify col1 binary(10);
151
select hex(col1) from t1;
152
hex(col1)
153
61000000000000000000
154
61200000000000000000
155
insert into t1 values ('b'),('b ');
156
select hex(col1) from t1;
157
hex(col1)
158
61000000000000000000
159
61200000000000000000
160
62000000000000000000
161
62200000000000000000
162
drop table t1;
163
CREATE TABLE 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', 
165
index idx(a)
166
);
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;
171
hex(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');
179
hex(a)
180
1F9480179366F2BF567E1C4B964C1EF029082020
181
EXPLAIN
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');
186
hex(a)
187
DROP TABLE t1;
188
CREATE TABLE t1 (
189
id numeric(20) NOT NULL,
190
lang varchar(8) NOT NULL,
191
msg varchar(32) NOT NULL,
192
PRIMARY KEY (id,lang)
193
);
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;
198
id	lang	msg
199
32	en	yyyyyyy
200
DROP TABLE t1;