summaryrefslogtreecommitdiff
path: root/mysql-test/main/auto_increment_ranges_innodb.result
blob: 7800099200f7f27f9f1fe05c6522259cecb787a7 (plain)
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
set default_storage_engine=innodb;
drop table if exists t1;
#
# Testing ranges with smallint
#
create table t1 (a smallint primary key auto_increment);
insert into t1 values(32767);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
truncate table t1;
insert into t1 values(32767-1);
insert into t1 values(NULL);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
select * from t1;
a
32766
32767
truncate table t1;
insert into t1 values(32767),(NULL);
ERROR 22003: Out of range value for column 'a' at row 2
select * from t1;
a
truncate table t1;
insert into t1 values(32767-1),(NULL),(NULL);
ERROR 22003: Out of range value for column 'a' at row 3
truncate table t1;
insert ignore into t1 values(32767+1);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
select * from t1;
a
32767
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
drop table t1;
#
# Testing ranges with unsigned smallint
#
create table t1 (a smallint unsigned primary key auto_increment);
insert into t1 values(65535);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
truncate table t1;
insert into t1 values(65535-1);
insert into t1 values(NULL);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
select * from t1;
a
65534
65535
truncate table t1;
insert into t1 values(65535),(NULL);
ERROR 22003: Out of range value for column 'a' at row 2
select * from t1;
a
truncate table t1;
insert into t1 values(65535-1),(NULL),(NULL);
ERROR 22003: Out of range value for column 'a' at row 3
truncate table t1;
insert ignore into t1 values(65535+1);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
select * from t1;
a
65535
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
drop table t1;
#
# Testing ranges with integer
#
create table t1 (a int primary key auto_increment);
insert into t1 values(2147483647);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
truncate table t1;
insert into t1 values(2147483647-1);
insert into t1 values(NULL);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
select * from t1;
a
2147483646
2147483647
truncate table t1;
insert into t1 values(2147483647),(NULL);
ERROR 22003: Out of range value for column 'a' at row 2
select * from t1;
a
truncate table t1;
insert into t1 values(2147483647-1),(NULL),(NULL);
ERROR 22003: Out of range value for column 'a' at row 3
truncate table t1;
insert ignore into t1 values(2147483647+1);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
select * from t1;
a
2147483647
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
drop table t1;
#
# Testing ranges with unsigned integer
#
create table t1 (a int unsigned primary key auto_increment);
insert into t1 values(4294967295);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
truncate table t1;
insert into t1 values(4294967295-1);
insert into t1 values(NULL);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
select * from t1;
a
4294967294
4294967295
truncate table t1;
insert into t1 values(4294967295),(NULL);
ERROR 22003: Out of range value for column 'a' at row 2
select * from t1;
a
truncate table t1;
insert into t1 values(4294967295-1),(NULL),(NULL);
ERROR 22003: Out of range value for column 'a' at row 3
truncate table t1;
insert ignore into t1 values(4294967295+1);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
select * from t1;
a
4294967295
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
drop table t1;
#
# Testing ranges with bigint
#
create table t1 (a bigint primary key auto_increment);
insert into t1 values(cast(9223372036854775807 as unsigned));
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
truncate table t1;
insert into t1 values(cast(9223372036854775807 as unsigned)-1);
insert into t1 values(NULL);
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
select * from t1;
a
9223372036854775806
9223372036854775807
truncate table t1;
insert into t1 values(cast(9223372036854775807 as unsigned)),(NULL);
ERROR 22003: Out of range value for column 'a' at row 2
select * from t1;
a
truncate table t1;
insert into t1 values(cast(9223372036854775807 as unsigned)-1),(NULL),(NULL);
ERROR 22003: Out of range value for column 'a' at row 3
truncate table t1;
insert ignore into t1 values(cast(9223372036854775807 as unsigned)+1);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
select * from t1;
a
9223372036854775807
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
drop table t1;
#
# Testing ranges with unsigned bigint
#
create table t1 (a bigint unsigned primary key auto_increment);
insert into t1 values(18446744073709551615-1);
insert into t1 values(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
insert into t1 values(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
truncate table t1;
insert into t1 values(18446744073709551615-1);
insert into t1 values(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
insert into t1 values(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
select * from t1;
a
18446744073709551614
truncate table t1;
insert into t1 values(18446744073709551615),(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
select * from t1;
a
truncate table t1;
insert into t1 values(18446744073709551615-1),(NULL),(NULL);
ERROR HY000: Failed to read auto-increment value from storage engine
drop table t1;
#
# Test IGNORE and strict mode
#
create table t1 (a smallint primary key auto_increment);
insert ignore into t1 values(32766),(NULL),(NULL),(1);
Warnings:
Warning	167	Out of range value for column 'a' at row 3
select * from t1;
a
1
32766
32767
truncate table t1;
set @org_mode=@@sql_mode;
set @@sql_mode='ansi,traditional';
insert ignore into t1 values(32766),(NULL),(NULL);
Warnings:
Warning	167	Out of range value for column 'a' at row 3
truncate table t1;
insert into t1 values(32766),(NULL),(NULL);
ERROR 22003: Out of range value for column 'a' at row 3
set @@sql_mode=@org_mode;
drop table t1;
#
# Test auto increment with negative numbers
#
CREATE TABLE t1 (a INTEGER AUTO_INCREMENT, PRIMARY KEY (a));
INSERT INTO t1 VALUES (NULL), (2), (-5), (NULL);
INSERT INTO t1 VALUES (NULL);
SELECT * FROM t1;
a
-5
1
2
3
5
TRUNCATE TABLE t1;
INSERT INTO t1 VALUES (-5), (NULL);
SELECT * FROM t1;
a
-5
1
DROP TABLE t1;
#
# Test inserting a value out-of-range into an auto increment column
#
CREATE TABLE t1 (a smallint AUTO_INCREMENT, PRIMARY KEY (a));
INSERT INTO t1 VALUES (2);
INSERT IGNORE INTO t1 VALUES (32768);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
INSERT INTO t1 VALUES (NULL);
ERROR 22003: Out of range value for column 'a' at row 1
SELECT * FROM t1;
a
2
32767
DROP TABLE t1;
#
# Test old behaviour
#
create table t1 (a smallint primary key auto_increment);
insert into t1 values(32766),(NULL);
delete from t1 where a=32767;
insert into t1 values(NULL);
ERROR 22003: Out of range value for column 'a' at row 1
drop table t1;
#
# MDEV-17333 Assertion in update_auto_increment() upon exotic LOAD
#
create or replace table t1 (pk int auto_increment, x int, primary key(pk), unique key(x))
with system versioning partition by system_time interval 2 day
(partition p1 history, partition pn current);
load data infile 'load.data' ignore into table t1;
Warnings:
Warning	1062	Duplicate entry '1' for key 'x'
Warning	1062	Duplicate entry '1' for key 'x'
drop table t1;
create table t1 (pk int auto_increment primary key, f varchar(20));
insert t1 (f) values ('a'), ('b'), ('c'), ('d');
select null, f into outfile 'load.data' from t1 limit 1;
load data infile 'load.data' into table t1;
insert t1 (f) values ('<===');
select * from t1;
pk	f
1	a
2	b
3	c
4	d
5	a
6	<===
drop table t1;
#
# MDEV-21842: auto_increment does not increment with compound primary
# key on partitioned table
#
create or replace table `t` (
`id` bigint(20) unsigned not null auto_increment,
`a` int(10) not null ,
`dt` date not null,
primary key (`id`, `dt`) ,
unique key (`a`, `dt`)
)
partition by range  columns(`dt`)
(
partition `p202002` values less than ('2020-03-01'),
partition `P202003` values less than ('2020-04-01')
);
connect  con1, localhost, root,,;
connect  con2, localhost, root,,;
connection con1;
start transaction;
insert into t (a, dt) values (1, '2020-02-29');
connection con2;
start transaction;
insert into t (a, dt) values (1, '2020-02-29');
connection con1;
insert into t (a, dt) values (2, '2020-02-29');
select auto_increment from information_schema.tables where table_name='t';
auto_increment
4
commit;
connection con2;
ERROR 23000: Duplicate entry '1-2020-02-29' for key 'a'
connection con1;
select auto_increment from information_schema.tables where table_name='t';
auto_increment
4
insert into t (a, dt) values (3, '2020-02-29');
insert into t (a, dt) values (4, '2020-02-29');
disconnect con1;
disconnect con2;
connection default;
select * from t;
id	a	dt
1	1	2020-02-29
3	2	2020-02-29
4	3	2020-02-29
5	4	2020-02-29
drop table t;