~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Imported InnoDB plugin with changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
/**************************************************************************
27
27
Creates a table memory object. */
28
 
 
 
28
UNIV_INTERN
29
29
dict_table_t*
30
30
dict_mem_table_create(
31
31
/*==================*/
42
42
        mem_heap_t*     heap;
43
43
 
44
44
        ut_ad(name);
45
 
        ut_ad(!(flags & ~DICT_TF_COMPACT));
 
45
        ut_a(!(flags & (~0 << DICT_TF_BITS)));
46
46
 
47
47
        heap = mem_heap_create(DICT_HEAP_SIZE);
48
48
 
49
 
        table = mem_heap_alloc(heap, sizeof(dict_table_t));
 
49
        table = mem_heap_zalloc(heap, sizeof(dict_table_t));
50
50
 
51
51
        table->heap = heap;
52
52
 
53
53
        table->flags = (unsigned int) flags;
54
54
        table->name = mem_heap_strdup(heap, name);
55
 
        table->dir_path_of_temp_table = NULL;
56
55
        table->space = (unsigned int) space;
57
 
        table->ibd_file_missing = FALSE;
58
 
        table->tablespace_discarded = FALSE;
59
 
        table->n_def = 0;
60
56
        table->n_cols = (unsigned int) (n_cols + DATA_N_SYS_COLS);
61
57
 
62
 
        table->n_mysql_handles_opened = 0;
63
 
        table->n_foreign_key_checks_running = 0;
64
 
 
65
 
        table->cached = FALSE;
66
 
 
67
58
        table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
68
59
                                     * sizeof(dict_col_t));
69
 
        table->col_names = NULL;
70
 
        UT_LIST_INIT(table->indexes);
71
60
 
72
61
        table->auto_inc_lock = mem_heap_alloc(heap, lock_get_size());
73
62
 
74
 
        table->query_cache_inv_trx_id = ut_dulint_zero;
75
 
 
76
 
        UT_LIST_INIT(table->locks);
77
 
        UT_LIST_INIT(table->foreign_list);
78
 
        UT_LIST_INIT(table->referenced_list);
79
 
 
80
 
#ifdef UNIV_DEBUG
81
 
        table->does_not_fit_in_memory = FALSE;
82
 
#endif /* UNIV_DEBUG */
83
 
 
84
 
        table->stat_initialized = FALSE;
85
 
 
86
 
        table->stat_modified_counter = 0;
87
 
 
88
 
        table->big_rows = 0;
89
 
 
90
63
        mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
91
64
 
92
 
        table->autoinc_inited = FALSE;
93
 
 
94
65
        /* The actual increment value will be set by MySQL, we simply
95
66
        default to 1 here.*/
96
67
        table->autoinc_increment = 1;
97
68
 
98
 
        /* The number of transactions that are either waiting on the
99
 
        AUTOINC lock or have been granted the lock. */
100
 
        table->n_waiting_or_granted_auto_inc_locks = 0;
101
 
 
102
69
#ifdef UNIV_DEBUG
103
70
        table->magic_n = DICT_TABLE_MAGIC_N;
104
71
#endif /* UNIV_DEBUG */
107
74
 
108
75
/********************************************************************
109
76
Free a table memory object. */
110
 
 
 
77
UNIV_INTERN
111
78
void
112
79
dict_mem_table_free(
113
80
/*================*/
170
137
 
171
138
/**************************************************************************
172
139
Adds a column definition to a table. */
173
 
 
 
140
UNIV_INTERN
174
141
void
175
142
dict_mem_table_add_col(
176
143
/*===================*/
198
165
                }
199
166
                if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
200
167
                        /* All preceding column names are empty. */
201
 
                        char* s = mem_heap_alloc(heap, table->n_def);
202
 
                        memset(s, 0, table->n_def);
 
168
                        char* s = mem_heap_zalloc(heap, table->n_def);
203
169
                        table->col_names = s;
204
170
                }
205
171
 
207
173
                                                     i, name, heap);
208
174
        }
209
175
 
210
 
        col = (dict_col_t*) dict_table_get_nth_col(table, i);
 
176
        col = dict_table_get_nth_col(table, i);
211
177
 
212
178
        col->ind = (unsigned int) i;
213
179
        col->ord_part = 0;
224
190
 
225
191
/**************************************************************************
226
192
Creates an index memory object. */
227
 
 
 
193
UNIV_INTERN
228
194
dict_index_t*
229
195
dict_mem_index_create(
230
196
/*==================*/
244
210
        ut_ad(table_name && index_name);
245
211
 
246
212
        heap = mem_heap_create(DICT_HEAP_SIZE);
247
 
        index = mem_heap_alloc(heap, sizeof(dict_index_t));
 
213
        index = mem_heap_zalloc(heap, sizeof(dict_index_t));
248
214
 
249
215
        index->heap = heap;
250
216
 
251
217
        index->type = type;
252
218
        index->space = (unsigned int) space;
253
 
        index->page = 0;
254
219
        index->name = mem_heap_strdup(heap, index_name);
255
220
        index->table_name = table_name;
256
 
        index->table = NULL;
257
 
        index->n_def = index->n_nullable = 0;
258
221
        index->n_fields = (unsigned int) n_fields;
259
222
        index->fields = mem_heap_alloc(heap, 1 + n_fields
260
223
                                       * sizeof(dict_field_t));
261
224
        /* The '1 +' above prevents allocation
262
225
        of an empty mem block */
263
 
        index->stat_n_diff_key_vals = NULL;
264
 
 
265
 
        index->cached = FALSE;
266
 
        memset(&index->lock, 0, sizeof index->lock);
267
226
#ifdef UNIV_DEBUG
268
227
        index->magic_n = DICT_INDEX_MAGIC_N;
269
228
#endif /* UNIV_DEBUG */
272
231
 
273
232
/**************************************************************************
274
233
Creates and initializes a foreign constraint memory object. */
275
 
 
 
234
UNIV_INTERN
276
235
dict_foreign_t*
277
236
dict_mem_foreign_create(void)
278
237
/*=========================*/
283
242
 
284
243
        heap = mem_heap_create(100);
285
244
 
286
 
        foreign = mem_heap_alloc(heap, sizeof(dict_foreign_t));
 
245
        foreign = mem_heap_zalloc(heap, sizeof(dict_foreign_t));
287
246
 
288
247
        foreign->heap = heap;
289
248
 
290
 
        foreign->id = NULL;
291
 
 
292
 
        foreign->type = 0;
293
 
        foreign->foreign_table_name = NULL;
294
 
        foreign->foreign_table = NULL;
295
 
        foreign->foreign_col_names = NULL;
296
 
 
297
 
        foreign->referenced_table_name = NULL;
298
 
        foreign->referenced_table = NULL;
299
 
        foreign->referenced_col_names = NULL;
300
 
 
301
 
        foreign->n_fields = 0;
302
 
 
303
 
        foreign->foreign_index = NULL;
304
 
        foreign->referenced_index = NULL;
305
 
 
306
249
        return(foreign);
307
250
}
308
251
 
310
253
Adds a field definition to an index. NOTE: does not take a copy
311
254
of the column name if the field is a column. The memory occupied
312
255
by the column name may be released only after publishing the index. */
313
 
 
 
256
UNIV_INTERN
314
257
void
315
258
dict_mem_index_add_field(
316
259
/*=====================*/
335
278
 
336
279
/**************************************************************************
337
280
Frees an index memory object. */
338
 
 
 
281
UNIV_INTERN
339
282
void
340
283
dict_mem_index_free(
341
284
/*================*/