[Commits] a0817923a14: MDEV-15308: Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed in ha_innodb::prepare_inplace_alter_table

jan jan.lindstrom at mariadb.com
Wed Apr 18 11:36:44 EEST 2018


revision-id: a0817923a141650ff37d9f8358bc938556981c69 (mariadb-10.0.34-34-ga0817923a14)
parent(s): 226ec99a3ed662bace80d70dd7fefd0db7b4af0a
author: Jan Lindström
committer: Jan Lindström
timestamp: 2018-04-18 11:35:31 +0300
message:

MDEV-15308: Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed in ha_innodb::prepare_inplace_alter_table

Problem was thet when items were removed from drop_list alter_info
flags were not adjusted accordingly in all cases.

---
 mysql-test/r/if_exists.result | 43 +++++++++++++++++++++++++++++++++++++++++++
 mysql-test/t/if_exists.test   | 33 +++++++++++++++++++++++++++++++++
 sql/sql_table.cc              |  8 +++++++-
 3 files changed, 83 insertions(+), 1 deletion(-)

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;
     }
 


More information about the commits mailing list