~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1,t2;
2
set @a := foo;
3
ERROR 42S22: Unknown column 'foo' in 'field list'
4
set @a := connection_id() + 3;
5
select @a - connection_id();
6
@a - connection_id()
7
3
8
set @b := 1;
9
select @b;
10
@b
11
1
12
CREATE TABLE t1 ( i int not null, v int not null,index (i));
13
insert into t1 values (1,1),(1,3),(2,1);
14
create table t2 (i int not null, unique (i));
15
insert into t2 select distinct i from t1;
16
select * from t2;
17
i
18
1
19
2
20
select distinct t2.i,@vv1:=if(sv1.i,1,0),@vv2:=if(sv2.i,1,0),@vv3:=if(sv3.i,1,0), @vv1+@vv2+@vv3 from t2 left join t1 as sv1 on sv1.i=t2.i and sv1.v=1 left join t1 as sv2 on sv2.i=t2.i and sv2.v=2 left join t1 as sv3 on sv3.i=t2.i and sv3.v=3;
21
i	@vv1:=if(sv1.i,1,0)	@vv2:=if(sv2.i,1,0)	@vv3:=if(sv3.i,1,0)	@vv1+@vv2+@vv3
22
1	1	0	1	2
23
2	1	0	0	1
24
explain select * from t1 where i=@vv1;
25
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
26
1	SIMPLE	t1	ref	i	i	4	const	1	
27
select @vv1,i,v from t1 where i=@vv1;
28
@vv1	i	v
29
1	1	1
30
1	1	3
31
explain select * from t1 where @vv1:=@vv1+1 and i=@vv1;
32
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
33
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
34
explain select @vv1:=i from t1 where i=@vv1;
35
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
36
1	SIMPLE	t1	index	NULL	i	4	NULL	3	Using where; Using index
37
explain select * from t1 where i=@vv1;
38
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
39
1	SIMPLE	t1	ref	i	i	4	const	1	
40
drop table t1,t2;
41
set @a=0,@b=0;
42
select @a:=10,   @b:=1,   @a > @b, @a < @b;
43
@a:=10	@b:=1	@a > @b	@a < @b
44
10	1	1	0
45
select @a:="10", @b:="1", @a > @b, @a < @b;
46
@a:="10"	@b:="1"	@a > @b	@a < @b
47
10	1	1	0
48
select @a:=10,   @b:=2,   @a > @b, @a < @b;
49
@a:=10	@b:=2	@a > @b	@a < @b
50
10	2	0	1
51
select @a:="10", @b:="2", @a > @b, @a < @b;
52
@a:="10"	@b:="2"	@a > @b	@a < @b
53
10	2	1	0
54
select @a:=1;
55
@a:=1
56
1
57
select @a, @a:=1;
58
@a	@a:=1
59
1	1
60
create table t1 (id int, d double, c char(10));
61
insert into t1 values (1,2.0, "test");
62
select @c:=0;
63
@c:=0
64
0
65
update t1 SET id=(@c:=@c+1);
66
select @c;
67
@c
68
1
69
select @c:=0;
70
@c:=0
71
0
72
update t1 set id=(@c:=@c+1);
73
select @c;
74
@c
75
1
76
select @c:=0;
77
@c:=0
78
0
79
select @c:=@c+1;
80
@c:=@c+1
81
1
82
select @d,(@d:=id),@d from t1;
83
@d	(@d:=id)	@d
84
NULL	1	1
85
select @e,(@e:=d),@e from t1;
86
@e	(@e:=d)	@e
87
NULL	2	2
88
select @f,(@f:=c),@f from t1;
89
@f	(@f:=c)	@f
90
NULL	test	test
91
set @g=1;
92
select @g,(@g:=c),@g from t1;
93
@g	(@g:=c)	@g
94
1	test	0
95
select @c, @d, @e, @f;
96
@c	@d	@e	@f
97
1	1	2	test
98
select @d:=id, @e:=id, @f:=id, @g:=@id from t1;
99
@d:=id	@e:=id	@f:=id	@g:=@id
100
1	1	1	NULL
101
select @c, @d, @e, @f, @g;
102
@c	@d	@e	@f	@g
103
1	1	1	1	NULL
104
drop table t1;
105
select @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b, @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b;
106
@a:=10	@b:=2	@a>@b	@a:="10"	@b:="2"	@a>@b	@a:=10	@b:=2	@a>@b	@a:="10"	@b:="2"	@a>@b
107
10	2	1	10	2	1	10	2	1	10	2	1
108
create table t1 (i int not null);
109
insert t1 values (1),(2),(2),(3),(3),(3);
110
select @a:=0;
111
@a:=0
112
0
113
select @a, @a:=@a+count(*), count(*), @a from t1 group by i;
114
@a	@a:=@a+count(*)	count(*)	@a
115
0	1	1	0
116
0	2	2	0
117
0	3	3	0
118
select @a:=0;
119
@a:=0
120
0
121
select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i;
122
@a+0	@a:=@a+0+count(*)	count(*)	@a+0
123
0	1	1	0
124
1	3	2	0
125
3	6	3	0
126
set @a=0;
127
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
128
@a	@a:="hello"	@a	@a:=3	@a	@a:="hello again"
129
0	hello	0	3	0	hello again
130
0	hello	0	3	0	hello again
131
0	hello	0	3	0	hello again
132
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
133
@a	@a:="hello"	@a	@a:=3	@a	@a:="hello again"
134
hello again	hello	hello again	3	hello again	hello again
135
hello again	hello	hello again	3	hello again	hello again
136
hello again	hello	hello again	3	hello again	hello again
137
drop table t1;
779.3.10 by Monty Taylor
Turned on -Wshadow.
138
set @a='test';
139
select collation(@a),coercibility(@a);
140
collation(@a)	coercibility(@a)
141
utf8_general_ci	2
142
select @a='TEST';
143
@a='TEST'
144
1
145
select @a='TEST' collate utf8_bin;
146
@a='TEST' collate utf8_bin
147
0
148
set @a='test' collate utf8_general_ci;
149
select collation(@a),coercibility(@a);
150
collation(@a)	coercibility(@a)
151
utf8_general_ci	2
152
select @a='TEST';
153
@a='TEST'
154
1
155
select @a='TEST' collate utf8_bin;
156
@a='TEST' collate utf8_bin
157
0
158
select collation(@a:='test');
159
collation(@a:='test')
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
160
utf8_general_ci
779.3.10 by Monty Taylor
Turned on -Wshadow.
161
select coercibility(@a:='test');
162
coercibility(@a:='test')
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
163
2
779.3.10 by Monty Taylor
Turned on -Wshadow.
164
select collation(@a:='test' collate utf8_bin);
165
collation(@a:='test' collate utf8_bin)
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
166
utf8_bin
779.3.10 by Monty Taylor
Turned on -Wshadow.
167
select coercibility(@a:='test' collate utf8_bin);
168
coercibility(@a:='test' collate utf8_bin)
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
169
2
779.3.10 by Monty Taylor
Turned on -Wshadow.
170
select (@a:='test' collate utf8_bin) = 'TEST';
171
(@a:='test' collate utf8_bin) = 'TEST'
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
172
0
173
select collation(@a),coercibility(@a);
174
collation(@a)	coercibility(@a)
175
utf8_bin	2
779.3.10 by Monty Taylor
Turned on -Wshadow.
176
select (@a:='test' collate utf8_bin) = 'TEST' collate utf8_general_ci;
177
(@a:='test' collate utf8_bin) = 'TEST' collate utf8_general_ci
1 by brian
clean slate
178
1
179
set @var= NULL ;
180
select FIELD( @var,'1it','Hit') as my_column;
181
my_column
182
0
183
select @v, coercibility(@v);
184
@v	coercibility(@v)
185
NULL	2
186
set @v1=null, @v2=1, @v3=1.1, @v4=now();
187
select coercibility(@v1),coercibility(@v2),coercibility(@v3),coercibility(@v4);
188
coercibility(@v1)	coercibility(@v2)	coercibility(@v3)	coercibility(@v4)
189
2	2	2	2
190
set session @honk=99;
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
191
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '@honk=99' at line 1
1 by brian
clean slate
192
select @@local.max_allowed_packet;
193
@@local.max_allowed_packet
194
#
195
select @@session.max_allowed_packet;
196
@@session.max_allowed_packet
197
#
198
select @@global.max_allowed_packet;
199
@@global.max_allowed_packet
200
#
201
select @@max_allowed_packet;
202
@@max_allowed_packet
203
#
204
select @@Max_Allowed_Packet;
205
@@Max_Allowed_Packet
206
#
207
select @@version;
208
@@version
209
#
210
select @@global.version;
211
@@global.version
212
#
213
End of 4.1 tests
214
set @first_var= NULL;
215
create table t1 select @first_var;
216
show create table t1;
217
Table	Create Table
218
t1	CREATE TABLE `t1` (
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
219
  `@first_var` blob
942.3.1 by Vladimir Kolesnikov
test generalizations
220
) ENGINE=DEFAULT
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
221
drop table t1;
222
set @first_var= cast(NULL as integer);
223
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'integer)' at line 1
1 by brian
clean slate
224
set @first_var= NULL;
225
create table t1 select @first_var;
226
show create table t1;
227
Table	Create Table
228
t1	CREATE TABLE `t1` (
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
229
  `@first_var` blob
942.3.1 by Vladimir Kolesnikov
test generalizations
230
) ENGINE=DEFAULT
1 by brian
clean slate
231
drop table t1;
232
set @first_var= concat(NULL);
233
create table t1 select @first_var;
234
show create table t1;
235
Table	Create Table
236
t1	CREATE TABLE `t1` (
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
237
  `@first_var` blob
942.3.1 by Vladimir Kolesnikov
test generalizations
238
) ENGINE=DEFAULT
1 by brian
clean slate
239
drop table t1;
240
set @first_var=1;
241
set @first_var= cast(NULL as CHAR);
242
create table t1 select @first_var;
243
show create table t1;
244
Table	Create Table
245
t1	CREATE TABLE `t1` (
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
246
  `@first_var` text
942.3.1 by Vladimir Kolesnikov
test generalizations
247
) ENGINE=DEFAULT
1 by brian
clean slate
248
drop table t1;
249
set @a=18446744071710965857;
250
select @a;
251
@a
252
18446744071710965857
253
CREATE TABLE `bigfailure` (
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
254
`afield` BIGINT NOT NULL
1 by brian
clean slate
255
);
256
INSERT INTO `bigfailure` VALUES (18446744071710965857);
257
SELECT * FROM bigfailure;
258
afield
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
259
-1998585759
1 by brian
clean slate
260
select * from (SELECT afield FROM bigfailure) as b;
261
afield
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
262
-1998585759
1 by brian
clean slate
263
select * from bigfailure where afield = (SELECT afield FROM bigfailure);
264
afield
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
265
-1998585759
1 by brian
clean slate
266
select * from bigfailure where afield = 18446744071710965857;
267
afield
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
268
-1998585759
269
select * from bigfailure where afield = '18446744071710965857';
270
afield
1 by brian
clean slate
271
select * from bigfailure where afield = 18446744071710965856+1;
272
afield
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
273
-1998585759
1 by brian
clean slate
274
SET @a := (SELECT afield FROM bigfailure);
275
SELECT @a;
276
@a
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
277
-1998585759
1 by brian
clean slate
278
SET @a := (select afield from (SELECT afield FROM bigfailure) as b);
279
SELECT @a;
280
@a
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
281
-1998585759
1 by brian
clean slate
282
SET @a := (select * from bigfailure where afield = (SELECT afield FROM bigfailure));
283
SELECT @a;
284
@a
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
285
-1998585759
1 by brian
clean slate
286
drop table bigfailure;
287
create table t1(f1 int, f2 int);
288
insert into t1 values (1,2),(2,3),(3,1);
289
select @var:=f2 from t1 group by f1 order by f2 desc limit 1;
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
290
@var:=f2 
291
3
292
select @var;
293
@var
294
3
295
drop table t1;
1 by brian
clean slate
296
insert into city 'blah';
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
297
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ''blah'' at line 1
1 by brian
clean slate
298
SHOW COUNT(*) WARNINGS;
299
@@session.warning_count
300
1
301
SHOW COUNT(*) ERRORS;
302
@@session.error_count
303
1
304
create table t1(f1 int, f2 varchar(2), f3 float, f4 decimal(2,1));
305
insert into t1 values 
306
(1, "a", 1.5, 1.6), (1, "a", 1.5, 1.6), (2, "b", 2.5, 2.6),
307
(3, "c", 3.5, 3.6), (4, "d", 4.5, 4.6), (1, "a", 1.5, 1.6),
308
(3, "c", 3.5, 3.6), (1, "a", 1.5, 1.6);
309
select @a:=f1, count(f1) from t1 group by 1 desc;
310
@a:=f1	count(f1)
311
4	1
312
3	2
313
2	1
314
1	4
315
select @a:=f1, count(f1) from t1 group by 1 asc;
316
@a:=f1	count(f1)
317
1	4
318
2	1
319
3	2
320
4	1
321
select @a:=f2, count(f2) from t1 group by 1 desc;
322
@a:=f2	count(f2)
323
d	1
324
c	2
325
b	1
326
a	4
327
select @a:=f3, count(f3) from t1 group by 1 desc;
328
@a:=f3	count(f3)
329
4.5	1
330
3.5	2
331
2.5	1
332
1.5	4
333
select @a:=f4, count(f4) from t1 group by 1 desc;
334
@a:=f4	count(f4)
335
4.6	1
336
3.6	2
337
2.6	1
338
1.6	4
339
drop table t1;
340
create table t1 (f1 int);
341
insert into t1 values (2), (1);
342
select @i := f1 as j from t1 order by 1;
343
j
344
1
345
2
346
drop table t1;
347
create table t1(a int);
348
insert into t1 values(5),(4),(4),(3),(2),(2),(2),(1);
349
set @rownum := 0;
350
set @rank := 0;
351
set @prev_score := NULL;
352
select @rownum := @rownum + 1 as row,
353
@rank := IF(@prev_score!=a, @rownum, @rank) as rank,
354
@prev_score := a as score
355
from t1 order by score desc;
356
drop table t1;
357
End of 5.1 tests