Commit 388af7a7 authored by marko's avatar marko

branches/zip: Minor cleanup of fast index creation diagnostics.

innobase_check_index_keys(): Remove unused parameters.  Use
sql_print_error() for error message output.

ha_innobase::add_index(): When row_merge_rename_tables() fails, do not
allow row_merge_drop_table() to alter the error code returned to MySQL.
parent 9194c3a9
/****************************************************** /******************************************************
Smart ALTER TABLE Smart ALTER TABLE
(c) 2005-2007 Innobase Oy (c) 2005-2008 Innobase Oy
*******************************************************/ *******************************************************/
#include <mysql_priv.h> #include <mysql_priv.h>
...@@ -212,44 +212,30 @@ int ...@@ -212,44 +212,30 @@ int
innobase_check_index_keys( innobase_check_index_keys(
/*======================*/ /*======================*/
/* out: 0 or error number */ /* out: 0 or error number */
TABLE* table, /* in: MySQL table */ const KEY* key_info, /* in: Indexes to be created */
dict_table_t* innodb_table, /* in: InnoDB table */
trx_t* trx, /* in: transaction */
KEY* key_info, /* in: Indexes to be created */
ulint num_of_keys) /* in: Number of indexes to ulint num_of_keys) /* in: Number of indexes to
be created */ be created */
{ {
Field* field;
ulint key_num; ulint key_num;
int error = 0;
ibool is_unsigned;
ut_ad(table && innodb_table && trx && key_info && num_of_keys); ut_ad(key_info);
ut_ad(num_of_keys);
for (key_num = 0; key_num < num_of_keys; key_num++) { for (key_num = 0; key_num < num_of_keys; key_num++) {
KEY* key; const KEY& key = key_info[key_num];
key = &(key_info[key_num]);
/* Check that the same index name does not appear /* Check that the same index name does not appear
twice in indexes to be created. */ twice in indexes to be created. */
for (ulint i = 0; i < key_num; i++) { for (ulint i = 0; i < key_num; i++) {
KEY* key2; const KEY& key2 = key_info[i];
key2 = &key_info[i];
if (0 == strcmp(key->name, key2->name)) { if (0 == strcmp(key.name, key2.name)) {
ut_print_timestamp(stderr); sql_print_error("InnoDB: key name `%s` appears"
" twice in CREATE INDEX\n",
key.name);
fputs(" InnoDB: Error: index ", stderr); return(ER_WRONG_NAME_FOR_INDEX);
ut_print_name(stderr, trx, FALSE, key->name);
fputs(" appears twice in create index\n",
stderr);
error = ER_WRONG_NAME_FOR_INDEX;
return(error);
} }
} }
...@@ -257,73 +243,66 @@ innobase_check_index_keys( ...@@ -257,73 +243,66 @@ innobase_check_index_keys(
prefix index field on an inappropriate data type and prefix index field on an inappropriate data type and
that the same colum does not appear twice in the index. */ that the same colum does not appear twice in the index. */
for (ulint i = 0; i < key->key_parts; i++) { for (ulint i = 0; i < key.key_parts; i++) {
KEY_PART_INFO* key_part1; const KEY_PART_INFO& key_part1
ulint col_type; /* Column type */ = key.key_part[i];
const Field* field
key_part1 = key->key_part + i; = key_part1.field;
ibool is_unsigned;
field = key_part1->field;
col_type = get_innobase_type_from_mysql_type(
&is_unsigned, field);
if (DATA_BLOB == col_type
|| (key_part1->length < field->pack_length()
&& field->type() != MYSQL_TYPE_VARCHAR)
|| (field->type() == MYSQL_TYPE_VARCHAR
&& key_part1->length < field->pack_length()
- ((Field_varstring*)field)->length_bytes)) {
if (col_type == DATA_INT
|| col_type == DATA_FLOAT
|| col_type == DATA_DOUBLE
|| col_type == DATA_DECIMAL) {
fprintf(stderr,
"InnoDB: error: MySQL is trying to create a column prefix index field\n"
"InnoDB: on an inappropriate data type. Table name %s, column name %s.\n",
innodb_table->name,
field->field_name);
error = ER_WRONG_KEY_COLUMN; switch (get_innobase_type_from_mysql_type(
&is_unsigned, field)) {
default:
break;
case DATA_INT:
case DATA_FLOAT:
case DATA_DOUBLE:
case DATA_DECIMAL:
if (field->type() == MYSQL_TYPE_VARCHAR) {
if (key_part1.length
>= field->pack_length()
- ((Field_varstring*) field)
->length_bytes) {
break;
}
} else {
if (key_part1.length
>= field->pack_length()) {
break;
} }
} }
for (ulint j = 0; j < i; j++) { sql_print_error("InnoDB: MySQL is trying to"
KEY_PART_INFO* key_part2; " create a column prefix"
" index field on an"
key_part2 = key->key_part + j; " inappropriate data type."
" column `%s`,"
if (0 == strcmp( " index `%s`.\n",
key_part1->field->field_name, field->field_name,
key_part2->field->field_name)) { key.name);
return(ER_WRONG_KEY_COLUMN);
ut_print_timestamp(stderr); }
fputs(" InnoDB: Error: column ",
stderr);
ut_print_name(stderr, trx, FALSE,
key_part1->field->field_name);
fputs(" appears twice in ", stderr);
ut_print_name(stderr, trx, FALSE,
key->name);
fputs("\n"
" InnoDB: This is not allowed in InnoDB.\n",
stderr);
error = ER_WRONG_KEY_COLUMN; for (ulint j = 0; j < i; j++) {
const KEY_PART_INFO& key_part2
= key.key_part[j];
return(error); if (strcmp(key_part1.field->field_name,
key_part2.field->field_name)) {
continue;
} }
sql_print_error("InnoDB: column `%s`"
" is not allowed to occur"
" twice in index `%s`.\n",
key_part1.field->field_name,
key.name);
return(ER_WRONG_KEY_COLUMN);
} }
} }
} }
return(error); return(0);
} }
/*********************************************************************** /***********************************************************************
...@@ -667,8 +646,7 @@ ha_innobase::add_index( ...@@ -667,8 +646,7 @@ ha_innobase::add_index(
/* Check that index keys are sensible */ /* Check that index keys are sensible */
error = innobase_check_index_keys( error = innobase_check_index_keys(key_info, num_of_keys);
table, innodb_table, trx, key_info, num_of_keys);
if (UNIV_UNLIKELY(error)) { if (UNIV_UNLIKELY(error)) {
err_exit: err_exit:
...@@ -860,8 +838,7 @@ ha_innobase::add_index( ...@@ -860,8 +838,7 @@ ha_innobase::add_index(
error = HA_ERR_TABLE_EXIST; error = HA_ERR_TABLE_EXIST;
break; break;
default: default:
error = convert_error_code_to_mysql( goto convert_error;
trx->error_state, user_thd);
} }
break; break;
} }
......
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