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