Commit c4f65d8f authored by Shunsuke Tokunaga's avatar Shunsuke Tokunaga Committed by GitHub

MDEV-21027 Assertion `part_share->auto_inc_initialized ||...

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 6dce6aec).

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
parent f31e935c
...@@ -873,5 +873,16 @@ UPDATE t1 SET pk = 0; ...@@ -873,5 +873,16 @@ UPDATE t1 SET pk = 0;
DROP TABLE t1; DROP TABLE t1;
} }
if (!$skip_update)
{
--echo #
--echo # MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
--echo # ha_partition::set_auto_increment_if_higher
--echo #
eval CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE=$engine PARTITION BY HASH (a) PARTITIONS 3;
REPLACE INTO t1 PARTITION (p0) VALUES (3);
DROP TABLE t1;
}
--echo ############################################################################## --echo ##############################################################################
} }
...@@ -1109,4 +1109,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam ...@@ -1109,4 +1109,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
INSERT INTO t1 VALUES (1,1),(2,2); INSERT INTO t1 VALUES (1,1),(2,2);
UPDATE t1 SET pk = 0; UPDATE t1 SET pk = 0;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
# ha_partition::set_auto_increment_if_higher
#
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='InnoDB' PARTITION BY HASH (a) PARTITIONS 3;
REPLACE INTO t1 PARTITION (p0) VALUES (3);
DROP TABLE t1;
############################################################################## ##############################################################################
...@@ -1156,4 +1156,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam ...@@ -1156,4 +1156,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
INSERT INTO t1 VALUES (1,1),(2,2); INSERT INTO t1 VALUES (1,1),(2,2);
UPDATE t1 SET pk = 0; UPDATE t1 SET pk = 0;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
# ha_partition::set_auto_increment_if_higher
#
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Aria' PARTITION BY HASH (a) PARTITIONS 3;
REPLACE INTO t1 PARTITION (p0) VALUES (3);
DROP TABLE t1;
############################################################################## ##############################################################################
...@@ -1137,4 +1137,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam ...@@ -1137,4 +1137,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
INSERT INTO t1 VALUES (1,1),(2,2); INSERT INTO t1 VALUES (1,1),(2,2);
UPDATE t1 SET pk = 0; UPDATE t1 SET pk = 0;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
# ha_partition::set_auto_increment_if_higher
#
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Memory' PARTITION BY HASH (a) PARTITIONS 3;
REPLACE INTO t1 PARTITION (p0) VALUES (3);
DROP TABLE t1;
############################################################################## ##############################################################################
...@@ -1156,4 +1156,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam ...@@ -1156,4 +1156,11 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
INSERT INTO t1 VALUES (1,1),(2,2); INSERT INTO t1 VALUES (1,1),(2,2);
UPDATE t1 SET pk = 0; UPDATE t1 SET pk = 0;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
# ha_partition::set_auto_increment_if_higher
#
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='MyISAM' PARTITION BY HASH (a) PARTITIONS 3;
REPLACE INTO t1 PARTITION (p0) VALUES (3);
DROP TABLE t1;
############################################################################## ##############################################################################
...@@ -3661,7 +3661,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) ...@@ -3661,7 +3661,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
} }
else else
{ {
check_insert_autoincrement(); check_insert_or_replace_autoincrement();
if (unlikely((error= open_read_partitions(name_buff, sizeof(name_buff))))) if (unlikely((error= open_read_partitions(name_buff, sizeof(name_buff)))))
goto err_handler; goto err_handler;
m_num_locks= m_file_sample->lock_count(); m_num_locks= m_file_sample->lock_count();
...@@ -8666,7 +8666,7 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names) ...@@ -8666,7 +8666,7 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names)
return 0; return 0;
} }
check_insert_autoincrement(); check_insert_or_replace_autoincrement();
if (bitmap_cmp(&m_opened_partitions, &m_part_info->read_partitions) != 0) if (bitmap_cmp(&m_opened_partitions, &m_part_info->read_partitions) != 0)
return 0; return 0;
......
...@@ -1400,15 +1400,16 @@ class ha_partition :public handler ...@@ -1400,15 +1400,16 @@ class ha_partition :public handler
unlock_auto_increment(); unlock_auto_increment();
} }
void check_insert_autoincrement() void check_insert_or_replace_autoincrement()
{ {
/* /*
If we INSERT into the table having the AUTO_INCREMENT column, If we INSERT or REPLACE into the table having the AUTO_INCREMENT column,
we have to read all partitions for the next autoincrement value we have to read all partitions for the next autoincrement value
unless we already did it. unless we already did it.
*/ */
if (!part_share->auto_inc_initialized && if (!part_share->auto_inc_initialized &&
ha_thd()->lex->sql_command == SQLCOM_INSERT && (ha_thd()->lex->sql_command == SQLCOM_INSERT ||
ha_thd()->lex->sql_command == SQLCOM_REPLACE) &&
table->found_next_number_field) table->found_next_number_field)
bitmap_set_all(&m_part_info->read_partitions); bitmap_set_all(&m_part_info->read_partitions);
} }
......
...@@ -1123,5 +1123,12 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam ...@@ -1123,5 +1123,12 @@ CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam
INSERT INTO t1 VALUES (1,1),(2,2); INSERT INTO t1 VALUES (1,1),(2,2);
UPDATE t1 SET pk = 0; UPDATE t1 SET pk = 0;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
# ha_partition::set_auto_increment_if_higher
#
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='TokuDB' PARTITION BY HASH (a) PARTITIONS 3;
REPLACE INTO t1 PARTITION (p0) VALUES (3);
DROP TABLE t1;
############################################################################## ##############################################################################
SET GLOBAL tokudb_prelock_empty = @tokudb_prelock_empty_saved; SET GLOBAL tokudb_prelock_empty = @tokudb_prelock_empty_saved;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment