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