Skip to content

Commit e077ce2

Browse files
MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION
During rebuild of partition, the partitioning engine calls alter_close_table(), which does not unlock and close some table instances of the target table. Then, the engine fails to rename partitions because there are table instances that are still locked. Closing all the table instance of the target table fixes the bug.
1 parent b59bc62 commit e077ce2

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ if (`SELECT IF('$engine' != 'InnoDB', 1, 0)`)
7878

7979
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp/mdev_27065 *
8080
--rmdir $MYSQLTEST_VARDIR/tmp/mdev_27065
81+
82+
--echo #
83+
--echo # MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION
84+
--echo #
85+
--eval CREATE TABLE t1 (c INT) ENGINE=$engine PARTITION BY KEY(c) PARTITIONS 4;
86+
LOCK TABLES t1 WRITE, t1 AS a READ;
87+
ALTER TABLE t1 REBUILD PARTITION p0;
88+
DROP TABLE t1;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ PARTITION p1 VALUES LESS THAN MAXVALUE
6161
Warnings:
6262
Warning 1618 <DATA DIRECTORY> table option of old schema is ignored
6363
DROP TABLE t1;
64+
#
65+
# MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION
66+
#
67+
CREATE TABLE t1 (c INT) ENGINE=InnoDB PARTITION BY KEY(c) PARTITIONS 4;;
68+
LOCK TABLES t1 WRITE, t1 AS a READ;
69+
ALTER TABLE t1 REBUILD PARTITION p0;
70+
DROP TABLE t1;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,10 @@ PARTITION p1 VALUES LESS THAN MAXVALUE
9595
Warnings:
9696
Warning 1618 <INDEX DIRECTORY> table option of old schema is ignored
9797
DROP TABLE t2;
98+
#
99+
# MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION
100+
#
101+
CREATE TABLE t1 (c INT) ENGINE=Aria PARTITION BY KEY(c) PARTITIONS 4;;
102+
LOCK TABLES t1 WRITE, t1 AS a READ;
103+
ALTER TABLE t1 REBUILD PARTITION p0;
104+
DROP TABLE t1;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ PARTITION p1 VALUES LESS THAN MAXVALUE
6868
Warnings:
6969
Warning 1618 <INDEX DIRECTORY> table option of old schema is ignored
7070
DROP TABLE t2;
71+
#
72+
# MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION
73+
#
74+
CREATE TABLE t1 (c INT) ENGINE=MyISAM PARTITION BY KEY(c) PARTITIONS 4;;
75+
LOCK TABLES t1 WRITE, t1 AS a READ;
76+
ALTER TABLE t1 REBUILD PARTITION p0;
77+
DROP TABLE t1;
7178
create table t1 ( c1 int, c2 int, c3 varchar(100)) delay_key_write=1
7279
partition by key(c1) (
7380
partition p01 data directory = 'MYSQL_TMP_DIR'

sql/sql_partition.cc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2005, 2017, Oracle and/or its affiliates.
2-
Copyright (c) 2009, 2018, MariaDB
2+
Copyright (c) 2009, 2022, MariaDB
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -6929,14 +6929,29 @@ static void alter_partition_lock_handling(ALTER_PARTITION_PARAM_TYPE *lpt)
69296929

69306930
static int alter_close_table(ALTER_PARTITION_PARAM_TYPE *lpt)
69316931
{
6932+
THD *thd= lpt->thd;
6933+
TABLE_SHARE *share= lpt->table->s;
69326934
DBUG_ENTER("alter_close_table");
69336935

6934-
if (lpt->table->db_stat)
6935-
{
6936-
mysql_lock_remove(lpt->thd, lpt->thd->lock, lpt->table);
6937-
lpt->table->file->ha_close();
6938-
lpt->table->db_stat= 0; // Mark file closed
6939-
}
6936+
TABLE *table= thd->open_tables;
6937+
do {
6938+
table= find_locked_table(table, share->db.str, share->table_name.str);
6939+
if (!table)
6940+
{
6941+
DBUG_RETURN(0);
6942+
}
6943+
6944+
if (table->db_stat)
6945+
{
6946+
mysql_lock_remove(thd, thd->lock, table);
6947+
if (int error= table->file->ha_close())
6948+
{
6949+
DBUG_RETURN(error);
6950+
}
6951+
table->db_stat= 0; // Mark file closed
6952+
}
6953+
} while ((table= table->next));
6954+
69406955
DBUG_RETURN(0);
69416956
}
69426957

0 commit comments

Comments
 (0)