~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to mysql-test/extra/rpl_tests/rpl_insert_id.test

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
-- source include/master-slave.inc
29
29
#should work for both SBR and RBR
30
30
 
31
 
connection master;
32
 
create table t1(a int auto_increment, key(a));
33
 
create table t2(b int auto_increment, c int, key(b));
 
31
# If concurrent inserts are on, it is not guaranteed that the rows
 
32
# inserted by INSERT are immediately accessible by SELECT in another
 
33
# thread. This would cause problems near the line 'connection master1'
 
34
# below. So we turn off concurrent inserts.
 
35
connection master;
 
36
SET @old_concurrent_insert= @@global.concurrent_insert;
 
37
SET @@global.concurrent_insert= 0;
 
38
 
 
39
connection master;
 
40
eval create table t1(a int auto_increment, key(a)) engine=$engine_type;
 
41
eval create table t2(b int auto_increment, c int, key(b)) engine=$engine_type;
34
42
insert into t1 values (1),(2),(3);
35
43
insert into t1 values (null);
36
44
insert into t2 values (null,last_insert_id());
68
76
 
69
77
drop table t2;
70
78
drop table t1;
71
 
create table t1(a int auto_increment, key(a));
72
 
create table t2(b int auto_increment, c int, key(b));
 
79
eval create table t1(a int auto_increment, key(a)) engine=$engine_type;
 
80
eval create table t2(b int auto_increment, c int, key(b)) engine=$engine_type;
73
81
insert into t1 values (10);
74
82
insert into t1 values (null),(null),(null);
75
83
insert into t2 values (5,0);
94
102
 
95
103
connection master;
96
104
SET TIMESTAMP=1000000000;
97
 
CREATE TABLE t1 ( a INT UNIQUE );
 
105
eval CREATE TABLE t1 ( a INT UNIQUE ) engine=$engine_type;
98
106
SET FOREIGN_KEY_CHECKS=0;
99
107
# Duplicate Key Errors
100
108
--error 1022, ER_DUP_ENTRY
109
117
--echo #
110
118
 
111
119
connection master;
112
 
create table t1(a int auto_increment, key(a));
113
 
create table t2(a int);
 
120
eval create table t1(a int auto_increment, key(a)) engine=$engine_type;
 
121
eval create table t2(a int) engine=$engine_type;
114
122
insert into t1 (a) values (null);
115
123
insert into t2 (a) select a from t1 where a is null;
116
124
insert into t2 (a) select a from t1 where a is null;
139
147
drop table if exists t1, t2;
140
148
--enable_warnings
141
149
 
142
 
create table t1 (
 
150
eval create table t1 (
143
151
  id int not null auto_increment,
144
152
  last_id int,
145
153
  primary key (id)
146
 
);
 
154
) engine=$engine_type;
147
155
create function bug15728() returns int(11)
148
156
  return last_insert_id();
149
157
 
152
160
insert into t1 (last_id) values (bug15728());
153
161
 
154
162
# Check that nested call replicates too.
155
 
create table t2 (
 
163
eval create table t2 (
156
164
  id int not null auto_increment,
157
165
  last_id int,
158
166
  primary key (id)
159
 
);
 
167
) engine=$engine_type;
160
168
delimiter |;
161
169
create function bug15728_insert() returns int(11) modifies sql data
162
170
begin
215
223
# test of BUG#20188 REPLACE or ON DUPLICATE KEY UPDATE in
216
224
# auto_increment breaks binlog
217
225
 
218
 
create table t1 (n int primary key auto_increment not null,
219
 
b int, unique(b));
 
226
eval create table t1 (n int primary key auto_increment not null,
 
227
                      b int, unique(b)) engine=$engine_type;
220
228
 
221
229
# First, test that we do not call restore_auto_increment() too early
222
230
# in write_record():
257
265
# and now test for the bug:
258
266
connection master;
259
267
drop table t1;
260
 
create table t1 (n int primary key auto_increment not null,
261
 
b int, unique(b));
 
268
eval create table t1 (n int primary key auto_increment not null,
 
269
                      b int, unique(b)) engine=$engine_type;
262
270
insert into t1 values(null,100);
263
271
select * from t1 order by n;
264
272
sync_slave_with_master;
282
290
 
283
291
connection master;
284
292
# testcase with INSERT VALUES
285
 
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT,
286
 
UNIQUE(b));
 
293
eval CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b INT,
 
294
                      UNIQUE(b)) ENGINE=$engine_type;
287
295
INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10;
288
 
SELECT * FROM t1;
 
296
SELECT * FROM t1 ORDER BY a;
289
297
sync_slave_with_master;
290
 
SELECT * FROM t1;
 
298
SELECT * FROM t1 ORDER BY a;
291
299
connection master;
292
300
drop table t1;
293
301
 
294
302
# tescase with INSERT SELECT
295
 
CREATE TABLE t1 (
 
303
eval CREATE TABLE t1 (
296
304
  id bigint(20) unsigned NOT NULL auto_increment,
297
305
  field_1 int(10) unsigned NOT NULL,
298
306
  field_2 varchar(255) NOT NULL,
299
307
  field_3 varchar(255) NOT NULL,
300
308
  PRIMARY KEY (id),
301
309
  UNIQUE KEY field_1 (field_1, field_2)
302
 
);
303
 
CREATE TABLE t2 (
 
310
) ENGINE=$engine_type;
 
311
eval CREATE TABLE t2 (
304
312
  field_a int(10) unsigned NOT NULL,
305
313
  field_b varchar(255) NOT NULL,
306
314
  field_c varchar(255) NOT NULL
307
 
);
 
315
) ENGINE=$engine_type;
308
316
INSERT INTO t2 (field_a, field_b, field_c) VALUES (1, 'a', '1a');
309
317
INSERT INTO t2 (field_a, field_b, field_c) VALUES (2, 'b', '2b');
310
318
INSERT INTO t2 (field_a, field_b, field_c) VALUES (3, 'c', '3c');
324
332
FROM t2
325
333
ON DUPLICATE KEY UPDATE
326
334
t1.field_3 = t2.field_c;
327
 
SELECT * FROM t1;
 
335
SELECT * FROM t1 ORDER BY id;
328
336
sync_slave_with_master;
329
 
SELECT * FROM t1;
 
337
SELECT * FROM t1 ORDER BY id;
330
338
connection master;
331
339
drop table t1, t2;
332
340
 
348
356
# Reset result of LAST_INSERT_ID().
349
357
SELECT LAST_INSERT_ID(0);
350
358
 
351
 
CREATE TABLE t1 (
 
359
eval CREATE TABLE t1 (
352
360
  id INT NOT NULL DEFAULT 0,
353
361
  last_id INT,
354
362
  PRIMARY KEY (id)
355
 
);
 
363
) ENGINE=$engine_type;
356
364
 
357
 
CREATE TABLE t2 (
 
365
eval CREATE TABLE t2 (
358
366
  id INT NOT NULL AUTO_INCREMENT,
359
367
  last_id INT,
360
368
  PRIMARY KEY (id)
361
 
);
 
369
) ENGINE=$engine_type;
362
370
 
363
371
delimiter |;
364
372
CREATE PROCEDURE p1()
369
377
delimiter ;|
370
378
 
371
379
CALL p1();
372
 
SELECT * FROM t1;
373
 
SELECT * FROM t2;
 
380
SELECT * FROM t1 ORDER BY id;
 
381
SELECT * FROM t2 ORDER BY id;
374
382
 
375
383
sync_slave_with_master;
376
 
SELECT * FROM t1;
377
 
SELECT * FROM t2;
 
384
SELECT * FROM t1 ORDER BY id;
 
385
SELECT * FROM t2 ORDER BY id;
378
386
 
379
387
connection master;
380
388
 
394
402
DROP TABLE IF EXISTS t1, t2;
395
403
--enable_warnings
396
404
 
397
 
CREATE TABLE t1 (
 
405
eval CREATE TABLE t1 (
398
406
    i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
399
407
    j INT DEFAULT 0
400
 
);
401
 
CREATE TABLE t2 (i INT);
 
408
) ENGINE=$engine_type;
 
409
eval CREATE TABLE t2 (i INT) ENGINE=$engine_type;
402
410
 
403
411
delimiter |;
404
412
CREATE PROCEDURE p1()
443
451
# Test statement-based replication of function calls.
444
452
INSERT INTO t1 (i) VALUES (NULL);
445
453
 
 
454
# Here, we rely on having set @@concurrent_insert= 0 (see comment at
 
455
# the top of this file).
446
456
connection master1;
447
457
INSERT INTO t1 (i) VALUES (NULL);
448
458
 
449
459
connection master;
450
460
SELECT f3();
451
461
 
452
 
SELECT * FROM t1;
453
 
SELECT * FROM t2;
 
462
SELECT * FROM t1 ORDER BY i;
 
463
SELECT * FROM t2 ORDER BY i;
454
464
 
455
465
sync_slave_with_master;
456
466
SELECT * FROM t1;
472
482
 
473
483
# Tests in this file are tightly bound together.  Recreate t2.
474
484
connection master;
475
 
create table t2 (
 
485
eval create table t2 (
476
486
  id int not null auto_increment,
477
487
  last_id int,
478
488
  primary key (id)
479
 
);
 
489
) engine=$engine_type;
480
490
 
481
491
 
482
492
# Test for BUG#20341 "stored function inserting into one
484
494
 
485
495
connection master;
486
496
truncate table t2;
487
 
create table t1 (id tinyint primary key); # no auto_increment
 
497
# no auto_increment
 
498
eval create table t1 (id tinyint primary key) engine=$engine_type;
488
499
 
489
500
delimiter |;
490
501
create function insid() returns int
504
515
delete from t2 where id>=5;
505
516
set sql_log_bin=1;
506
517
insert into t1 select insid();
507
 
select * from t1;
508
 
select * from t2;
 
518
select * from t1 order by id;
 
519
select * from t2 order by id;
509
520
 
510
521
sync_slave_with_master;
511
 
select * from t1;
512
 
select * from t2;
 
522
select * from t1 order by id;
 
523
select * from t2 order by id;
513
524
 
514
525
connection master;
515
526
drop table t1;
516
527
drop function insid;
517
528
 
518
529
truncate table t2;
519
 
create table t1 (n int primary key auto_increment not null,
520
 
b int, unique(b));
 
530
eval create table t1 (n int primary key auto_increment not null,
 
531
                      b int, unique(b)) engine=$engine_type;
521
532
delimiter |;
522
533
create procedure foo()
523
534
begin
528
539
end|
529
540
delimiter ;|
530
541
call foo();
531
 
select * from t1;
532
 
select * from t2;
 
542
select * from t1 order by n;
 
543
select * from t2 order by id;
533
544
 
534
545
sync_slave_with_master;
535
 
select * from t1;
536
 
select * from t2;
 
546
select * from t1 order by n;
 
547
select * from t2 order by id;
537
548
 
538
549
connection master;
539
550
drop table t1, t2;
540
551
drop procedure foo;
 
552
SET @@global.concurrent_insert= @old_concurrent_insert;
541
553
sync_slave_with_master;