Commit fd1bd26b authored by osku's avatar osku

Remove dict_col_t::name, replace it with a packed array of column names in

dict_table_t. This saves 8-15+ bytes of memory per column on 64-bit
machines.
parent f77f36b2
...@@ -394,17 +394,26 @@ const char* ...@@ -394,17 +394,26 @@ const char*
dict_table_get_col_name( dict_table_get_col_name(
/*====================*/ /*====================*/
/* out: column name. NOTE: not /* out: column name. NOTE: not
guaranteed to stay valid if guaranteed to stay valid if table is
table is modified in any way modified in any way (columns added,
(columns added, etc.). */ etc.). */
const dict_table_t* table, /* in: table */ const dict_table_t* table, /* in: table */
ulint i) /* in: column number */ ulint col_nr) /* in: column number */
{ {
ulint i;
const char* s;
ut_ad(table); ut_ad(table);
ut_ad(i < table->n_def); ut_ad(col_nr < table->n_def);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
return(dict_table_get_nth_col(table, i)->name); s = table->col_names;
for (i = 0; i < col_nr; i++) {
s += strlen(s) + 1;
}
return(s);
} }
/************************************************************************ /************************************************************************
......
...@@ -66,6 +66,7 @@ dict_mem_table_create( ...@@ -66,6 +66,7 @@ dict_mem_table_create(
table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS) table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
* sizeof(dict_col_t)); * sizeof(dict_col_t));
table->col_names = NULL;
UT_LIST_INIT(table->indexes); UT_LIST_INIT(table->indexes);
table->auto_inc_lock = mem_heap_alloc(heap, lock_get_size()); table->auto_inc_lock = mem_heap_alloc(heap, lock_get_size());
...@@ -107,9 +108,74 @@ dict_mem_table_free( ...@@ -107,9 +108,74 @@ dict_mem_table_free(
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
mutex_free(&(table->autoinc_mutex)); mutex_free(&(table->autoinc_mutex));
if (table->col_names && (table->n_def < table->n_cols)) {
ut_free((void*)table->col_names);
}
mem_heap_free(table->heap); mem_heap_free(table->heap);
} }
/********************************************************************
Add 'name' to end of the col_names array (see dict_table_t::col_names). Call
ut_free on col_names (if not NULL), allocate new array (if heap, from it,
otherwise with ut_malloc), and copy col_names + name to it. */
static
const char*
dict_add_col_name(
/*==============*/
/* out: new column names array */
const char* col_names, /* in: existing column names, or
NULL */
ulint cols, /* in: number of existing columns */
const char* name, /* in: new column name */
mem_heap_t* heap) /* in: heap, or NULL */
{
ulint i;
ulint old_len;
ulint new_len;
ulint total_len;
const char* s;
char* res;
ut_a(((cols == 0) && !col_names) || ((cols > 0) && col_names));
ut_a(*name);
/* Find out length of existing array. */
if (col_names) {
s = col_names;
for (i = 0; i < cols; i++) {
s += strlen(s) + 1;
}
old_len = s - col_names;
} else {
old_len = 0;
}
new_len = strlen(name) + 1;
total_len = old_len + new_len;
if (heap) {
res = mem_heap_alloc(heap, total_len);
} else {
res = ut_malloc(total_len);
}
if (old_len > 0) {
memcpy(res, col_names, old_len);
}
memcpy(res + old_len, name, new_len);
if (col_names) {
ut_free((char*)col_names);
}
return(res);
}
/************************************************************************** /**************************************************************************
Adds a column definition to a table. */ Adds a column definition to a table. */
...@@ -125,16 +191,21 @@ dict_mem_table_add_col( ...@@ -125,16 +191,21 @@ dict_mem_table_add_col(
dict_col_t* col; dict_col_t* col;
ulint mbminlen; ulint mbminlen;
ulint mbmaxlen; ulint mbmaxlen;
mem_heap_t* heap;
ut_ad(table && name); ut_ad(table && name);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
table->n_def++; table->n_def++;
heap = table->n_def < table->n_cols ? NULL : table->heap;
table->col_names = dict_add_col_name(table->col_names,
table->n_def - 1,
name, heap);
col = (dict_col_t*) dict_table_get_nth_col(table, table->n_def - 1); col = (dict_col_t*) dict_table_get_nth_col(table, table->n_def - 1);
col->ind = table->n_def - 1; col->ind = table->n_def - 1;
col->name = mem_heap_strdup(table->heap, name);
col->ord_part = 0; col->ord_part = 0;
col->mtype = mtype; col->mtype = mtype;
......
...@@ -413,11 +413,12 @@ const char* ...@@ -413,11 +413,12 @@ const char*
dict_table_get_col_name( dict_table_get_col_name(
/*====================*/ /*====================*/
/* out: column name. NOTE: not /* out: column name. NOTE: not
guaranteed to stay valid if guaranteed to stay valid if table is
table is modified in any way modified in any way (columns added,
(columns added, etc.). */ etc.). */
const dict_table_t* table, /* in: table */ const dict_table_t* table, /* in: table */
ulint i); /* in: column number */ ulint col_nr);/* in: column number */
/************************************************************************** /**************************************************************************
Prints a table definition. */ Prints a table definition. */
......
...@@ -156,8 +156,6 @@ struct dict_col_struct{ ...@@ -156,8 +156,6 @@ struct dict_col_struct{
unsigned ord_part:1; /* nonzero if this column unsigned ord_part:1; /* nonzero if this column
appears in the ordering fields appears in the ordering fields
of an index */ of an index */
const char* name; /* name */
}; };
/* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column /* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column
...@@ -312,6 +310,12 @@ struct dict_table_struct{ ...@@ -312,6 +310,12 @@ struct dict_table_struct{
unsigned n_def:10;/* number of columns defined so far */ unsigned n_def:10;/* number of columns defined so far */
unsigned n_cols:10;/* number of columns */ unsigned n_cols:10;/* number of columns */
dict_col_t* cols; /* array of column descriptions */ dict_col_t* cols; /* array of column descriptions */
const char* col_names;
/* n_def column names packed in an
"name1\0name2\0...nameN\0" array. until
n_def reaches n_cols, this is allocated with
ut_malloc, and the final size array is
allocated through the table's heap. */
hash_node_t name_hash; /* hash chain node */ hash_node_t name_hash; /* hash chain node */
hash_node_t id_hash; /* hash chain node */ hash_node_t id_hash; /* hash chain node */
UT_LIST_BASE_NODE_T(dict_index_t) UT_LIST_BASE_NODE_T(dict_index_t)
......
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