~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/dict0load.h

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1996, 2009, 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
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
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
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
31
31
#include "dict0types.h"
32
32
#include "ut0byte.h"
33
33
#include "mem0mem.h"
34
 
#include "btr0types.h"
35
 
 
36
 
/** enum that defines all 6 system table IDs */
37
 
enum dict_system_table_id {
38
 
        SYS_TABLES = 0,
39
 
        SYS_INDEXES,
40
 
        SYS_COLUMNS,
41
 
        SYS_FIELDS,
42
 
        SYS_FOREIGN,
43
 
        SYS_FOREIGN_COLS,
44
 
 
45
 
        /* This must be last item. Defines the number of system tables. */
46
 
        SYS_NUM_SYSTEM_TABLES
47
 
};
48
 
 
49
 
typedef enum dict_system_table_id       dict_system_id_t;
50
 
 
51
 
/** Status bit for dict_process_sys_tables_rec() */
52
 
enum dict_table_info {
53
 
        DICT_TABLE_LOAD_FROM_RECORD = 0,/*!< Directly populate a dict_table_t
54
 
                                        structure with information from
55
 
                                        a SYS_TABLES record */
56
 
        DICT_TABLE_LOAD_FROM_CACHE = 1, /*!< Check first whether dict_table_t
57
 
                                        is in the cache, if so, return it */
58
 
        DICT_TABLE_UPDATE_STATS = 2     /*!< whether to update statistics
59
 
                                        when loading SYS_TABLES information. */
60
 
};
61
 
 
62
 
typedef enum dict_table_info    dict_table_info_t;
63
34
 
64
35
/********************************************************************//**
65
36
In a crash recovery we already have all the tablespace objects created.
83
54
dict_get_first_table_name_in_db(
84
55
/*============================*/
85
56
        const char*     name);  /*!< in: database name which ends to '/' */
86
 
 
87
 
/********************************************************************//**
88
 
Loads a table definition from a SYS_TABLES record to dict_table_t.
89
 
Does not load any columns or indexes.
90
 
@return error message, or NULL on success */
91
 
UNIV_INTERN
92
 
const char*
93
 
dict_load_table_low(
94
 
/*================*/
95
 
        const char*     name,           /*!< in: table name */
96
 
        const rec_t*    rec,            /*!< in: SYS_TABLES record */
97
 
        dict_table_t**  table);         /*!< out,own: table, or NULL */
98
 
/********************************************************************//**
99
 
Loads a table column definition from a SYS_COLUMNS record to
100
 
dict_table_t.
101
 
@return error message, or NULL on success */
102
 
UNIV_INTERN
103
 
const char*
104
 
dict_load_column_low(
105
 
/*=================*/
106
 
        dict_table_t*   table,          /*!< in/out: table, could be NULL
107
 
                                        if we just populate a dict_column_t
108
 
                                        struct with information from
109
 
                                        a SYS_COLUMNS record */
110
 
        mem_heap_t*     heap,           /*!< in/out: memory heap
111
 
                                        for temporary storage */
112
 
        dict_col_t*     column,         /*!< out: dict_column_t to fill,
113
 
                                        or NULL if table != NULL */
114
 
        table_id_t*     table_id,       /*!< out: table id */
115
 
        const char**    col_name,       /*!< out: column name */
116
 
        const rec_t*    rec);           /*!< in: SYS_COLUMNS record */
117
 
/********************************************************************//**
118
 
Loads an index definition from a SYS_INDEXES record to dict_index_t.
119
 
If allocate=TRUE, we will create a dict_index_t structure and fill it
120
 
accordingly. If allocated=FALSE, the dict_index_t will be supplied by
121
 
the caller and filled with information read from the record.  @return
122
 
error message, or NULL on success */
123
 
UNIV_INTERN
124
 
const char*
125
 
dict_load_index_low(
126
 
/*================*/
127
 
        byte*           table_id,       /*!< in/out: table id (8 bytes),
128
 
                                        an "in" value if allocate=TRUE
129
 
                                        and "out" when allocate=FALSE */
130
 
        const char*     table_name,     /*!< in: table name */
131
 
        mem_heap_t*     heap,           /*!< in/out: temporary memory heap */
132
 
        const rec_t*    rec,            /*!< in: SYS_INDEXES record */
133
 
        ibool           allocate,       /*!< in: TRUE=allocate *index,
134
 
                                        FALSE=fill in a pre-allocated
135
 
                                        *index */
136
 
        dict_index_t**  index);         /*!< out,own: index, or NULL */
137
 
/********************************************************************//**
138
 
Loads an index field definition from a SYS_FIELDS record to
139
 
dict_index_t.
140
 
@return error message, or NULL on success */
141
 
UNIV_INTERN
142
 
const char*
143
 
dict_load_field_low(
144
 
/*================*/
145
 
        byte*           index_id,       /*!< in/out: index id (8 bytes)
146
 
                                        an "in" value if index != NULL
147
 
                                        and "out" if index == NULL */
148
 
        dict_index_t*   index,          /*!< in/out: index, could be NULL
149
 
                                        if we just populate a dict_field_t
150
 
                                        struct with information from
151
 
                                        a SYS_FIELDS record */
152
 
        dict_field_t*   sys_field,      /*!< out: dict_field_t to be
153
 
                                        filled */
154
 
        ulint*          pos,            /*!< out: Field position */
155
 
        byte*           last_index_id,  /*!< in: last index id */
156
 
        mem_heap_t*     heap,           /*!< in/out: memory heap
157
 
                                        for temporary storage */
158
 
        const rec_t*    rec);           /*!< in: SYS_FIELDS record */
159
57
/********************************************************************//**
160
58
Loads a table definition and also all its index definitions, and also
161
59
the cluster definition if the table is a member in a cluster. Also loads
168
66
dict_table_t*
169
67
dict_load_table(
170
68
/*============*/
171
 
        const char*     name,   /*!< in: table name in the
 
69
        const char*     name);  /*!< in: table name in the
172
70
                                databasename/tablename format */
173
 
        ibool           cached);/*!< in: TRUE=add to cache, FALSE=do not */
174
71
/***********************************************************************//**
175
72
Loads a table object based on the table id.
176
73
@return table; NULL if table does not exist */
178
75
dict_table_t*
179
76
dict_load_table_on_id(
180
77
/*==================*/
181
 
        table_id_t      table_id);      /*!< in: table id */
 
78
        dulint  table_id);      /*!< in: table id */
182
79
/********************************************************************//**
183
80
This function is called when the database is booted.
184
81
Loads system table index definitions except for the clustered index which
200
97
dict_load_foreigns(
201
98
/*===============*/
202
99
        const char*     table_name,     /*!< in: table name */
203
 
        ibool           check_recursive,/*!< in: Whether to check recursive
204
 
                                        load of tables chained by FK */
205
100
        ibool           check_charsets);/*!< in: TRUE=check charsets
206
101
                                        compatibility */
207
102
/********************************************************************//**
216
111
UNIV_INTERN void dict_print_with_callback(dict_print_callback, void *);
217
112
 
218
113
 
219
 
/********************************************************************//**
220
 
This function opens a system table, and return the first record.
221
 
@return first record of the system table */
222
 
UNIV_INTERN
223
 
const rec_t*
224
 
dict_startscan_system(
225
 
/*==================*/
226
 
        btr_pcur_t*     pcur,           /*!< out: persistent cursor to
227
 
                                        the record */
228
 
        mtr_t*          mtr,            /*!< in: the mini-transaction */
229
 
        dict_system_id_t system_id);    /*!< in: which system table to open */
230
 
/********************************************************************//**
231
 
This function get the next system table record as we scan the table.
232
 
@return the record if found, NULL if end of scan. */
233
 
UNIV_INTERN
234
 
const rec_t*
235
 
dict_getnext_system(
236
 
/*================*/
237
 
        btr_pcur_t*     pcur,           /*!< in/out: persistent cursor
238
 
                                        to the record */
239
 
        mtr_t*          mtr);           /*!< in: the mini-transaction */
240
 
/********************************************************************//**
241
 
This function processes one SYS_TABLES record and populate the dict_table_t
242
 
struct for the table. Extracted out of dict_print() to be used by
243
 
both monitor table output and information schema innodb_sys_tables output.
244
 
@return error message, or NULL on success */
245
 
UNIV_INTERN
246
 
const char*
247
 
dict_process_sys_tables_rec(
248
 
/*========================*/
249
 
        mem_heap_t*     heap,           /*!< in: temporary memory heap */
250
 
        const rec_t*    rec,            /*!< in: SYS_TABLES record */
251
 
        dict_table_t**  table,          /*!< out: dict_table_t to fill */
252
 
        dict_table_info_t status);      /*!< in: status bit controls
253
 
                                        options such as whether we shall
254
 
                                        look for dict_table_t from cache
255
 
                                        first */
256
 
/********************************************************************//**
257
 
This function parses a SYS_INDEXES record and populate a dict_index_t
258
 
structure with the information from the record. For detail information
259
 
about SYS_INDEXES fields, please refer to dict_boot() function.
260
 
@return error message, or NULL on success */
261
 
UNIV_INTERN
262
 
const char*
263
 
dict_process_sys_indexes_rec(
264
 
/*=========================*/
265
 
        mem_heap_t*     heap,           /*!< in/out: heap memory */
266
 
        const rec_t*    rec,            /*!< in: current SYS_INDEXES rec */
267
 
        dict_index_t*   index,          /*!< out: dict_index_t to be
268
 
                                        filled */
269
 
        table_id_t*     table_id);      /*!< out: table id */
270
 
/********************************************************************//**
271
 
This function parses a SYS_COLUMNS record and populate a dict_column_t
272
 
structure with the information from the record.
273
 
@return error message, or NULL on success */
274
 
UNIV_INTERN
275
 
const char*
276
 
dict_process_sys_columns_rec(
277
 
/*=========================*/
278
 
        mem_heap_t*     heap,           /*!< in/out: heap memory */
279
 
        const rec_t*    rec,            /*!< in: current SYS_COLUMNS rec */
280
 
        dict_col_t*     column,         /*!< out: dict_col_t to be filled */
281
 
        table_id_t*     table_id,       /*!< out: table id */
282
 
        const char**    col_name);      /*!< out: column name */
283
 
/********************************************************************//**
284
 
This function parses a SYS_FIELDS record and populate a dict_field_t
285
 
structure with the information from the record.
286
 
@return error message, or NULL on success */
287
 
UNIV_INTERN
288
 
const char*
289
 
dict_process_sys_fields_rec(
290
 
/*========================*/
291
 
        mem_heap_t*     heap,           /*!< in/out: heap memory */
292
 
        const rec_t*    rec,            /*!< in: current SYS_FIELDS rec */
293
 
        dict_field_t*   sys_field,      /*!< out: dict_field_t to be
294
 
                                        filled */
295
 
        ulint*          pos,            /*!< out: Field position */
296
 
        index_id_t*     index_id,       /*!< out: current index id */
297
 
        index_id_t      last_id);       /*!< in: previous index id */
298
 
/********************************************************************//**
299
 
This function parses a SYS_FOREIGN record and populate a dict_foreign_t
300
 
structure with the information from the record. For detail information
301
 
about SYS_FOREIGN fields, please refer to dict_load_foreign() function
302
 
@return error message, or NULL on success */
303
 
UNIV_INTERN
304
 
const char*
305
 
dict_process_sys_foreign_rec(
306
 
/*=========================*/
307
 
        mem_heap_t*     heap,           /*!< in/out: heap memory */
308
 
        const rec_t*    rec,            /*!< in: current SYS_FOREIGN rec */
309
 
        dict_foreign_t* foreign);       /*!< out: dict_foreign_t to be
310
 
                                        filled */
311
 
/********************************************************************//**
312
 
This function parses a SYS_FOREIGN_COLS record and extract necessary
313
 
information from the record and return to caller.
314
 
@return error message, or NULL on success */
315
 
UNIV_INTERN
316
 
const char*
317
 
dict_process_sys_foreign_col_rec(
318
 
/*=============================*/
319
 
        mem_heap_t*     heap,           /*!< in/out: heap memory */
320
 
        const rec_t*    rec,            /*!< in: current SYS_FOREIGN_COLS rec */
321
 
        const char**    name,           /*!< out: foreign key constraint name */
322
 
        const char**    for_col_name,   /*!< out: referencing column name */
323
 
        const char**    ref_col_name,   /*!< out: referenced column name
324
 
                                        in referenced table */
325
 
        ulint*          pos);           /*!< out: column position */
 
114
 
326
115
#ifndef UNIV_NONINL
327
116
#include "dict0load.ic"
328
117
#endif