Commit 489d8296 authored by marko's avatar marko

branches/zip: ha_innobase:add_index(): Report HA_ERR_TABLE_EXIST when the

temporary table cannot be created or renamed.

innodb-index.test,result: Add test cases where a temporary table already
exists.
parent 52a89286
......@@ -8327,8 +8327,18 @@ ha_innobase::add_index(
if (!indexed_table) {
error = convert_error_code_to_mysql(trx->error_state,
user_thd);
switch (trx->error_state) {
case DB_TABLESPACE_ALREADY_EXISTS:
case DB_DUPLICATE_KEY:
my_error(HA_ERR_TABLE_EXIST, MYF(0),
new_table_name);
error = HA_ERR_TABLE_EXIST;
break;
default:
error = convert_error_code_to_mysql(
trx->error_state, user_thd);
}
row_mysql_unlock_data_dictionary(trx);
goto err_exit;
}
......@@ -8421,7 +8431,7 @@ ha_innobase::add_index(
index, num_created);
}
break;
goto convert_error;
}
/* If a new primary key was defined for the table and
......@@ -8443,6 +8453,17 @@ ha_innobase::add_index(
if (error != DB_SUCCESS) {
row_merge_drop_table(trx, indexed_table);
switch (error) {
case DB_TABLESPACE_ALREADY_EXISTS:
case DB_DUPLICATE_KEY:
my_error(HA_ERR_TABLE_EXIST, MYF(0), tmp_name);
error = HA_ERR_TABLE_EXIST;
break;
default:
error = convert_error_code_to_mysql(
trx->error_state, user_thd);
}
break;
}
......@@ -8457,7 +8478,7 @@ ha_innobase::add_index(
are no more references to it. */
error = row_merge_drop_table(trx, innodb_table);
break;
goto convert_error;
case DB_PRIMARY_KEY_IS_NULL:
my_error(ER_PRIMARY_CANT_HAVE_NULL, MYF(0));
......@@ -8473,6 +8494,9 @@ ha_innobase::add_index(
row_merge_drop_indexes(trx, indexed_table,
index, num_created);
}
convert_error:
error = convert_error_code_to_mysql(error, user_thd);
}
mem_heap_free(heap);
......@@ -8485,7 +8509,7 @@ ha_innobase::add_index(
/* There might be work for utility threads.*/
srv_active_wake_master_thread();
DBUG_RETURN(convert_error_code_to_mysql(error, user_thd));
DBUG_RETURN(error);
}
/***********************************************************************
......
......@@ -46,6 +46,13 @@ t1 CREATE TABLE `t1` (
KEY `d2` (`d`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `t1#1`(a INT PRIMARY KEY) ENGINE=InnoDB;
alter table t1 add unique index (c), add index (d);
ERROR HY000: Table 'test/t1@00231' already exists
rename table `t1#1` to `t1#2`;
alter table t1 add unique index (c), add index (d);
ERROR HY000: Table 'test/t1@00232' already exists
drop table `t1#2`;
alter table t1 add unique index (c), add index (d);
show create table t1;
Table Create Table
......
......@@ -16,6 +16,19 @@ alter table t1 add unique index (b);
show create table t1;
alter table t1 add index (b);
show create table t1;
-- Check how existing tables interfere with temporary tables.
-- The error code is somewhat misleading. If innodb_file_per_table=1,
-- "File exists" from the operating system will translate into -1.
CREATE TABLE `t1#1`(a INT PRIMARY KEY) ENGINE=InnoDB;
--error 156
alter table t1 add unique index (c), add index (d);
rename table `t1#1` to `t1#2`;
--error 156
alter table t1 add unique index (c), add index (d);
drop table `t1#2`;
alter table t1 add unique index (c), add index (d);
show create table t1;
explain select * from t1 order by c;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment