~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1996, 2009, 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 include/dict0load.h
21
 
Loads to the memory cache database object definitions
22
 
from dictionary tables
23
 
 
24
 
Created 4/24/1996 Heikki Tuuri
25
 
*******************************************************/
26
 
 
27
 
#ifndef dict0load_h
28
 
#define dict0load_h
29
 
 
30
 
#include "univ.i"
31
 
#include "dict0types.h"
32
 
#include "ut0byte.h"
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
 
 
64
 
/********************************************************************//**
65
 
In a crash recovery we already have all the tablespace objects created.
66
 
This function compares the space id information in the InnoDB data dictionary
67
 
to what we already read with fil_load_single_table_tablespaces().
68
 
 
69
 
In a normal startup, we create the tablespace objects for every table in
70
 
InnoDB's data dictionary, if the corresponding .ibd file exists.
71
 
We also scan the biggest space id, and store it to fil_system. */
72
 
UNIV_INTERN
73
 
void
74
 
dict_check_tablespaces_and_store_max_id(
75
 
/*====================================*/
76
 
        ibool   in_crash_recovery);     /*!< in: are we doing a crash recovery */
77
 
/********************************************************************//**
78
 
Finds the first table name in the given database.
79
 
@return own: table name, NULL if does not exist; the caller must free
80
 
the memory in the string! */
81
 
UNIV_INTERN
82
 
char*
83
 
dict_get_first_table_name_in_db(
84
 
/*============================*/
85
 
        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
 
/********************************************************************//**
160
 
Loads a table definition and also all its index definitions, and also
161
 
the cluster definition if the table is a member in a cluster. Also loads
162
 
all foreign key constraints where the foreign key is in the table or where
163
 
a foreign key references columns in this table.
164
 
@return table, NULL if does not exist; if the table is stored in an
165
 
.ibd file, but the file does not exist, then we set the
166
 
ibd_file_missing flag TRUE in the table object we return */
167
 
UNIV_INTERN
168
 
dict_table_t*
169
 
dict_load_table(
170
 
/*============*/
171
 
        const char*     name,   /*!< in: table name in the
172
 
                                databasename/tablename format */
173
 
        ibool           cached);/*!< in: TRUE=add to cache, FALSE=do not */
174
 
/***********************************************************************//**
175
 
Loads a table object based on the table id.
176
 
@return table; NULL if table does not exist */
177
 
UNIV_INTERN
178
 
dict_table_t*
179
 
dict_load_table_on_id(
180
 
/*==================*/
181
 
        table_id_t      table_id);      /*!< in: table id */
182
 
/********************************************************************//**
183
 
This function is called when the database is booted.
184
 
Loads system table index definitions except for the clustered index which
185
 
is added to the dictionary cache at booting before calling this function. */
186
 
UNIV_INTERN
187
 
void
188
 
dict_load_sys_table(
189
 
/*================*/
190
 
        dict_table_t*   table); /*!< in: system table */
191
 
/***********************************************************************//**
192
 
Loads foreign key constraints where the table is either the foreign key
193
 
holder or where the table is referenced by a foreign key. Adds these
194
 
constraints to the data dictionary. Note that we know that the dictionary
195
 
cache already contains all constraints where the other relevant table is
196
 
already in the dictionary cache.
197
 
@return DB_SUCCESS or error code */
198
 
UNIV_INTERN
199
 
ulint
200
 
dict_load_foreigns(
201
 
/*===============*/
202
 
        const char*     table_name,     /*!< in: table name */
203
 
        ibool           check_recursive,/*!< in: Whether to check recursive
204
 
                                        load of tables chained by FK */
205
 
        ibool           check_charsets);/*!< in: TRUE=check charsets
206
 
                                        compatibility */
207
 
/********************************************************************//**
208
 
Prints to the standard output information on all tables found in the data
209
 
dictionary system table. */
210
 
UNIV_INTERN
211
 
void
212
 
dict_print(void);
213
 
/*============*/
214
 
 
215
 
typedef void (*dict_print_callback)(void *ptr, const char *);
216
 
UNIV_INTERN void dict_print_with_callback(dict_print_callback, void *);
217
 
 
218
 
 
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 */
326
 
#ifndef UNIV_NONINL
327
 
#include "dict0load.ic"
328
 
#endif
329
 
 
330
 
#endif