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)) {
ut_print_timestamp(stderr);
fputs(" InnoDB: Error: index ", stderr);
ut_print_name(stderr, trx, FALSE, key->name);
fputs(" appears twice in create index\n",
stderr);
error = ER_WRONG_NAME_FOR_INDEX; if (0 == strcmp(key.name, key2.name)) {
sql_print_error("InnoDB: key name `%s` appears"
" twice in CREATE INDEX\n",
key.name);
return(error); return(ER_WRONG_NAME_FOR_INDEX);
} }
} }
...@@ -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.field;
ibool is_unsigned;
key_part1 = key->key_part + i; switch (get_innobase_type_from_mysql_type(
&is_unsigned, field)) {
field = key_part1->field; default:
break;
col_type = get_innobase_type_from_mysql_type( case DATA_INT:
&is_unsigned, field); case DATA_FLOAT:
case DATA_DOUBLE:
if (DATA_BLOB == col_type case DATA_DECIMAL:
|| (key_part1->length < field->pack_length() if (field->type() == MYSQL_TYPE_VARCHAR) {
&& field->type() != MYSQL_TYPE_VARCHAR) if (key_part1.length
|| (field->type() == MYSQL_TYPE_VARCHAR >= field->pack_length()
&& key_part1->length < field->pack_length() - ((Field_varstring*) field)
- ((Field_varstring*)field)->length_bytes)) { ->length_bytes) {
break;
if (col_type == DATA_INT }
|| col_type == DATA_FLOAT } else {
|| col_type == DATA_DOUBLE if (key_part1.length
|| col_type == DATA_DECIMAL) { >= field->pack_length()) {
fprintf(stderr, break;
"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;
} }
sql_print_error("InnoDB: MySQL is trying to"
" create a column prefix"
" index field on an"
" inappropriate data type."
" column `%s`,"
" index `%s`.\n",
field->field_name,
key.name);
return(ER_WRONG_KEY_COLUMN);
} }
for (ulint j = 0; j < i; j++) { for (ulint j = 0; j < i; j++) {
KEY_PART_INFO* key_part2; const KEY_PART_INFO& key_part2
= key.key_part[j];
key_part2 = key->key_part + j;
if (0 == strcmp(
key_part1->field->field_name,
key_part2->field->field_name)) {
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); if (strcmp(key_part1.field->field_name,
key_part2.field->field_name)) {
ut_print_name(stderr, trx, FALSE, continue;
key->name);
fputs("\n"
" InnoDB: This is not allowed in InnoDB.\n",
stderr);
error = ER_WRONG_KEY_COLUMN;
return(error);
} }
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