~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/dict/dict0mem.c

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
40
40
#define DICT_HEAP_SIZE          100     /*!< initial memory heap size when
41
41
                                        creating a table or index object */
42
42
 
43
 
#ifdef UNIV_PFS_MUTEX
44
 
/* Key to register autoinc_mutex with performance schema */
45
 
UNIV_INTERN mysql_pfs_key_t     autoinc_mutex_key;
46
 
#endif /* UNIV_PFS_MUTEX */
47
 
 
48
43
/**********************************************************************//**
49
44
Creates a table memory object.
50
45
@return own: table object */
64
59
        mem_heap_t*     heap;
65
60
 
66
61
        ut_ad(name);
67
 
        ut_a(!(flags & (SIZE_MAX << DICT_TF2_BITS)));
 
62
        ut_a(!(flags & (~0 << DICT_TF2_BITS)));
68
63
 
69
64
        heap = mem_heap_create(DICT_HEAP_SIZE);
70
65
 
71
 
        table = static_cast<dict_table_struct *>(mem_heap_zalloc(heap, sizeof(dict_table_t)));
 
66
        table = mem_heap_zalloc(heap, sizeof(dict_table_t));
72
67
 
73
68
        table->heap = heap;
74
69
 
75
70
        table->flags = (unsigned int) flags;
76
 
        table->name = static_cast<char *>(ut_malloc(strlen(name) + 1));
77
 
        memcpy(table->name, name, strlen(name) + 1);
 
71
        table->name = mem_heap_strdup(heap, name);
78
72
        table->space = (unsigned int) space;
79
73
        table->n_cols = (unsigned int) (n_cols + DATA_N_SYS_COLS);
80
74
 
81
 
        table->cols = static_cast<dict_col_t *>(mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
82
 
                                     * sizeof(dict_col_t)));
 
75
        table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
 
76
                                     * sizeof(dict_col_t));
83
77
 
84
78
#ifndef UNIV_HOTBACKUP
85
 
        table->autoinc_lock = static_cast<lock_t *>(mem_heap_alloc(heap, lock_get_size()));
 
79
        table->autoinc_lock = mem_heap_alloc(heap, lock_get_size());
86
80
 
87
 
        mutex_create(autoinc_mutex_key,
88
 
                     &table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
 
81
        mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
89
82
 
90
83
        table->autoinc = 0;
91
84
 
113
106
#ifndef UNIV_HOTBACKUP
114
107
        mutex_free(&(table->autoinc_mutex));
115
108
#endif /* UNIV_HOTBACKUP */
116
 
        ut_free(table->name);
117
109
        mem_heap_free(table->heap);
118
110
}
119
111
 
154
146
        new_len = strlen(name) + 1;
155
147
        total_len = old_len + new_len;
156
148
 
157
 
        res = static_cast<char *>(mem_heap_alloc(heap, total_len));
 
149
        res = mem_heap_alloc(heap, total_len);
158
150
 
159
151
        if (old_len > 0) {
160
152
                memcpy(res, col_names, old_len);
179
171
        ulint           len)    /*!< in: precision */
180
172
{
181
173
        dict_col_t*     col;
 
174
#ifndef UNIV_HOTBACKUP
 
175
        ulint           mbminlen;
 
176
        ulint           mbmaxlen;
 
177
#endif /* !UNIV_HOTBACKUP */
182
178
        ulint           i;
183
179
 
184
180
        ut_ad(table);
193
189
                }
194
190
                if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
195
191
                        /* All preceding column names are empty. */
196
 
                        char* s = static_cast<char *>(mem_heap_zalloc(heap, table->n_def));
 
192
                        char* s = mem_heap_zalloc(heap, table->n_def);
197
193
                        table->col_names = s;
198
194
                }
199
195
 
203
199
 
204
200
        col = dict_table_get_nth_col(table, i);
205
201
 
206
 
        dict_mem_fill_column_struct(col, i, mtype, prtype, len);
207
 
}
208
 
 
209
 
 
210
 
/**********************************************************************//**
211
 
This function populates a dict_col_t memory structure with
212
 
supplied information. */
213
 
UNIV_INTERN
214
 
void
215
 
dict_mem_fill_column_struct(
216
 
/*========================*/
217
 
        dict_col_t*     column,         /*!< out: column struct to be
218
 
                                        filled */
219
 
        ulint           col_pos,        /*!< in: column position */
220
 
        ulint           mtype,          /*!< in: main data type */
221
 
        ulint           prtype,         /*!< in: precise type */
222
 
        ulint           col_len)        /*!< in: column length */
223
 
{
224
 
#ifndef UNIV_HOTBACKUP
225
 
        ulint   mbminlen;
226
 
        ulint   mbmaxlen;
227
 
#endif /* !UNIV_HOTBACKUP */
228
 
 
229
 
        column->ind = (unsigned int) col_pos;
230
 
        column->ord_part = 0;
231
 
        column->mtype = (unsigned int) mtype;
232
 
        column->prtype = (unsigned int) prtype;
233
 
        column->len = (unsigned int) col_len;
234
 
#ifndef UNIV_HOTBACKUP
235
 
        dtype_get_mblen(mtype, prtype, &mbminlen, &mbmaxlen);
236
 
        dict_col_set_mbminmaxlen(column, mbminlen, mbmaxlen);
 
202
        col->ind = (unsigned int) i;
 
203
        col->ord_part = 0;
 
204
 
 
205
        col->mtype = (unsigned int) mtype;
 
206
        col->prtype = (unsigned int) prtype;
 
207
        col->len = (unsigned int) len;
 
208
 
 
209
#ifndef UNIV_HOTBACKUP
 
210
        dtype_get_mblen(mtype, prtype, &mbminlen, &mbmaxlen);
 
211
 
 
212
        col->mbminlen = (unsigned int) mbminlen;
 
213
        col->mbmaxlen = (unsigned int) mbmaxlen;
237
214
#endif /* !UNIV_HOTBACKUP */
238
215
}
239
216
 
259
236
        ut_ad(table_name && index_name);
260
237
 
261
238
        heap = mem_heap_create(DICT_HEAP_SIZE);
262
 
        index = static_cast<dict_index_t *>(mem_heap_zalloc(heap, sizeof(dict_index_t)));
263
 
 
264
 
        dict_mem_fill_index_struct(index, heap, table_name, index_name,
265
 
                                   space, type, n_fields);
266
 
 
 
239
        index = mem_heap_zalloc(heap, sizeof(dict_index_t));
 
240
 
 
241
        index->heap = heap;
 
242
 
 
243
        index->type = type;
 
244
#ifndef UNIV_HOTBACKUP
 
245
        index->space = (unsigned int) space;
 
246
#endif /* !UNIV_HOTBACKUP */
 
247
        index->name = mem_heap_strdup(heap, index_name);
 
248
        index->table_name = table_name;
 
249
        index->n_fields = (unsigned int) n_fields;
 
250
        index->fields = mem_heap_alloc(heap, 1 + n_fields
 
251
                                       * sizeof(dict_field_t));
 
252
        /* The '1 +' above prevents allocation
 
253
        of an empty mem block */
 
254
#ifdef UNIV_DEBUG
 
255
        index->magic_n = DICT_INDEX_MAGIC_N;
 
256
#endif /* UNIV_DEBUG */
267
257
        return(index);
268
258
}
269
259
 
280
270
 
281
271
        heap = mem_heap_create(100);
282
272
 
283
 
        foreign = static_cast<dict_foreign_t *>(mem_heap_zalloc(heap, sizeof(dict_foreign_t)));
 
273
        foreign = mem_heap_zalloc(heap, sizeof(dict_foreign_t));
284
274
 
285
275
        foreign->heap = heap;
286
276