mirror of
https://github.com/MariaDB/server.git
synced 2025-01-25 00:04:33 +01:00
branches/5.1: Fix Bug#47720 - REPLACE INTO Autoincrement column with negative values.
This bug is similiar to the negative autoinc filter patch from earlier, with the additional handling of filtering out the negative column values set explicitly by the user. rb://184 Approved by Heikki.
This commit is contained in:
parent
07ce318c4e
commit
8401ded572
3 changed files with 74 additions and 12 deletions
|
@ -4060,24 +4060,29 @@ no_commit:
|
||||||
update the table upper limit. Note: last_value
|
update the table upper limit. Note: last_value
|
||||||
will be 0 if get_auto_increment() was not called.*/
|
will be 0 if get_auto_increment() was not called.*/
|
||||||
|
|
||||||
if (auto_inc <= col_max_value
|
if (auto_inc >= prebuilt->autoinc_last_value) {
|
||||||
&& auto_inc >= prebuilt->autoinc_last_value) {
|
|
||||||
set_max_autoinc:
|
set_max_autoinc:
|
||||||
ut_a(prebuilt->autoinc_increment > 0);
|
/* This should filter out the negative
|
||||||
|
values set explicitly by the user. */
|
||||||
|
if (auto_inc <= col_max_value) {
|
||||||
|
ut_a(prebuilt->autoinc_increment > 0);
|
||||||
|
|
||||||
ulonglong need;
|
ulonglong need;
|
||||||
ulonglong offset;
|
ulonglong offset;
|
||||||
|
|
||||||
offset = prebuilt->autoinc_offset;
|
offset = prebuilt->autoinc_offset;
|
||||||
need = prebuilt->autoinc_increment;
|
need = prebuilt->autoinc_increment;
|
||||||
|
|
||||||
auto_inc = innobase_next_autoinc(
|
auto_inc = innobase_next_autoinc(
|
||||||
auto_inc, need, offset, col_max_value);
|
auto_inc,
|
||||||
|
need, offset, col_max_value);
|
||||||
|
|
||||||
err = innobase_set_max_autoinc(auto_inc);
|
err = innobase_set_max_autoinc(
|
||||||
|
auto_inc);
|
||||||
|
|
||||||
if (err != DB_SUCCESS) {
|
if (err != DB_SUCCESS) {
|
||||||
error = err;
|
error = err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1151,3 +1151,42 @@ T1 CREATE TABLE `T1` (
|
||||||
PRIMARY KEY (`C1`)
|
PRIMARY KEY (`C1`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
|
||||||
DROP TABLE T1;
|
DROP TABLE T1;
|
||||||
|
DROP TABLE IF EXISTS t1;
|
||||||
|
Warnings:
|
||||||
|
Note 1051 Unknown table 't1'
|
||||||
|
CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 SET c1 = 1;
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
|
||||||
|
INSERT INTO t1 SET c1 = 2;
|
||||||
|
INSERT INTO t1 SET c1 = -1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
INSERT INTO t1 SET c1 = -1;
|
||||||
|
Got one of the listed errors
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
REPLACE INTO t1 VALUES (-1);
|
||||||
|
SELECT * FROM t1;
|
||||||
|
c1
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`c1` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
PRIMARY KEY (`c1`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
|
@ -639,3 +639,21 @@ INSERT INTO T1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
|
||||||
INSERT INTO T1(C2) VALUES ('innodb');
|
INSERT INTO T1(C2) VALUES ('innodb');
|
||||||
SHOW CREATE TABLE T1;
|
SHOW CREATE TABLE T1;
|
||||||
DROP TABLE T1;
|
DROP TABLE T1;
|
||||||
|
|
||||||
|
##
|
||||||
|
# 47720: REPLACE INTO Autoincrement column with negative values
|
||||||
|
#
|
||||||
|
DROP TABLE IF EXISTS t1;
|
||||||
|
CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
|
||||||
|
INSERT INTO t1 SET c1 = 1;
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
INSERT INTO t1 SET c1 = 2;
|
||||||
|
INSERT INTO t1 SET c1 = -1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
-- error ER_DUP_ENTRY,1062
|
||||||
|
INSERT INTO t1 SET c1 = -1;
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
REPLACE INTO t1 VALUES (-1);
|
||||||
|
SELECT * FROM t1;
|
||||||
|
SHOW CREATE TABLE t1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue