Commit 396f3422 authored by jyang's avatar jyang

branches/zip: Port bug #46000 related changes from 5.1 to zip

branch. Due to different code path for creating index in zip
branch comparing to 5.1), the index reserved name check function
is extended to be used in ha_innobase::add_index(). 
rb://190  Approved by: Marko
parent 7e6a345f
...@@ -229,21 +229,6 @@ static handler *innobase_create_handler(handlerton *hton, ...@@ -229,21 +229,6 @@ static handler *innobase_create_handler(handlerton *hton,
TABLE_SHARE *table, TABLE_SHARE *table,
MEM_ROOT *mem_root); MEM_ROOT *mem_root);
/***********************************************************************
This function checks each index name for a table against reserved
system default primary index name 'GEN_CLUST_INDEX'. If a name matches,
this function pushes an error message to the client, and returns true. */
static
bool
innobase_index_name_is_reserved(
/*============================*/
/* out: true if index name matches a
reserved name */
const trx_t* trx, /* in: InnoDB transaction handle */
const TABLE* form, /* in: information on table
columns and indexes */
const char* norm_name); /* in: table name */
/* "GEN_CLUST_INDEX" is the name reserved for Innodb default /* "GEN_CLUST_INDEX" is the name reserved for Innodb default
system primary index. */ system primary index. */
static const char innobase_index_reserve_name[]= "GEN_CLUST_INDEX"; static const char innobase_index_reserve_name[]= "GEN_CLUST_INDEX";
...@@ -6342,7 +6327,8 @@ ha_innobase::create( ...@@ -6342,7 +6327,8 @@ ha_innobase::create(
/* Check for name conflicts (with reserved name) for /* Check for name conflicts (with reserved name) for
any user indices to be created. */ any user indices to be created. */
if (innobase_index_name_is_reserved(trx, form, norm_name)) { if (innobase_index_name_is_reserved(trx, form->key_info,
form->s->keys)) {
error = -1; error = -1;
goto cleanup; goto cleanup;
} }
...@@ -9803,36 +9789,39 @@ static int show_innodb_vars(THD *thd, SHOW_VAR *var, char *buff) ...@@ -9803,36 +9789,39 @@ static int show_innodb_vars(THD *thd, SHOW_VAR *var, char *buff)
/*********************************************************************** /***********************************************************************
This function checks each index name for a table against reserved This function checks each index name for a table against reserved
system default primary index name 'GEN_CLUST_INDEX'. If a name matches, system default primary index name 'GEN_CLUST_INDEX'. If a name matches,
this function pushes an error message to the client, and returns true. */ this function pushes an warning message to the client, and returns true. */
static extern "C" UNIV_INTERN
bool bool
innobase_index_name_is_reserved( innobase_index_name_is_reserved(
/*============================*/ /*============================*/
/* out: true if an index name /* out: true if an index name
matches the reserved name */ matches the reserved name */
const trx_t* trx, /* in: InnoDB transaction handle */ const trx_t* trx, /* in: InnoDB transaction handle */
const TABLE* form, /* in: information on table const KEY* key_info, /* in: Indexes to be created */
columns and indexes */ ulint num_of_keys) /* in: Number of indexes to
const char* norm_name) /* in: table name */ be created. */
{ {
KEY* key; const KEY* key;
uint key_num; /* index number */ uint key_num; /* index number */
for (key_num = 0; key_num < form->s->keys; key_num++) { for (key_num = 0; key_num < num_of_keys; key_num++) {
key = form->key_info + key_num; key = &key_info[key_num];
if (innobase_strcasecmp(key->name, if (innobase_strcasecmp(key->name,
innobase_index_reserve_name) == 0) { innobase_index_reserve_name) == 0) {
/* Push warning to mysql */ /* Push warning to mysql */
push_warning_printf((THD*) trx->mysql_thd, push_warning_printf((THD*) trx->mysql_thd,
MYSQL_ERROR::WARN_LEVEL_ERROR, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_CANT_CREATE_TABLE, ER_WRONG_NAME_FOR_INDEX,
"Cannot Create Index with name " "Cannot Create Index with name "
"'%s'. The name is reserved " "'%s'. The name is reserved "
"for the system default primary " "for the system default primary "
"index.", "index.",
innobase_index_reserve_name); innobase_index_reserve_name);
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0),
innobase_index_reserve_name);
return(true); return(true);
} }
} }
......
...@@ -282,3 +282,21 @@ trx_t* ...@@ -282,3 +282,21 @@ trx_t*
innobase_trx_allocate( innobase_trx_allocate(
/*==================*/ /*==================*/
MYSQL_THD thd); /*!< in: user thread handle */ MYSQL_THD thd); /*!< in: user thread handle */
/*********************************************************************//**
This function checks each index name for a table against reserved
system default primary index name 'GEN_CLUST_INDEX'. If a name
matches, this function pushes an warning message to the client,
and returns true. */
extern "C"
bool
innobase_index_name_is_reserved(
/*============================*/
/* out: true if the index name
matches the reserved name */
const trx_t* trx, /* in: InnoDB transaction handle */
const KEY* key_info, /* in: Indexes to be created */
ulint num_of_keys); /* in: Number of indexes to
be created. */
...@@ -628,7 +628,7 @@ ha_innobase::add_index( ...@@ -628,7 +628,7 @@ ha_innobase::add_index(
ulint num_created = 0; ulint num_created = 0;
ibool dict_locked = FALSE; ibool dict_locked = FALSE;
ulint new_primary; ulint new_primary;
ulint error; int error;
DBUG_ENTER("ha_innobase::add_index"); DBUG_ENTER("ha_innobase::add_index");
ut_a(table); ut_a(table);
...@@ -656,9 +656,13 @@ ha_innobase::add_index( ...@@ -656,9 +656,13 @@ ha_innobase::add_index(
innodb_table = indexed_table innodb_table = indexed_table
= dict_table_get(prebuilt->table->name, FALSE); = dict_table_get(prebuilt->table->name, FALSE);
/* Check that index keys are sensible */ /* Check if the index name is reserved. */
if (innobase_index_name_is_reserved(trx, key_info, num_of_keys)) {
error = innobase_check_index_keys(key_info, num_of_keys); error = -1;
} else {
/* Check that index keys are sensible */
error = innobase_check_index_keys(key_info, num_of_keys);
}
if (UNIV_UNLIKELY(error)) { if (UNIV_UNLIKELY(error)) {
err_exit: err_exit:
......
create table bug46000(`id` int,key `GEN_CLUST_INDEX`(`id`))engine=innodb; create table bug46000(`id` int,key `GEN_CLUST_INDEX`(`id`))engine=innodb;
ERROR HY000: Can't create table 'test.bug46000' (errno: -1) ERROR 42000: Incorrect index name 'GEN_CLUST_INDEX'
create table bug46000(`id` int, key `GEN_clust_INDEX`(`id`))engine=innodb; create table bug46000(`id` int, key `GEN_clust_INDEX`(`id`))engine=innodb;
ERROR HY000: Can't create table 'test.bug46000' (errno: -1) ERROR 42000: Incorrect index name 'GEN_CLUST_INDEX'
show errors; show warnings;
Level Code Message Level Code Message
Error 1005 Cannot Create Index with name 'GEN_CLUST_INDEX'. The name is reserved for the system default primary index. Warning 1280 Cannot Create Index with name 'GEN_CLUST_INDEX'. The name is reserved for the system default primary index.
Error 1280 Incorrect index name 'GEN_CLUST_INDEX'
Error 1005 Can't create table 'test.bug46000' (errno: -1) Error 1005 Can't create table 'test.bug46000' (errno: -1)
create table bug46000(id int) engine=innodb; create table bug46000(id int) engine=innodb;
create index GEN_CLUST_INDEX on bug46000(id); create index GEN_CLUST_INDEX on bug46000(id);
ERROR HY000: Can't create table '#sql-temporary' (errno: -1) ERROR 42000: Incorrect index name 'GEN_CLUST_INDEX'
show errors; show warnings;
Level Code Message Level Code Message
Error 1005 Cannot Create Index with name 'GEN_CLUST_INDEX'. The name is reserved for the system default primary index. Warning 1280 Cannot Create Index with name 'GEN_CLUST_INDEX'. The name is reserved for the system default primary index.
Error 1005 Can't create table '#sql-temporary' (errno: -1) Error 1280 Incorrect index name 'GEN_CLUST_INDEX'
Error 1030 Got error -1 from storage engine
create index idx on bug46000(id); create index idx on bug46000(id);
drop table bug46000; drop table bug46000;
...@@ -7,24 +7,22 @@ ...@@ -7,24 +7,22 @@
# This 'create table' operation should fail because of # This 'create table' operation should fail because of
# using the reserve name as its index name. # using the reserve name as its index name.
--error ER_CANT_CREATE_TABLE --error ER_WRONG_NAME_FOR_INDEX
create table bug46000(`id` int,key `GEN_CLUST_INDEX`(`id`))engine=innodb; create table bug46000(`id` int,key `GEN_CLUST_INDEX`(`id`))engine=innodb;
# Mixed upper/lower case of the reserved key words # Mixed upper/lower case of the reserved key words
--error ER_CANT_CREATE_TABLE --error ER_WRONG_NAME_FOR_INDEX
create table bug46000(`id` int, key `GEN_clust_INDEX`(`id`))engine=innodb; create table bug46000(`id` int, key `GEN_clust_INDEX`(`id`))engine=innodb;
show errors; show warnings;
create table bug46000(id int) engine=innodb; create table bug46000(id int) engine=innodb;
# This 'create index' operation should fail. # This 'create index' operation should fail.
--replace_regex /'[^']*test.#sql-[0-9a-f_]*'/'#sql-temporary'/ --error ER_WRONG_NAME_FOR_INDEX
--error ER_CANT_CREATE_TABLE
create index GEN_CLUST_INDEX on bug46000(id); create index GEN_CLUST_INDEX on bug46000(id);
--replace_regex /'[^']*test.#sql-[0-9a-f_]*'/'#sql-temporary'/ show warnings;
show errors;
# This 'create index' operation should succeed, no # This 'create index' operation should succeed, no
# temp table left from last failed create index # temp table left from last failed create index
......
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