~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#
# test of updating of keys
#

--disable_warnings
drop table if exists t1,t2;
--enable_warnings

create table t1 (a int auto_increment , primary key (a));
insert into t1 values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL); 
update t1 set a=a+10 where a > 34;
update t1 set a=a+100 where a > 0;

# Some strange updates to test some otherwise unused code
update t1 set a=a+100 where a=1 and a=2;
--error ER_BAD_FIELD_ERROR
update t1 set a=b+100 where a=1 and a=2; 
--error ER_BAD_FIELD_ERROR
update t1 set a=b+100 where c=1 and a=2; 
--error ER_BAD_FIELD_ERROR
update t1 set d=a+100 where a=1;
select * from t1;
drop table t1;

CREATE TABLE t1
 (
 place_id int NOT NULL,
 shows int DEFAULT '0' NOT NULL,
 ishows int DEFAULT '0' NOT NULL,
 ushows int DEFAULT '0' NOT NULL,
 clicks int DEFAULT '0' NOT NULL,
 iclicks int DEFAULT '0' NOT NULL,
 uclicks int DEFAULT '0' NOT NULL,
 ts timestamp,
 PRIMARY KEY (place_id,ts)
 );

INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
VALUES (1,0,0,0,0,0,0,20000928174434);
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;
drop table t1;

#
# Test bug with update reported by Jan Legenhausen
#

CREATE TEMPORARY TABLE t1 (
  lfdnr int NOT NULL default '0',
  ticket int NOT NULL default '0',
  client varchar(255) NOT NULL default '',
  replyto varchar(255) NOT NULL default '',
  subject varchar(100) NOT NULL default '',
  timestamp_arg int NOT NULL default '0',
  tstamp timestamp NOT NULL,
  status int NOT NULL default '0',
  type varchar(15) NOT NULL default '',
  assignment int NOT NULL default '0',
  fupcount int NOT NULL default '0',
  parent int NOT NULL default '0',
  activity int NOT NULL default '0',
  priority int NOT NULL default '1',
  cc varchar(255) NOT NULL default '',
  bcc varchar(255) NOT NULL default '',
  body text NOT NULL,
  comment text,
  header text,
  PRIMARY KEY  (lfdnr),
  KEY k1 (timestamp_arg),
  KEY k2 (type),
  KEY k3 (parent),
  KEY k4 (assignment),
  KEY ticket (ticket)
) ENGINE=MyISAM;

INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');

alter table t1 change lfdnr lfdnr int not null auto_increment;
update t1 set status=1 where type='Open';
select status from t1;
drop table t1;

#
# Test of ORDER BY
#

create table t1 (a int not null, b int not null, key (a));
insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
SET @tmp=0;
update t1 set b=(@tmp:=@tmp+1) order by a;
update t1 set b=99 where a=1 order by b asc limit 1;
select * from t1 order by a,b;
update t1 set b=100 where a=1 order by b desc limit 2;
update t1 set a=a+10+b where a=1 order by b;
select * from t1 order by a,b;
create table t2 (a int not null, b int not null);
insert into t2 values (1,1),(1,2),(1,3);
update t1 set b=(select distinct 1 from (select * from t2) a);
drop table t1,t2;

#
# Test with limit (Bug #393)
#

CREATE TEMPORARY TABLE t1 (
   `id_param` int NOT NULL default '0',
   `nom_option` char(40) NOT NULL default '',
   `valid` int NOT NULL default '0',
   KEY `id_param` (`id_param`,`nom_option`)
 ) ENGINE=MyISAM;

INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1);

UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1;
select * from t1;
drop table t1;

#
# Bug #8057
#
create table t1 (id int not null auto_increment primary key, id_str varchar(32));
insert into t1 (id_str) values ("test");
update t1 set id_str = concat(id_str, id) where id = last_insert_id();
select * from t1;
drop table t1;

#
# Bug #8942: a problem with update and partial key part
#

create table t1 (a int, b char(255), key(a, b(20)));
insert into t1 values (0, '1');
update t1 set b = b + 1 where a = 0;
select * from t1;
drop table t1;

#
# Bug #11868 Update with subquery with ref built with a key from the updated
#            table crashes server
#
create table t1(f1 int, f2 int);
create table t2(f3 int, f4 int);
create index idx on t2(f3);
insert into t1 values(1,0),(2,0);
insert into t2 values(1,1),(2,2);
UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
select * from t1;
drop table t1,t2;

#
# Bug #13180 sometimes server accepts sum func in update/delete where condition
#
create table t1(f1 int);
select DATABASE();
--error ER_INVALID_GROUP_FUNC_USE
update t1 set f1=1 where count(*)=1;
select DATABASE();
--error ER_INVALID_GROUP_FUNC_USE
delete from t1 where count(*)=1;
drop table t1;

# BUG#12915: Optimize "DELETE|UPDATE ... ORDER BY ... LIMIT n" to use an index
create table t1 ( a int, b int default 0, index (a) );
insert into t1 (a) values (0),(0),(0),(0),(0),(0),(0),(0);

flush status;
select a from t1 order by a limit 1;
--replace_column 2 #
show status like 'handler_read%';

flush status;
update t1 set a=9999 order by a limit 1;
update t1 set b=9999 order by a limit 1;
--replace_column 2 #
show status like 'handler_read%';

flush status;
delete from t1 order by a limit 1;
--replace_column 2 #
show status like 'handler_read%';

flush status;
delete from t1 order by a desc limit 1;
--replace_column 2 #
show status like 'handler_read%';

alter table t1 disable keys;

flush status;
delete from t1 order by a limit 1;
--replace_column 2 #
show status like 'handler_read%';

# PBXT: this select returns a different result to
# innodb because the 2 updates above change different rows
select * from t1;
update t1 set a=a+10,b=1 order by a limit 3;
update t1 set a=a+11,b=2 order by a limit 3;
update t1 set a=a+12,b=3 order by a limit 3;
select * from t1 order by a;

drop table t1;

#
# Bug#14186 select datefield is null not updated
#
create table t1 (f1 date NULL);
insert into t1 values('2000-01-01'),(NULL);
update t1 set f1='2002-02-02' where f1 is null;
select * from t1;
drop table t1;

# BUG#15935
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, filler1 char(200), filler2 char(200), key(a));
insert into t2 select A.a + 10*B.a, 'filler','filler' from t1 A CROSS JOIN t1 B;
flush status;
update t2 set a=3 where a=2;
--replace_column 2 #
show status like 'handler_read%';
drop table t1, t2;

#
# Bug #16510 Updating field named like '*name' caused server crash
#
create table t1(f1 int, `*f2` int);
insert into t1 values (1,1);
update t1 set `*f2`=1;
drop table t1;

#
# Bug#25126: Wrongly resolved field leads to a crash
#
create table t1(f1 int);
--error ER_BAD_FIELD_ERROR
update t1 set f2=1 order by f2;
drop table t1;
# End of 4.1 tests

#
# Bug #24035: performance degradation with condition int_field=big_decimal
#

CREATE TABLE t1 (
  request_id int NOT NULL auto_increment,
  user_id varchar(12) default NULL,
  time_stamp datetime,
  ip_address varchar(15) default NULL,
  PRIMARY KEY (request_id),
  KEY user_id_2 (user_id,time_stamp)
);

INSERT INTO t1 (user_id) VALUES ('user1');
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;

flush status;
SELECT user_id FROM t1 WHERE request_id=9999999999999; 
--replace_column 2 #
show status like '%Handler_read%';
SELECT user_id FROM t1 WHERE request_id=999999999999999999999999999999; 
--replace_column 2 #
show status like '%Handler_read%';
UPDATE t1 SET user_id=null WHERE request_id=9999999999999;
--replace_column 2 #
show status like '%Handler_read%';
UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999;
--replace_column 2 #
show status like '%Handler_read%';

DROP TABLE t1;

#
# Bug #24010: INSERT INTO ... SELECT fails on unique constraint with data it 
# doesn't select
#
CREATE TABLE t1 (

  a int,
  quux decimal( 31, 30 ),

  UNIQUE KEY bar (a),
  KEY quux (quux)
);

INSERT INTO
 t1 ( a, quux )
VALUES
    ( 1,    1 ),
    ( 2,  0.1 );

INSERT INTO t1( a )
  SELECT @newA := 1 + a FROM t1 WHERE quux <= 0.1;

SELECT * FROM t1;

DROP TABLE t1;

#
# Bug #22364: Inconsistent "matched rows" when executing UPDATE
#

connect (con1,localhost,root,,test);
connection con1;

set tmp_table_size=1024;

# Create the test tables
create table t1 (id int, a int, key idx(a));
create table t2 (id int not null auto_increment primary key, a int);
insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
insert into t2(a) select a from t2; 
insert into t2(a) select a from t2;
insert into t2(a) select a from t2; 
update t2 set a=id;
insert into t1 select * from t2;

# PBXT: Rows changed are different here between InnoDB and PBXT
# because PBXT does not update the rows that are not modified!
# InnoDB seems to do this....
# Check that the number of matched rows is correct when the temporary
# table is small enough to not be converted to MyISAM
select count(*) from t1 join t2 on (t1.a=t2.a);

# Increase table sizes
insert into t2(a) select a from t2; 
update t2 set a=id; 
truncate t1; 
insert into t1 select * from t2; 

# Check that the number of matched rows is correct when the temporary
# table has to be converted to MyISAM
select count(*) from t1 join t2 on (t1.a=t2.a);

# Check that the number of matched rows is correct when there are duplicate
# key errors
update t1 set a=1;
update t2 set a=1;
select count(*) from t1 join t2 on (t1.a=t2.a);

drop table t1,t2;

#
# Bug #439719: Drizzle crash when running random query generator
#
CREATE TABLE t1(col1 enum('a','b') NOT NULL, col2 enum('a','b') DEFAULT NULL, KEY col2 (col2));
UPDATE t1 SET col1 = "crash" WHERE col2 = now() ;

connection default;
disconnect con1;

drop table t1;
--echo End of 5.0 tests