1
/*****************************************************************************
3
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/dict0load.h
21
Loads to the memory cache database object definitions
22
from dictionary tables
24
Created 4/24/1996 Heikki Tuuri
25
*******************************************************/
31
#include "dict0types.h"
34
#include "btr0types.h"
36
/** enum that defines all 6 system table IDs */
37
enum dict_system_table_id {
45
/* This must be last item. Defines the number of system tables. */
49
typedef enum dict_system_table_id dict_system_id_t;
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. */
62
typedef enum dict_table_info dict_table_info_t;
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().
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. */
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! */
83
dict_get_first_table_name_in_db(
84
/*============================*/
85
const char* name); /*!< in: database name which ends to '/' */
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 */
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
101
@return error message, or NULL on success */
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 */
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
136
dict_index_t** index); /*!< out,own: index, or NULL */
137
/********************************************************************//**
138
Loads an index field definition from a SYS_FIELDS record to
140
@return error message, or NULL on success */
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
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 */
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 */
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. */
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 */
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
207
/********************************************************************//**
208
Prints to the standard output information on all tables found in the data
209
dictionary system table. */
215
typedef void (*dict_print_callback)(void *ptr, const char *);
216
UNIV_INTERN void dict_print_with_callback(dict_print_callback, void *);
219
/********************************************************************//**
220
This function opens a system table, and return the first record.
221
@return first record of the system table */
224
dict_startscan_system(
225
/*==================*/
226
btr_pcur_t* pcur, /*!< out: persistent cursor to
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. */
237
btr_pcur_t* pcur, /*!< in/out: persistent cursor
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 */
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
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 */
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
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 */
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 */
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
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 */
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
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 */
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 */
327
#include "dict0load.ic"