Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mysql-test/suite/parts/r/mdev_40995.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# MDEV-40995 concurrent INSERT ... SELECT on a partitioned InnoDB table
# can leave the table-level AUTO_INCREMENT counter behind MAX(pk)
#
CREATE TABLE t1 (
id INT AUTO_INCREMENT,
pk2 INT NOT NULL,
a INT,
PRIMARY KEY (id, pk2),
UNIQUE KEY (a, pk2)
) ENGINE=InnoDB PARTITION BY HASH(pk2) PARTITIONS 2;
INSERT INTO t1 (pk2, a) VALUES (1, 10), (1, 100), (1, 110);
connect con1,localhost,root,,;
connect con2,localhost,root,,;
connection con1;
SET DEBUG_SYNC = 'ha_partition_get_auto_increment_after_reservation SIGNAL start_t2 WAIT_FOR t2_done EXECUTE 1';
INSERT INTO t1 (pk2, a) SELECT pk2, a+10 FROM t1 WHERE pk2=1 ORDER BY a;;
connection con2;
SET DEBUG_SYNC = 'now WAIT_FOR start_t2';
INSERT INTO t1 (pk2, a) VALUES (2, 200);
SET DEBUG_SYNC = 'now SIGNAL t2_done';
connection con1;
ERROR 23000: Duplicate entry '110-1' for key 'a'
connection default;
INSERT INTO t1 (pk2, a) VALUES (2, 300);
INSERT INTO t1 (pk2, a) VALUES (2, 400);
DROP TABLE t1;
SET DEBUG_SYNC = 'RESET';
1 change: 1 addition & 0 deletions mysql-test/suite/parts/t/mdev_40995-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--innodb-autoinc-lock-mode=2
41 changes: 41 additions & 0 deletions mysql-test/suite/parts/t/mdev_40995.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--source include/have_debug_sync.inc
--source include/have_partition.inc
--source include/have_innodb.inc

--echo #
--echo # MDEV-40995 concurrent INSERT ... SELECT on a partitioned InnoDB table
--echo # can leave the table-level AUTO_INCREMENT counter behind MAX(pk)
--echo #

CREATE TABLE t1 (
id INT AUTO_INCREMENT,
pk2 INT NOT NULL,
a INT,
PRIMARY KEY (id, pk2),
UNIQUE KEY (a, pk2)
) ENGINE=InnoDB PARTITION BY HASH(pk2) PARTITIONS 2;

INSERT INTO t1 (pk2, a) VALUES (1, 10), (1, 100), (1, 110);

--connect (con1,localhost,root,,)
--connect (con2,localhost,root,,)

--connection con1
SET DEBUG_SYNC = 'ha_partition_get_auto_increment_after_reservation SIGNAL start_t2 WAIT_FOR t2_done EXECUTE 1';
--send INSERT INTO t1 (pk2, a) SELECT pk2, a+10 FROM t1 WHERE pk2=1 ORDER BY a;

--connection con2
SET DEBUG_SYNC = 'now WAIT_FOR start_t2';
INSERT INTO t1 (pk2, a) VALUES (2, 200);
SET DEBUG_SYNC = 'now SIGNAL t2_done';

--connection con1
--error ER_DUP_ENTRY
--reap

--connection default
INSERT INTO t1 (pk2, a) VALUES (2, 300);
INSERT INTO t1 (pk2, a) VALUES (2, 400);

DROP TABLE t1;
SET DEBUG_SYNC = 'RESET';
4 changes: 3 additions & 1 deletion sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11107,6 +11107,7 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment,
part_share->next_auto_inc_val+= nb_desired_values * increment;

unlock_auto_increment();
DEBUG_SYNC(ha_thd(), "ha_partition_get_auto_increment_after_reservation");
DBUG_PRINT("info", ("*first_value: %lu", (ulong) *first_value));
*nb_reserved_values= nb_desired_values;
}
Expand Down Expand Up @@ -11139,7 +11140,8 @@ void ha_partition::release_auto_increment()
we can lower the reserved value.
*/
if (next_insert_id < next_auto_inc_val &&
auto_inc_interval_for_cur_row.maximum() >= next_auto_inc_val)
auto_inc_interval_for_cur_row.maximum() >= next_auto_inc_val &&
next_insert_id >= auto_inc_interval_for_cur_row.minimum())
{
THD *thd= ha_thd();
/*
Expand Down