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