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