From 11b498d6e0972d33dd35df9ef5211f3f969829f3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 26 Mar 2014 09:41:16 +0100 Subject: [PATCH] build_frm_image(): don't try to guess the "real table name" from the field list, it doesn't work if ALTER TABLE has replaced all fields. Instead, pass the correct original table name down from the caller. --- mysql-test/r/comment_column.result | 3 +++ mysql-test/t/comment_column.test | 2 ++ sql/sql_table.cc | 19 +++++++++++++------ sql/unireg.cc | 13 ++----------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/comment_column.result b/mysql-test/r/comment_column.result index 6ddd9eaf3de..552a83da472 100644 --- a/mysql-test/r/comment_column.result +++ b/mysql-test/r/comment_column.result @@ -408,4 +408,7 @@ Warning 1688 Comment for index 'i1' is too long (max = 1024) CREATE INDEX i2 ON t1_toupg(c2) COMMENT '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; Warnings: Warning 1688 Comment for index 'i2' is too long (max = 1024) +ALTER TABLE t1_toupg drop column c1, drop column c2, drop column c3, add column c4 int, COMMENT='012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012301234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; +Warnings: +Warning 1628 Comment for table 't1_toupg' is too long (max = 2048) drop table t1_toupg; diff --git a/mysql-test/t/comment_column.test b/mysql-test/t/comment_column.test index 90976d143b5..de1c9b8ce47 100644 --- a/mysql-test/t/comment_column.test +++ b/mysql-test/t/comment_column.test @@ -125,6 +125,8 @@ ALTER TABLE t1_toupg ADD c3 TIMESTAMP COMMENT 'abcdefghijabcdefghijabcdefghijabc ALTER TABLE t1_toupg ADD INDEX i1(c1) COMMENT '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; # Add index with comment using CREATE INDEX CREATE INDEX i2 ON t1_toupg(c2) COMMENT '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; +# Alter the existing table, replace all columns, change comment +ALTER TABLE t1_toupg drop column c1, drop column c2, drop column c3, add column c4 int, COMMENT='012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012301234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'; drop table t1_toupg; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a815ec2ea8f..878e40cbb02 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4559,6 +4559,9 @@ err: Create a table @param thd Thread object + @param orig_db Database for error messages + @param orig_table_name Table name for error messages + (it's different from table_name for ALTER TABLE) @param db Database @param table_name Table name @param path Path to table (i.e. to its .FRM file without @@ -4587,6 +4590,7 @@ err: static int create_table_impl(THD *thd, + const char *orig_db, const char *orig_table_name, const char *db, const char *table_name, const char *path, HA_CREATE_INFO *create_info, @@ -4767,8 +4771,9 @@ int create_table_impl(THD *thd, } else { - file= mysql_create_frm_image(thd, db, table_name, create_info, alter_info, - create_table_mode, key_info, key_count, frm); + file= mysql_create_frm_image(thd, orig_db, orig_table_name, create_info, + alter_info, create_table_mode, key_info, + key_count, frm); if (!file) goto err; if (rea_create_table(thd, frm, path, db, table_name, create_info, @@ -4884,9 +4889,9 @@ int mysql_create_table_no_lock(THD *thd, } } - res= create_table_impl(thd, db, table_name, path, create_info, - alter_info, create_table_mode, is_trans, - ¬_used_1, ¬_used_2, &frm); + res= create_table_impl(thd, db, table_name, db, table_name, path, + create_info, alter_info, create_table_mode, + is_trans, ¬_used_1, ¬_used_2, &frm); my_free(const_cast(frm.str)); return res; } @@ -8514,7 +8519,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, tmp_disable_binlog(thd); create_info->options|=HA_CREATE_TMP_ALTER; - error= create_table_impl(thd, alter_ctx.new_db, alter_ctx.tmp_name, + error= create_table_impl(thd, + alter_ctx.db, alter_ctx.table_name, + alter_ctx.new_db, alter_ctx.tmp_name, alter_ctx.get_tmp_path(), create_info, alter_info, C_ALTER_TABLE_FRM_ONLY, NULL, diff --git a/sql/unireg.cc b/sql/unireg.cc index ad2d711be99..4e4af221ddb 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -173,24 +173,15 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table, if (tmp_len < create_info->comment.length) { - char *real_table_name= (char*) table; - List_iterator it(create_fields); - Create_field *field; - while ((field=it++)) - { - if (field->field && field->field->table && - (real_table_name= field->field->table->s->table_name.str)) - break; - } if (thd->is_strict_mode()) { my_error(ER_TOO_LONG_TABLE_COMMENT, MYF(0), - real_table_name, TABLE_COMMENT_MAXLEN); + table, TABLE_COMMENT_MAXLEN); DBUG_RETURN(frm); } char warn_buff[MYSQL_ERRMSG_SIZE]; my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_TABLE_COMMENT), - real_table_name, TABLE_COMMENT_MAXLEN); + table, TABLE_COMMENT_MAXLEN); push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_TOO_LONG_TABLE_COMMENT, warn_buff); create_info->comment.length= tmp_len;