Commit f304ce10 authored by marko's avatar marko

branches/zip: Minor cleanup.

innobase_copy_index_field_def(): Remove parameter heap.  The field->name
will not be deallocated before the copied index has been added to the
data dictionary cache.

innobase_copy_index_def(): Add const qualifier to dict_index_t*.
Add an assertion !dict_index_is_clust(index).

ha_innobase::add_index(): Add the missing user_thd parameter to the
convert_error_code_to_mysql() call that was forgotten from r1686.

merge_index_field_struct: Add const qualifier to field_name.

merge_index_def_struct: Add const qualifier to name.

row_merge_build_indexes(): Improve the function comment.

row_merge_drop_table(): Remove bogus assertion ut_a(table->to_be_dropped).
parent 992f5be1
...@@ -8067,8 +8067,10 @@ innobase_create_index_def( ...@@ -8067,8 +8067,10 @@ innobase_create_index_def(
mem_heap_t* heap) /* in: heap where memory mem_heap_t* heap) /* in: heap where memory
is allocated */ is allocated */
{ {
ulint len; ulint i;
ulint n_fields = key->key_parts; ulint len;
ulint n_fields = key->key_parts;
char* index_name;
DBUG_ENTER("innobase_create_index_def"); DBUG_ENTER("innobase_create_index_def");
...@@ -8077,18 +8079,16 @@ innobase_create_index_def( ...@@ -8077,18 +8079,16 @@ innobase_create_index_def(
index->ind_type = 0; index->ind_type = 0;
index->n_fields = n_fields; index->n_fields = n_fields;
len = strlen(key->name) + 2; len = strlen(key->name) + 1;
index->name = (char *)mem_heap_alloc(heap, len); index->name = index_name = (char*) mem_heap_alloc(heap,
len + !new_primary);
--len;
if (UNIV_LIKELY(!new_primary)) { if (UNIV_LIKELY(!new_primary)) {
*index->name = TEMP_TABLE_PREFIX; *index_name++ = TEMP_TABLE_PREFIX;
memcpy(index->name + 1, key->name, len);
} else {
memcpy(index->name, key->name, len);
} }
memcpy(index_name, key->name, len);
if (key->flags & HA_NOSAME) { if (key->flags & HA_NOSAME) {
index->ind_type |= DICT_UNIQUE; index->ind_type |= DICT_UNIQUE;
} }
...@@ -8097,7 +8097,7 @@ innobase_create_index_def( ...@@ -8097,7 +8097,7 @@ innobase_create_index_def(
index->ind_type |= DICT_CLUSTERED; index->ind_type |= DICT_CLUSTERED;
} }
for (ulint i = 0; i < n_fields; i++) { for (i = 0; i < n_fields; i++) {
innobase_create_index_field_def(&key->key_part[i], heap, innobase_create_index_field_def(&key->key_part[i], heap,
&index->fields[i]); &index->fields[i]);
} }
...@@ -8112,14 +8112,13 @@ void ...@@ -8112,14 +8112,13 @@ void
innobase_copy_index_field_def( innobase_copy_index_field_def(
/*==========================*/ /*==========================*/
const dict_field_t* field, /* in: definition to copy */ const dict_field_t* field, /* in: definition to copy */
mem_heap_t* heap, /* in: memory heap */
merge_index_field_t* index_field) /* out: copied definition */ merge_index_field_t* index_field) /* out: copied definition */
{ {
DBUG_ENTER("innobase_copy_index_field_def"); DBUG_ENTER("innobase_copy_index_field_def");
DBUG_ASSERT(field != NULL); DBUG_ASSERT(field != NULL);
DBUG_ASSERT(index_field != NULL); DBUG_ASSERT(index_field != NULL);
index_field->field_name = mem_heap_strdup(heap, field->name); index_field->field_name = field->name;
index_field->prefix_len = field->prefix_len; index_field->prefix_len = field->prefix_len;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -8131,7 +8130,7 @@ static ...@@ -8131,7 +8130,7 @@ static
void void
innobase_copy_index_def( innobase_copy_index_def(
/*====================*/ /*====================*/
dict_index_t* index, /* in: index definition to copy */ const dict_index_t* index, /* in: index definition to copy */
merge_index_def_t* new_index,/* out: Index definition */ merge_index_def_t* new_index,/* out: Index definition */
mem_heap_t* heap) /* in: heap where allocated */ mem_heap_t* heap) /* in: heap where allocated */
{ {
...@@ -8139,27 +8138,24 @@ innobase_copy_index_def( ...@@ -8139,27 +8138,24 @@ innobase_copy_index_def(
ulint i; ulint i;
DBUG_ENTER("innobase_copy_index_def"); DBUG_ENTER("innobase_copy_index_def");
DBUG_ASSERT(!dict_index_is_clust(index));
if (!dict_index_is_clust(index)) { /* Note that from the secondary index we take only
/* Note that from the secondary index we take only those fields that user defined to be in the index.
those fields that user defined to be in the index. In the internal representation more colums were
In the internal representation more colums were added and those colums are not copied .*/
added and those colums are not copied.*/
n_fields = index->n_user_defined_cols; n_fields = index->n_user_defined_cols;
} else {
n_fields = index->n_fields;
}
new_index->fields = (merge_index_field_t*) mem_heap_alloc( new_index->fields = (merge_index_field_t*) mem_heap_alloc(
heap, n_fields * sizeof *new_index->fields); heap, n_fields * sizeof *new_index->fields);
new_index->ind_type = index->type; new_index->ind_type = index->type;
new_index->n_fields = n_fields; new_index->n_fields = n_fields;
new_index->name = mem_heap_strdup(heap, index->name); new_index->name = index->name;
for (i = 0; i < n_fields; i++) { for (i = 0; i < n_fields; i++) {
innobase_copy_index_field_def(&index->fields[i], heap, innobase_copy_index_field_def(&index->fields[i],
&new_index->fields[i]); &new_index->fields[i]);
} }
...@@ -8218,30 +8214,25 @@ innobase_create_key_def( ...@@ -8218,30 +8214,25 @@ innobase_create_key_def(
dict_index_t* index; dict_index_t* index;
/* Create the PRIMARY key index definition */ /* Create the PRIMARY key index definition */
innobase_create_index_def(key_info, new_primary, innobase_create_index_def(key_info, TRUE, indexdef++, heap);
indexdef++, heap);
row_mysql_lock_data_dictionary(trx); row_mysql_lock_data_dictionary(trx);
/* Skip the clustered index */ /* Skip the clustered index */
i = 1;
index = dict_table_get_next_index( index = dict_table_get_next_index(
dict_table_get_first_index(table)); dict_table_get_first_index(table));
/* Copy the definitions of old secondary indexes */ /* Copy the definitions of secondary indexes */
while (index) { while (index) {
ut_a(!dict_index_is_clust(index));
innobase_copy_index_def(index, indexdef++, heap); innobase_copy_index_def(index, indexdef++, heap);
index = dict_table_get_next_index(index); index = dict_table_get_next_index(index);
} }
row_mysql_unlock_data_dictionary(trx); row_mysql_unlock_data_dictionary(trx);
/* Skip the primary key */
i = 1;
} }
/* Create definitions for added secondary indexes. */ /* Create definitions for added secondary indexes. */
...@@ -8376,7 +8367,8 @@ err_exit: ...@@ -8376,7 +8367,8 @@ err_exit:
if (!indexed_table) { if (!indexed_table) {
error = convert_error_code_to_mysql(trx->error_state); 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;
} }
......
...@@ -24,8 +24,8 @@ Created 13/06/2005 Jan Lindstrom ...@@ -24,8 +24,8 @@ Created 13/06/2005 Jan Lindstrom
/* This structure holds index field definitions */ /* This structure holds index field definitions */
struct merge_index_field_struct { struct merge_index_field_struct {
ulint prefix_len; /* Prefix len */ ulint prefix_len; /* Prefix len */
char* field_name; /* Field name */ const char* field_name; /* Field name */
}; };
typedef struct merge_index_field_struct merge_index_field_t; typedef struct merge_index_field_struct merge_index_field_t;
...@@ -33,10 +33,11 @@ typedef struct merge_index_field_struct merge_index_field_t; ...@@ -33,10 +33,11 @@ typedef struct merge_index_field_struct merge_index_field_t;
/* This structure holds index definitions */ /* This structure holds index definitions */
struct merge_index_def_struct { struct merge_index_def_struct {
ulint n_fields; /* Number of fields in index */ const char* name; /* Index name */
ulint ind_type; /* 0, DICT_UNIQUE or DICT_CLUSTERED */ ulint ind_type; /* 0, DICT_UNIQUE,
char* name; /* Index name */ or DICT_CLUSTERED */
merge_index_field_t* fields; /* Field definitions */ ulint n_fields; /* Number of fields in index */
merge_index_field_t* fields; /* Field definitions */
}; };
typedef struct merge_index_def_struct merge_index_def_t; typedef struct merge_index_def_struct merge_index_def_t;
...@@ -125,12 +126,11 @@ row_merge_build_indexes( ...@@ -125,12 +126,11 @@ row_merge_build_indexes(
/*====================*/ /*====================*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
trx_t* trx, /* in: transaction */ trx_t* trx, /* in: transaction */
dict_table_t* old_table, /* in: Table where rows are dict_table_t* old_table, /* in: table where rows are
read from */ read from */
dict_table_t* new_table, /* in: Table where indexes are dict_table_t* new_table, /* in: table where indexes are
created. Note that old_table == created; identical to old_table
new_table if we are creating a unless creating a PRIMARY KEY */
secondary keys. */
dict_index_t** indexes, /* in: indexes to be created */ dict_index_t** indexes, /* in: indexes to be created */
ulint n_indexes); /* in: size of indexes[] */ ulint n_indexes); /* in: size of indexes[] */
#endif /* row0merge.h */ #endif /* row0merge.h */
...@@ -1665,10 +1665,9 @@ row_merge_drop_table( ...@@ -1665,10 +1665,9 @@ row_merge_drop_table(
dict_locked = TRUE; dict_locked = TRUE;
} }
ut_a(table->to_be_dropped);
ut_a(*table->name == TEMP_TABLE_PREFIX); ut_a(*table->name == TEMP_TABLE_PREFIX);
/* Drop the table immediately iff it is not references by MySQL */ /* Drop the table immediately if it is not referenced by MySQL */
if (table->n_mysql_handles_opened == 0) { if (table->n_mysql_handles_opened == 0) {
/* Copy table->name, because table will have been /* Copy table->name, because table will have been
freed when row_drop_table_for_mysql_no_commit() freed when row_drop_table_for_mysql_no_commit()
...@@ -1697,12 +1696,11 @@ row_merge_build_indexes( ...@@ -1697,12 +1696,11 @@ row_merge_build_indexes(
/*====================*/ /*====================*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
trx_t* trx, /* in: transaction */ trx_t* trx, /* in: transaction */
dict_table_t* old_table, /* in: Table where rows are dict_table_t* old_table, /* in: table where rows are
read from */ read from */
dict_table_t* new_table, /* in: Table where indexes are dict_table_t* new_table, /* in: table where indexes are
created. Note that old_table == created; identical to old_table
new_table if we are creating a unless creating a PRIMARY KEY */
secondary keys. */
dict_index_t** indexes, /* in: indexes to be created */ dict_index_t** indexes, /* in: indexes to be created */
ulint n_indexes) /* in: size of indexes[] */ ulint n_indexes) /* in: size of indexes[] */
{ {
......
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