List:Internals« Previous MessageNext Message »
From:Marko Mäkelä Date:April 7 2005 11:16am
Subject:bk commit into 4.1 tree (marko:1.2170) BUG#5574
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of marko. When marko does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2170 05/04/07 12:16:41 marko@stripped +4 -0
  InnoDB: Prevent ALTER TABLE ... ENGINE=...
  if there are foreign key constraints on the table. (Bug #5574)

  sql/sql_table.cc
    1.277 05/04/07 12:16:34 marko@stripped +4 -0
    Check handler::can_switch_engines() before switching storage engines

  sql/handler.h
    1.136 05/04/07 12:16:34 marko@stripped +2 -0
    Add method can_switch_engines()

  sql/ha_innodb.h
    1.79 05/04/07 12:16:34 marko@stripped +1 -0
    Add method can_switch_engines()

  sql/ha_innodb.cc
    1.188 05/04/07 12:16:34 marko@stripped +26 -0
    Add method can_switch_engines()

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	marko
# Host:	hundin.mysql.fi
# Root:	/home/marko/mysql-4.1

--- 1.135/sql/handler.h	Fri Mar 25 22:36:02 2005
+++ 1.136/sql/handler.h	Thu Apr  7 12:16:34 2005
@@ -450,6 +450,8 @@
   virtual void append_create_info(String *packet) {}
   virtual char* get_foreign_key_create_info()
   { return(NULL);}  /* gets foreign key create string from InnoDB */
+  /* used in ALTER TABLE; 1 if changing storage engine is allowed */
+  virtual bool can_switch_engines() { return 1; }
   /* used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
   virtual uint referenced_by_foreign_key() { return 0;}
   virtual void init_table_handle_for_HANDLER()

--- 1.276/sql/sql_table.cc	Sat Apr  2 21:28:51 2005
+++ 1.277/sql/sql_table.cc	Thu Apr  7 12:16:34 2005
@@ -3109,6 +3109,10 @@
   /* Safety fix for innodb */
   if (lower_case_table_names)
     my_casedn_str(files_charset_info, tmp_name);
+  if (new_db_type != old_db_type && !table->file->can_switch_engines()) {
+    my_error(ER_ROW_IS_REFERENCED, MYF(0));
+    goto err;
+  }
   create_info->db_type=new_db_type;
   if (!create_info->comment)
     create_info->comment=table->comment;

--- 1.187/sql/ha_innodb.cc	Mon Apr  4 19:41:36 2005
+++ 1.188/sql/ha_innodb.cc	Thu Apr  7 12:16:34 2005
@@ -4789,6 +4789,32 @@
   	return(str);
 }
 
+/*********************************************************************
+Checks if ALTER TABLE may change the storage engine of the table.
+Changing storage engines is not allowed for tables for which there
+are foreign key constraints (parent or child tables). */
+
+bool
+ha_innobase::can_switch_engines(void)
+/*=================================*/
+{
+	row_prebuilt_t* prebuilt	= (row_prebuilt_t*) innobase_prebuilt;
+	bool	can_switch;
+
+ 	DBUG_ENTER("ha_innobase::can_switch_engines");
+	prebuilt->trx->op_info =
+			"determining if there are foreign key constraints";
+	row_mysql_lock_data_dictionary(prebuilt->trx);
+
+	can_switch = !UT_LIST_GET_FIRST(prebuilt->table->referenced_list)
+			&& !UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
+
+	row_mysql_unlock_data_dictionary(prebuilt->trx);
+	prebuilt->trx->op_info = "";
+
+	DBUG_RETURN(can_switch);
+}
+
 /***********************************************************************
 Checks if a table is referenced by a foreign key. The MySQL manual states that
 a REPLACE is either equivalent to an INSERT, or DELETE(s) + INSERT. Only a

--- 1.78/sql/ha_innodb.h	Tue Mar  1 16:08:27 2005
+++ 1.79/sql/ha_innodb.h	Thu Apr  7 12:16:34 2005
@@ -161,6 +161,7 @@
 	int check(THD* thd, HA_CHECK_OPT* check_opt);
         char* update_table_comment(const char* comment);
 	char* get_foreign_key_create_info();
+	bool can_switch_engines();
   	uint referenced_by_foreign_key();
 	void free_foreign_key_create_info(char* str);	
   	THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
Thread
bk commit into 4.1 tree (marko:1.2170) BUG#5574Marko Mäkelä7 Apr