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