From 908676dfd9d981fd0f37a7cf9332abac522f1936 Mon Sep 17 00:00:00 2001
From: Monty <monty@mariadb.org>
Date: Tue, 22 May 2018 23:05:01 +0300
Subject: 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.
---
 sql/sql_table.cc | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

(limited to 'sql/sql_table.cc')

diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 27d579a6b19..376c1362cc7 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -5808,10 +5808,28 @@ drop_create_field:
     List_iterator<Alter_drop> drop_it(alter_info->drop_list);
     Alter_drop *drop;
     bool remove_drop;
+    ulonglong left_flags= 0;
     while ((drop= drop_it++))
     {
+      ulonglong cur_flag= 0;
+      switch (drop->type) {
+      case Alter_drop::COLUMN:
+        cur_flag= Alter_info::ALTER_DROP_COLUMN;
+        break;
+      case Alter_drop::FOREIGN_KEY:
+        cur_flag= Alter_info::DROP_FOREIGN_KEY;
+        break;
+      case Alter_drop::KEY:
+        cur_flag= Alter_info::ALTER_DROP_INDEX;
+        break;
+      default:
+        break;
+      }
       if (!drop->drop_if_exists)
+      {
+        left_flags|= cur_flag;
         continue;
+      }
       remove_drop= TRUE;
       if (drop->type == Alter_drop::COLUMN)
       {
@@ -5887,12 +5905,15 @@ drop_create_field:
             ER_CANT_DROP_FIELD_OR_KEY, ER(ER_CANT_DROP_FIELD_OR_KEY),
             drop->name);
         drop_it.remove();
-        if (alter_info->drop_list.is_empty())
-          alter_info->flags&= ~(Alter_info::ALTER_DROP_COLUMN |
-                                Alter_info::ALTER_DROP_INDEX  |
-                                Alter_info::DROP_FOREIGN_KEY);
       }
+      else
+        left_flags|= cur_flag;
     }
+    /* Reset state to what's left in drop list */
+    alter_info->flags&= ~(Alter_info::ALTER_DROP_COLUMN |
+                          Alter_info::ALTER_DROP_INDEX  |
+                          Alter_info::DROP_FOREIGN_KEY);
+    alter_info->flags|= left_flags;
   }
 
   /* ALTER TABLE ADD KEY IF NOT EXISTS */
-- 
cgit v1.2.1


From d8da920264a0321e6d03b3cbe3c3b414f622aefa Mon Sep 17 00:00:00 2001
From: Monty <monty@mariadb.org>
Date: Fri, 25 May 2018 11:51:43 +0300
Subject: MDEV-10679 Crash in performance schema and partitioning with
 discovery

Crash happened because in discover, table->work_part_info was not properly
reset before execution.
Fixed by resetting before calling execute alter table, create table or
mysql_create_frm_image.
---
 sql/sql_table.cc | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'sql/sql_table.cc')

diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 31da585443a..a68f9e626e0 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -6057,6 +6057,7 @@ remove_key:
     }
   }
   
+  DBUG_ASSERT(thd->work_part_info == 0);
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   partition_info *tab_part_info= table->part_info;
   thd->work_part_info= thd->lex->part_info;
@@ -8411,6 +8412,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
 {
   DBUG_ENTER("mysql_alter_table");
 
+  thd->work_part_info= 0;                       // Used by partitioning
+
   /*
     Check if we attempt to alter mysql.slow_log or
     mysql.general_log table and return an error if
-- 
cgit v1.2.1