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(
mem_heap_t* heap) /* in: heap where memory
is allocated */
{
ulint i;
ulint len;
ulint n_fields = key->key_parts;
char* index_name;
DBUG_ENTER("innobase_create_index_def");
......@@ -8077,18 +8079,16 @@ innobase_create_index_def(
index->ind_type = 0;
index->n_fields = n_fields;
len = strlen(key->name) + 2;
index->name = (char *)mem_heap_alloc(heap, len);
--len;
len = strlen(key->name) + 1;
index->name = index_name = (char*) mem_heap_alloc(heap,
len + !new_primary);
if (UNIV_LIKELY(!new_primary)) {
*index->name = TEMP_TABLE_PREFIX;
memcpy(index->name + 1, key->name, len);
} else {
memcpy(index->name, key->name, len);
*index_name++ = TEMP_TABLE_PREFIX;
}
memcpy(index_name, key->name, len);
if (key->flags & HA_NOSAME) {
index->ind_type |= DICT_UNIQUE;
}
......@@ -8097,7 +8097,7 @@ innobase_create_index_def(
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,
&index->fields[i]);
}
......@@ -8112,14 +8112,13 @@ void
innobase_copy_index_field_def(
/*==========================*/
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 */
{
DBUG_ENTER("innobase_copy_index_field_def");
DBUG_ASSERT(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;
DBUG_VOID_RETURN;
......@@ -8131,7 +8130,7 @@ static
void
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 */
mem_heap_t* heap) /* in: heap where allocated */
{
......@@ -8139,27 +8138,24 @@ innobase_copy_index_def(
ulint i;
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
those fields that user defined to be in the index.
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;
} else {
n_fields = index->n_fields;
}
new_index->fields = (merge_index_field_t*) mem_heap_alloc(
heap, n_fields * sizeof *new_index->fields);
new_index->ind_type = index->type;
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++) {
innobase_copy_index_field_def(&index->fields[i], heap,
innobase_copy_index_field_def(&index->fields[i],
&new_index->fields[i]);
}
......@@ -8218,30 +8214,25 @@ innobase_create_key_def(
dict_index_t* index;
/* Create the PRIMARY key index definition */
innobase_create_index_def(key_info, new_primary,
indexdef++, heap);
innobase_create_index_def(key_info, TRUE, indexdef++, heap);
row_mysql_lock_data_dictionary(trx);
/* Skip the clustered index */
i = 1;
index = dict_table_get_next_index(
dict_table_get_first_index(table));
/* Copy the definitions of old secondary indexes */
/* Copy the definitions of secondary indexes */
while (index) {
ut_a(!dict_index_is_clust(index));
innobase_copy_index_def(index, indexdef++, heap);
index = dict_table_get_next_index(index);
}
row_mysql_unlock_data_dictionary(trx);
/* Skip the primary key */
i = 1;
}
/* Create definitions for added secondary indexes. */
......@@ -8376,7 +8367,8 @@ err_exit:
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);
goto err_exit;
}
......
......@@ -25,7 +25,7 @@ Created 13/06/2005 Jan Lindstrom
struct merge_index_field_struct {
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;
......@@ -33,9 +33,10 @@ typedef struct merge_index_field_struct merge_index_field_t;
/* This structure holds index definitions */
struct merge_index_def_struct {
const char* name; /* Index name */
ulint ind_type; /* 0, DICT_UNIQUE,
or DICT_CLUSTERED */
ulint n_fields; /* Number of fields in index */
ulint ind_type; /* 0, DICT_UNIQUE or DICT_CLUSTERED */
char* name; /* Index name */
merge_index_field_t* fields; /* Field definitions */
};
......@@ -125,12 +126,11 @@ row_merge_build_indexes(
/*====================*/
/* out: DB_SUCCESS or error code */
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 */
dict_table_t* new_table, /* in: Table where indexes are
created. Note that old_table ==
new_table if we are creating a
secondary keys. */
dict_table_t* new_table, /* in: table where indexes are
created; identical to old_table
unless creating a PRIMARY KEY */
dict_index_t** indexes, /* in: indexes to be created */
ulint n_indexes); /* in: size of indexes[] */
#endif /* row0merge.h */
......@@ -1665,10 +1665,9 @@ row_merge_drop_table(
dict_locked = TRUE;
}
ut_a(table->to_be_dropped);
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) {
/* Copy table->name, because table will have been
freed when row_drop_table_for_mysql_no_commit()
......@@ -1697,12 +1696,11 @@ row_merge_build_indexes(
/*====================*/
/* out: DB_SUCCESS or error code */
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 */
dict_table_t* new_table, /* in: Table where indexes are
created. Note that old_table ==
new_table if we are creating a
secondary keys. */
dict_table_t* new_table, /* in: table where indexes are
created; identical to old_table
unless creating a PRIMARY KEY */
dict_index_t** indexes, /* in: indexes to be created */
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