~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/delayed.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# delayed works differently in embedded server
 
2
--source include/not_embedded.inc
 
3
#
 
4
# test of DELAYED insert and timestamps
 
5
# (Can't be tested with purify :( )
 
6
#
 
7
 
 
8
--disable_warnings
 
9
drop table if exists t1;
 
10
--enable_warnings
 
11
create table t1 (a char(10), tmsp timestamp);
 
12
insert into t1 set a = 1;
 
13
insert delayed into t1 set a = 2;
 
14
insert into t1 set a = 3, tmsp=NULL;
 
15
insert delayed into t1 set a = 4;
 
16
insert delayed into t1 set a = 5, tmsp = 19711006010203;
 
17
insert delayed into t1 (a, tmsp) values (6, 19711006010203);
 
18
insert delayed into t1 (a, tmsp) values (7, NULL);
 
19
# Wait until the rows are flushed to the table files.
 
20
FLUSH TABLE t1;
 
21
insert into t1 set a = 8,tmsp=19711006010203;
 
22
select * from t1 where tmsp=0;
 
23
select * from t1 where tmsp=19711006010203;
 
24
drop table t1;
 
25
 
 
26
#
 
27
# Test bug when inserting NULL into an auto_increment field with
 
28
# INSERT DELAYED
 
29
#
 
30
 
 
31
create table t1 (a int not null auto_increment primary key, b char(10));
 
32
insert delayed into t1 values (1,"b");
 
33
insert delayed into t1 values (null,"c");
 
34
insert delayed into t1 values (3,"d"),(null,"e");
 
35
--error 1136
 
36
insert delayed into t1 values (3,"this will give an","error");
 
37
# Wait until the rows are flushed to the table files.
 
38
FLUSH TABLE t1;
 
39
show status like 'not_flushed_delayed_rows';
 
40
select * from t1;
 
41
drop table t1;
 
42
 
 
43
# End of 4.1 tests
 
44
 
 
45
#
 
46
# Bug #12226: Crash when a delayed insert fails due to a duplicate key
 
47
#
 
48
create table t1 (a int not null primary key);
 
49
insert into t1 values (1);
 
50
insert delayed into t1 values (1);
 
51
select * from t1;
 
52
drop table t1;
 
53
 
 
54
#
 
55
# Bug #20195: INSERT DELAYED with auto_increment is assigned wrong values
 
56
#
 
57
CREATE TABLE t1 ( a int(10) NOT NULL auto_increment, PRIMARY KEY (a));
 
58
 
 
59
# Make one delayed insert to start the separate thread
 
60
insert delayed into t1 values(null);
 
61
 
 
62
# Do some normal inserts
 
63
insert into t1 values(null);
 
64
insert into t1 values(null);
 
65
 
 
66
# Discarded, since the delayed-counter is 2, which is already used
 
67
insert delayed into t1 values(null);
 
68
 
 
69
# Discarded, since the delayed-counter is 3, which is already used
 
70
insert delayed into t1 values(null);
 
71
 
 
72
# Works, since the delayed-counter is 4, which is unused
 
73
insert delayed into t1 values(null);
 
74
 
 
75
# Do some more inserts
 
76
insert into t1 values(null);
 
77
insert into t1 values(null);
 
78
insert into t1 values(null);
 
79
 
 
80
# Delete one of the above to make a hole
 
81
delete from t1 where a=6;
 
82
 
 
83
# Discarded, since the delayed-counter is 5, which is already used
 
84
insert delayed into t1 values(null);
 
85
 
 
86
# Works, since the delayed-counter is 6, which is unused (the row we deleted)
 
87
insert delayed into t1 values(null);
 
88
 
 
89
# Discarded, since the delayed-counter is 7, which is already used
 
90
insert delayed into t1 values(null);
 
91
 
 
92
# Works, since the delayed-counter is 8, which is unused
 
93
insert delayed into t1 values(null);
 
94
 
 
95
# Wait until the rows are flushed to the table files.
 
96
FLUSH TABLE t1;
 
97
# Check what we have now
 
98
select * from t1 order by a;
 
99
 
 
100
DROP TABLE t1;
 
101
 
 
102
#
 
103
# Bug#20627 - INSERT DELAYED does not honour auto_increment_* variables
 
104
#
 
105
SET @bug20627_old_auto_increment_offset=
 
106
                @@auto_increment_offset;
 
107
SET @bug20627_old_auto_increment_increment=
 
108
                @@auto_increment_increment;
 
109
SET @bug20627_old_session_auto_increment_offset=
 
110
                @@session.auto_increment_offset;
 
111
SET @bug20627_old_session_auto_increment_increment=
 
112
                @@session.auto_increment_increment;
 
113
SET @@auto_increment_offset= 2;
 
114
SET @@auto_increment_increment= 3;
 
115
SET @@session.auto_increment_offset= 4;
 
116
SET @@session.auto_increment_increment= 5;
 
117
#
 
118
# Normal insert as reference.
 
119
CREATE TABLE t1 (
 
120
  c1 INT NOT NULL AUTO_INCREMENT,
 
121
  PRIMARY KEY (c1)
 
122
  );
 
123
INSERT INTO t1 VALUES (NULL),(NULL),(NULL);
 
124
# Check what we have now
 
125
SELECT * FROM t1;
 
126
DROP TABLE t1;
 
127
#
 
128
# Delayed insert.
 
129
CREATE TABLE t1 (
 
130
  c1 INT NOT NULL AUTO_INCREMENT,
 
131
  PRIMARY KEY (c1)
 
132
  );
 
133
INSERT DELAYED INTO t1 VALUES (NULL),(NULL),(NULL);
 
134
# Wait until the rows are flushed to the table files.
 
135
FLUSH TABLE t1;
 
136
# Check what we have now
 
137
SELECT * FROM t1;
 
138
DROP TABLE t1;
 
139
#
 
140
# Cleanup
 
141
SET             @@auto_increment_offset=
 
142
    @bug20627_old_auto_increment_offset;
 
143
SET             @@auto_increment_increment=
 
144
    @bug20627_old_auto_increment_increment;
 
145
SET             @@session.auto_increment_offset=
 
146
    @bug20627_old_session_auto_increment_offset;
 
147
SET             @@session.auto_increment_increment=
 
148
    @bug20627_old_session_auto_increment_increment;
 
149
 
 
150
#
 
151
# Bug#20830 - INSERT DELAYED does not honour SET INSERT_ID
 
152
#
 
153
SET @bug20830_old_auto_increment_offset=
 
154
                @@auto_increment_offset;
 
155
SET @bug20830_old_auto_increment_increment=
 
156
                @@auto_increment_increment;
 
157
SET @bug20830_old_session_auto_increment_offset=
 
158
                @@session.auto_increment_offset;
 
159
SET @bug20830_old_session_auto_increment_increment=
 
160
                @@session.auto_increment_increment;
 
161
SET @@auto_increment_offset= 2;
 
162
SET @@auto_increment_increment= 3;
 
163
SET @@session.auto_increment_offset= 4;
 
164
SET @@session.auto_increment_increment= 5;
 
165
#
 
166
# Normal insert as reference.
 
167
CREATE TABLE t1 (
 
168
  c1 INT(11) NOT NULL AUTO_INCREMENT,
 
169
  c2 INT(11) DEFAULT NULL,
 
170
  PRIMARY KEY (c1)
 
171
  );
 
172
SET insert_id= 14;
 
173
INSERT INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13);
 
174
INSERT INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23);
 
175
# Restart sequence at a different value.
 
176
INSERT INTO t1 VALUES(  69, 31), (NULL, 32), (NULL, 33);
 
177
INSERT INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43);
 
178
# Restart sequence at a different value.
 
179
SET insert_id= 114;
 
180
INSERT INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53);
 
181
INSERT INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63);
 
182
# Set one value below the maximum value.
 
183
INSERT INTO t1 VALUES(  49, 71), (NULL, 72), (NULL, 73);
 
184
INSERT INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83);
 
185
# Create a duplicate value.
 
186
SET insert_id= 114;
 
187
--error ER_DUP_ENTRY
 
188
INSERT INTO t1 VALUES(NULL, 91);
 
189
INSERT INTO t1 VALUES           (NULL, 92), (NULL, 93);
 
190
# Check what we have now
 
191
SELECT * FROM t1;
 
192
SELECT COUNT(*) FROM t1;
 
193
SELECT SUM(c1) FROM t1;
 
194
DROP TABLE t1;
 
195
#
 
196
# Delayed insert.
 
197
CREATE TABLE t1 (
 
198
  c1 INT(11) NOT NULL AUTO_INCREMENT,
 
199
  c2 INT(11) DEFAULT NULL,
 
200
  PRIMARY KEY (c1)
 
201
  );
 
202
SET insert_id= 14;
 
203
INSERT DELAYED INTO t1 VALUES(NULL, 11), (NULL, 12), (NULL, 13);
 
204
INSERT DELAYED INTO t1 VALUES(NULL, 21), (NULL, 22), (NULL, 23);
 
205
# Restart sequence at a different value.
 
206
INSERT DELAYED INTO t1 VALUES(  69, 31), (NULL, 32), (NULL, 33);
 
207
INSERT DELAYED INTO t1 VALUES(NULL, 41), (NULL, 42), (NULL, 43);
 
208
# Restart sequence at a different value.
 
209
SET insert_id= 114;
 
210
INSERT DELAYED INTO t1 VALUES(NULL, 51), (NULL, 52), (NULL, 53);
 
211
INSERT DELAYED INTO t1 VALUES(NULL, 61), (NULL, 62), (NULL, 63);
 
212
# Set one value below the maximum value.
 
213
INSERT DELAYED INTO t1 VALUES(  49, 71), (NULL, 72), (NULL, 73);
 
214
INSERT DELAYED INTO t1 VALUES(NULL, 81), (NULL, 82), (NULL, 83);
 
215
# Create a duplicate value.
 
216
SET insert_id= 114;
 
217
INSERT DELAYED INTO t1 VALUES(NULL, 91);
 
218
INSERT DELAYED INTO t1 VALUES           (NULL, 92), (NULL, 93);
 
219
# Wait until the rows are flushed to the table files.
 
220
FLUSH TABLE t1;
 
221
# Check what we have now
 
222
SELECT * FROM t1;
 
223
SELECT COUNT(*) FROM t1;
 
224
SELECT SUM(c1) FROM t1;
 
225
DROP TABLE t1;
 
226
#
 
227
# Cleanup
 
228
SET             @@auto_increment_offset=
 
229
    @bug20830_old_auto_increment_offset;
 
230
SET             @@auto_increment_increment=
 
231
    @bug20830_old_auto_increment_increment;
 
232
SET             @@session.auto_increment_offset=
 
233
    @bug20830_old_session_auto_increment_offset;
 
234
SET             @@session.auto_increment_increment=
 
235
    @bug20830_old_session_auto_increment_increment;
 
236
 
 
237
#
 
238
# BUG#26238 - inserted delayed always inserts 0 for BIT columns
 
239
#
 
240
CREATE TABLE t1(a BIT);
 
241
INSERT DELAYED INTO t1 VALUES(1);
 
242
FLUSH TABLE t1;
 
243
SELECT HEX(a) FROM t1;
 
244
DROP TABLE t1;
 
245
 
 
246
#
 
247
# Bug #32676: insert delayed crash with wrong column and function specified
 
248
#
 
249
CREATE TABLE t1 (a INT);
 
250
--error  ER_BAD_FIELD_ERROR
 
251
INSERT DELAYED INTO t1 SET b= b();
 
252
DROP TABLE t1;
 
253
 
 
254
--echo End of 5.0 tests
 
255
 
 
256
#
 
257
# Bug#27358 INSERT DELAYED does not honour SQL_MODE of the client
 
258
#
 
259
--disable_warnings
 
260
DROP TABLE IF EXISTS t1,t2;
 
261
--enable_warnings
 
262
SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
 
263
CREATE TABLE `t1` (
 
264
  `id` int(11) PRIMARY KEY auto_increment,
 
265
  `f1` varchar(10) NOT NULL UNIQUE
 
266
);
 
267
INSERT DELAYED INTO t1 VALUES(0,"test1");
 
268
sleep 1;
 
269
SELECT * FROM t1;
 
270
SET SQL_MODE='PIPES_AS_CONCAT';
 
271
INSERT DELAYED INTO t1 VALUES(0,'a' || 'b');
 
272
sleep 1;
 
273
SELECT * FROM t1;
 
274
SET SQL_MODE='ERROR_FOR_DIVISION_BY_ZERO,STRICT_ALL_TABLES';
 
275
--error 1365
 
276
INSERT DELAYED INTO t1 VALUES(mod(1,0),"test3");
 
277
CREATE TABLE t2 (
 
278
  `id` int(11) PRIMARY KEY auto_increment,
 
279
  `f1` date
 
280
);
 
281
SET SQL_MODE='NO_ZERO_DATE,STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
 
282
--error ER_TRUNCATED_WRONG_VALUE
 
283
INSERT DELAYED INTO t2 VALUES (0,'0000-00-00');
 
284
--error ER_TRUNCATED_WRONG_VALUE
 
285
INSERT DELAYED INTO t2 VALUES (0,'2007-00-00');
 
286
DROP TABLE t1,t2;
 
287
 
 
288
#
 
289
# Bug#40536: SELECT is blocked by INSERT DELAYED waiting on upgrading lock,
 
290
#            even with low_priority_updates
 
291
#
 
292
 
 
293
set @old_delayed_updates = @@global.low_priority_updates;
 
294
set global low_priority_updates = 1;
 
295
select @@global.low_priority_updates;
 
296
 
 
297
--disable_warnings
 
298
drop table if exists t1;
 
299
--enable_warnings
 
300
create table t1 (a int, b int);
 
301
insert into t1 values (1,1);
 
302
lock table t1 read;
 
303
connect (update,localhost,root,,);
 
304
connection update;
 
305
--echo connection: update
 
306
--send insert delayed into t1 values (2,2);
 
307
connection default;
 
308
let $wait_condition=
 
309
  select count(*) = 1 from information_schema.processlist
 
310
  where command = "Delayed insert" and state = "upgrading lock";
 
311
--source include/wait_condition.inc
 
312
connect (select,localhost,root,,);
 
313
--echo connection: select
 
314
select * from t1;
 
315
connection default;
 
316
--echo connection: default
 
317
select * from t1;
 
318
connection default;
 
319
disconnect update;
 
320
disconnect select;
 
321
unlock tables;
 
322
let $wait_condition=
 
323
  select count(*) = 1 from information_schema.processlist
 
324
  where command = "Delayed insert" and state = "Waiting for INSERT";
 
325
--source include/wait_condition.inc
 
326
select * from t1;
 
327
drop table t1;
 
328
 
 
329
set global low_priority_updates = @old_delayed_updates;
 
330
 
 
331
 
 
332
--echo #
 
333
--echo # Bug #47682 strange behaviour of INSERT DELAYED
 
334
--echo #
 
335
 
 
336
--disable_warnings
 
337
DROP TABLE IF EXISTS t1, t2;
 
338
--enable_warnings
 
339
 
 
340
CREATE TABLE t1 (f1 integer);
 
341
CREATE TABLE t2 (f1 integer);
 
342
 
 
343
FLUSH TABLES WITH READ LOCK;
 
344
LOCK TABLES t1 READ;
 
345
 
 
346
# ER_CANT_UPDATE_WITH_READLOCK with normal execution
 
347
# ER_TABLE_NOT_LOCKED when executed as prepared statement
 
348
--error ER_CANT_UPDATE_WITH_READLOCK, ER_TABLE_NOT_LOCKED
 
349
INSERT DELAYED INTO t2 VALUES (1);
 
350
 
 
351
UNLOCK TABLES;
 
352
DROP TABLE t1, t2;
 
353
 
 
354
 
 
355
--echo End of 5.1 tests