mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
75e7132fca
The idea of this fix is that it's enough to prevent the next_auto_inc_val from incrementing if an error, to fix this problem and also the MDEV-17333. So this patch basically reverts the existing fix to the MDEV-17333.
339 lines
9.2 KiB
Text
339 lines
9.2 KiB
Text
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;
|