List:Commits« Previous MessageNext Message »
From:marko.makela Date:April 11 2012 11:19am
Subject:bzr push into mysql-trunk-wl5545 branch (marko.makela:3886 to 3887) WL#5545
View as plain text  
 3887 Marko Mäkelä	2012-04-11
      WL#5545 review cleanup: refactor column renaming.
      
      dict_mem_table_col_rename_low(), dict_mem_table_col_rename(): Refactored from
      innobase_rename_column().

    modified:
      storage/innobase/dict/dict0mem.cc
      storage/innobase/handler/handler0alter.cc
      storage/innobase/include/dict0mem.h
 3886 Marko Mäkelä	2012-04-11 [merge]
      Merge mysql-trunk to mysql-trunk-wl5545.

    added:
      mysql-test/suite/binlog/r/binlog_gtid_cache.result
      mysql-test/suite/binlog/t/binlog_gtid_cache-master.opt
      mysql-test/suite/binlog/t/binlog_gtid_cache.test
    modified:
      mysql-test/r/alter_table.result
      mysql-test/t/alter_table.test
      sql/binlog.cc
      sql/handler.h
      sql/mysqld.cc
      sql/sql_table.cc
      storage/innobase/api/api0api.cc
      storage/innobase/api/api0misc.cc
      storage/innobase/btr/btr0btr.cc
      storage/innobase/btr/btr0cur.cc
      storage/innobase/buf/buf0buf.cc
      storage/innobase/buf/buf0dump.cc
      storage/innobase/buf/buf0flu.cc
      storage/innobase/buf/buf0rea.cc
      storage/innobase/dict/dict0boot.cc
      storage/innobase/dict/dict0crea.cc
      storage/innobase/dict/dict0dict.cc
      storage/innobase/dict/dict0load.cc
      storage/innobase/dict/dict0stats.cc
      storage/innobase/fil/fil0fil.cc
      storage/innobase/fts/fts0ast.cc
      storage/innobase/fts/fts0config.cc
      storage/innobase/fts/fts0fts.cc
      storage/innobase/fts/fts0opt.cc
      storage/innobase/fts/fts0que.cc
      storage/innobase/fts/fts0sql.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/handler/ha_innodb.h
      storage/innobase/handler/handler0alter.cc
      storage/innobase/handler/i_s.cc
      storage/innobase/ibuf/ibuf0ibuf.cc
      storage/innobase/include/api0api.h
      storage/innobase/include/api0misc.h
      storage/innobase/include/btr0cur.h
      storage/innobase/include/buf0buf.h
      storage/innobase/include/db0err.h
      storage/innobase/include/dict0boot.h
      storage/innobase/include/dict0crea.h
      storage/innobase/include/dict0dict.h
      storage/innobase/include/dict0load.h
      storage/innobase/include/dict0stats.h
      storage/innobase/include/fil0fil.h
      storage/innobase/include/fts0ast.h
      storage/innobase/include/fts0fts.h
      storage/innobase/include/fts0priv.h
      storage/innobase/include/ha_prototypes.h
      storage/innobase/include/lock0lock.h
      storage/innobase/include/log0recv.h
      storage/innobase/include/que0que.h
      storage/innobase/include/read0read.h
      storage/innobase/include/read0read.ic
      storage/innobase/include/row0ftsort.h
      storage/innobase/include/row0ins.h
      storage/innobase/include/row0log.h
      storage/innobase/include/row0merge.h
      storage/innobase/include/row0mysql.h
      storage/innobase/include/row0sel.h
      storage/innobase/include/row0uins.h
      storage/innobase/include/row0umod.h
      storage/innobase/include/row0upd.h
      storage/innobase/include/row0vers.h
      storage/innobase/include/srv0srv.h
      storage/innobase/include/srv0start.h
      storage/innobase/include/trx0rec.h
      storage/innobase/include/trx0roll.h
      storage/innobase/include/trx0sys.h
      storage/innobase/include/trx0trx.h
      storage/innobase/include/trx0undo.h
      storage/innobase/include/ut0ut.h
      storage/innobase/lock/lock0lock.cc
      storage/innobase/log/log0recv.cc
      storage/innobase/os/os0file.cc
      storage/innobase/que/que0que.cc
      storage/innobase/row/row0ftsort.cc
      storage/innobase/row/row0ins.cc
      storage/innobase/row/row0log.cc
      storage/innobase/row/row0merge.cc
      storage/innobase/row/row0mysql.cc
      storage/innobase/row/row0purge.cc
      storage/innobase/row/row0sel.cc
      storage/innobase/row/row0uins.cc
      storage/innobase/row/row0umod.cc
      storage/innobase/row/row0undo.cc
      storage/innobase/row/row0upd.cc
      storage/innobase/row/row0vers.cc
      storage/innobase/srv/srv0conc.cc
      storage/innobase/srv/srv0srv.cc
      storage/innobase/srv/srv0start.cc
      storage/innobase/trx/trx0i_s.cc
      storage/innobase/trx/trx0rec.cc
      storage/innobase/trx/trx0roll.cc
      storage/innobase/trx/trx0sys.cc
      storage/innobase/trx/trx0trx.cc
      storage/innobase/trx/trx0undo.cc
      storage/innobase/ut/ut0ut.cc
=== modified file 'storage/innobase/dict/dict0mem.cc'
--- a/storage/innobase/dict/dict0mem.cc	revid:marko.makela@stripped
+++ b/storage/innobase/dict/dict0mem.cc	revid:marko.makela@oracle.com-20120411111757-y58t0aim4g5h4lex
@@ -243,6 +243,148 @@ dict_mem_table_add_col(
 	dict_mem_fill_column_struct(col, i, mtype, prtype, len);
 }
 
+/**********************************************************************//**
+Renames a column of a table in the data dictionary cache. */
+static __attribute__((nonnull))
+void
+dict_mem_table_col_rename_low(
+/*==========================*/
+	dict_table_t*	table,	/*!< in/out: table */
+	const char*	from,	/*!< in: old column name */
+	const char*	to,	/*!< in: new column name */
+	const char*	s,	/*!< in: pointer to table->col_names */
+	unsigned	i)	/*!< in: column offset corresponding to s */
+{
+	size_t from_len = strlen(from), to_len = strlen(to);
+
+	ut_ad(!strcmp(from, s));
+	ut_ad(i < table->n_def);
+
+	if (from_len == to_len) {
+		/* The easy case: simply replace the column name in
+		table->col_names. */
+		strcpy(const_cast<char*>(s), to);
+	} else {
+		/* We need to adjust all affected index->field
+		pointers, as in dict_index_add_col(). First, copy
+		table->col_names. */
+		ulint	prefix_len	= s - table->col_names;
+
+		for (; i < table->n_def; i++) {
+			s += strlen(s) + 1;
+		}
+
+		ulint	full_len	= s - table->col_names;
+		char*	col_names;
+
+		if (to_len > from_len) {
+			col_names = static_cast<char*>(
+				mem_heap_alloc(
+					table->heap,
+					full_len + to_len - from_len));
+
+			memcpy(col_names, table->col_names, prefix_len);
+		} else {
+			col_names = const_cast<char*>(table->col_names);
+		}
+
+		memcpy(col_names + prefix_len, to, to_len);
+		memmove(col_names + prefix_len + to_len,
+			table->col_names + (prefix_len + from_len),
+			full_len - (prefix_len + from_len));
+
+		/* Replace the field names in every index. */
+		for (dict_index_t* index = dict_table_get_first_index(table);
+		     index != NULL;
+		     index = dict_table_get_next_index(index)) {
+			ulint	n_fields = dict_index_get_n_fields(index);
+
+			for (ulint i = 0; i < n_fields; i++) {
+				dict_field_t*	field
+					= dict_index_get_nth_field(
+						index, i);
+				ulint		name_ofs
+					= field->name - table->col_names;
+				if (name_ofs <= prefix_len) {
+					field->name = col_names + name_ofs;
+				} else {
+					ut_a(name_ofs < full_len);
+					field->name = col_names
+						+ name_ofs + to_len - from_len;
+				}
+			}
+		}
+
+		table->col_names = col_names;
+	}
+
+	/* Replace the field names in every foreign key constraint. */
+	for (dict_foreign_t* foreign = UT_LIST_GET_FIRST(table->foreign_list);
+	     foreign != NULL;
+	     foreign = UT_LIST_GET_NEXT(foreign_list, foreign)) {
+		for (unsigned f = 0; f < foreign->n_fields; f++) {
+			/* These can point straight to
+			table->col_names, because the foreign key
+			constraints will be freed at the same time
+			when the table object is freed. */
+			foreign->foreign_col_names[f]
+				= dict_index_get_nth_field(
+					foreign->foreign_index, f)->name;
+		}
+	}
+
+	for (dict_foreign_t* foreign = UT_LIST_GET_FIRST(
+		     table->referenced_list);
+	     foreign != NULL;
+	     foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
+		for (unsigned f = 0; f < foreign->n_fields; f++) {
+			/* foreign->referenced_col_names[] need to be
+			copies, because the constraint may become
+			orphan when foreign_key_checks=0 and the
+			parent table is dropped. */
+
+			const char* col_name = dict_index_get_nth_field(
+				foreign->referenced_index, f)->name;
+
+			if (strcmp(foreign->referenced_col_names[f],
+				   col_name)) {
+				foreign->referenced_col_names[f]
+					= mem_heap_strdup(
+						foreign->heap, col_name);
+			}
+		}
+	}
+}
+
+/**********************************************************************//**
+Renames a column of a table in the data dictionary cache.
+@return whether the operation succeeded */
+UNIV_INTERN
+bool
+dict_mem_table_col_rename(
+/*======================*/
+	dict_table_t*	table,	/*!< in/out: table */
+	const char*	from,	/*!< in: old column name */
+	const char*	to)	/*!< in: new column name */
+{
+	unsigned	i;
+	const char*	s = table->col_names;
+
+	if (!s) {
+		return(false);
+	}
+
+	for (i = 0; i < table->n_def; i++) {
+		if (!strcmp(from, s)) {
+			dict_mem_table_col_rename_low(table, from, to, s, i);
+			return(true);
+		}
+
+		s += strlen(s) + 1;
+	}
+
+	return(false);
+}
 
 /**********************************************************************//**
 This function populates a dict_col_t memory structure with

=== modified file 'storage/innobase/handler/handler0alter.cc'
--- a/storage/innobase/handler/handler0alter.cc	revid:marko.makela@stripped11104639-10cskae35odu3ou4
+++ b/storage/innobase/handler/handler0alter.cc	revid:marko.makela@stripped1757-y58t0aim4g5h4lex
@@ -2542,131 +2542,12 @@ innobase_rename_column(
 	}
 
 	/* Rename the column in the data dictionary cache. */
-	const char*	s = prebuilt->table->col_names;
-
-	if (!s) {
-not_found:
+	if (!dict_mem_table_col_rename(prebuilt->table, from, to)) {
 		DBUG_ASSERT(0);
 		my_error(ER_NOT_KEYFILE, MYF(0), prebuilt->table->name);
 		DBUG_RETURN(true);
 	}
 
-	unsigned i;
-
-	for (i = 0; i < prebuilt->table->n_def; i++) {
-		if (!strcmp(from, s)) {
-			goto found_name;
-		}
-
-		s += strlen(s) + 1;
-	}
-
-	goto not_found;
-
-found_name:
-	size_t from_len = strlen(from), to_len = strlen(to);
-
-	if (from_len == to_len) {
-		/* The easy case: simply replace the column name in
-		prebuilt->table->col_names. */
-		strcpy(const_cast<char*>(s), to);
-	} else {
-		/* We need to adjust all affected index->field
-		pointers, as in dict_index_add_col(). First, copy
-		prebuilt->table->col_names. */
-		ulint	prefix_len	= s - prebuilt->table->col_names;
-
-		for (; i < prebuilt->table->n_def; i++) {
-			s += strlen(s) + 1;
-		}
-
-		ulint	full_len	= s - prebuilt->table->col_names;
-		char*	col_names;
-
-		if (to_len > from_len) {
-			col_names = static_cast<char*>(
-				mem_heap_alloc(
-					prebuilt->table->heap,
-					full_len + to_len - from_len));
-
-			memcpy(col_names, prebuilt->table->col_names,
-			       prefix_len);
-		} else {
-			col_names = const_cast<char*>(
-				prebuilt->table->col_names);
-		}
-
-		memcpy(col_names + prefix_len, to, to_len);
-		memmove(col_names + prefix_len + to_len,
-			prebuilt->table->col_names + (prefix_len + from_len),
-			full_len - (prefix_len + from_len));
-
-		/* Replace the field names in every index. */
-		for (dict_index_t* index = dict_table_get_first_index(
-			     prebuilt->table);
-		     index != NULL;
-		     index = dict_table_get_next_index(index)) {
-			ulint	n_fields = dict_index_get_n_fields(index);
-
-			for (ulint i = 0; i < n_fields; i++) {
-				dict_field_t*	field
-					= dict_index_get_nth_field(
-						index, i);
-				ulint		name_ofs
-					= field->name
-					- prebuilt->table->col_names;
-				if (name_ofs <= prefix_len) {
-					field->name = col_names + name_ofs;
-				} else {
-					ut_a(name_ofs < full_len);
-					field->name = col_names
-						+ name_ofs + to_len - from_len;
-				}
-			}
-		}
-
-		prebuilt->table->col_names = col_names;
-	}
-
-	/* Replace the field names in every foreign key constraint. */
-	for (dict_foreign_t* foreign = UT_LIST_GET_FIRST(
-		     prebuilt->table->foreign_list);
-	     foreign != NULL;
-	     foreign = UT_LIST_GET_NEXT(foreign_list, foreign)) {
-		for (unsigned f = 0; f < foreign->n_fields; f++) {
-			/* These can point straight to
-			table->col_names, because the foreign key
-			constraints will be freed at the same time
-			when the table object is freed. */
-			foreign->foreign_col_names[f]
-				= dict_index_get_nth_field(
-					foreign->foreign_index, f)
-				->name;
-		}
-	}
-
-	for (dict_foreign_t* foreign = UT_LIST_GET_FIRST(
-		     prebuilt->table->referenced_list);
-	     foreign != NULL;
-	     foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
-		for (unsigned f = 0; f < foreign->n_fields; f++) {
-			/* foreign->referenced_col_names[] need to be
-			copies, because the constraint may become
-			orphan when foreign_key_checks=0 and the
-			parent table is dropped. */
-
-			const char* col_name = dict_index_get_nth_field(
-				foreign->referenced_index, f)->name;
-
-			if (strcmp(foreign->referenced_col_names[f],
-				   col_name)) {
-				foreign->referenced_col_names[f]
-					= mem_heap_strdup(
-						foreign->heap, col_name);
-			}
-		}
-	}
-
 	DBUG_RETURN(false);
 }
 

=== modified file 'storage/innobase/include/dict0mem.h'
--- a/storage/innobase/include/dict0mem.h	revid:marko.makela@stripped
+++ b/storage/innobase/include/dict0mem.h	revid:marko.makela@stripped
@@ -250,7 +250,19 @@ dict_mem_table_add_col(
 	const char*	name,	/*!< in: column name, or NULL */
 	ulint		mtype,	/*!< in: main datatype */
 	ulint		prtype,	/*!< in: precise type */
-	ulint		len);	/*!< in: precision */
+	ulint		len)	/*!< in: precision */
+	__attribute__((nonnull(1)));
+/**********************************************************************//**
+Renames a column of a table in the data dictionary cache.
+@return whether the operation succeeded */
+UNIV_INTERN
+bool
+dict_mem_table_col_rename(
+/*======================*/
+	dict_table_t*	table,	/*!< in/out: table */
+	const char*	from,	/*!< in: old column name */
+	const char*	to)	/*!< in: new column name */
+	__attribute__((nonnull));
 /**********************************************************************//**
 This function populates a dict_col_t memory structure with
 supplied information. */

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-wl5545 branch (marko.makela:3886 to 3887) WL#5545marko.makela11 Apr