~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-12-06 22:41:03 UTC
  • mto: (656.1.7 devel)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: monty@inaugust.com-20081206224103-jdouqwt9hb0f01y1
Moved non-working tests into broken suite for easier running of working tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/******************************************************************//**
20
 
@file dict/dict0mem.c
 
1
/**********************************************************************
21
2
Data dictionary memory object creation
22
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
23
6
Created 1/8/1996 Heikki Tuuri
24
7
***********************************************************************/
25
8
 
33
16
#include "data0type.h"
34
17
#include "mach0data.h"
35
18
#include "dict0dict.h"
36
 
#ifndef UNIV_HOTBACKUP
37
 
# include "lock0lock.h"
38
 
#endif /* !UNIV_HOTBACKUP */
 
19
#include "que0que.h"
 
20
#include "pars0pars.h"
 
21
#include "lock0lock.h"
39
22
 
40
 
#define DICT_HEAP_SIZE          100     /*!< initial memory heap size when
 
23
#define DICT_HEAP_SIZE          100     /* initial memory heap size when
41
24
                                        creating a table or index object */
42
25
 
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
 
/**********************************************************************//**
49
 
Creates a table memory object.
50
 
@return own: table object */
 
26
/**************************************************************************
 
27
Creates a table memory object. */
51
28
UNIV_INTERN
52
29
dict_table_t*
53
30
dict_mem_table_create(
54
31
/*==================*/
55
 
        const char*     name,   /*!< in: table name */
56
 
        ulint           space,  /*!< in: space where the clustered index of
 
32
                                /* out, own: table object */
 
33
        const char*     name,   /* in: table name */
 
34
        ulint           space,  /* in: space where the clustered index of
57
35
                                the table is placed; this parameter is
58
36
                                ignored if the table is made a member of
59
37
                                a cluster */
60
 
        ulint           n_cols, /*!< in: number of columns */
61
 
        ulint           flags)  /*!< in: table flags */
 
38
        ulint           n_cols, /* in: number of columns */
 
39
        ulint           flags)  /* in: table flags */
62
40
{
63
41
        dict_table_t*   table;
64
42
        mem_heap_t*     heap;
65
43
 
66
44
        ut_ad(name);
67
 
        ut_a(!(flags & (SIZE_MAX << DICT_TF2_BITS)));
 
45
        ut_a(!(flags & (~0 << DICT_TF_BITS)));
68
46
 
69
47
        heap = mem_heap_create(DICT_HEAP_SIZE);
70
48
 
71
 
        table = static_cast<dict_table_struct *>(mem_heap_zalloc(heap, sizeof(dict_table_t)));
 
49
        table = mem_heap_zalloc(heap, sizeof(dict_table_t));
72
50
 
73
51
        table->heap = heap;
74
52
 
75
53
        table->flags = (unsigned int) flags;
76
 
        table->name = static_cast<char *>(ut_malloc(strlen(name) + 1));
77
 
        memcpy(table->name, name, strlen(name) + 1);
 
54
        table->name = mem_heap_strdup(heap, name);
78
55
        table->space = (unsigned int) space;
79
56
        table->n_cols = (unsigned int) (n_cols + DATA_N_SYS_COLS);
80
57
 
81
 
        table->cols = static_cast<dict_col_t *>(mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
82
 
                                     * sizeof(dict_col_t)));
83
 
 
84
 
#ifndef UNIV_HOTBACKUP
85
 
        table->autoinc_lock = static_cast<lock_t *>(mem_heap_alloc(heap, lock_get_size()));
86
 
 
87
 
        mutex_create(autoinc_mutex_key,
88
 
                     &table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
 
58
        table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
 
59
                                     * sizeof(dict_col_t));
 
60
 
 
61
        table->autoinc_lock = mem_heap_alloc(heap, lock_get_size());
 
62
 
 
63
        mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
89
64
 
90
65
        table->autoinc = 0;
91
66
 
92
67
        /* The number of transactions that are either waiting on the
93
68
        AUTOINC lock or have been granted the lock. */
94
69
        table->n_waiting_or_granted_auto_inc_locks = 0;
95
 
#endif /* !UNIV_HOTBACKUP */
96
70
 
97
 
        ut_d(table->magic_n = DICT_TABLE_MAGIC_N);
 
71
#ifdef UNIV_DEBUG
 
72
        table->magic_n = DICT_TABLE_MAGIC_N;
 
73
#endif /* UNIV_DEBUG */
98
74
        return(table);
99
75
}
100
76
 
101
 
/****************************************************************//**
 
77
/********************************************************************
102
78
Free a table memory object. */
103
79
UNIV_INTERN
104
80
void
105
81
dict_mem_table_free(
106
82
/*================*/
107
 
        dict_table_t*   table)          /*!< in: table */
 
83
        dict_table_t*   table)          /* in: table */
108
84
{
109
85
        ut_ad(table);
110
86
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
111
 
        ut_d(table->cached = FALSE);
112
87
 
113
 
#ifndef UNIV_HOTBACKUP
114
88
        mutex_free(&(table->autoinc_mutex));
115
 
#endif /* UNIV_HOTBACKUP */
116
 
        ut_free(table->name);
117
89
        mem_heap_free(table->heap);
118
90
}
119
91
 
120
 
/****************************************************************//**
121
 
Append 'name' to 'col_names'.  @see dict_table_t::col_names
122
 
@return new column names array */
 
92
/********************************************************************
 
93
Append 'name' to 'col_names' (@see dict_table_t::col_names). */
123
94
static
124
95
const char*
125
96
dict_add_col_name(
126
97
/*==============*/
127
 
        const char*     col_names,      /*!< in: existing column names, or
 
98
                                        /* out: new column names array */
 
99
        const char*     col_names,      /* in: existing column names, or
128
100
                                        NULL */
129
 
        ulint           cols,           /*!< in: number of existing columns */
130
 
        const char*     name,           /*!< in: new column name */
131
 
        mem_heap_t*     heap)           /*!< in: heap */
 
101
        ulint           cols,           /* in: number of existing columns */
 
102
        const char*     name,           /* in: new column name */
 
103
        mem_heap_t*     heap)           /* in: heap */
132
104
{
133
105
        ulint   old_len;
134
106
        ulint   new_len;
154
126
        new_len = strlen(name) + 1;
155
127
        total_len = old_len + new_len;
156
128
 
157
 
        res = static_cast<char *>(mem_heap_alloc(heap, total_len));
 
129
        res = mem_heap_alloc(heap, total_len);
158
130
 
159
131
        if (old_len > 0) {
160
132
                memcpy(res, col_names, old_len);
165
137
        return(res);
166
138
}
167
139
 
168
 
/**********************************************************************//**
 
140
/**************************************************************************
169
141
Adds a column definition to a table. */
170
142
UNIV_INTERN
171
143
void
172
144
dict_mem_table_add_col(
173
145
/*===================*/
174
 
        dict_table_t*   table,  /*!< in: table */
175
 
        mem_heap_t*     heap,   /*!< in: temporary memory heap, or NULL */
176
 
        const char*     name,   /*!< in: column name, or NULL */
177
 
        ulint           mtype,  /*!< in: main datatype */
178
 
        ulint           prtype, /*!< in: precise type */
179
 
        ulint           len)    /*!< in: precision */
 
146
        dict_table_t*   table,  /* in: table */
 
147
        mem_heap_t*     heap,   /* in: temporary memory heap, or NULL */
 
148
        const char*     name,   /* in: column name, or NULL */
 
149
        ulint           mtype,  /* in: main datatype */
 
150
        ulint           prtype, /* in: precise type */
 
151
        ulint           len)    /* in: precision */
180
152
{
181
153
        dict_col_t*     col;
 
154
        ulint           mbminlen;
 
155
        ulint           mbmaxlen;
182
156
        ulint           i;
183
157
 
184
158
        ut_ad(table);
193
167
                }
194
168
                if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
195
169
                        /* All preceding column names are empty. */
196
 
                        char* s = static_cast<char *>(mem_heap_zalloc(heap, table->n_def));
 
170
                        char* s = mem_heap_zalloc(heap, table->n_def);
197
171
                        table->col_names = s;
198
172
                }
199
173
 
203
177
 
204
178
        col = dict_table_get_nth_col(table, i);
205
179
 
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);
237
 
#endif /* !UNIV_HOTBACKUP */
238
 
}
239
 
 
240
 
/**********************************************************************//**
241
 
Creates an index memory object.
242
 
@return own: index object */
 
180
        col->ind = (unsigned int) i;
 
181
        col->ord_part = 0;
 
182
 
 
183
        col->mtype = (unsigned int) mtype;
 
184
        col->prtype = (unsigned int) prtype;
 
185
        col->len = (unsigned int) len;
 
186
 
 
187
        dtype_get_mblen(mtype, prtype, &mbminlen, &mbmaxlen);
 
188
 
 
189
        col->mbminlen = (unsigned int) mbminlen;
 
190
        col->mbmaxlen = (unsigned int) mbmaxlen;
 
191
}
 
192
 
 
193
/**************************************************************************
 
194
Creates an index memory object. */
243
195
UNIV_INTERN
244
196
dict_index_t*
245
197
dict_mem_index_create(
246
198
/*==================*/
247
 
        const char*     table_name,     /*!< in: table name */
248
 
        const char*     index_name,     /*!< in: index name */
249
 
        ulint           space,          /*!< in: space where the index tree is
 
199
                                        /* out, own: index object */
 
200
        const char*     table_name,     /* in: table name */
 
201
        const char*     index_name,     /* in: index name */
 
202
        ulint           space,          /* in: space where the index tree is
250
203
                                        placed, ignored if the index is of
251
204
                                        the clustered type */
252
 
        ulint           type,           /*!< in: DICT_UNIQUE,
 
205
        ulint           type,           /* in: DICT_UNIQUE,
253
206
                                        DICT_CLUSTERED, ... ORed */
254
 
        ulint           n_fields)       /*!< in: number of fields */
 
207
        ulint           n_fields)       /* in: number of fields */
255
208
{
256
209
        dict_index_t*   index;
257
210
        mem_heap_t*     heap;
259
212
        ut_ad(table_name && index_name);
260
213
 
261
214
        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
 
 
 
215
        index = mem_heap_zalloc(heap, sizeof(dict_index_t));
 
216
 
 
217
        index->heap = heap;
 
218
 
 
219
        index->type = type;
 
220
        index->space = (unsigned int) space;
 
221
        index->name = mem_heap_strdup(heap, index_name);
 
222
        index->table_name = table_name;
 
223
        index->n_fields = (unsigned int) n_fields;
 
224
        index->fields = mem_heap_alloc(heap, 1 + n_fields
 
225
                                       * sizeof(dict_field_t));
 
226
        /* The '1 +' above prevents allocation
 
227
        of an empty mem block */
 
228
#ifdef UNIV_DEBUG
 
229
        index->magic_n = DICT_INDEX_MAGIC_N;
 
230
#endif /* UNIV_DEBUG */
267
231
        return(index);
268
232
}
269
233
 
270
 
/**********************************************************************//**
271
 
Creates and initializes a foreign constraint memory object.
272
 
@return own: foreign constraint struct */
 
234
/**************************************************************************
 
235
Creates and initializes a foreign constraint memory object. */
273
236
UNIV_INTERN
274
237
dict_foreign_t*
275
238
dict_mem_foreign_create(void)
276
239
/*=========================*/
 
240
                                /* out, own: foreign constraint struct */
277
241
{
278
242
        dict_foreign_t* foreign;
279
243
        mem_heap_t*     heap;
280
244
 
281
245
        heap = mem_heap_create(100);
282
246
 
283
 
        foreign = static_cast<dict_foreign_t *>(mem_heap_zalloc(heap, sizeof(dict_foreign_t)));
 
247
        foreign = mem_heap_zalloc(heap, sizeof(dict_foreign_t));
284
248
 
285
249
        foreign->heap = heap;
286
250
 
287
251
        return(foreign);
288
252
}
289
253
 
290
 
/**********************************************************************//**
 
254
/**************************************************************************
291
255
Adds a field definition to an index. NOTE: does not take a copy
292
256
of the column name if the field is a column. The memory occupied
293
257
by the column name may be released only after publishing the index. */
295
259
void
296
260
dict_mem_index_add_field(
297
261
/*=====================*/
298
 
        dict_index_t*   index,          /*!< in: index */
299
 
        const char*     name,           /*!< in: column name */
300
 
        ulint           prefix_len)     /*!< in: 0 or the column prefix length
 
262
        dict_index_t*   index,          /* in: index */
 
263
        const char*     name,           /* in: column name */
 
264
        ulint           prefix_len)     /* in: 0 or the column prefix length
301
265
                                        in a MySQL index like
302
266
                                        INDEX (textcol(25)) */
303
267
{
314
278
        field->prefix_len = (unsigned int) prefix_len;
315
279
}
316
280
 
317
 
/**********************************************************************//**
 
281
/**************************************************************************
318
282
Frees an index memory object. */
319
283
UNIV_INTERN
320
284
void
321
285
dict_mem_index_free(
322
286
/*================*/
323
 
        dict_index_t*   index)  /*!< in: index */
 
287
        dict_index_t*   index)  /* in: index */
324
288
{
325
289
        ut_ad(index);
326
290
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);