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