2
# Test of auto_increment with offset
4
#####################################
7
# Change: NDB does not support auto inc
8
# in this usage. Currently there is no
9
# plan to implment. Skipping test when
10
# NDB is default engine.
11
#####################################
12
-- source include/not_ndb_default.inc
13
-- source include/master-slave.inc
15
eval create table t1 (a int not null auto_increment,b int, primary key (a)) engine=$engine_type2 auto_increment=3;
16
insert into t1 values (NULL,1),(NULL,2),(NULL,3);
19
sync_slave_with_master;
24
eval create table t1 (a int not null auto_increment,b int, primary key (a)) engine=$engine_type2;
25
insert into t1 values (1,1),(NULL,2),(3,3),(NULL,4);
26
delete from t1 where b=4;
27
insert into t1 values (NULL,5),(NULL,6);
30
sync_slave_with_master;
36
set @@session.auto_increment_increment=100, @@session.auto_increment_offset=10;
37
show variables like "%auto_inc%";
39
eval create table t1 (a int not null auto_increment, primary key (a)) engine=$engine_type2;
40
# Insert with 2 insert statements to get better testing of logging
41
insert into t1 values (NULL),(5),(NULL);
42
insert into t1 values (250),(NULL);
44
insert into t1 values (1000);
46
insert into t1 values(NULL),(NULL);
49
sync_slave_with_master;
55
# Same test with innodb (as the innodb code is a bit different)
57
eval create table t1 (a int not null auto_increment, primary key (a)) engine=$engine_type;
58
# Insert with 2 insert statements to get better testing of logging
59
insert into t1 values (NULL),(5),(NULL);
60
insert into t1 values (250),(NULL);
62
insert into t1 values (1000);
64
insert into t1 values(NULL),(NULL);
67
sync_slave_with_master;
72
set @@session.auto_increment_increment=1, @@session.auto_increment_offset=1;
73
eval create table t1 (a int not null auto_increment, primary key (a)) engine=$engine_type2;
74
# Insert with 2 insert statements to get better testing of logging
75
insert into t1 values (NULL),(5),(NULL),(NULL);
76
insert into t1 values (500),(NULL),(502),(NULL),(NULL);
80
insert into t1 values(600),(NULL),(NULL);
82
insert ignore into t1 values(600),(NULL),(NULL),(610),(NULL);
85
sync_slave_with_master;
91
# Test that auto-increment works when slave has rows in the table
93
set @@session.auto_increment_increment=10, @@session.auto_increment_offset=1;
95
eval create table t1 (a int not null auto_increment, primary key (a)) engine=$engine_type2;
97
sync_slave_with_master;
98
insert into t1 values(2),(12),(22),(32),(42);
101
insert into t1 values (NULL),(NULL);
102
insert into t1 values (3),(NULL),(NULL);
105
sync_slave_with_master;
108
# Test for BUG#20524 "auto_increment_* not observed when inserting
109
# a too large value". When an autogenerated value was bigger than the
110
# maximum possible value of the field, it was truncated to that max
111
# possible value, without being "rounded down" to still honour
112
# auto_increment_* variables.
116
create table t1 (a tinyint not null auto_increment primary key) engine=myisam;
117
insert into t1 values(103);
118
set auto_increment_increment=11;
119
set auto_increment_offset=4;
120
insert into t1 values(null);
121
insert into t1 values(null);
123
insert into t1 values(null);
124
select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t1 order by a;
126
# same but with a larger value
127
create table t2 (a tinyint unsigned not null auto_increment primary key) engine=myisam;
128
set auto_increment_increment=10;
129
set auto_increment_offset=1;
131
insert into t2 values(null);
132
select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t2 order by a;
134
# An offset so big that even first value does not fit
135
create table t3 like t1;
136
set auto_increment_increment=1000;
137
set auto_increment_offset=700;
138
insert into t3 values(null);
139
select * from t3 order by a;
140
sync_slave_with_master;
141
select * from t1 order by a;
142
select * from t2 order by a;
143
select * from t3 order by a;
150
sync_slave_with_master;