Skip to content

Commit 7153e15

Browse files
committed
Revert "MDEV-8827 Duplicate key with auto increment"
This reverts commit ef47b62. The parent commit 07ba556 which is a backport of mysql/mysql-server@1198267 fixes the issue differently.
1 parent 07ba556 commit 7153e15

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

mysql-test/suite/innodb/r/innodb-autoinc.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Variable_name Value
567567
auto_increment_increment 65535
568568
auto_increment_offset 65535
569569
INSERT INTO t1 VALUES (NULL),(NULL);
570-
ERROR HY000: Failed to read auto-increment value from storage engine
570+
ERROR 22003: Out of range value for column 'c1' at row 1
571571
SELECT * FROM t1;
572572
c1
573573
1
@@ -660,7 +660,7 @@ t2 CREATE TABLE `t2` (
660660
`n` int(10) unsigned NOT NULL,
661661
`o` enum('FALSE','TRUE') DEFAULT NULL,
662662
PRIMARY KEY (`m`)
663-
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1
663+
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1
664664
INSERT INTO t1 (b,c) SELECT n,o FROM t2 ;
665665
SHOW CREATE TABLE t1;
666666
Table Create Table

mysql-test/suite/innodb/t/innodb-autoinc.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ INSERT INTO t1 VALUES (18446744073709551610); #-- 2^64 - 2
349349
SELECT * FROM t1;
350350
SET @@SESSION.AUTO_INCREMENT_INCREMENT=1152921504606846976, @@SESSION.AUTO_INCREMENT_OFFSET=1152921504606846976;
351351
SHOW VARIABLES LIKE "%auto_inc%";
352-
--error 1467
352+
--error 167
353353
INSERT INTO t1 VALUES (NULL),(NULL);
354354
SELECT * FROM t1;
355355
DROP TABLE t1;

storage/innobase/handler/ha_innodb.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,11 +1504,10 @@ innobase_next_autoinc(
15041504
if (next_value == 0) {
15051505
ulonglong next;
15061506

1507-
if (current >= offset) {
1507+
if (current > offset) {
15081508
next = (current - offset) / step;
15091509
} else {
1510-
next = 0;
1511-
block -= step;
1510+
next = (offset - current) / step;
15121511
}
15131512

15141513
ut_a(max_value > next);
@@ -10530,12 +10529,15 @@ ha_innobase::get_auto_increment(
1053010529

1053110530
current = *first_value;
1053210531

10533-
if (prebuilt->autoinc_increment != increment) {
10532+
/* If the increment step of the auto increment column
10533+
decreases then it is not affecting the immediate
10534+
next value in the series. */
10535+
if (prebuilt->autoinc_increment > increment) {
1053410536

1053510537
current = autoinc - prebuilt->autoinc_increment;
1053610538

1053710539
current = innobase_next_autoinc(
10538-
current, 1, increment, offset, col_max_value);
10540+
current, 1, increment, 1, col_max_value);
1053910541

1054010542
dict_table_autoinc_initialize(prebuilt->table, current);
1054110543

storage/xtradb/handler/ha_innodb.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,11 +1774,10 @@ innobase_next_autoinc(
17741774
if (next_value == 0) {
17751775
ulonglong next;
17761776

1777-
if (current >= offset) {
1777+
if (current > offset) {
17781778
next = (current - offset) / step;
17791779
} else {
1780-
next = 0;
1781-
block -= step;
1780+
next = (offset - current) / step;
17821781
}
17831782

17841783
ut_a(max_value > next);
@@ -11799,12 +11798,15 @@ ha_innobase::get_auto_increment(
1179911798

1180011799
current = *first_value;
1180111800

11802-
if (prebuilt->autoinc_increment != increment) {
11801+
/* If the increment step of the auto increment column
11802+
decreases then it is not affecting the immediate
11803+
next value in the series. */
11804+
if (prebuilt->autoinc_increment > increment) {
1180311805

1180411806
current = autoinc - prebuilt->autoinc_increment;
1180511807

1180611808
current = innobase_next_autoinc(
11807-
current, 1, increment, offset, col_max_value);
11809+
current, 1, increment, 1, col_max_value);
1180811810

1180911811
dict_table_autoinc_initialize(prebuilt->table, current);
1181011812

0 commit comments

Comments
 (0)