summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lindström <jan.lindstrom@mariadb.com>2018-04-18 11:35:31 +0300
committerJan Lindström <jan.lindstrom@mariadb.com>2018-04-18 11:35:31 +0300
commita0817923a141650ff37d9f8358bc938556981c69 (patch)
treee5293ce937c65e5bec2843b5980ffbae9d827517
parent226ec99a3ed662bace80d70dd7fefd0db7b4af0a (diff)
downloadmariadb-git-a0817923a141650ff37d9f8358bc938556981c69.tar.gz
MDEV-15308: Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed in ha_innodb::prepare_inplace_alter_tablebb-10.0-MDEV-15308
Problem was thet when items were removed from drop_list alter_info flags were not adjusted accordingly in all cases.
-rw-r--r--mysql-test/r/if_exists.result43
-rw-r--r--mysql-test/t/if_exists.test33
-rw-r--r--sql/sql_table.cc8
3 files changed, 83 insertions, 1 deletions
diff --git a/mysql-test/r/if_exists.result b/mysql-test/r/if_exists.result
new file mode 100644
index 00000000000..4cb718b9cfc
--- /dev/null
+++ b/mysql-test/r/if_exists.result
@@ -0,0 +1,43 @@
+CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
+ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN b;
+Warnings:
+Note 1091 Can't DROP 'fk'; check that column/key exists
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
+ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN b;
+Warnings:
+Note 1091 Can't DROP 'fk'; check that column/key exists
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT, c INT, KEY(c)) ENGINE=InnoDB;
+ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN c;
+Warnings:
+Note 1091 Can't DROP 'fk'; check that column/key exists
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT, c INT, KEY c1(c)) ENGINE=InnoDB;
+ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP INDEX c1;
+Warnings:
+Note 1091 Can't DROP 'fk'; check that column/key exists
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
diff --git a/mysql-test/t/if_exists.test b/mysql-test/t/if_exists.test
new file mode 100644
index 00000000000..420efaba150
--- /dev/null
+++ b/mysql-test/t/if_exists.test
@@ -0,0 +1,33 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-15308: Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed in ha_innodb::prepare_inplace_alter_table
+#
+
+CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
+ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN b;
+SHOW CREATE TABLE t1;
+
+# Cleanup
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
+ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN b;
+SHOW CREATE TABLE t1;
+
+# Cleanup
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT, b INT, c INT, KEY(c)) ENGINE=InnoDB;
+ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN c;
+SHOW CREATE TABLE t1;
+
+# Cleanup
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT, b INT, c INT, KEY c1(c)) ENGINE=InnoDB;
+ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP INDEX c1;
+SHOW CREATE TABLE t1;
+
+# Cleanup
+DROP TABLE t1;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 607f20d2396..c33ac784d91 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -7430,6 +7430,9 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
if (table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_column(thd, table, field);
drop_it.remove();
+ if (alter_info->drop_list.is_empty())
+ alter_info->flags&= ~(Alter_info::ALTER_DROP_INDEX |
+ Alter_info::DROP_FOREIGN_KEY);
continue;
}
/* Check if field is changed */
@@ -7654,8 +7657,11 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
TRUE);
}
}
- }
+ }
drop_it.remove();
+ if (alter_info->drop_list.is_empty())
+ alter_info->flags&= ~(Alter_info::ALTER_DROP_INDEX |
+ Alter_info::DROP_FOREIGN_KEY);
continue;
}