Commit 07d004c4 authored by marko's avatar marko

branches/zip: Reduce memory allocation and pointer indirection

in fast index creation.

innobase_create_index_def(), innobase_copy_index_def(): Copy to pre-allocated
space.

innobase_create_key_def(): Change the return type from merge_index_def_t**
to merge_index_def_t*.
parent f0c4bdbc
...@@ -7889,25 +7889,21 @@ innobase_create_index_field_def( ...@@ -7889,25 +7889,21 @@ innobase_create_index_field_def(
/*********************************************************************** /***********************************************************************
Create index definition for key */ Create index definition for key */
static static
merge_index_def_t* void
innobase_create_index_def( innobase_create_index_def(
/*======================*/ /*======================*/
/* out: Index definition */ KEY* key, /* in: key definition */
KEY* key, /* in: key definition */ bool new_primary, /* in: TRUE=generating
bool new_primary, /* in: TRUE=generating a new primary key */
a new primary key */ merge_index_def_t* index, /* out: index definition */
mem_heap_t* heap) /* in: heap where memory mem_heap_t* heap) /* in: heap where memory
is allocated */ is allocated */
{ {
ulint len; ulint len;
merge_index_def_t* index;
ulint n_fields = key->key_parts; ulint n_fields = key->key_parts;
DBUG_ENTER("innobase_create_index_def"); DBUG_ENTER("innobase_create_index_def");
index = (merge_index_def_t*) mem_heap_alloc_noninline(
heap, sizeof(merge_index_def_t));
index->fields = (merge_index_field_t*) mem_heap_alloc_noninline( index->fields = (merge_index_field_t*) mem_heap_alloc_noninline(
heap, n_fields * sizeof *index->fields); heap, n_fields * sizeof *index->fields);
...@@ -7938,7 +7934,7 @@ innobase_create_index_def( ...@@ -7938,7 +7934,7 @@ innobase_create_index_def(
&index->fields[i]); &index->fields[i]);
} }
DBUG_RETURN(index); DBUG_VOID_RETURN;
} }
/*********************************************************************** /***********************************************************************
...@@ -7965,21 +7961,18 @@ innobase_copy_index_field_def( ...@@ -7965,21 +7961,18 @@ innobase_copy_index_field_def(
/*********************************************************************** /***********************************************************************
Copy index definition for the index */ Copy index definition for the index */
static static
merge_index_def_t* void
innobase_copy_index_def( innobase_copy_index_def(
/*====================*/ /*====================*/
/* out: Index definition */ dict_index_t* index, /* in: index definition to copy */
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 memory is allocated */ mem_heap_t* heap) /* in: heap where allocated */
{ {
merge_index_def_t* new_index; ulint n_fields;
ulint n_fields; ulint i;
ulint i;
DBUG_ENTER("innobase_copy_index_def"); DBUG_ENTER("innobase_copy_index_def");
ut_a(index && heap);
if (!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.
...@@ -7991,9 +7984,6 @@ innobase_copy_index_def( ...@@ -7991,9 +7984,6 @@ innobase_copy_index_def(
n_fields = index->n_fields; n_fields = index->n_fields;
} }
new_index = (merge_index_def_t*) mem_heap_alloc_noninline(
heap, sizeof(merge_index_def_t));
new_index->fields = (merge_index_field_t*) mem_heap_alloc_noninline( new_index->fields = (merge_index_field_t*) mem_heap_alloc_noninline(
heap, n_fields * sizeof *new_index->fields); heap, n_fields * sizeof *new_index->fields);
...@@ -8006,7 +7996,7 @@ innobase_copy_index_def( ...@@ -8006,7 +7996,7 @@ innobase_copy_index_def(
&new_index->fields[i]); &new_index->fields[i]);
} }
DBUG_RETURN(new_index); DBUG_VOID_RETURN;
} }
/*********************************************************************** /***********************************************************************
...@@ -8026,7 +8016,7 @@ ENDIF ...@@ -8026,7 +8016,7 @@ ENDIF
*/ */
static static
merge_index_def_t** merge_index_def_t*
innobase_create_key_def( innobase_create_key_def(
/*====================*/ /*====================*/
/* out: key definitions or NULL */ /* out: key definitions or NULL */
...@@ -8039,8 +8029,8 @@ innobase_create_key_def( ...@@ -8039,8 +8029,8 @@ innobase_create_key_def(
be created */ be created */
{ {
ulint i = 0; ulint i = 0;
merge_index_def_t** indexdef; merge_index_def_t* indexdef;
merge_index_def_t** indexdefs; merge_index_def_t* indexdefs;
bool new_primary; bool new_primary;
DBUG_ENTER("innobase_create_key_def"); DBUG_ENTER("innobase_create_key_def");
...@@ -8048,10 +8038,9 @@ innobase_create_key_def( ...@@ -8048,10 +8038,9 @@ innobase_create_key_def(
/* We do not need to count the original primary key */ /* We do not need to count the original primary key */
const ulint n_indexes = n_keys + UT_LIST_GET_LEN(table->indexes) - 1; const ulint n_indexes = n_keys + UT_LIST_GET_LEN(table->indexes) - 1;
indexdef = indexdefs = (merge_index_def_t**) indexdef = indexdefs = (merge_index_def_t*)
mem_heap_alloc_noninline(heap, sizeof *indexdef * n_indexes); mem_heap_alloc_noninline(heap, sizeof *indexdef * n_indexes);
/* Primary key if defined is always the first index defined for /* Primary key if defined is always the first index defined for
the table */ the table */
...@@ -8062,8 +8051,8 @@ innobase_create_key_def( ...@@ -8062,8 +8051,8 @@ innobase_create_key_def(
dict_index_t* index; dict_index_t* index;
/* Create the PRIMARY key index definition */ /* Create the PRIMARY key index definition */
*indexdef = innobase_create_index_def(key_info, innobase_create_index_def(key_info, new_primary,
new_primary, heap); indexdef++, heap);
row_mysql_lock_data_dictionary(trx); row_mysql_lock_data_dictionary(trx);
...@@ -8074,13 +8063,11 @@ innobase_create_key_def( ...@@ -8074,13 +8063,11 @@ innobase_create_key_def(
/* Copy the definitions of old secondary indexes */ /* Copy the definitions of old secondary indexes */
++indexdef; /* Since we've copied the primary key info */
while (index) { while (index) {
ut_a(!dict_index_is_clust(index)); ut_a(!dict_index_is_clust(index));
*indexdef++ = innobase_copy_index_def(index, heap); innobase_copy_index_def(index, indexdef++, heap);
index = dict_table_get_next_index_noninline(index); index = dict_table_get_next_index_noninline(index);
} }
...@@ -8093,8 +8080,8 @@ innobase_create_key_def( ...@@ -8093,8 +8080,8 @@ innobase_create_key_def(
/* Create definitions for added secondary indexes. */ /* Create definitions for added secondary indexes. */
while (i < n_keys) { while (i < n_keys) {
*indexdef++ = innobase_create_index_def(&key_info[i++], innobase_create_index_def(&key_info[i++], new_primary,
new_primary, heap); indexdef++, heap);
} }
n_keys = indexdef - indexdefs; n_keys = indexdef - indexdefs;
...@@ -8140,7 +8127,7 @@ ha_innobase::add_index( ...@@ -8140,7 +8127,7 @@ ha_innobase::add_index(
dict_index_t** index; /* Index to be created */ dict_index_t** index; /* Index to be created */
dict_table_t* innodb_table; /* InnoDB table in dictionary */ dict_table_t* innodb_table; /* InnoDB table in dictionary */
dict_table_t* indexed_table; /* Table where indexes are created */ dict_table_t* indexed_table; /* Table where indexes are created */
merge_index_def_t** index_defs; /* Index definitions */ merge_index_def_t* index_defs; /* Index definitions */
mem_heap_t* heap; /* Heap for index definitions */ mem_heap_t* heap; /* Heap for index definitions */
trx_t* trx; /* Transaction */ trx_t* trx; /* Transaction */
trx_t* parent_trx; trx_t* parent_trx;
...@@ -8205,7 +8192,7 @@ ha_innobase::add_index( ...@@ -8205,7 +8192,7 @@ ha_innobase::add_index(
to drop all original secondary indexes from the table. These to drop all original secondary indexes from the table. These
indexes will be rebuilt below. */ indexes will be rebuilt below. */
new_primary = 0 != (DICT_CLUSTERED & index_defs[0]->ind_type); new_primary = 0 != (DICT_CLUSTERED & index_defs[0].ind_type);
if (new_primary) { if (new_primary) {
char* new_table_name = innobase_create_temporary_tablename( char* new_table_name = innobase_create_temporary_tablename(
...@@ -8250,14 +8237,14 @@ ha_innobase::add_index( ...@@ -8250,14 +8237,14 @@ ha_innobase::add_index(
for (ulint i = 0; i < num_of_idx; i++) { for (ulint i = 0; i < num_of_idx; i++) {
index[i] = row_merge_create_index(trx, indexed_table, index[i] = row_merge_create_index(trx, indexed_table,
index_defs[i]); &index_defs[i]);
if (!index[i]) { if (!index[i]) {
error = trx->error_state; error = trx->error_state;
goto error_handling; goto error_handling;
} }
if (index_defs[i]->ind_type & DICT_UNIQUE) { if (index_defs[i].ind_type & DICT_UNIQUE) {
new_unique = TRUE; new_unique = TRUE;
} }
......
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