Skip to content

Commit 5375f0b

Browse files
MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table | Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
The bug is caused by a similar mechanism as MDEV-21027. The function, check_insert_or_replace_autoincrement, failed to open all the partitions on INSERT SELECT statements and it results in the assertion error.
1 parent f339ef3 commit 5375f0b

8 files changed

+89
-14
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,20 +860,22 @@ SELECT LAST_INSERT_ID();
860860
SELECT * FROM t1;
861861
DROP TABLE t1;
862862
}
863+
--echo ##############################################################################
864+
}
863865

864866
if (!$skip_update)
865867
{
866868
--echo #
867869
--echo # MDEV-19622 Assertion failures in
868870
--echo # ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
869871
--echo #
870-
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam PARTITION BY HASH(a);
872+
eval CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=$engine PARTITION BY HASH(a);
871873
INSERT INTO t1 VALUES (1,1),(2,2);
872874
UPDATE t1 SET pk = 0;
873875
DROP TABLE t1;
874876
}
875877

876-
if (!$skip_update)
878+
if (!$skip_delete)
877879
{
878880
--echo #
879881
--echo # MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
@@ -884,5 +886,14 @@ REPLACE INTO t1 PARTITION (p0) VALUES (3);
884886
DROP TABLE t1;
885887
}
886888

887-
--echo ##############################################################################
889+
if (!$skip_truncate)
890+
{
891+
--echo #
892+
--echo # MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
893+
--echo # Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
894+
--echo #
895+
eval CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE=$engine PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
896+
ALTER TABLE t1 TRUNCATE PARTITION p1;
897+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
898+
DROP TABLE t1;
888899
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,26 @@ PARTITIONS 2
695695
SELECT * FROM t1 ORDER BY c1;
696696
c1
697697
DROP TABLE t1;
698+
#
699+
# MDEV-19622 Assertion failures in
700+
# ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
701+
#
702+
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE='Blackhole' PARTITION BY HASH(a);
703+
INSERT INTO t1 VALUES (1,1),(2,2);
704+
UPDATE t1 SET pk = 0;
705+
DROP TABLE t1;
706+
#
707+
# MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()'
708+
# ha_partition::set_auto_increment_if_higher
709+
#
710+
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Blackhole' PARTITION BY HASH (a) PARTITIONS 3;
711+
REPLACE INTO t1 PARTITION (p0) VALUES (3);
712+
DROP TABLE t1;
713+
#
714+
# MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
715+
# Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
716+
#
717+
CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE='Blackhole' PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
718+
ALTER TABLE t1 TRUNCATE PARTITION p1;
719+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
720+
DROP TABLE t1;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,12 @@ SELECT * FROM t1;
11011101
a
11021102
0
11031103
DROP TABLE t1;
1104+
##############################################################################
11041105
#
11051106
# MDEV-19622 Assertion failures in
11061107
# ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
11071108
#
1108-
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam PARTITION BY HASH(a);
1109+
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE='InnoDB' PARTITION BY HASH(a);
11091110
INSERT INTO t1 VALUES (1,1),(2,2);
11101111
UPDATE t1 SET pk = 0;
11111112
DROP TABLE t1;
@@ -1116,4 +1117,11 @@ DROP TABLE t1;
11161117
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='InnoDB' PARTITION BY HASH (a) PARTITIONS 3;
11171118
REPLACE INTO t1 PARTITION (p0) VALUES (3);
11181119
DROP TABLE t1;
1119-
##############################################################################
1120+
#
1121+
# MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
1122+
# Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
1123+
#
1124+
CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE='InnoDB' PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
1125+
ALTER TABLE t1 TRUNCATE PARTITION p1;
1126+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
1127+
DROP TABLE t1;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,12 @@ SELECT * FROM t1;
11481148
a
11491149
0
11501150
DROP TABLE t1;
1151+
##############################################################################
11511152
#
11521153
# MDEV-19622 Assertion failures in
11531154
# ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
11541155
#
1155-
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam PARTITION BY HASH(a);
1156+
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE='Aria' PARTITION BY HASH(a);
11561157
INSERT INTO t1 VALUES (1,1),(2,2);
11571158
UPDATE t1 SET pk = 0;
11581159
DROP TABLE t1;
@@ -1163,4 +1164,11 @@ DROP TABLE t1;
11631164
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Aria' PARTITION BY HASH (a) PARTITIONS 3;
11641165
REPLACE INTO t1 PARTITION (p0) VALUES (3);
11651166
DROP TABLE t1;
1166-
##############################################################################
1167+
#
1168+
# MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
1169+
# Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
1170+
#
1171+
CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE='Aria' PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
1172+
ALTER TABLE t1 TRUNCATE PARTITION p1;
1173+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
1174+
DROP TABLE t1;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,12 @@ SELECT * FROM t1;
11291129
a
11301130
0
11311131
DROP TABLE t1;
1132+
##############################################################################
11321133
#
11331134
# MDEV-19622 Assertion failures in
11341135
# ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
11351136
#
1136-
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam PARTITION BY HASH(a);
1137+
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE='Memory' PARTITION BY HASH(a);
11371138
INSERT INTO t1 VALUES (1,1),(2,2);
11381139
UPDATE t1 SET pk = 0;
11391140
DROP TABLE t1;
@@ -1144,4 +1145,11 @@ DROP TABLE t1;
11441145
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='Memory' PARTITION BY HASH (a) PARTITIONS 3;
11451146
REPLACE INTO t1 PARTITION (p0) VALUES (3);
11461147
DROP TABLE t1;
1147-
##############################################################################
1148+
#
1149+
# MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
1150+
# Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
1151+
#
1152+
CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE='Memory' PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
1153+
ALTER TABLE t1 TRUNCATE PARTITION p1;
1154+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
1155+
DROP TABLE t1;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,12 @@ SELECT * FROM t1;
11481148
a
11491149
0
11501150
DROP TABLE t1;
1151+
##############################################################################
11511152
#
11521153
# MDEV-19622 Assertion failures in
11531154
# ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
11541155
#
1155-
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam PARTITION BY HASH(a);
1156+
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE='MyISAM' PARTITION BY HASH(a);
11561157
INSERT INTO t1 VALUES (1,1),(2,2);
11571158
UPDATE t1 SET pk = 0;
11581159
DROP TABLE t1;
@@ -1163,4 +1164,11 @@ DROP TABLE t1;
11631164
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='MyISAM' PARTITION BY HASH (a) PARTITIONS 3;
11641165
REPLACE INTO t1 PARTITION (p0) VALUES (3);
11651166
DROP TABLE t1;
1166-
##############################################################################
1167+
#
1168+
# MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
1169+
# Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
1170+
#
1171+
CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE='MyISAM' PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
1172+
ALTER TABLE t1 TRUNCATE PARTITION p1;
1173+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
1174+
DROP TABLE t1;

sql/ha_partition.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,8 @@ class ha_partition :public handler
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_INSERT_SELECT ||
14121413
ha_thd()->lex->sql_command == SQLCOM_REPLACE) &&
14131414
table->found_next_number_field)
14141415
bitmap_set_all(&m_part_info->read_partitions);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,11 +1115,12 @@ SELECT * FROM t1;
11151115
a
11161116
0
11171117
DROP TABLE t1;
1118+
##############################################################################
11181119
#
11191120
# MDEV-19622 Assertion failures in
11201121
# ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table
11211122
#
1122-
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=myisam PARTITION BY HASH(a);
1123+
CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE='TokuDB' PARTITION BY HASH(a);
11231124
INSERT INTO t1 VALUES (1,1),(2,2);
11241125
UPDATE t1 SET pk = 0;
11251126
DROP TABLE t1;
@@ -1130,5 +1131,12 @@ DROP TABLE t1;
11301131
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE='TokuDB' PARTITION BY HASH (a) PARTITIONS 3;
11311132
REPLACE INTO t1 PARTITION (p0) VALUES (3);
11321133
DROP TABLE t1;
1133-
##############################################################################
1134+
#
1135+
# MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table |
1136+
# Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed.
1137+
#
1138+
CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE='TokuDB' PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
1139+
ALTER TABLE t1 TRUNCATE PARTITION p1;
1140+
INSERT INTO t1 PARTITION (p1) (c) SELECT 1;
1141+
DROP TABLE t1;
11341142
SET GLOBAL tokudb_prelock_empty = @tokudb_prelock_empty_saved;

0 commit comments

Comments
 (0)