Skip to content

Commit 908676d

Browse files
committed
MDEV-15308 Assertion `ha_alter_info->alter_info->drop_list.elements
Problem was that handle_if_exists_options() didn't correct alter_info->flags when things was removed from the list.
1 parent da71c1b commit 908676d

File tree

3 files changed

+118
-4
lines changed

3 files changed

+118
-4
lines changed

mysql-test/r/alter_table.result

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,3 +2164,64 @@ t1 CREATE TABLE `t1` (
21642164
`b` int(11) DEFAULT NULL
21652165
) ENGINE=InnoDB DEFAULT CHARSET=utf8
21662166
DROP TABLE t1;
2167+
#
2168+
#
2169+
# MDEV-15308
2170+
# Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed
2171+
# in ha_innodb::prepare_inplace_alter_table
2172+
#
2173+
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
2174+
ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN b;
2175+
Warnings:
2176+
Note 1091 Can't DROP 'fk'; check that column/key exists
2177+
SHOW CREATE TABLE t1;
2178+
Table Create Table
2179+
t1 CREATE TABLE `t1` (
2180+
`a` int(11) DEFAULT NULL
2181+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
2182+
DROP TABLE t1;
2183+
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
2184+
ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN b;
2185+
Warnings:
2186+
Note 1091 Can't DROP 'fk'; check that column/key exists
2187+
SHOW CREATE TABLE t1;
2188+
Table Create Table
2189+
t1 CREATE TABLE `t1` (
2190+
`a` int(11) DEFAULT NULL
2191+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
2192+
DROP TABLE t1;
2193+
CREATE TABLE t1 (a INT, b INT, c INT, KEY(c)) ENGINE=InnoDB;
2194+
ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN c;
2195+
Warnings:
2196+
Note 1091 Can't DROP 'fk'; check that column/key exists
2197+
SHOW CREATE TABLE t1;
2198+
Table Create Table
2199+
t1 CREATE TABLE `t1` (
2200+
`a` int(11) DEFAULT NULL,
2201+
`b` int(11) DEFAULT NULL
2202+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
2203+
DROP TABLE t1;
2204+
CREATE TABLE t1 (a INT, b INT, c INT, KEY c1(c)) ENGINE=InnoDB;
2205+
ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP INDEX c1;
2206+
Warnings:
2207+
Note 1091 Can't DROP 'fk'; check that column/key exists
2208+
SHOW CREATE TABLE t1;
2209+
Table Create Table
2210+
t1 CREATE TABLE `t1` (
2211+
`a` int(11) DEFAULT NULL,
2212+
`b` int(11) DEFAULT NULL,
2213+
`c` int(11) DEFAULT NULL
2214+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
2215+
DROP TABLE t1;
2216+
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
2217+
ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN IF EXISTS c;
2218+
Warnings:
2219+
Note 1091 Can't DROP 'fk'; check that column/key exists
2220+
Note 1091 Can't DROP 'c'; check that column/key exists
2221+
SHOW CREATE TABLE t1;
2222+
Table Create Table
2223+
t1 CREATE TABLE `t1` (
2224+
`a` int(11) DEFAULT NULL,
2225+
`b` int(11) DEFAULT NULL
2226+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
2227+
DROP TABLE t1;

mysql-test/t/alter_table.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,3 +1809,35 @@ SHOW CREATE TABLE t1;
18091809
ALTER TABLE t1 CONVERT TO CHARACTER SET utf8;
18101810
SHOW CREATE TABLE t1;
18111811
DROP TABLE t1;
1812+
1813+
--echo #
1814+
--echo #
1815+
--echo # MDEV-15308
1816+
--echo # Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed
1817+
--echo # in ha_innodb::prepare_inplace_alter_table
1818+
--echo #
1819+
1820+
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
1821+
ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN b;
1822+
SHOW CREATE TABLE t1;
1823+
DROP TABLE t1;
1824+
1825+
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
1826+
ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN b;
1827+
SHOW CREATE TABLE t1;
1828+
DROP TABLE t1;
1829+
1830+
CREATE TABLE t1 (a INT, b INT, c INT, KEY(c)) ENGINE=InnoDB;
1831+
ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN c;
1832+
SHOW CREATE TABLE t1;
1833+
DROP TABLE t1;
1834+
1835+
CREATE TABLE t1 (a INT, b INT, c INT, KEY c1(c)) ENGINE=InnoDB;
1836+
ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP INDEX c1;
1837+
SHOW CREATE TABLE t1;
1838+
DROP TABLE t1;
1839+
1840+
CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
1841+
ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN IF EXISTS c;
1842+
SHOW CREATE TABLE t1;
1843+
DROP TABLE t1;

sql/sql_table.cc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5808,10 +5808,28 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info)
58085808
List_iterator<Alter_drop> drop_it(alter_info->drop_list);
58095809
Alter_drop *drop;
58105810
bool remove_drop;
5811+
ulonglong left_flags= 0;
58115812
while ((drop= drop_it++))
58125813
{
5814+
ulonglong cur_flag= 0;
5815+
switch (drop->type) {
5816+
case Alter_drop::COLUMN:
5817+
cur_flag= Alter_info::ALTER_DROP_COLUMN;
5818+
break;
5819+
case Alter_drop::FOREIGN_KEY:
5820+
cur_flag= Alter_info::DROP_FOREIGN_KEY;
5821+
break;
5822+
case Alter_drop::KEY:
5823+
cur_flag= Alter_info::ALTER_DROP_INDEX;
5824+
break;
5825+
default:
5826+
break;
5827+
}
58135828
if (!drop->drop_if_exists)
5829+
{
5830+
left_flags|= cur_flag;
58145831
continue;
5832+
}
58155833
remove_drop= TRUE;
58165834
if (drop->type == Alter_drop::COLUMN)
58175835
{
@@ -5887,12 +5905,15 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info)
58875905
ER_CANT_DROP_FIELD_OR_KEY, ER(ER_CANT_DROP_FIELD_OR_KEY),
58885906
drop->name);
58895907
drop_it.remove();
5890-
if (alter_info->drop_list.is_empty())
5891-
alter_info->flags&= ~(Alter_info::ALTER_DROP_COLUMN |
5892-
Alter_info::ALTER_DROP_INDEX |
5893-
Alter_info::DROP_FOREIGN_KEY);
58945908
}
5909+
else
5910+
left_flags|= cur_flag;
58955911
}
5912+
/* Reset state to what's left in drop list */
5913+
alter_info->flags&= ~(Alter_info::ALTER_DROP_COLUMN |
5914+
Alter_info::ALTER_DROP_INDEX |
5915+
Alter_info::DROP_FOREIGN_KEY);
5916+
alter_info->flags|= left_flags;
58965917
}
58975918

58985919
/* ALTER TABLE ADD KEY IF NOT EXISTS */

0 commit comments

Comments
 (0)