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 @@ err_exit: ...@@ -8327,8 +8327,18 @@ err_exit:
if (!indexed_table) { if (!indexed_table) {
error = convert_error_code_to_mysql(trx->error_state, switch (trx->error_state) {
user_thd); 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); row_mysql_unlock_data_dictionary(trx);
goto err_exit; goto err_exit;
} }
...@@ -8421,7 +8431,7 @@ error_handling: ...@@ -8421,7 +8431,7 @@ error_handling:
index, num_created); index, num_created);
} }
break; goto convert_error;
} }
/* If a new primary key was defined for the table and /* If a new primary key was defined for the table and
...@@ -8443,6 +8453,17 @@ error_handling: ...@@ -8443,6 +8453,17 @@ error_handling:
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
row_merge_drop_table(trx, indexed_table); 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; break;
} }
...@@ -8457,7 +8478,7 @@ error_handling: ...@@ -8457,7 +8478,7 @@ error_handling:
are no more references to it. */ are no more references to it. */
error = row_merge_drop_table(trx, innodb_table); error = row_merge_drop_table(trx, innodb_table);
break; goto convert_error;
case DB_PRIMARY_KEY_IS_NULL: case DB_PRIMARY_KEY_IS_NULL:
my_error(ER_PRIMARY_CANT_HAVE_NULL, MYF(0)); my_error(ER_PRIMARY_CANT_HAVE_NULL, MYF(0));
...@@ -8473,6 +8494,9 @@ error_handling: ...@@ -8473,6 +8494,9 @@ error_handling:
row_merge_drop_indexes(trx, indexed_table, row_merge_drop_indexes(trx, indexed_table,
index, num_created); index, num_created);
} }
convert_error:
error = convert_error_code_to_mysql(error, user_thd);
} }
mem_heap_free(heap); mem_heap_free(heap);
...@@ -8485,7 +8509,7 @@ error_handling: ...@@ -8485,7 +8509,7 @@ error_handling:
/* There might be work for utility threads.*/ /* There might be work for utility threads.*/
srv_active_wake_master_thread(); 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` ( ...@@ -46,6 +46,13 @@ t1 CREATE TABLE `t1` (
KEY `d2` (`d`), KEY `d2` (`d`),
KEY `b` (`b`) KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) 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); alter table t1 add unique index (c), add index (d);
show create table t1; show create table t1;
Table Create Table Table Create Table
......
...@@ -16,6 +16,19 @@ alter table t1 add unique index (b); ...@@ -16,6 +16,19 @@ alter table t1 add unique index (b);
show create table t1; show create table t1;
alter table t1 add index (b); alter table t1 add index (b);
show create table t1; 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); alter table t1 add unique index (c), add index (d);
show create table t1; show create table t1;
explain select * from t1 order by c; 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