1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 1996, 2016, Oracle and/or its affiliates. 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., |
15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /**************************************************//** |
20 | @file include/dict0boot.h |
21 | Data dictionary creation and booting |
22 | |
23 | Created 4/18/1996 Heikki Tuuri |
24 | *******************************************************/ |
25 | |
26 | #ifndef dict0boot_h |
27 | #define dict0boot_h |
28 | |
29 | #include "univ.i" |
30 | |
31 | #include "mtr0mtr.h" |
32 | #include "mtr0log.h" |
33 | #include "ut0byte.h" |
34 | #include "buf0buf.h" |
35 | #include "fsp0fsp.h" |
36 | #include "dict0dict.h" |
37 | |
38 | typedef byte dict_hdr_t; |
39 | |
40 | /**********************************************************************//** |
41 | Gets a pointer to the dictionary header and x-latches its page. |
42 | @return pointer to the dictionary header, page x-latched */ |
43 | dict_hdr_t* |
44 | dict_hdr_get( |
45 | /*=========*/ |
46 | mtr_t* mtr); /*!< in: mtr */ |
47 | /**********************************************************************//** |
48 | Returns a new table, index, or space id. */ |
49 | void |
50 | dict_hdr_get_new_id( |
51 | /*================*/ |
52 | table_id_t* table_id, /*!< out: table id |
53 | (not assigned if NULL) */ |
54 | index_id_t* index_id, /*!< out: index id |
55 | (not assigned if NULL) */ |
56 | ulint* space_id, /*!< out: space id |
57 | (not assigned if NULL) */ |
58 | const dict_table_t* table, /*!< in: table */ |
59 | bool disable_redo); /*!< in: if true and table |
60 | object is NULL |
61 | then disable-redo */ |
62 | /**********************************************************************//** |
63 | Writes the current value of the row id counter to the dictionary header file |
64 | page. */ |
65 | void |
66 | dict_hdr_flush_row_id(void); |
67 | /*=======================*/ |
68 | /**********************************************************************//** |
69 | Returns a new row id. |
70 | @return the new id */ |
71 | UNIV_INLINE |
72 | row_id_t |
73 | dict_sys_get_new_row_id(void); |
74 | /*=========================*/ |
75 | /**********************************************************************//** |
76 | Reads a row id from a record or other 6-byte stored form. |
77 | @return row id */ |
78 | UNIV_INLINE |
79 | row_id_t |
80 | dict_sys_read_row_id( |
81 | /*=================*/ |
82 | const byte* field); /*!< in: record field */ |
83 | /**********************************************************************//** |
84 | Writes a row id to a record or other 6-byte stored form. */ |
85 | UNIV_INLINE |
86 | void |
87 | dict_sys_write_row_id( |
88 | /*==================*/ |
89 | byte* field, /*!< in: record field */ |
90 | row_id_t row_id);/*!< in: row id */ |
91 | /*****************************************************************//** |
92 | Initializes the data dictionary memory structures when the database is |
93 | started. This function is also called when the data dictionary is created. |
94 | @return DB_SUCCESS or error code. */ |
95 | dberr_t |
96 | dict_boot(void) |
97 | /*===========*/ |
98 | MY_ATTRIBUTE((warn_unused_result)); |
99 | |
100 | /*****************************************************************//** |
101 | Creates and initializes the data dictionary at the server bootstrap. |
102 | @return DB_SUCCESS or error code. */ |
103 | dberr_t |
104 | dict_create(void) |
105 | /*=============*/ |
106 | MY_ATTRIBUTE((warn_unused_result)); |
107 | |
108 | /*********************************************************************//** |
109 | Check if a table id belongs to system table. |
110 | @return true if the table id belongs to a system table. */ |
111 | UNIV_INLINE |
112 | bool |
113 | dict_is_sys_table( |
114 | /*==============*/ |
115 | table_id_t id) /*!< in: table id to check */ |
116 | MY_ATTRIBUTE((warn_unused_result)); |
117 | |
118 | /* Space id and page no where the dictionary header resides */ |
119 | #define DICT_HDR_SPACE 0 /* the SYSTEM tablespace */ |
120 | #define DICT_HDR_PAGE_NO FSP_DICT_HDR_PAGE_NO |
121 | |
122 | /* The ids for the basic system tables and their indexes */ |
123 | #define DICT_TABLES_ID 1 |
124 | #define DICT_COLUMNS_ID 2 |
125 | #define DICT_INDEXES_ID dict_index_t::DICT_INDEXES_ID /* 3 */ |
126 | #define DICT_FIELDS_ID 4 |
127 | /* The following is a secondary index on SYS_TABLES */ |
128 | #define DICT_TABLE_IDS_ID 5 |
129 | |
130 | #define DICT_HDR_FIRST_ID 10 /* the ids for tables etc. start |
131 | from this number, except for basic |
132 | system tables and their above defined |
133 | indexes; ibuf tables and indexes are |
134 | assigned as the id the number |
135 | DICT_IBUF_ID_MIN plus the space id */ |
136 | |
137 | /* The offset of the dictionary header on the page */ |
138 | #define DICT_HDR FSEG_PAGE_DATA |
139 | |
140 | /*-------------------------------------------------------------*/ |
141 | /* Dictionary header offsets */ |
142 | #define DICT_HDR_ROW_ID 0 /* The latest assigned row id */ |
143 | #define DICT_HDR_TABLE_ID 8 /* The latest assigned table id */ |
144 | #define DICT_HDR_INDEX_ID 16 /* The latest assigned index id */ |
145 | #define DICT_HDR_MAX_SPACE_ID 24 /* The latest assigned space id,or 0*/ |
146 | #define DICT_HDR_MIX_ID_LOW 28 /* Obsolete,always DICT_HDR_FIRST_ID*/ |
147 | #define DICT_HDR_TABLES 32 /* Root of SYS_TABLES clust index */ |
148 | #define DICT_HDR_TABLE_IDS 36 /* Root of SYS_TABLE_IDS sec index */ |
149 | #define DICT_HDR_COLUMNS 40 /* Root of SYS_COLUMNS clust index */ |
150 | #define DICT_HDR_INDEXES 44 /* Root of SYS_INDEXES clust index */ |
151 | #define DICT_HDR_FIELDS 48 /* Root of SYS_FIELDS clust index */ |
152 | |
153 | #define 56 /* Segment header for the tablespace |
154 | segment into which the dictionary |
155 | header is created */ |
156 | /*-------------------------------------------------------------*/ |
157 | |
158 | /* The columns in SYS_TABLES */ |
159 | enum dict_col_sys_tables_enum { |
160 | DICT_COL__SYS_TABLES__NAME = 0, |
161 | DICT_COL__SYS_TABLES__ID = 1, |
162 | DICT_COL__SYS_TABLES__N_COLS = 2, |
163 | DICT_COL__SYS_TABLES__TYPE = 3, |
164 | DICT_COL__SYS_TABLES__MIX_ID = 4, |
165 | DICT_COL__SYS_TABLES__MIX_LEN = 5, |
166 | DICT_COL__SYS_TABLES__CLUSTER_ID = 6, |
167 | DICT_COL__SYS_TABLES__SPACE = 7, |
168 | DICT_NUM_COLS__SYS_TABLES = 8 |
169 | }; |
170 | /* The field numbers in the SYS_TABLES clustered index */ |
171 | enum dict_fld_sys_tables_enum { |
172 | DICT_FLD__SYS_TABLES__NAME = 0, |
173 | DICT_FLD__SYS_TABLES__DB_TRX_ID = 1, |
174 | DICT_FLD__SYS_TABLES__DB_ROLL_PTR = 2, |
175 | DICT_FLD__SYS_TABLES__ID = 3, |
176 | DICT_FLD__SYS_TABLES__N_COLS = 4, |
177 | DICT_FLD__SYS_TABLES__TYPE = 5, |
178 | DICT_FLD__SYS_TABLES__MIX_ID = 6, |
179 | DICT_FLD__SYS_TABLES__MIX_LEN = 7, |
180 | DICT_FLD__SYS_TABLES__CLUSTER_ID = 8, |
181 | DICT_FLD__SYS_TABLES__SPACE = 9, |
182 | DICT_NUM_FIELDS__SYS_TABLES = 10 |
183 | }; |
184 | /* The field numbers in the SYS_TABLE_IDS index */ |
185 | enum dict_fld_sys_table_ids_enum { |
186 | DICT_FLD__SYS_TABLE_IDS__ID = 0, |
187 | DICT_FLD__SYS_TABLE_IDS__NAME = 1, |
188 | DICT_NUM_FIELDS__SYS_TABLE_IDS = 2 |
189 | }; |
190 | /* The columns in SYS_COLUMNS */ |
191 | enum dict_col_sys_columns_enum { |
192 | DICT_COL__SYS_COLUMNS__TABLE_ID = 0, |
193 | DICT_COL__SYS_COLUMNS__POS = 1, |
194 | DICT_COL__SYS_COLUMNS__NAME = 2, |
195 | DICT_COL__SYS_COLUMNS__MTYPE = 3, |
196 | DICT_COL__SYS_COLUMNS__PRTYPE = 4, |
197 | DICT_COL__SYS_COLUMNS__LEN = 5, |
198 | DICT_COL__SYS_COLUMNS__PREC = 6, |
199 | DICT_NUM_COLS__SYS_COLUMNS = 7 |
200 | }; |
201 | /* The field numbers in the SYS_COLUMNS clustered index */ |
202 | enum dict_fld_sys_columns_enum { |
203 | DICT_FLD__SYS_COLUMNS__TABLE_ID = 0, |
204 | DICT_FLD__SYS_COLUMNS__POS = 1, |
205 | DICT_FLD__SYS_COLUMNS__DB_TRX_ID = 2, |
206 | DICT_FLD__SYS_COLUMNS__DB_ROLL_PTR = 3, |
207 | DICT_FLD__SYS_COLUMNS__NAME = 4, |
208 | DICT_FLD__SYS_COLUMNS__MTYPE = 5, |
209 | DICT_FLD__SYS_COLUMNS__PRTYPE = 6, |
210 | DICT_FLD__SYS_COLUMNS__LEN = 7, |
211 | DICT_FLD__SYS_COLUMNS__PREC = 8, |
212 | DICT_NUM_FIELDS__SYS_COLUMNS = 9 |
213 | }; |
214 | /* The columns in SYS_INDEXES */ |
215 | enum dict_col_sys_indexes_enum { |
216 | DICT_COL__SYS_INDEXES__TABLE_ID = 0, |
217 | DICT_COL__SYS_INDEXES__ID = 1, |
218 | DICT_COL__SYS_INDEXES__NAME = 2, |
219 | DICT_COL__SYS_INDEXES__N_FIELDS = 3, |
220 | DICT_COL__SYS_INDEXES__TYPE = 4, |
221 | DICT_COL__SYS_INDEXES__SPACE = 5, |
222 | DICT_COL__SYS_INDEXES__PAGE_NO = 6, |
223 | DICT_COL__SYS_INDEXES__MERGE_THRESHOLD = 7, |
224 | DICT_NUM_COLS__SYS_INDEXES = 8 |
225 | }; |
226 | /* The field numbers in the SYS_INDEXES clustered index */ |
227 | enum dict_fld_sys_indexes_enum { |
228 | DICT_FLD__SYS_INDEXES__TABLE_ID = 0, |
229 | DICT_FLD__SYS_INDEXES__ID = 1, |
230 | DICT_FLD__SYS_INDEXES__DB_TRX_ID = 2, |
231 | DICT_FLD__SYS_INDEXES__DB_ROLL_PTR = 3, |
232 | DICT_FLD__SYS_INDEXES__NAME = 4, |
233 | DICT_FLD__SYS_INDEXES__N_FIELDS = 5, |
234 | DICT_FLD__SYS_INDEXES__TYPE = 6, |
235 | DICT_FLD__SYS_INDEXES__SPACE = 7, |
236 | DICT_FLD__SYS_INDEXES__PAGE_NO = 8, |
237 | DICT_FLD__SYS_INDEXES__MERGE_THRESHOLD = 9, |
238 | DICT_NUM_FIELDS__SYS_INDEXES = 10 |
239 | }; |
240 | /* The columns in SYS_FIELDS */ |
241 | enum dict_col_sys_fields_enum { |
242 | DICT_COL__SYS_FIELDS__INDEX_ID = 0, |
243 | DICT_COL__SYS_FIELDS__POS = 1, |
244 | DICT_COL__SYS_FIELDS__COL_NAME = 2, |
245 | DICT_NUM_COLS__SYS_FIELDS = 3 |
246 | }; |
247 | /* The field numbers in the SYS_FIELDS clustered index */ |
248 | enum dict_fld_sys_fields_enum { |
249 | DICT_FLD__SYS_FIELDS__INDEX_ID = 0, |
250 | DICT_FLD__SYS_FIELDS__POS = 1, |
251 | DICT_FLD__SYS_FIELDS__DB_TRX_ID = 2, |
252 | DICT_FLD__SYS_FIELDS__DB_ROLL_PTR = 3, |
253 | DICT_FLD__SYS_FIELDS__COL_NAME = 4, |
254 | DICT_NUM_FIELDS__SYS_FIELDS = 5 |
255 | }; |
256 | /* The columns in SYS_FOREIGN */ |
257 | enum dict_col_sys_foreign_enum { |
258 | DICT_COL__SYS_FOREIGN__ID = 0, |
259 | DICT_COL__SYS_FOREIGN__FOR_NAME = 1, |
260 | DICT_COL__SYS_FOREIGN__REF_NAME = 2, |
261 | DICT_COL__SYS_FOREIGN__N_COLS = 3, |
262 | DICT_NUM_COLS__SYS_FOREIGN = 4 |
263 | }; |
264 | /* The field numbers in the SYS_FOREIGN clustered index */ |
265 | enum dict_fld_sys_foreign_enum { |
266 | DICT_FLD__SYS_FOREIGN__ID = 0, |
267 | DICT_FLD__SYS_FOREIGN__DB_TRX_ID = 1, |
268 | DICT_FLD__SYS_FOREIGN__DB_ROLL_PTR = 2, |
269 | DICT_FLD__SYS_FOREIGN__FOR_NAME = 3, |
270 | DICT_FLD__SYS_FOREIGN__REF_NAME = 4, |
271 | DICT_FLD__SYS_FOREIGN__N_COLS = 5, |
272 | DICT_NUM_FIELDS__SYS_FOREIGN = 6 |
273 | }; |
274 | /* The field numbers in the SYS_FOREIGN_FOR_NAME secondary index */ |
275 | enum dict_fld_sys_foreign_for_name_enum { |
276 | DICT_FLD__SYS_FOREIGN_FOR_NAME__NAME = 0, |
277 | DICT_FLD__SYS_FOREIGN_FOR_NAME__ID = 1, |
278 | DICT_NUM_FIELDS__SYS_FOREIGN_FOR_NAME = 2 |
279 | }; |
280 | /* The columns in SYS_FOREIGN_COLS */ |
281 | enum dict_col_sys_foreign_cols_enum { |
282 | DICT_COL__SYS_FOREIGN_COLS__ID = 0, |
283 | DICT_COL__SYS_FOREIGN_COLS__POS = 1, |
284 | DICT_COL__SYS_FOREIGN_COLS__FOR_COL_NAME = 2, |
285 | DICT_COL__SYS_FOREIGN_COLS__REF_COL_NAME = 3, |
286 | DICT_NUM_COLS__SYS_FOREIGN_COLS = 4 |
287 | }; |
288 | /* The field numbers in the SYS_FOREIGN_COLS clustered index */ |
289 | enum dict_fld_sys_foreign_cols_enum { |
290 | DICT_FLD__SYS_FOREIGN_COLS__ID = 0, |
291 | DICT_FLD__SYS_FOREIGN_COLS__POS = 1, |
292 | DICT_FLD__SYS_FOREIGN_COLS__DB_TRX_ID = 2, |
293 | DICT_FLD__SYS_FOREIGN_COLS__DB_ROLL_PTR = 3, |
294 | DICT_FLD__SYS_FOREIGN_COLS__FOR_COL_NAME = 4, |
295 | DICT_FLD__SYS_FOREIGN_COLS__REF_COL_NAME = 5, |
296 | DICT_NUM_FIELDS__SYS_FOREIGN_COLS = 6 |
297 | }; |
298 | /* The columns in SYS_TABLESPACES */ |
299 | enum dict_col_sys_tablespaces_enum { |
300 | DICT_COL__SYS_TABLESPACES__SPACE = 0, |
301 | DICT_COL__SYS_TABLESPACES__NAME = 1, |
302 | DICT_COL__SYS_TABLESPACES__FLAGS = 2, |
303 | DICT_NUM_COLS__SYS_TABLESPACES = 3 |
304 | }; |
305 | /* The field numbers in the SYS_TABLESPACES clustered index */ |
306 | enum dict_fld_sys_tablespaces_enum { |
307 | DICT_FLD__SYS_TABLESPACES__SPACE = 0, |
308 | DICT_FLD__SYS_TABLESPACES__DB_TRX_ID = 1, |
309 | DICT_FLD__SYS_TABLESPACES__DB_ROLL_PTR = 2, |
310 | DICT_FLD__SYS_TABLESPACES__NAME = 3, |
311 | DICT_FLD__SYS_TABLESPACES__FLAGS = 4, |
312 | DICT_NUM_FIELDS__SYS_TABLESPACES = 5 |
313 | }; |
314 | /* The columns in SYS_DATAFILES */ |
315 | enum dict_col_sys_datafiles_enum { |
316 | DICT_COL__SYS_DATAFILES__SPACE = 0, |
317 | DICT_COL__SYS_DATAFILES__PATH = 1, |
318 | DICT_NUM_COLS__SYS_DATAFILES = 2 |
319 | }; |
320 | /* The field numbers in the SYS_DATAFILES clustered index */ |
321 | enum dict_fld_sys_datafiles_enum { |
322 | DICT_FLD__SYS_DATAFILES__SPACE = 0, |
323 | DICT_FLD__SYS_DATAFILES__DB_TRX_ID = 1, |
324 | DICT_FLD__SYS_DATAFILES__DB_ROLL_PTR = 2, |
325 | DICT_FLD__SYS_DATAFILES__PATH = 3, |
326 | DICT_NUM_FIELDS__SYS_DATAFILES = 4 |
327 | }; |
328 | |
329 | /* The columns in SYS_VIRTUAL */ |
330 | enum dict_col_sys_virtual_enum { |
331 | DICT_COL__SYS_VIRTUAL__TABLE_ID = 0, |
332 | DICT_COL__SYS_VIRTUAL__POS = 1, |
333 | DICT_COL__SYS_VIRTUAL__BASE_POS = 2, |
334 | DICT_NUM_COLS__SYS_VIRTUAL = 3 |
335 | }; |
336 | /* The field numbers in the SYS_VIRTUAL clustered index */ |
337 | enum dict_fld_sys_virtual_enum { |
338 | DICT_FLD__SYS_VIRTUAL__TABLE_ID = 0, |
339 | DICT_FLD__SYS_VIRTUAL__POS = 1, |
340 | DICT_FLD__SYS_VIRTUAL__BASE_POS = 2, |
341 | DICT_FLD__SYS_VIRTUAL__DB_TRX_ID = 3, |
342 | DICT_FLD__SYS_VIRTUAL__DB_ROLL_PTR = 4, |
343 | DICT_NUM_FIELDS__SYS_VIRTUAL = 5 |
344 | }; |
345 | |
346 | /* A number of the columns above occur in multiple tables. These are the |
347 | length of thos fields. */ |
348 | #define DICT_FLD_LEN_SPACE 4 |
349 | #define DICT_FLD_LEN_FLAGS 4 |
350 | |
351 | /* When a row id which is zero modulo this number (which must be a power of |
352 | two) is assigned, the field DICT_HDR_ROW_ID on the dictionary header page is |
353 | updated */ |
354 | #define DICT_HDR_ROW_ID_WRITE_MARGIN 256 |
355 | |
356 | #include "dict0boot.ic" |
357 | |
358 | #endif |
359 | |