Skip to content

Commit c4f65d8

Browse files
authored
MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed in ha_partition::set_auto_increment_if_higher
ha_partition::set_auto_increment_if_higher expects part_share->auto_inc_initialized is true or can_use_for_auto_inc_init() is false (but as the comment of this method says, it returns false only if we use Spider engine with DROP TABLE or ALTER TABLE query). However, part_share->auto_inc_initialized becomes true only after all partitions are opened (since 6dce6ae). Therefore, I added a conditional expression in order to read all partitions when we execute REPLACE on a table that has an AUTO_INCREMENT column. Reviewed by: Nayuta Yanagisawa Reviewed by: Alexey Botchkov
1 parent f31e935 commit c4f65d8

8 files changed

+52
-5
lines changed

mysql-test/suite/parts/inc/partition_auto_increment.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,5 +873,16 @@ UPDATE t1 SET pk = 0;
873873
DROP TABLE t1;
874874
}
875875

876+
if (!$skip_update)
877+
{
878+
--echo #
879+
--echo # MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
880+
--echo # ha_partition::set_auto_increment_if_higher
881+
--echo #
882+
eval CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE=$engine PARTITION BY HASH (a) PARTITIONS 3;
883+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
884+
DROP TABLE t1;
885+
}
886+
876887
--echo ##############################################################################
877888
}

mysql-test/suite/parts/r/partition_auto_increment_innodb.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,4 +1109,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
11091109
INSERT INTO t1 VALUES (1,1),(2,2);
11101110
UPDATE t1 SET pk = 0;
11111111
DROP TABLE t1;
1112+
#
1113+
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
1114+
# ha_partition::set_auto_increment_if_higher
1115+
#
1116+
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='InnoDB' PARTITION BY HASH (a) PARTITIONS 3;
1117+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
1118+
DROP TABLE t1;
11121119
##############################################################################

mysql-test/suite/parts/r/partition_auto_increment_maria.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,4 +1156,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
11561156
INSERT INTO t1 VALUES (1,1),(2,2);
11571157
UPDATE t1 SET pk = 0;
11581158
DROP TABLE t1;
1159+
#
1160+
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
1161+
# ha_partition::set_auto_increment_if_higher
1162+
#
1163+
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Aria' PARTITION BY HASH (a) PARTITIONS 3;
1164+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
1165+
DROP TABLE t1;
11591166
##############################################################################

mysql-test/suite/parts/r/partition_auto_increment_memory.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,4 +1137,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
11371137
INSERT INTO t1 VALUES (1,1),(2,2);
11381138
UPDATE t1 SET pk = 0;
11391139
DROP TABLE t1;
1140+
#
1141+
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
1142+
# ha_partition::set_auto_increment_if_higher
1143+
#
1144+
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Memory' PARTITION BY HASH (a) PARTITIONS 3;
1145+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
1146+
DROP TABLE t1;
11401147
##############################################################################

mysql-test/suite/parts/r/partition_auto_increment_myisam.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,4 +1156,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
11561156
INSERT INTO t1 VALUES (1,1),(2,2);
11571157
UPDATE t1 SET pk = 0;
11581158
DROP TABLE t1;
1159+
#
1160+
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
1161+
# ha_partition::set_auto_increment_if_higher
1162+
#
1163+
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='MyISAM' PARTITION BY HASH (a) PARTITIONS 3;
1164+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
1165+
DROP TABLE t1;
11591166
##############################################################################

sql/ha_partition.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,7 +3661,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
36613661
}
36623662
else
36633663
{
3664-
check_insert_autoincrement();
3664+
check_insert_or_replace_autoincrement();
36653665
if (unlikely((error= open_read_partitions(name_buff, sizeof(name_buff)))))
36663666
goto err_handler;
36673667
m_num_locks= m_file_sample->lock_count();
@@ -8666,7 +8666,7 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names)
86668666
return 0;
86678667
}
86688668

8669-
check_insert_autoincrement();
8669+
check_insert_or_replace_autoincrement();
86708670
if (bitmap_cmp(&m_opened_partitions, &m_part_info->read_partitions) != 0)
86718671
return 0;
86728672

sql/ha_partition.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,15 +1400,16 @@ class ha_partition :public handler
14001400
unlock_auto_increment();
14011401
}
14021402

1403-
void check_insert_autoincrement()
1403+
void check_insert_or_replace_autoincrement()
14041404
{
14051405
/*
1406-
If we INSERT into the table having the AUTO_INCREMENT column,
1406+
If we INSERT or REPLACE into the table having the AUTO_INCREMENT column,
14071407
we have to read all partitions for the next autoincrement value
14081408
unless we already did it.
14091409
*/
14101410
if (!part_share->auto_inc_initialized &&
1411-
ha_thd()->lex->sql_command == SQLCOM_INSERT &&
1411+
(ha_thd()->lex->sql_command == SQLCOM_INSERT ||
1412+
ha_thd()->lex->sql_command == SQLCOM_REPLACE) &&
14121413
table->found_next_number_field)
14131414
bitmap_set_all(&m_part_info->read_partitions);
14141415
}

storage/tokudb/mysql-test/tokudb_parts/r/partition_auto_increment_tokudb.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,5 +1123,12 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
11231123
INSERT INTO t1 VALUES (1,1),(2,2);
11241124
UPDATE t1 SET pk = 0;
11251125
DROP TABLE t1;
1126+
#
1127+
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
1128+
# ha_partition::set_auto_increment_if_higher
1129+
#
1130+
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='TokuDB' PARTITION BY HASH (a) PARTITIONS 3;
1131+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
1132+
DROP TABLE t1;
11261133
##############################################################################
11271134
SET GLOBAL tokudb_prelock_empty = @tokudb_prelock_empty_saved;

0 commit comments

Comments
 (0)