From 0c39357235d1f01abfc3d578540ef7d700abdd09 Mon Sep 17 00:00:00 2001
From: Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com>
Date: Mon, 6 May 2013 15:19:37 +0200
Subject: [PATCH 01/11] Updated spec file for Bug16488773

---
 support-files/mysql.spec.sh | 30 ------------------------------
 1 file changed, 30 deletions(-)

diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh
index b439d2c1956..c153b22b7c5 100644
--- a/support-files/mysql.spec.sh
+++ b/support-files/mysql.spec.sh
@@ -300,7 +300,6 @@ Obsoletes:      mysql mysql-server mysql-advanced mysql-server-advanced
 Obsoletes:      MySQL-server-classic MySQL-server-community MySQL-server-enterprise
 Obsoletes:      MySQL-server-advanced-gpl MySQL-server-enterprise-gpl
 Provides:       msqlormysql MySQL MySQL-server MySQL-server-advanced
-Provides:       mysql
 %endif
 
 %description -n MySQL-server%{product_suffix}
@@ -975,35 +974,6 @@ mv -f  $STATUS_FILE ${STATUS_FILE}-LAST  # for "triggerpostun"
 #scheduled service packs and more.  Visit www.mysql.com/enterprise for more
 #information."
 
-%preun -n MySQL-server%{product_suffix}
-
-# Which '$1' does this refer to?  Fedora docs have info:
-# " ... a count of the number of versions of the package that are installed.
-#   Action                           Count
-#   Install the first time           1
-#   Upgrade                          2 or higher (depending on the number of versions installed)
-#   Remove last version of package   0 "
-#
-#  http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html
- 
-if [ $1 = 0 ] ; then
-        # Stop MySQL before uninstalling it
-        if [ -x %{_sysconfdir}/init.d/mysql ] ; then
-                %{_sysconfdir}/init.d/mysql stop > /dev/null
-                # Remove autostart of MySQL
-                # use chkconfig on Enterprise Linux and newer SuSE releases
-                if [ -x /sbin/chkconfig ] ; then
-                        /sbin/chkconfig --del mysql
-                # For older SuSE Linux versions
-                elif [ -x /sbin/insserv ] ; then
-                        /sbin/insserv -r %{_sysconfdir}/init.d/mysql
-                fi
-        fi
-fi
-
-# We do not remove the mysql user since it may still own a lot of
-# database files.
-
 %triggerpostun -n MySQL-server%{product_suffix} --MySQL-server-community
 
 # Setup: We renamed this package, so any existing "server-community"

From cee2dfa3aaf03de1033299593ae269d598cc992c Mon Sep 17 00:00:00 2001
From: Jon Olav Hauglid <jon.hauglid@oracle.com>
Date: Mon, 6 May 2013 16:06:32 +0200
Subject: [PATCH 02/11] Bug#16757869: INNODB: POSSIBLE REGRESSION IN 5.5.31,
 BUG#16004999

The problem was that if UPDATE with subselect caused a
deadlock inside InnoDB, this deadlock was not properly
handled by the SQL layer. This meant that the SQL layer
would try to unlock the row after InnoDB had rolled
back the transaction. This caused an assertion inside
InnoDB.

This patch fixes the problem by checking for errors
reported by SQL_SELECT::skip_record() and not calling
unlock_row() if any errors have been reported.

This bug is similar to Bug#13586591, but for UPDATE
rather than DELETE. Similar issues in filesort/opt_range/
sql_select will be investigated and handled in the scope
of Bug#16767929
---
 sql/sql_update.cc | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 5bc11e942f6..a29d474fbfc 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -555,7 +555,10 @@ int mysql_update(THD *thd,
         if (select && select->skip_record(thd, &skip_record))
         {
           error= 1;
-          table->file->unlock_row();
+          /*
+            Don't try unlocking the row if skip_record reported an error since
+            in this case the transaction might have been rolled back already.
+          */
           break;
         }
         if (!skip_record)
@@ -801,8 +804,17 @@ int mysql_update(THD *thd,
         }
       }
     }
-    else
+    /*
+      Don't try unlocking the row if skip_record reported an error since in
+      this case the transaction might have been rolled back already.
+    */
+    else if (!thd->is_error())
       table->file->unlock_row();
+    else
+    {
+      error= 1;
+      break;
+    }
     thd->warning_info->inc_current_row_for_warning();
     if (thd->is_error())
     {

From f8c904090a2cc4f571d98cfff554ffb0ff5684f0 Mon Sep 17 00:00:00 2001
From: Annamalai Gurusami <annamalai.gurusami@oracle.com>
Date: Mon, 6 May 2013 20:31:26 +0530
Subject: [PATCH 03/11] Bug #16722314 FOREIGN KEY ID MODIFIED DURING EXPORT Bug
 #16754901 PARS_INFO_FREE NOT CALLED IN DICT_CREATE_ADD_FOREIGN_TO_DICTIONARY

Merging the fix from mysql-5.5 to mysql-5.5.32-release.
---
 storage/innobase/dict/dict0crea.c        |  59 ++++++++++---
 storage/innobase/dict/dict0dict.c        | 102 ++++++++++++++++++++---
 storage/innobase/handler/ha_innodb.cc    |  82 ++++++++++++++----
 storage/innobase/include/dict0types.h    |   5 +-
 storage/innobase/include/ha_prototypes.h |  22 ++++-
 storage/innobase/row/row0mysql.c         |  31 +++++--
 6 files changed, 250 insertions(+), 51 deletions(-)

diff --git a/storage/innobase/dict/dict0crea.c b/storage/innobase/dict/dict0crea.c
index cb3dbcbe4ac..bd4e449d11b 100644
--- a/storage/innobase/dict/dict0crea.c
+++ b/storage/innobase/dict/dict0crea.c
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -44,6 +44,21 @@ Created 1/8/1996 Heikki Tuuri
 #include "ut0vec.h"
 #include "ha_prototypes.h"
 
+/*************************************************************************
+Checks if a table name contains the string TEMP_TABLE_PATH_PREFIX which
+denotes temporary tables in MySQL. */
+static
+ibool
+row_is_mysql_tmp_table_name(
+/*========================*/
+				/* out: TRUE if temporary table */
+	const char*     name)   /* in: table name in the form
+				'database/tablename' */
+{
+	return(strstr(name, TEMP_TABLE_PATH_PREFIX) != NULL);
+}
+
+
 /*****************************************************************//**
 Based on a table object, this function builds the entry to be inserted
 in the SYS_TABLES system table.
@@ -1424,26 +1439,46 @@ dict_create_add_foreign_to_dictionary(
 {
 	ulint		error;
 	ulint		i;
-
-	pars_info_t*	info = pars_info_create();
+	pars_info_t*	info;
 
 	if (foreign->id == NULL) {
-		char*	stripped_name;
 		/* Generate a new constraint id */
 		ulint	namelen	= strlen(table->name);
 		char*	id	= mem_heap_alloc(foreign->heap, namelen + 20);
-		/* no overflow if number < 1e13 */
-		sprintf(id, "%s_ibfk_%lu", table->name, (ulong) (*id_nr)++);
-		foreign->id = id;
 
-		stripped_name = strchr(foreign->id, '/') + 1;
-		if (innobase_check_identifier_length(stripped_name)) {
-			fprintf(stderr, "InnoDB: Generated foreign key "
-				"name (%s) is too long\n", foreign->id);
-			return(DB_IDENTIFIER_TOO_LONG);
+		if (row_is_mysql_tmp_table_name(table->name)) {
+			sprintf(id, "%s_ibfk_%lu", table->name,
+				(ulong) (*id_nr)++);
+		} else {
+			char	table_name[MAX_TABLE_NAME_LEN + 20] = "";
+			uint	errors = 0;
+
+			strncpy(table_name, table->name,
+				MAX_TABLE_NAME_LEN + 20);
+
+			innobase_convert_to_system_charset(
+				strchr(table_name, '/') + 1,
+				strchr(table->name, '/') + 1,
+				MAX_TABLE_NAME_LEN, &errors);
+
+			if (errors) {
+				strncpy(table_name, table->name,
+					MAX_TABLE_NAME_LEN + 20);
+			}
+
+			sprintf(id, "%s_ibfk_%lu", table_name,
+				(ulong) (*id_nr)++);
+
+			if (innobase_check_identifier_length(
+				strchr(id,'/') + 1)) {
+				return(DB_IDENTIFIER_TOO_LONG);
+			}
 		}
+		foreign->id = id;
 	}
 
+	info = pars_info_create();
+
 	pars_info_add_str_literal(info, "id", foreign->id);
 
 	pars_info_add_str_literal(info, "for_name", table->name);
diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c
index 215ac35ae5b..aec2264ad1c 100644
--- a/storage/innobase/dict/dict0dict.c
+++ b/storage/innobase/dict/dict0dict.c
@@ -1116,22 +1116,78 @@ dict_table_rename_in_cache(
 			dict_mem_foreign_table_name_lookup_set(foreign, FALSE);
 		}
 		if (strchr(foreign->id, '/')) {
+			/* This is a >= 4.0.18 format id */
+
 			ulint	db_len;
 			char*	old_id;
+			char    old_name_cs_filename[MAX_TABLE_NAME_LEN+20];
+			uint    errors = 0;
 
-			/* This is a >= 4.0.18 format id */
+			/* All table names are internally stored in charset
+			my_charset_filename (except the temp tables and the
+			partition identifier suffix in partition tables). The
+			foreign key constraint names are internally stored
+			in UTF-8 charset.  The variable fkid here is used
+			to store foreign key constraint name in charset
+			my_charset_filename for comparison further below. */
+			char    fkid[MAX_TABLE_NAME_LEN+20];
+			ibool	on_tmp = FALSE;
+
+			/* The old table name in my_charset_filename is stored
+			in old_name_cs_filename */
+
+			strncpy(old_name_cs_filename, old_name,
+				MAX_TABLE_NAME_LEN);
+			if (strstr(old_name, TEMP_TABLE_PATH_PREFIX) == NULL) {
+
+				innobase_convert_to_system_charset(
+					strchr(old_name_cs_filename, '/') + 1,
+					strchr(old_name, '/') + 1,
+					MAX_TABLE_NAME_LEN, &errors);
+
+				if (errors) {
+					/* There has been an error to convert
+					old table into UTF-8.  This probably
+					means that the old table name is
+					actually in UTF-8. */
+					innobase_convert_to_filename_charset(
+						strchr(old_name_cs_filename,
+						       '/') + 1,
+						strchr(old_name, '/') + 1,
+						MAX_TABLE_NAME_LEN);
+				} else {
+					/* Old name already in
+					my_charset_filename */
+					strncpy(old_name_cs_filename, old_name,
+						MAX_TABLE_NAME_LEN);
+				}
+			}
+
+			strncpy(fkid, foreign->id, MAX_TABLE_NAME_LEN);
+
+			if (strstr(fkid, TEMP_TABLE_PATH_PREFIX) == NULL) {
+				innobase_convert_to_filename_charset(
+					strchr(fkid, '/') + 1,
+					strchr(foreign->id, '/') + 1,
+					MAX_TABLE_NAME_LEN+20);
+			} else {
+				on_tmp = TRUE;
+			}
 
 			old_id = mem_strdup(foreign->id);
 
-			if (ut_strlen(foreign->id) > ut_strlen(old_name)
+			if (ut_strlen(fkid) > ut_strlen(old_name_cs_filename)
 			    + ((sizeof dict_ibfk) - 1)
-			    && !memcmp(foreign->id, old_name,
-				       ut_strlen(old_name))
-			    && !memcmp(foreign->id + ut_strlen(old_name),
+			    && !memcmp(fkid, old_name_cs_filename,
+				       ut_strlen(old_name_cs_filename))
+			    && !memcmp(fkid + ut_strlen(old_name_cs_filename),
 				       dict_ibfk, (sizeof dict_ibfk) - 1)) {
 
 				/* This is a generated >= 4.0.18 format id */
 
+				char	table_name[MAX_TABLE_NAME_LEN] = "";
+				uint	errors = 0;
+
 				if (strlen(table->name) > strlen(old_name)) {
 					foreign->id = mem_heap_alloc(
 						foreign->heap,
@@ -1139,11 +1195,36 @@ dict_table_rename_in_cache(
 						+ strlen(old_id) + 1);
 				}
 
+				/* Convert the table name to UTF-8 */
+				strncpy(table_name, table->name,
+					MAX_TABLE_NAME_LEN);
+				innobase_convert_to_system_charset(
+					strchr(table_name, '/') + 1,
+					strchr(table->name, '/') + 1,
+					MAX_TABLE_NAME_LEN, &errors);
+
+				if (errors) {
+					/* Table name could not be converted
+					from charset my_charset_filename to
+					UTF-8. This means that the table name
+					is already in UTF-8 (#mysql#50). */
+					strncpy(table_name, table->name,
+						MAX_TABLE_NAME_LEN);
+				}
+
 				/* Replace the prefix 'databasename/tablename'
 				with the new names */
-				strcpy(foreign->id, table->name);
-				strcat(foreign->id,
-				       old_id + ut_strlen(old_name));
+				strcpy(foreign->id, table_name);
+				if (on_tmp) {
+					strcat(foreign->id,
+					       old_id + ut_strlen(old_name));
+				} else {
+					sprintf(strchr(foreign->id, '/') + 1,
+						"%s%s",
+						strchr(table_name, '/') +1,
+						strstr(old_id, "_ibfk_") );
+				}
+
 			} else {
 				/* This is a >= 4.0.18 format id where the user
 				gave the id name */
@@ -4691,7 +4772,6 @@ dict_print_info_on_foreign_key_in_create_format(
 	dict_foreign_t*	foreign,	/*!< in: foreign key constraint */
 	ibool		add_newline)	/*!< in: whether to add a newline */
 {
-	char		constraint_name[MAX_TABLE_NAME_LEN];
 	const char*	stripped_id;
 	ulint	i;
 
@@ -4713,9 +4793,7 @@ dict_print_info_on_foreign_key_in_create_format(
 	}
 
 	fputs(" CONSTRAINT ", file);
-	innobase_convert_from_id(&my_charset_filename, constraint_name,
-				 stripped_id, MAX_TABLE_NAME_LEN);
-	ut_print_name(file, trx, FALSE, constraint_name);
+	ut_print_name(file, trx, FALSE, stripped_id);
 	fputs(" FOREIGN KEY (", file);
 
 	for (i = 0;;) {
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index fea4ae05ae3..5df84d7cd04 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -1159,33 +1159,27 @@ innobase_convert_from_table_id(
 
 /**********************************************************************
 Check if the length of the identifier exceeds the maximum allowed.
-The input to this function is an identifier in charset my_charset_filename.
 return true when length of identifier is too long. */
-extern "C" UNIV_INTERN
+extern "C"
 my_bool
 innobase_check_identifier_length(
 /*=============================*/
-	const char*	id)	/* in: identifier to check.  it must belong
-				to charset my_charset_filename */
+	const char*	id)	/* in: FK identifier to check excluding the
+				database portion. */
 {
-	char		tmp[MAX_TABLE_NAME_LEN + 10];
-	uint		errors;
-	uint		len;
 	int		well_formed_error = 0;
-	CHARSET_INFO*	cs1 = &my_charset_filename;
-	CHARSET_INFO*	cs2 = thd_charset(current_thd);
+	CHARSET_INFO	*cs = system_charset_info;
+	DBUG_ENTER("innobase_check_identifier_length");
 
-	len = strconvert(cs1, id, cs2, tmp, MAX_TABLE_NAME_LEN + 10, &errors);
+	uint res = cs->cset->well_formed_len(cs, id, id + strlen(id),
+					     NAME_CHAR_LEN,
+					     &well_formed_error);
 
-	uint res = cs2->cset->well_formed_len(cs2, tmp, tmp + len,
-					      NAME_CHAR_LEN,
-					      &well_formed_error);
-
-	if (well_formed_error || res != len) {
-		my_error(ER_TOO_LONG_IDENT, MYF(0), tmp);
-		return(true);
+	if (well_formed_error || res == NAME_CHAR_LEN) {
+		my_error(ER_TOO_LONG_IDENT, MYF(0), id);
+		DBUG_RETURN(true);
 	}
-	return(false);
+	DBUG_RETURN(false);
 }
 
 /******************************************************************//**
@@ -11966,3 +11960,55 @@ test_innobase_convert_name()
 }
 
 #endif /* UNIV_COMPILE_TEST_FUNCS */
+
+/**********************************************************************
+Converts an identifier from my_charset_filename to UTF-8 charset. */
+extern "C"
+uint
+innobase_convert_to_filename_charset(
+/*=================================*/
+	char*		to,	/* out: converted identifier */
+	const char*	from,	/* in: identifier to convert */
+	ulint		len)	/* in: length of 'to', in bytes */
+{
+	uint		errors;
+	uint		rlen;
+	CHARSET_INFO*	cs_to = &my_charset_filename;
+	CHARSET_INFO*	cs_from = system_charset_info;
+
+	rlen = strconvert(cs_from, from, cs_to, to, len, &errors);
+
+	if (errors) {
+		fprintf(stderr, "InnoDB: There was a problem in converting"
+			"'%s' in charset %s to charset %s", from, cs_from->name,
+			cs_to->name);
+	}
+
+	return(rlen);
+}
+
+/**********************************************************************
+Converts an identifier from my_charset_filename to UTF-8 charset. */
+extern "C"
+uint
+innobase_convert_to_system_charset(
+/*===============================*/
+	char*		to,	/* out: converted identifier */
+	const char*	from,	/* in: identifier to convert */
+	ulint		len,	/* in: length of 'to', in bytes */
+	uint*		errors)	/* out: error return */
+{
+	uint		rlen;
+	CHARSET_INFO*	cs1 = &my_charset_filename;
+	CHARSET_INFO*	cs2 = system_charset_info;
+
+	rlen = strconvert(cs1, from, cs2, to, len, errors);
+
+	if (*errors) {
+		fprintf(stderr, "InnoDB: There was a problem in converting"
+			"'%s' in charset %s to charset %s", from, cs1->name,
+			cs2->name);
+	}
+
+	return(rlen);
+}
diff --git a/storage/innobase/include/dict0types.h b/storage/innobase/include/dict0types.h
index f0a05a38070..8e3a04f7956 100644
--- a/storage/innobase/include/dict0types.h
+++ b/storage/innobase/include/dict0types.h
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
+Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -58,4 +58,7 @@ enum dict_err_ignore {
 
 typedef enum dict_err_ignore		dict_err_ignore_t;
 
+#define TEMP_TABLE_PREFIX                "#sql"
+#define TEMP_TABLE_PATH_PREFIX           "/" TEMP_TABLE_PREFIX
+
 #endif
diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h
index ae0188fdaa1..dc730f9b6b3 100644
--- a/storage/innobase/include/ha_prototypes.h
+++ b/storage/innobase/include/ha_prototypes.h
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 2006, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 2000, 2013, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -307,4 +307,24 @@ innobase_check_identifier_length(
 	const char*	id);	/* in: identifier to check.  it must belong
 				to charset my_charset_filename */
 
+/**********************************************************************
+Converts an identifier from my_charset_filename to UTF-8 charset. */
+uint
+innobase_convert_to_system_charset(
+/*===============================*/
+	char*           to,		/* out: converted identifier */
+	const char*     from,		/* in: identifier to convert */
+	ulint           len,		/* in: length of 'to', in bytes */
+	uint*		errors);	/* out: error return */
+
+/**********************************************************************
+Converts an identifier from my_charset_filename to UTF-8 charset. */
+uint
+innobase_convert_to_filename_charset(
+/*=================================*/
+	char*           to,     /* out: converted identifier */
+	const char*     from,   /* in: identifier to convert */
+	ulint           len);   /* in: length of 'to', in bytes */
+
+
 #endif
diff --git a/storage/innobase/row/row0mysql.c b/storage/innobase/row/row0mysql.c
index d97476dcdb1..ff8f79f4f3f 100644
--- a/storage/innobase/row/row0mysql.c
+++ b/storage/innobase/row/row0mysql.c
@@ -53,7 +53,7 @@ Created 9/17/2000 Heikki Tuuri
 #include "ibuf0ibuf.h"
 #include "m_string.h"
 #include "my_sys.h"
-
+#include "ha_prototypes.h"
 
 /** Provide optional 4.x backwards compatibility for 5.0 and above */
 UNIV_INTERN ibool	row_rollback_on_timeout	= FALSE;
@@ -3956,12 +3956,29 @@ row_rename_table_for_mysql(
 		goto end;
 	} else if (!new_is_tmp) {
 		/* Rename all constraints. */
+		char	new_table_name[MAX_TABLE_NAME_LEN] = "";
+		uint	errors = 0;
 
 		info = pars_info_create();
 
 		pars_info_add_str_literal(info, "new_table_name", new_name);
 		pars_info_add_str_literal(info, "old_table_name", old_name);
 
+		strncpy(new_table_name, new_name, MAX_TABLE_NAME_LEN);
+		innobase_convert_to_system_charset(
+			strchr(new_table_name, '/') + 1,
+			strchr(new_name, '/') +1,
+			MAX_TABLE_NAME_LEN, &errors);
+
+		if (errors) {
+			/* Table name could not be converted from charset
+			my_charset_filename to UTF-8. This means that the
+			table name is already in UTF-8 (#mysql#50). */
+			strncpy(new_table_name, new_name, MAX_TABLE_NAME_LEN);
+		}
+
+		pars_info_add_str_literal(info, "new_table_utf8", new_table_name);
+
 		err = que_eval_sql(
 			info,
 			"PROCEDURE RENAME_CONSTRAINT_IDS () IS\n"
@@ -3973,6 +3990,7 @@ row_rename_table_for_mysql(
 			"old_t_name_len INT;\n"
 			"new_db_name_len INT;\n"
 			"id_len INT;\n"
+			"offset INT;\n"
 			"found INT;\n"
 			"BEGIN\n"
 			"found := 1;\n"
@@ -3981,8 +3999,6 @@ row_rename_table_for_mysql(
 			"new_db_name := SUBSTR(:new_table_name, 0,\n"
 			"                      new_db_name_len);\n"
 			"old_t_name_len := LENGTH(:old_table_name);\n"
-			"gen_constr_prefix := CONCAT(:old_table_name,\n"
-			"                            '_ibfk_');\n"
 			"WHILE found = 1 LOOP\n"
 			"       SELECT ID INTO foreign_id\n"
 			"        FROM SYS_FOREIGN\n"
@@ -3999,12 +4015,13 @@ row_rename_table_for_mysql(
 			"        id_len := LENGTH(foreign_id);\n"
 			"        IF (INSTR(foreign_id, '/') > 0) THEN\n"
 			"               IF (INSTR(foreign_id,\n"
-			"                         gen_constr_prefix) > 0)\n"
+			"                         '_ibfk_') > 0)\n"
 			"               THEN\n"
+                        "                offset := INSTR(foreign_id, '_ibfk_') - 1;\n"
 			"                new_foreign_id :=\n"
-			"                CONCAT(:new_table_name,\n"
-			"                SUBSTR(foreign_id, old_t_name_len,\n"
-			"                       id_len - old_t_name_len));\n"
+			"                CONCAT(:new_table_utf8,\n"
+			"                SUBSTR(foreign_id, offset,\n"
+			"                       id_len - offset));\n"
 			"               ELSE\n"
 			"                new_foreign_id :=\n"
 			"                CONCAT(new_db_name,\n"

From 648d2b08cfaf334d0ac530ebaf4d182338483915 Mon Sep 17 00:00:00 2001
From: Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com>
Date: Tue, 7 May 2013 14:36:46 +0200
Subject: [PATCH 04/11] ULN-RPMs bug fix for BR16298542

---
 packaging/rpm-uln/mysql.spec.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/packaging/rpm-uln/mysql.spec.sh b/packaging/rpm-uln/mysql.spec.sh
index ec195bc9e16..233e4bae194 100644
--- a/packaging/rpm-uln/mysql.spec.sh
+++ b/packaging/rpm-uln/mysql.spec.sh
@@ -662,6 +662,7 @@ rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/postinstall
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-*.spec
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-log-rotate
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/ChangeLog
+rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/solaris/postinstall-solaris
 rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/mysql-stress-test.pl.1*
 rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/mysql-test-run.pl.1*
 

From 35654a6a0ed44bcb53f294e80aecb0adb68b0546 Mon Sep 17 00:00:00 2001
From: Jon Olav Hauglid <jon.hauglid@oracle.com>
Date: Wed, 8 May 2013 12:08:20 +0200
Subject: [PATCH 05/11] Bug#16779374: NEW ERROR MESSAGE ADDED TO 5.5 AFTER 5.6
 GA - REUSING               NUMBER ALREADY USED BY 5.6

The problem was that the patch for Bug#13004581 added a new error
message to 5.5. This causes it to use an error number already used
in 5.6 by ER_CANNOT_LOAD_FROM_TABLE_V2. Which means that error
message number stability between GA releases is broken.

This patch fixes the problem by removing the error message and
using ER_UNKNOWN_ERROR instead.
---
 sql/share/errmsg-utf8.txt | 2 --
 sql/sql_class.cc          | 6 ++++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index e3bdf3fc8ef..e7ef0f74f1e 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -6506,8 +6506,6 @@ ER_UNSUPPORTED_ENGINE
 ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST
   eng "INSERT into autoincrement field which is not the first part in the composed primary key is unsafe."
 
-WARN_ON_BLOCKHOLE_IN_RBR
-  eng "Row events are not logged for %s statements that modify BLACKHOLE tables in row format. Table(s): '%-.192s'"
 #
 #  End of 5.5 error messages.
 #
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index a2e30bda20a..fb4ed99b8bb 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -4443,8 +4443,10 @@ int THD::decide_logging_format(TABLE_LIST *tables)
         */
         table_names.replace(table_names.length()-1, 1, ".", 1);
         push_warning_printf(this, MYSQL_ERROR::WARN_LEVEL_WARN,
-                            WARN_ON_BLOCKHOLE_IN_RBR,
-                            ER(WARN_ON_BLOCKHOLE_IN_RBR),
+                            ER_UNKNOWN_ERROR,
+                            "Row events are not logged for %s statements "
+                            "that modify BLACKHOLE tables in row format. "
+                            "Table(s): '%-.192s'",
                             is_update ? "UPDATE" : "DELETE",
                             table_names.c_ptr());
       }

From c1bdbff8ca1bd6ebdcfcaa60cadc52b465bf9600 Mon Sep 17 00:00:00 2001
From: Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com>
Date: Mon, 13 May 2013 09:46:44 +0200
Subject: [PATCH 06/11]  Adding fix for Bug#16798868

---
 support-files/mysql.spec.sh | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh
index c153b22b7c5..9e49db8a9c1 100644
--- a/support-files/mysql.spec.sh
+++ b/support-files/mysql.spec.sh
@@ -974,6 +974,35 @@ mv -f  $STATUS_FILE ${STATUS_FILE}-LAST  # for "triggerpostun"
 #scheduled service packs and more.  Visit www.mysql.com/enterprise for more
 #information."
 
+%preun -n MySQL-server%{product_suffix}
+
+# Which '$1' does this refer to?  Fedora docs have info:
+# " ... a count of the number of versions of the package that are installed.
+#   Action                           Count
+#   Install the first time           1
+#   Upgrade                          2 or higher (depending on the number of versions installed)
+#   Remove last version of package   0 "
+#
+#  http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html
+ 
+if [ $1 = 0 ] ; then
+        # Stop MySQL before uninstalling it
+        if [ -x %{_sysconfdir}/init.d/mysql ] ; then
+                %{_sysconfdir}/init.d/mysql stop > /dev/null
+                # Remove autostart of MySQL
+                # use chkconfig on Enterprise Linux and newer SuSE releases
+                if [ -x /sbin/chkconfig ] ; then
+                        /sbin/chkconfig --del mysql
+                # For older SuSE Linux versions
+                elif [ -x /sbin/insserv ] ; then
+                        /sbin/insserv -r %{_sysconfdir}/init.d/mysql
+                fi
+        fi
+fi
+
+# We do not remove the mysql user since it may still own a lot of
+# database files.
+
 %triggerpostun -n MySQL-server%{product_suffix} --MySQL-server-community
 
 # Setup: We renamed this package, so any existing "server-community"

From 3ba53d175a6a4c108ff5eeb57d1ad789beba0754 Mon Sep 17 00:00:00 2001
From: Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com>
Date: Mon, 13 May 2013 10:21:09 +0200
Subject: [PATCH 07/11] Updated copyright year information

---
 support-files/mysql.spec.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh
index 9e49db8a9c1..311ce566abc 100644
--- a/support-files/mysql.spec.sh
+++ b/support-files/mysql.spec.sh
@@ -1,4 +1,4 @@
-# Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

From 8e572235468b069859692136c9159c4ab6a6bea3 Mon Sep 17 00:00:00 2001
From: Murthy Narkedimilli <murthy.narkedimilli@oracle.com>
Date: Wed, 15 May 2013 15:37:20 +0200
Subject: [PATCH 08/11] Bug 16812255 - 5.5.32 PKG INSTALLATION FAILED DURING
 MYSQL_INSTALL_DB EXECUTION

---
 packaging/solaris/CMakeLists.txt              |  2 +-
 ...nstall-solaris.sh => postinstall_check.sh} | 50 -------------------
 2 files changed, 1 insertion(+), 51 deletions(-)
 rename packaging/solaris/{postinstall-solaris.sh => postinstall_check.sh} (57%)

diff --git a/packaging/solaris/CMakeLists.txt b/packaging/solaris/CMakeLists.txt
index 02881e0af8f..6add0d81950 100644
--- a/packaging/solaris/CMakeLists.txt
+++ b/packaging/solaris/CMakeLists.txt
@@ -22,7 +22,7 @@
 # It is important not to pollute "/usr/bin".
 SET(inst_location ${INSTALL_SUPPORTFILESDIR})
 
-FOREACH(script  postinstall-solaris)
+FOREACH(script  postinstall_check)
   CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh 
                  ${CMAKE_CURRENT_BINARY_DIR}/${script} COPYONLY )
 
diff --git a/packaging/solaris/postinstall-solaris.sh b/packaging/solaris/postinstall_check.sh
similarity index 57%
rename from packaging/solaris/postinstall-solaris.sh
rename to packaging/solaris/postinstall_check.sh
index 027969fcf0e..e58ea394b8e 100644
--- a/packaging/solaris/postinstall-solaris.sh
+++ b/packaging/solaris/postinstall_check.sh
@@ -58,67 +58,17 @@ fi
 
 chown -R $myuser:$mygroup $mydatadir
 
-# Solaris patch 119255 (somewhere around revision 42) changes the behaviour
-# of pkgadd to set TMPDIR internally to a root-owned install directory.  This
-# has the unfortunate side effect of breaking running mysql_install_db with
-# the --user=mysql argument as mysqld uses TMPDIR if set, and is unable to
-# write temporary tables to that directory.  To work around this issue, we
-# create a subdirectory inside TMPDIR (if set) for mysqld to write to.
-#
-# Idea from Ben Hekster <heksterb@gmail.com> in bug#31164
-
-if [ -n "$TMPDIR" ] ; then
-  savetmpdir="$TMPDIR"
-  TMPDIR="$TMPDIR/mysql.$$"
-  export TMPDIR
-  mkdir "$TMPDIR"
-  chown $myuser:$mygroup "$TMPDIR"
-fi
-
 if [ -n "$INSTALL" ] ; then
   # We install/update the system tables
   (
     cd "$mybasedir"
     scripts/mysql_install_db \
 	  --rpm \
-	  --random-passwords \
 	  --user=mysql \
 	  --basedir="$mybasedir" \
 	  --datadir=$mydatadir
   )
 fi
 
-if [ -n "$savetmpdir" ] ; then
-  TMPDIR="$savetmpdir"
-fi
-
-# ----------------------------------------------------------------------
-
-# Handle situation there is old start script installed already
-
-# If old start script is a soft link, we just remove it
-[ -h "$mystart" ] && rm -f "$mystart"
-
-# If old start script is a file, we rename it
-[ -f "$mystart" ] && mv -f "$mystart" "$mystart.old.$$"
-
-# ----------------------------------------------------------------------
-
-# We create a copy of an unmodified start script,
-# as a reference for the one maybe modifying it
-
-cp -f "$mystart1.in" "$mystart.in" || exit 1
-
-# We rewrite some scripts
-
-for script in "$mystart" "$mystart1" "$myinstdb" ; do
-  script_in="$script.in"
-  sed -e "s,@basedir@,$mybasedir,g" \
-      -e "s,@datadir@,$mydatadir,g" "$script_in" > "$script"
-  chmod u+x $script
-done
-
-rm -f "$mystart.in"
-
 exit 0
 

From 98d2a1f2003a8223afb1e07ab3e0fbf464c0f3b8 Mon Sep 17 00:00:00 2001
From: Murthy Narkedimilli <murthy.narkedimilli@oracle.com>
Date: Wed, 15 May 2013 16:29:31 +0200
Subject: [PATCH 09/11] Fixing the RPM-ULN build issue by ignoring the
 postinstall_check.sh.

---
 packaging/rpm-uln/mysql.spec.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packaging/rpm-uln/mysql.spec.sh b/packaging/rpm-uln/mysql.spec.sh
index 233e4bae194..62f652ab586 100644
--- a/packaging/rpm-uln/mysql.spec.sh
+++ b/packaging/rpm-uln/mysql.spec.sh
@@ -662,7 +662,7 @@ rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/postinstall
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-*.spec
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-log-rotate
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/ChangeLog
-rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/solaris/postinstall-solaris
+rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/solaris/postinstall_check
 rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/mysql-stress-test.pl.1*
 rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/mysql-test-run.pl.1*
 

From 1ec94a504b248f01460facf4b31e1b5c89917b17 Mon Sep 17 00:00:00 2001
From: Murthy Narkedimilli <murthy.narkedimilli@oracle.com>
Date: Thu, 16 May 2013 10:24:26 +0200
Subject: [PATCH 10/11] Changes to verify the solaris upgrade issue.

---
 packaging/solaris/postinstall_check.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/packaging/solaris/postinstall_check.sh b/packaging/solaris/postinstall_check.sh
index e58ea394b8e..e61c670c384 100644
--- a/packaging/solaris/postinstall_check.sh
+++ b/packaging/solaris/postinstall_check.sh
@@ -43,7 +43,8 @@ mystart=/etc/init.d/mysql
 # Check: Is this a first installation, or an upgrade ?
 
 if [ -d "$mydatadir/mysql" ] ; then
-  :   # If the directory for system table files exists, we assume an upgrade.
+   # If the directory for system table files exists, we assume an upgrade.
+  INSTALL=upgrade
 else
   INSTALL=new  # This is a new installation, the directory will soon be created.
 fi
@@ -58,7 +59,7 @@ fi
 
 chown -R $myuser:$mygroup $mydatadir
 
-if [ -n "$INSTALL" ] ; then
+if [ "$INSTALL" -eq "new" ] ; then
   # We install/update the system tables
   (
     cd "$mybasedir"

From 020dcec4a12e61cf5853623a2cd7b06d6bdb351f Mon Sep 17 00:00:00 2001
From: Murthy Narkedimilli <murthy.narkedimilli@oracle.com>
Date: Thu, 16 May 2013 17:33:32 +0200
Subject: [PATCH 11/11] Fix for BUG# 16812255: Removing the --random-password
 option which is supported only for MYSQL server versions 5.6 and above.

---
 packaging/rpm-uln/mysql.spec.sh               |  2 +-
 packaging/solaris/CMakeLists.txt              |  2 +-
 ...nstall_check.sh => postinstall-solaris.sh} | 60 +++++++++++++++++--
 3 files changed, 58 insertions(+), 6 deletions(-)
 rename packaging/solaris/{postinstall_check.sh => postinstall-solaris.sh} (52%)

diff --git a/packaging/rpm-uln/mysql.spec.sh b/packaging/rpm-uln/mysql.spec.sh
index 62f652ab586..233e4bae194 100644
--- a/packaging/rpm-uln/mysql.spec.sh
+++ b/packaging/rpm-uln/mysql.spec.sh
@@ -662,7 +662,7 @@ rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/postinstall
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-*.spec
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-log-rotate
 rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/ChangeLog
-rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/solaris/postinstall_check
+rm -f ${RPM_BUILD_ROOT}%{_datadir}/mysql/solaris/postinstall-solaris
 rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/mysql-stress-test.pl.1*
 rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/mysql-test-run.pl.1*
 
diff --git a/packaging/solaris/CMakeLists.txt b/packaging/solaris/CMakeLists.txt
index 6add0d81950..02881e0af8f 100644
--- a/packaging/solaris/CMakeLists.txt
+++ b/packaging/solaris/CMakeLists.txt
@@ -22,7 +22,7 @@
 # It is important not to pollute "/usr/bin".
 SET(inst_location ${INSTALL_SUPPORTFILESDIR})
 
-FOREACH(script  postinstall_check)
+FOREACH(script  postinstall-solaris)
   CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${script}.sh 
                  ${CMAKE_CURRENT_BINARY_DIR}/${script} COPYONLY )
 
diff --git a/packaging/solaris/postinstall_check.sh b/packaging/solaris/postinstall-solaris.sh
similarity index 52%
rename from packaging/solaris/postinstall_check.sh
rename to packaging/solaris/postinstall-solaris.sh
index e61c670c384..fcc980cd13e 100644
--- a/packaging/solaris/postinstall_check.sh
+++ b/packaging/solaris/postinstall-solaris.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -43,8 +43,7 @@ mystart=/etc/init.d/mysql
 # Check: Is this a first installation, or an upgrade ?
 
 if [ -d "$mydatadir/mysql" ] ; then
-   # If the directory for system table files exists, we assume an upgrade.
-  INSTALL=upgrade
+  :   # If the directory for system table files exists, we assume an upgrade.
 else
   INSTALL=new  # This is a new installation, the directory will soon be created.
 fi
@@ -59,7 +58,28 @@ fi
 
 chown -R $myuser:$mygroup $mydatadir
 
-if [ "$INSTALL" -eq "new" ] ; then
+# Solaris patch 119255 (somewhere around revision 42) changes the behaviour
+# of pkgadd to set TMPDIR internally to a root-owned install directory.  This
+# has the unfortunate side effect of breaking running mysql_install_db with
+# the --user=mysql argument as mysqld uses TMPDIR if set, and is unable to
+# write temporary tables to that directory.  To work around this issue, we
+# create a subdirectory inside TMPDIR (if set) for mysqld to write to.
+#
+# Idea from Ben Hekster <heksterb@gmail.com> in bug#31164
+
+if [ -n "$TMPDIR" ] ; then
+  savetmpdir="$TMPDIR"
+  TMPDIR="$TMPDIR/mysql.$$"
+  export TMPDIR
+  mkdir "$TMPDIR"
+  chown $myuser:$mygroup "$TMPDIR"
+fi
+
+
+# BUG# 16812255: Removing the option --random-passwords
+# as this is supported only for MYSQL releases 5.6 and above.
+ 
+if [ -n "$INSTALL" ] ; then
   # We install/update the system tables
   (
     cd "$mybasedir"
@@ -71,5 +91,37 @@ if [ "$INSTALL" -eq "new" ] ; then
   )
 fi
 
+if [ -n "$savetmpdir" ] ; then
+  TMPDIR="$savetmpdir"
+fi
+
+# ----------------------------------------------------------------------
+
+# Handle situation there is old start script installed already
+
+# If old start script is a soft link, we just remove it
+[ -h "$mystart" ] && rm -f "$mystart"
+
+# If old start script is a file, we rename it
+[ -f "$mystart" ] && mv -f "$mystart" "$mystart.old.$$"
+
+# ----------------------------------------------------------------------
+
+# We create a copy of an unmodified start script,
+# as a reference for the one maybe modifying it
+
+cp -f "$mystart1.in" "$mystart.in" || exit 1
+
+# We rewrite some scripts
+
+for script in "$mystart" "$mystart1" "$myinstdb" ; do
+  script_in="$script.in"
+  sed -e "s,@basedir@,$mybasedir,g" \
+      -e "s,@datadir@,$mydatadir,g" "$script_in" > "$script"
+  chmod u+x $script
+done
+
+rm -f "$mystart.in"
+
 exit 0