1
by brian
clean slate |
1 |
#
|
2 |
# Test of auto_increment with offset |
|
3 |
#
|
|
4 |
#####################################
|
|
5 |
# By: JBM |
|
6 |
# Date: 2006-02-10 |
|
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 |
|
14 |
||
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); |
|
17 |
select * from t1; |
|
18 |
||
19 |
sync_slave_with_master; |
|
20 |
select * from t1; |
|
21 |
connection master; |
|
22 |
drop table t1; |
|
23 |
||
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); |
|
28 |
select * from t1; |
|
29 |
||
30 |
sync_slave_with_master; |
|
31 |
select * from t1; |
|
32 |
connection master; |
|
33 |
||
34 |
drop table t1; |
|
35 |
||
36 |
set @@session.auto_increment_increment=100, @@session.auto_increment_offset=10; |
|
37 |
show variables like "%auto_inc%"; |
|
38 |
||
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); |
|
43 |
select * from t1; |
|
44 |
insert into t1 values (1000); |
|
45 |
set @@insert_id=400; |
|
46 |
insert into t1 values(NULL),(NULL); |
|
47 |
select * from t1; |
|
48 |
||
49 |
sync_slave_with_master; |
|
50 |
select * from t1; |
|
51 |
connection master; |
|
52 |
drop table t1; |
|
53 |
||
54 |
#
|
|
55 |
# Same test with innodb (as the innodb code is a bit different) |
|
56 |
#
|
|
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); |
|
61 |
select * from t1; |
|
62 |
insert into t1 values (1000); |
|
63 |
set @@insert_id=400; |
|
64 |
insert into t1 values(NULL),(NULL); |
|
65 |
select * from t1; |
|
66 |
||
67 |
sync_slave_with_master; |
|
68 |
select * from t1; |
|
69 |
connection master; |
|
70 |
drop table t1; |
|
71 |
||
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); |
|
77 |
select * from t1; |
|
78 |
set @@insert_id=600; |
|
79 |
--error ER_DUP_ENTRY |
|
80 |
insert into t1 values(600),(NULL),(NULL); |
|
81 |
set @@insert_id=600; |
|
82 |
insert ignore into t1 values(600),(NULL),(NULL),(610),(NULL); |
|
83 |
select * from t1; |
|
84 |
||
85 |
sync_slave_with_master; |
|
86 |
select * from t1; |
|
87 |
connection master; |
|
88 |
drop table t1; |
|
89 |
||
90 |
#
|
|
91 |
# Test that auto-increment works when slave has rows in the table |
|
92 |
#
|
|
93 |
set @@session.auto_increment_increment=10, @@session.auto_increment_offset=1; |
|
94 |
||
95 |
eval create table t1 (a int not null auto_increment, primary key (a)) engine=$engine_type2; |
|
96 |
||
97 |
sync_slave_with_master; |
|
98 |
insert into t1 values(2),(12),(22),(32),(42); |
|
99 |
connection master; |
|
100 |
||
101 |
insert into t1 values (NULL),(NULL); |
|
102 |
insert into t1 values (3),(NULL),(NULL); |
|
103 |
select * from t1; |
|
104 |
||
105 |
sync_slave_with_master; |
|
106 |
select * from t1; |
|
107 |
||
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. |
|
113 |
||
114 |
connection master; |
|
115 |
drop table t1; |
|
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); |
|
122 |
--error ER_DUP_ENTRY |
|
123 |
insert into t1 values(null); |
|
124 |
select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t1 order by a; |
|
125 |
||
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; |
|
130 |
set insert_id=1000; |
|
131 |
insert into t2 values(null); |
|
132 |
select a, mod(a-@@auto_increment_offset,@@auto_increment_increment) from t2 order by a; |
|
133 |
||
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; |
|
144 |
||
145 |
connection master; |
|
146 |
||
147 |
drop table t1,t2,t3; |
|
148 |
||
149 |
# End cleanup |
|
150 |
sync_slave_with_master; |