~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# Initialise
2
--disable_warnings
3
drop table if exists t1,t2;
4
--enable_warnings
5
6
--error 1054
7
set @a := foo;
8
set @a := connection_id() + 3;
9
select @a - connection_id();
10
11
set @b := 1;
12
select @b;
13
14
# Check using and setting variables with SELECT DISTINCT
15
16
CREATE TABLE t1 ( i int not null, v int not null,index (i));
17
insert into t1 values (1,1),(1,3),(2,1); 
18
create table t2 (i int not null, unique (i));
19
insert into t2 select distinct i from t1;
20
select * from t2; 
21
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;
22
explain select * from t1 where i=@vv1;
23
select @vv1,i,v from t1 where i=@vv1;
24
explain select * from t1 where @vv1:=@vv1+1 and i=@vv1;
25
explain select @vv1:=i from t1 where i=@vv1;
26
explain select * from t1 where i=@vv1;
27
drop table t1,t2;
28
29
# Check types of variables
30
set @a=0,@b=0;
31
select @a:=10,   @b:=1,   @a > @b, @a < @b;
32
# Note that here a and b will be avaluated as number
33
select @a:="10", @b:="1", @a > @b, @a < @b;
34
# Note that here a and b will be avaluated as strings
35
select @a:=10,   @b:=2,   @a > @b, @a < @b;
36
select @a:="10", @b:="2", @a > @b, @a < @b;
37
38
# Fixed bug #1194
39
select @a:=1;
40
select @a, @a:=1;
41
42
create table t1 (id int, d double, c char(10));
43
insert into t1 values (1,2.0, "test");
44
select @c:=0;
45
update t1 SET id=(@c:=@c+1);
46
select @c;
47
select @c:=0;
48
update t1 set id=(@c:=@c+1);
49
select @c;
50
select @c:=0;
51
select @c:=@c+1;
52
select @d,(@d:=id),@d from t1;
53
select @e,(@e:=d),@e from t1;
54
select @f,(@f:=c),@f from t1;
55
set @g=1;
56
select @g,(@g:=c),@g from t1;
57
select @c, @d, @e, @f;
58
select @d:=id, @e:=id, @f:=id, @g:=@id from t1;
59
select @c, @d, @e, @f, @g;
60
drop table t1;
61
62
# just for fun :)
63
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;
64
65
#
66
# bug#1739
67
# Item_func_set_user_var sets update_query_id, Item_func_get_user_var checks it
68
#
69
create table t1 (i int not null);
70
insert t1 values (1),(2),(2),(3),(3),(3);
71
select @a:=0; select @a, @a:=@a+count(*), count(*), @a from t1 group by i;
72
select @a:=0; select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i;
73
74
set @a=0;
75
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
76
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
77
drop table t1;
78
79
#
80
# Bug #2244: User variables didn't copy collation and derivation
81
# attributes from values they were initialized to.
82
#
83
779.3.10 by Monty Taylor
Turned on -Wshadow.
84
set @a='test';
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
85
select collation(@a),coercibility(@a);
779.3.10 by Monty Taylor
Turned on -Wshadow.
86
select @a='TEST';
87
select @a='TEST' collate utf8_bin;
1 by brian
clean slate
88
779.3.10 by Monty Taylor
Turned on -Wshadow.
89
set @a='test' collate utf8_general_ci;
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
90
select collation(@a),coercibility(@a);
779.3.10 by Monty Taylor
Turned on -Wshadow.
91
select @a='TEST';
92
select @a='TEST' collate utf8_bin;
1 by brian
clean slate
93
94
#
95
# Check the same invoking Item_set_user_var
96
#
779.3.10 by Monty Taylor
Turned on -Wshadow.
97
select collation(@a:='test');
98
select coercibility(@a:='test');
99
select collation(@a:='test' collate utf8_bin);
100
select coercibility(@a:='test' collate utf8_bin);
101
select (@a:='test' collate utf8_bin) = 'TEST';
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
102
select collation(@a),coercibility(@a);
779.3.10 by Monty Taylor
Turned on -Wshadow.
103
select (@a:='test' collate utf8_bin) = 'TEST' collate utf8_general_ci;
1 by brian
clean slate
104
105
#
106
# Bug #6321 strange error:
107
#   string function FIELD(<uservariable content NULL>, ...)
108
#
109
set @var= NULL ;
110
select FIELD( @var,'1it','Hit') as my_column;
111
112
#
113
# Bug#9425 A user variable doesn't always have implicit coercibility
114
#
115
select @v, coercibility(@v);
116
set @v1=null, @v2=1, @v3=1.1, @v4=now();
117
select coercibility(@v1),coercibility(@v2),coercibility(@v3),coercibility(@v4);
118
119
#
120
# Bug #9286  SESSION/GLOBAL should be disallowed for user variables
121
#
122
--error 1064
123
set session @honk=99;
124
125
#
126
# Bug #10724  @@local not preserved in column name of select
127
#
128
# The value doesn't actually matter, we just care about the column name
129
--replace_column 1 #
130
select @@local.max_allowed_packet;
131
--replace_column 1 #
132
select @@session.max_allowed_packet;
133
--replace_column 1 #
134
select @@global.max_allowed_packet;
135
--replace_column 1 #
136
select @@max_allowed_packet;
137
--replace_column 1 #
138
select @@Max_Allowed_Packet;
139
--replace_column 1 #
140
select @@version;
141
--replace_column 1 #
142
select @@global.version;
143
144
--echo End of 4.1 tests
145
146
# Bug #6598: problem with cast(NULL as signed integer);
147
#
148
149
set @first_var= NULL;
150
create table t1 select @first_var;
942.3.1 by Vladimir Kolesnikov
test generalizations
151
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
152
show create table t1;
153
drop table t1;
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
154
155
# This is not supported by Drizzle
156
--error 1064
642.1.50 by Lee
merge with latest from the trunk
157
set @first_var= cast(NULL as integer);
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
158
#create table t1 select @first_var;
942.3.1 by Vladimir Kolesnikov
test generalizations
159
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
160
#show create table t1;
161
#drop table t1;
162
1 by brian
clean slate
163
set @first_var= NULL;
164
create table t1 select @first_var;
942.3.1 by Vladimir Kolesnikov
test generalizations
165
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
166
show create table t1;
167
drop table t1;
168
set @first_var= concat(NULL);
169
create table t1 select @first_var;
942.3.1 by Vladimir Kolesnikov
test generalizations
170
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
171
show create table t1;
172
drop table t1;
173
set @first_var=1;
174
set @first_var= cast(NULL as CHAR);
175
create table t1 select @first_var;
942.3.1 by Vladimir Kolesnikov
test generalizations
176
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
177
show create table t1;
178
drop table t1;
179
180
#
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
181
# Bug #7498 User variable SET saves SIGNED BIGINT as BIGINT
1 by brian
clean slate
182
#
183
184
# First part, set user var to large number and select it
185
set @a=18446744071710965857;
186
select @a;
187
188
# Second part, set user var from large number in table
189
# then select it
190
CREATE TABLE `bigfailure` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
191
  `afield` BIGINT NOT NULL
1 by brian
clean slate
192
);
193
INSERT INTO `bigfailure` VALUES (18446744071710965857);
194
SELECT * FROM bigfailure;
195
select * from (SELECT afield FROM bigfailure) as b;
196
select * from bigfailure where afield = (SELECT afield FROM bigfailure);
197
select * from bigfailure where afield = 18446744071710965857;
198
# This is fixed in 5.0, to be uncommented there
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
199
select * from bigfailure where afield = '18446744071710965857';
1 by brian
clean slate
200
select * from bigfailure where afield = 18446744071710965856+1;
201
202
SET @a := (SELECT afield FROM bigfailure);
203
SELECT @a;
204
SET @a := (select afield from (SELECT afield FROM bigfailure) as b);
205
SELECT @a;
206
SET @a := (select * from bigfailure where afield = (SELECT afield FROM bigfailure));
207
SELECT @a;
208
209
drop table bigfailure;
210
211
#
212
# Bug#16861: User defined variable can have a wrong value if a tmp table was
213
#            used.
214
#
215
create table t1(f1 int, f2 int);
216
insert into t1 values (1,2),(2,3),(3,1);
217
select @var:=f2 from t1 group by f1 order by f2 desc limit 1;
218
select @var;
642.1.51 by Lee
enable user_var, user_var-binlog and symlink tests
219
# Bug 310977, uncomment this test after the bug is fixed
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
220
#create table t2 as select @var:=f2 from t1 group by f1 order by f2 desc limit 1;
221
#select * from t2;
222
#select @var;
223
drop table t1;
224
#drop table t2;
1 by brian
clean slate
225
226
#
227
# Bug#19024 - SHOW COUNT(*) WARNINGS not return Errors 
228
#
229
--error 1064
230
insert into city 'blah';
231
SHOW COUNT(*) WARNINGS;
232
SHOW COUNT(*) ERRORS;
233
234
#
235
# Bug#28494: Grouping by Item_func_set_user_var produces incorrect result.
236
#
237
create table t1(f1 int, f2 varchar(2), f3 float, f4 decimal(2,1));
238
insert into t1 values 
239
  (1, "a", 1.5, 1.6), (1, "a", 1.5, 1.6), (2, "b", 2.5, 2.6),
240
  (3, "c", 3.5, 3.6), (4, "d", 4.5, 4.6), (1, "a", 1.5, 1.6),
241
  (3, "c", 3.5, 3.6), (1, "a", 1.5, 1.6);
242
select @a:=f1, count(f1) from t1 group by 1 desc;
243
select @a:=f1, count(f1) from t1 group by 1 asc;
244
select @a:=f2, count(f2) from t1 group by 1 desc;
245
select @a:=f3, count(f3) from t1 group by 1 desc;
246
select @a:=f4, count(f4) from t1 group by 1 desc;
247
drop table t1;
248
249
#
250
# Bug#32482: Crash for a query with ORDER BY a user variable.
251
#
252
create table t1 (f1 int);
253
insert into t1 values (2), (1);
254
select @i := f1 as j from t1 order by 1;
255
drop table t1;
256
# Bug #32260: User variables in query cause server crash
257
#
258
create table t1(a int);
259
insert into t1 values(5),(4),(4),(3),(2),(2),(2),(1);
260
set @rownum := 0;
261
set @rank := 0;
262
set @prev_score := NULL;
263
# Disable the result log as we assign a value to a user variable in one part 
264
# of a statement and use the same variable in other part of the same statement,
265
# so we can get unexpected results.
266
--disable_result_log
267
select @rownum := @rownum + 1 as row,
268
 @rank := IF(@prev_score!=a, @rownum, @rank) as rank,
269
 @prev_score := a as score
270
from t1 order by score desc;
271
--enable_result_log
272
drop table t1;
273
274
--echo End of 5.1 tests