mirror of
https://github.com/MariaDB/server.git
synced 2025-01-24 15:54:37 +01:00
branches/5.1: Ignore negative values supplied by the user when calculating the
next value to store in dict_table_t. Setting autoincrement columns top negative values is undefined behavior and this change should bring the behavior of InnoDB closer to what users expect. Added several tests to check. rb://162
This commit is contained in:
parent
d20d02dd11
commit
ef9f6104ea
3 changed files with 323 additions and 1 deletions
|
@ -7784,6 +7784,7 @@ ha_innobase::get_auto_increment(
|
||||||
AUTOINC counter after attempting to insert the row. */
|
AUTOINC counter after attempting to insert the row. */
|
||||||
if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
|
if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
|
||||||
ulonglong need;
|
ulonglong need;
|
||||||
|
ulonglong current;
|
||||||
ulonglong next_value;
|
ulonglong next_value;
|
||||||
ulonglong col_max_value;
|
ulonglong col_max_value;
|
||||||
|
|
||||||
|
@ -7792,11 +7793,12 @@ ha_innobase::get_auto_increment(
|
||||||
col_max_value = innobase_get_int_col_max_value(
|
col_max_value = innobase_get_int_col_max_value(
|
||||||
table->next_number_field);
|
table->next_number_field);
|
||||||
|
|
||||||
|
current = *first_value > col_max_value ? autoinc : *first_value;
|
||||||
need = *nb_reserved_values * increment;
|
need = *nb_reserved_values * increment;
|
||||||
|
|
||||||
/* Compute the last value in the interval */
|
/* Compute the last value in the interval */
|
||||||
next_value = innobase_next_autoinc(
|
next_value = innobase_next_autoinc(
|
||||||
*first_value, need, offset, col_max_value);
|
current, need, offset, col_max_value);
|
||||||
|
|
||||||
prebuilt->autoinc_last_value = next_value;
|
prebuilt->autoinc_last_value = next_value;
|
||||||
|
|
||||||
|
|
|
@ -889,3 +889,218 @@ d1
|
||||||
4
|
4
|
||||||
5
|
5
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
|
||||||
|
SHOW VARIABLES LIKE "%auto_inc%";
|
||||||
|
Variable_name Value
|
||||||
|
auto_increment_increment 1
|
||||||
|
auto_increment_offset 1
|
||||||
|
CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-127, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` tinyint(4) NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
-127 innodb
|
||||||
|
-1 innodb
|
||||||
|
1 NULL
|
||||||
|
2 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (-127, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
1 NULL
|
||||||
|
2 innodb
|
||||||
|
3 innodb
|
||||||
|
4 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-32767, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` smallint(6) NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
-32767 innodb
|
||||||
|
-1 innodb
|
||||||
|
1 NULL
|
||||||
|
2 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (-32757, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
1 NULL
|
||||||
|
2 innodb
|
||||||
|
3 innodb
|
||||||
|
4 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-8388607, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` mediumint(9) NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
-8388607 innodb
|
||||||
|
-1 innodb
|
||||||
|
1 NULL
|
||||||
|
2 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (-8388607, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
1 NULL
|
||||||
|
2 innodb
|
||||||
|
3 innodb
|
||||||
|
4 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-2147483647, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
-2147483647 innodb
|
||||||
|
-1 innodb
|
||||||
|
1 NULL
|
||||||
|
2 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (-2147483647, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
1 NULL
|
||||||
|
2 innodb
|
||||||
|
3 innodb
|
||||||
|
4 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
-9223372036854775807 innodb
|
||||||
|
-1 innodb
|
||||||
|
1 NULL
|
||||||
|
2 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
|
||||||
|
Warnings:
|
||||||
|
Warning 1264 Out of range value for column 'c1' at row 1
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`c2` varchar(10) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1 c2
|
||||||
|
1 NULL
|
||||||
|
2 innodb
|
||||||
|
3 innodb
|
||||||
|
4 NULL
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
|
@ -502,3 +502,108 @@ ALTER TABLE t1 AUTO_INCREMENT = 3;
|
||||||
INSERT INTO t1 VALUES(null);
|
INSERT INTO t1 VALUES(null);
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
# If the user has specified negative values for an AUTOINC column then
|
||||||
|
# InnoDB should ignore those values when setting the table's max value.
|
||||||
|
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
|
||||||
|
SHOW VARIABLES LIKE "%auto_inc%";
|
||||||
|
# TINYINT
|
||||||
|
CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-127, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-127, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
#
|
||||||
|
# SMALLINT
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-32767, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-32757, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
#
|
||||||
|
# MEDIUMINT
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-8388607, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-8388607, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
#
|
||||||
|
# INT
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-2147483647, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-2147483647, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
#
|
||||||
|
# BIGINT
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 VALUES (1, NULL);
|
||||||
|
INSERT INTO t1 VALUES (-1, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
|
||||||
|
INSERT INTO t1 VALUES (NULL, NULL);
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
# End negative number check
|
||||||
|
|
Loading…
Add table
Reference in a new issue