28 #include "mysql_version.h"
31 #include "dict0load.ic"
51 static const char* SYSTEM_TABLE_NAME[] = {
64 UNIV_INTERN my_bool srv_load_corrupted = FALSE;
80 dict_index_get_nth_field(
119 dfield = dtuple_get_nth_field(tuple, 0);
124 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
127 rec = btr_pcur_get_rec(&pcur);
139 field = rec_get_nth_field_old(
140 rec, DICT_FLD__SYS_TABLES__NAME, &len);
142 if (len < strlen(name)
143 ||
ut_memcmp(name, field, strlen(name)) != 0) {
190 srv_fatal_semaphore_wait_threshold,
191 SRV_SEMAPHORE_WAIT_EXTENSION);
202 err_msg =
static_cast<const char*
>(
211 fprintf(stderr,
" InnoDB: %s\n", err_msg);
225 os_decrement_counter_by_amount(
227 srv_fatal_semaphore_wait_threshold,
228 SRV_SEMAPHORE_WAIT_EXTENSION);
236 dict_getnext_system_low(
247 rec = btr_pcur_get_rec(pcur);
279 ut_a(system_id < SYS_NUM_SYSTEM_TABLES);
288 rec = dict_getnext_system_low(pcur, mtr);
310 rec = dict_getnext_system_low(pcur, mtr);
336 const char* err_msg = NULL;
339 field = (
const char*) rec_get_nth_field_old(
340 rec, DICT_FLD__SYS_TABLES__NAME, &len);
344 ut_ad(mtr_memo_contains_page(mtr, rec, MTR_MEMO_PAGE_S_FIX));
359 err_msg =
"Table not found in cache";
385 table_id_t* table_id)
394 heap, rec, FALSE, &index);
412 table_id_t* table_id,
413 const char** col_name)
419 table_id, col_name, rec);
437 index_id_t* index_id,
450 pos, last_index_id, heap, rec);
474 ulint n_fields_and_type;
477 return(
"delete-marked record in SYS_FOREIGN");
481 return(
"wrong number of columns in SYS_FOREIGN record");
484 field = rec_get_nth_field_old(
485 rec, DICT_FLD__SYS_FOREIGN__ID, &len);
486 if (len == 0 || len == UNIV_SQL_NULL) {
488 return(
"incorrect column length in SYS_FOREIGN");
498 rec, DICT_FLD__SYS_FOREIGN__DB_TRX_ID, &len);
499 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
503 rec, DICT_FLD__SYS_FOREIGN__DB_ROLL_PTR, &len);
504 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
511 field = rec_get_nth_field_old(
512 rec, DICT_FLD__SYS_FOREIGN__FOR_NAME, &len);
513 if (len == 0 || len == UNIV_SQL_NULL) {
517 heap, (
const char*) field, len);
519 field = rec_get_nth_field_old(
520 rec, DICT_FLD__SYS_FOREIGN__REF_NAME, &len);
521 if (len == 0 || len == UNIV_SQL_NULL) {
525 heap, (
const char*) field, len);
527 field = rec_get_nth_field_old(
528 rec, DICT_FLD__SYS_FOREIGN__N_COLS, &len);
534 foreign->
type = (
unsigned int) (n_fields_and_type >> 24);
535 foreign->
n_fields = (
unsigned int) (n_fields_and_type & 0x3FFUL);
551 const char** for_col_name,
552 const char** ref_col_name,
560 return(
"delete-marked record in SYS_FOREIGN_COLS");
564 return(
"wrong number of columns in SYS_FOREIGN_COLS record");
567 field = rec_get_nth_field_old(
568 rec, DICT_FLD__SYS_FOREIGN_COLS__ID, &len);
569 if (len == 0 || len == UNIV_SQL_NULL) {
571 return(
"incorrect column length in SYS_FOREIGN_COLS");
575 field = rec_get_nth_field_old(
576 rec, DICT_FLD__SYS_FOREIGN_COLS__POS, &len);
583 rec, DICT_FLD__SYS_FOREIGN_COLS__DB_TRX_ID, &len);
584 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
588 rec, DICT_FLD__SYS_FOREIGN_COLS__DB_ROLL_PTR, &len);
589 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
593 field = rec_get_nth_field_old(
594 rec, DICT_FLD__SYS_FOREIGN_COLS__FOR_COL_NAME, &len);
595 if (len == 0 || len == UNIV_SQL_NULL) {
600 field = rec_get_nth_field_old(
601 rec, DICT_FLD__SYS_FOREIGN_COLS__REF_COL_NAME, &len);
602 if (len == 0 || len == UNIV_SQL_NULL) {
628 *space = ULINT_UNDEFINED;
630 *flags = ULINT_UNDEFINED;
633 return(
"delete-marked record in SYS_TABLESPACES");
637 return(
"wrong number of columns in SYS_TABLESPACES record");
640 field = rec_get_nth_field_old(
641 rec, DICT_FLD__SYS_TABLESPACES__SPACE, &len);
642 if (len != DICT_FLD_LEN_SPACE) {
644 return(
"incorrect column length in SYS_TABLESPACES");
649 rec, DICT_FLD__SYS_TABLESPACES__DB_TRX_ID, &len);
650 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
655 rec, DICT_FLD__SYS_TABLESPACES__DB_ROLL_PTR, &len);
656 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
660 field = rec_get_nth_field_old(
661 rec, DICT_FLD__SYS_TABLESPACES__NAME, &len);
662 if (len == 0 || len == UNIV_SQL_NULL) {
667 field = rec_get_nth_field_old(
668 rec, DICT_FLD__SYS_TABLESPACES__FLAGS, &len);
669 if (len != DICT_FLD_LEN_FLAGS) {
694 return(
"delete-marked record in SYS_DATAFILES");
698 return(
"wrong number of columns in SYS_DATAFILES record");
701 field = rec_get_nth_field_old(
702 rec, DICT_FLD__SYS_DATAFILES__SPACE, &len);
703 if (len != DICT_FLD_LEN_SPACE) {
705 return(
"incorrect column length in SYS_DATAFILES");
710 rec, DICT_FLD__SYS_DATAFILES__DB_TRX_ID, &len);
711 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
716 rec, DICT_FLD__SYS_DATAFILES__DB_ROLL_PTR, &len);
717 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
721 field = rec_get_nth_field_old(
722 rec, DICT_FLD__SYS_DATAFILES__PATH, &len);
723 if (len == 0 || len == UNIV_SQL_NULL) {
736 dict_sys_tables_get_flags(
746 field = rec_get_nth_field_old(
747 rec, DICT_FLD__SYS_TABLES__TYPE, &len);
757 field = rec_get_nth_field_old(
758 rec, DICT_FLD__SYS_TABLES__N_COLS, &len);
766 if (ULINT_UNDEFINED == dict_sys_tables_type_validate(type, n_cols)) {
767 return(ULINT_UNDEFINED);
770 return(dict_sys_tables_type_to_tf(type, n_cols));
801 char* dict_filepath = NULL;
811 ut_ad(name_of_col_is(sys_datafiles, sys_index,
812 DICT_FLD__SYS_DATAFILES__SPACE,
"SPACE"));
813 ut_ad(name_of_col_is(sys_datafiles, sys_index,
814 DICT_FLD__SYS_DATAFILES__PATH,
"PATH"));
817 dfield = dtuple_get_nth_field(tuple, DICT_FLD__SYS_DATAFILES__SPACE);
825 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
828 rec = btr_pcur_get_rec(&pcur);
836 field = rec_get_nth_field_old(
837 rec, DICT_FLD__SYS_DATAFILES__PATH, &len);
838 ut_a(len > 0 || len == UNIV_SQL_NULL);
839 ut_a(len < OS_FILE_MAX_PATH);
848 return(dict_filepath);
859 const char* filepath)
864 #ifdef UNIV_SYNC_DEBUG
870 trx->
op_info =
"update filepath";
880 "PROCEDURE UPDATE_FILEPATH () IS\n"
882 "UPDATE SYS_DATAFILES"
883 " SET PATH = :path\n"
884 " WHERE SPACE = :space;\n"
885 "END;\n", FALSE, trx);
891 if (err == DB_SUCCESS) {
895 "The InnoDB data dictionary table SYS_DATAFILES "
896 "for tablespace ID %lu was updated to use file %s.",
897 (ulong) space_id, filepath);
900 "Problem updating InnoDB data dictionary table "
901 "SYS_DATAFILES for tablespace ID %lu to file %s.",
902 (ulong) space_id, filepath);
917 const char* filepath,
923 #ifdef UNIV_SYNC_DEBUG
930 trx->
op_info =
"insert tablespace and filepath";
938 space, name, fsp_flags, filepath, trx,
false);
982 + DICT_HDR_MAX_SPACE_ID,
991 rec = btr_pcur_get_rec(&pcur);
1021 field = rec_get_nth_field_old(
1022 rec, DICT_FLD__SYS_TABLES__NAME, &len);
1029 table_name,
sizeof(table_name), name, FALSE);
1031 flags = dict_sys_tables_get_flags(rec);
1032 if (UNIV_UNLIKELY(flags == ULINT_UNDEFINED)) {
1034 field = rec_get_nth_field_old(
1035 rec, DICT_FLD__SYS_TABLES__TYPE, &len);
1040 "Table '%s' in InnoDB data dictionary"
1041 " has unknown type %lx", table_name, flags);
1046 field = rec_get_nth_field_old(
1047 rec, DICT_FLD__SYS_TABLES__SPACE, &len);
1063 field = rec_get_nth_field_old(
1064 rec, DICT_FLD__SYS_TABLES__MIX_LEN, &len);
1066 bool is_temp =
false;
1067 bool discarded =
false;
1075 field = rec_get_nth_field_old(
1076 rec, DICT_FLD__SYS_TABLES__N_COLS, &len);
1085 if (space_id == 0) {
1088 goto next_tablespace;
1091 switch (dict_check) {
1097 space_id, name, TRUE, !(is_temp || discarded),
1105 space_id, name, FALSE, FALSE,
1113 "DISCARD flag set for table '%s',"
1125 char* filepath = NULL;
1142 if (err != DB_SUCCESS) {
1144 "Tablespace open failed for '%s', "
1145 "ignored.", table_name);
1155 if (space_id > max_space_id) {
1156 max_space_id = space_id;
1185 table_id_t* table_id,
1186 const char** col_name,
1197 ut_ad(table || column);
1200 return(
"delete-marked record in SYS_COLUMNS");
1204 return(
"wrong number of columns in SYS_COLUMNS record");
1207 field = rec_get_nth_field_old(
1208 rec, DICT_FLD__SYS_COLUMNS__TABLE_ID, &len);
1211 return(
"incorrect column length in SYS_COLUMNS");
1217 return(
"SYS_COLUMNS.TABLE_ID mismatch");
1220 field = rec_get_nth_field_old(
1221 rec, DICT_FLD__SYS_COLUMNS__POS, &len);
1229 if (table && table->
n_def != pos) {
1230 return(
"SYS_COLUMNS.POS mismatch");
1234 rec, DICT_FLD__SYS_COLUMNS__DB_TRX_ID, &len);
1235 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
1239 rec, DICT_FLD__SYS_COLUMNS__DB_ROLL_PTR, &len);
1240 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
1244 field = rec_get_nth_field_old(
1245 rec, DICT_FLD__SYS_COLUMNS__NAME, &len);
1246 if (len == 0 || len == UNIV_SQL_NULL) {
1256 field = rec_get_nth_field_old(
1257 rec, DICT_FLD__SYS_COLUMNS__MTYPE, &len);
1264 field = rec_get_nth_field_old(
1265 rec, DICT_FLD__SYS_COLUMNS__PRTYPE, &len);
1281 DATA_MYSQL_BINARY_CHARSET_COLL);
1288 data_mysql_default_charset_coll);
1292 field = rec_get_nth_field_old(
1293 rec, DICT_FLD__SYS_COLUMNS__LEN, &len);
1298 field = rec_get_nth_field_old(
1299 rec, DICT_FLD__SYS_COLUMNS__PREC, &len);
1343 ut_ad(name_of_col_is(sys_columns, sys_index,
1344 DICT_FLD__SYS_COLUMNS__NAME,
"NAME"));
1345 ut_ad(name_of_col_is(sys_columns, sys_index,
1346 DICT_FLD__SYS_COLUMNS__PREC,
"PREC"));
1349 dfield = dtuple_get_nth_field(tuple, 0);
1357 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
1359 for (i = 0; i + DATA_N_SYS_COLS < (ulint) table->
n_cols; i++) {
1360 const char* err_msg;
1363 rec = btr_pcur_get_rec(&pcur);
1371 fprintf(stderr,
"InnoDB: %s\n", err_msg);
1388 if (table->fts == NULL) {
1395 col = dict_table_get_nth_col(table, i);
1399 if (col->
prtype & DATA_FTS_DOC_ID) {
1402 DICT_TF2_FLAG_UNSET(
1417 static const char* dict_load_field_del =
"delete-marked record in SYS_FIELDS";
1437 byte* last_index_id,
1444 ulint pos_and_prefix_len;
1450 ut_a((!index) || (!sys_field));
1453 return(dict_load_field_del);
1457 return(
"wrong number of columns in SYS_FIELDS record");
1460 field = rec_get_nth_field_old(
1461 rec, DICT_FLD__SYS_FIELDS__INDEX_ID, &len);
1464 return(
"incorrect column length in SYS_FIELDS");
1468 ut_a(last_index_id);
1469 memcpy(index_id, (
const char*) field, 8);
1470 first_field = memcmp(index_id, last_index_id, 8);
1472 first_field = (index->
n_def == 0);
1473 if (memcmp(field, index_id, 8)) {
1474 return(
"SYS_FIELDS.INDEX_ID mismatch");
1486 field = rec_get_nth_field_old(
1487 rec, DICT_FLD__SYS_FIELDS__POS, &len);
1494 if (index && UNIV_UNLIKELY
1495 ((pos_and_prefix_len & 0xFFFFUL) != index->
n_def
1496 && (pos_and_prefix_len >> 16 & 0xFFFF) != index->
n_def)) {
1497 return(
"SYS_FIELDS.POS mismatch");
1500 if (first_field || pos_and_prefix_len > 0xFFFFUL) {
1501 prefix_len = pos_and_prefix_len & 0xFFFFUL;
1502 position = (pos_and_prefix_len & 0xFFFF0000UL) >> 16;
1505 position = pos_and_prefix_len & 0xFFFFUL;
1509 rec, DICT_FLD__SYS_FIELDS__DB_TRX_ID, &len);
1510 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
1514 rec, DICT_FLD__SYS_FIELDS__DB_ROLL_PTR, &len);
1515 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
1519 field = rec_get_nth_field_old(
1520 rec, DICT_FLD__SYS_FIELDS__COL_NAME, &len);
1521 if (len == 0 || len == UNIV_SQL_NULL) {
1534 heap, (
const char*) field, len);
1570 ut_ad(name_of_col_is(sys_fields, sys_index,
1571 DICT_FLD__SYS_FIELDS__COL_NAME,
"COL_NAME"));
1574 dfield = dtuple_get_nth_field(tuple, 0);
1582 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
1584 for (i = 0; i < index->
n_fields; i++) {
1585 const char* err_msg;
1587 rec = btr_pcur_get_rec(&pcur);
1594 if (err_msg == dict_load_field_del) {
1600 }
else if (err_msg) {
1601 fprintf(stderr,
"InnoDB: %s\n", err_msg);
1617 static const char* dict_load_index_del =
"delete-marked record in SYS_INDEXES";
1619 static const char* dict_load_index_id_err =
"SYS_INDEXES.TABLE_ID mismatch";
1658 return(dict_load_index_del);
1662 return(
"wrong number of columns in SYS_INDEXES record");
1665 field = rec_get_nth_field_old(
1666 rec, DICT_FLD__SYS_INDEXES__TABLE_ID, &len);
1669 return(
"incorrect column length in SYS_INDEXES");
1674 memcpy(table_id, (
const char*) field, 8);
1675 }
else if (memcmp(field, table_id, 8)) {
1678 return(dict_load_index_id_err);
1681 field = rec_get_nth_field_old(
1682 rec, DICT_FLD__SYS_INDEXES__ID, &len);
1690 rec, DICT_FLD__SYS_INDEXES__DB_TRX_ID, &len);
1691 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
1695 rec, DICT_FLD__SYS_INDEXES__DB_ROLL_PTR, &len);
1696 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
1700 field = rec_get_nth_field_old(
1701 rec, DICT_FLD__SYS_INDEXES__NAME, &name_len);
1702 if (name_len == UNIV_SQL_NULL) {
1709 field = rec_get_nth_field_old(
1710 rec, DICT_FLD__SYS_INDEXES__N_FIELDS, &len);
1716 field = rec_get_nth_field_old(
1717 rec, DICT_FLD__SYS_INDEXES__TYPE, &len);
1723 return(
"unknown SYS_INDEXES.TYPE bits");
1726 field = rec_get_nth_field_old(
1727 rec, DICT_FLD__SYS_INDEXES__SPACE, &len);
1733 field = rec_get_nth_field_old(
1734 rec, DICT_FLD__SYS_INDEXES__PAGE_NO, &len);
1741 space, type, n_fields);
1746 space, type, n_fields);
1751 ut_ad((*index)->page);
1761 static __attribute__((nonnull))
1788 ut_ad(name_of_col_is(sys_indexes, sys_index,
1789 DICT_FLD__SYS_INDEXES__NAME,
"NAME"));
1790 ut_ad(name_of_col_is(sys_indexes, sys_index,
1791 DICT_FLD__SYS_INDEXES__PAGE_NO,
"PAGE_NO"));
1794 dfield = dtuple_get_nth_field(tuple, 0);
1802 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
1806 const char* err_msg;
1814 if (dict_table_get_first_index(table) == NULL
1817 "Cannot load table %s "
1818 "because it has no indexes in "
1819 "InnoDB internal data dictionary.",
1828 rec = btr_pcur_get_rec(&pcur);
1832 == DICT_NUM_FIELDS__SYS_INDEXES) {
1835 field = rec_get_nth_field_old(
1836 rec, DICT_FLD__SYS_INDEXES__NAME, &len);
1838 if (len != UNIV_SQL_NULL
1849 ut_ad((index == NULL && err_msg != NULL)
1850 || (index != NULL && err_msg == NULL));
1852 if (err_msg == dict_load_index_id_err) {
1856 if (dict_table_get_first_index(table) == NULL
1859 "Failed to load the "
1860 "clustered index for table %s "
1861 "because of the following error: %s. "
1862 "Refusing to load the rest of the "
1863 "indexes (if any) and the whole table "
1864 "altogether.", table->name, err_msg);
1870 }
else if (err_msg == dict_load_index_del) {
1873 }
else if (err_msg) {
1874 fprintf(stderr,
"InnoDB: %s\n", err_msg);
1887 fputs(
" InnoDB: ", stderr);
1889 fputs(
" is corrupted\n", stderr);
1891 if (!srv_load_corrupted
1906 fputs(
" InnoDB: load corrupted index ", stderr);
1912 if (index->
type & DICT_FTS
1915 ut_a(table->fts != NULL);
1924 "Unknown type %lu of index %s of table %s",
1925 (ulong) index->
type, index->
name, table->name);
1931 && !table->ibd_file_missing
1932 && (!(index->
type & DICT_FTS))) {
1935 "InnoDB: Error: trying to load index %s"
1937 "InnoDB: but the index tree has been freed!\n",
1938 index->
name, table->name);
1953 "InnoDB: Index is corrupt but forcing"
1954 " load into data dictionary\n");
1962 && NULL == dict_table_get_first_index(table)) {
1964 fputs(
"InnoDB: Error: trying to load index ",
1967 fputs(
" for table ", stderr);
1969 fputs(
"\nInnoDB: but the first index"
1970 " is not clustered!\n", stderr);
1976 && !strcmp(
"ID_IND", index->
name)))) {
1982 dict_load_fields(index, heap);
1985 table, index, index->
page, FALSE);
1992 if (UNIV_UNLIKELY(error != DB_SUCCESS)) {
2004 ut_a(table->fts->indexes != NULL);
2035 return(
"delete-marked record in SYS_TABLES");
2039 return(
"wrong number of columns in SYS_TABLES record");
2043 rec, DICT_FLD__SYS_TABLES__NAME, &len);
2044 if (len == 0 || len == UNIV_SQL_NULL) {
2046 return(
"incorrect column length in SYS_TABLES");
2049 rec, DICT_FLD__SYS_TABLES__DB_TRX_ID, &len);
2050 if (len != DATA_TRX_ID_LEN && len != UNIV_SQL_NULL) {
2054 rec, DICT_FLD__SYS_TABLES__DB_ROLL_PTR, &len);
2055 if (len != DATA_ROLL_PTR_LEN && len != UNIV_SQL_NULL) {
2064 field = rec_get_nth_field_old(
2065 rec, DICT_FLD__SYS_TABLES__N_COLS, &len);
2078 rec, DICT_FLD__SYS_TABLES__MIX_ID, &len);
2083 field = rec_get_nth_field_old(
2084 rec, DICT_FLD__SYS_TABLES__MIX_LEN, &len);
2096 rec, DICT_FLD__SYS_TABLES__CLUSTER_ID, &len);
2097 if (len != UNIV_SQL_NULL) {
2101 field = rec_get_nth_field_old(
2102 rec, DICT_FLD__SYS_TABLES__SPACE, &len);
2110 flags = dict_sys_tables_get_flags(rec);
2112 if (UNIV_UNLIKELY(flags == ULINT_UNDEFINED)) {
2113 field = rec_get_nth_field_old(
2114 rec, DICT_FLD__SYS_TABLES__TYPE, &len);
2119 fputs(
" InnoDB: Error: table ", stderr);
2121 fprintf(stderr,
"\n"
2122 "InnoDB: in InnoDB data dictionary"
2123 " has unknown type %lx.\n",
2125 return(
"incorrect flags in SYS_TABLES");
2133 if (flags2 & ~DICT_TF2_BIT_MASK) {
2135 fputs(
" InnoDB: Warning: table ", stderr);
2137 fprintf(stderr,
"\n"
2138 "InnoDB: in InnoDB data dictionary"
2139 " has unknown flags %lx.\n",
2143 flags2 &= DICT_TF2_BIT_MASK;
2153 name, space, n_cols & ~DICT_N_COLS_COMPACT, flags, flags2);
2155 field = rec_get_nth_field_old(rec, DICT_FLD__SYS_TABLES__ID, &len);
2160 (*table)->ibd_file_missing = FALSE;
2186 if (strcmp(filepath, default_filepath)) {
2187 ulint pathlen = strlen(filepath);
2188 ut_a(pathlen < OS_FILE_MAX_PATH);
2189 ut_a(0 == strcmp(filepath + pathlen - 4,
".ibd"));
2210 bool dict_mutex_own)
2217 if (!dict_mutex_own) {
2230 if (!dict_mutex_own) {
2267 char* filepath = NULL;
2268 const char* err_msg;
2280 ut_ad(name_of_col_is(sys_tables, sys_index,
2281 DICT_FLD__SYS_TABLES__ID,
"ID"));
2282 ut_ad(name_of_col_is(sys_tables, sys_index,
2283 DICT_FLD__SYS_TABLES__N_COLS,
"N_COLS"));
2284 ut_ad(name_of_col_is(sys_tables, sys_index,
2285 DICT_FLD__SYS_TABLES__TYPE,
"TYPE"));
2286 ut_ad(name_of_col_is(sys_tables, sys_index,
2287 DICT_FLD__SYS_TABLES__MIX_LEN,
"MIX_LEN"));
2288 ut_ad(name_of_col_is(sys_tables, sys_index,
2289 DICT_FLD__SYS_TABLES__SPACE,
"SPACE"));
2292 dfield = dtuple_get_nth_field(tuple, 0);
2297 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
2299 rec = btr_pcur_get_rec(&pcur);
2312 field = rec_get_nth_field_old(
2313 rec, DICT_FLD__SYS_TABLES__NAME, &len);
2326 fprintf(stderr,
" InnoDB: %s\n", err_msg);
2337 if (table->
space == 0) {
2342 "Table '%s' tablespace is set as discarded.",
2348 table->
space, name, FALSE, FALSE,
true, heap,
2358 "Failed to find tablespace for "
2359 "table '%s' in the cache. "
2360 "Attempting to load the tablespace "
2361 "with space id %lu.",
2362 table_name, (ulong) table->
space);
2374 table->
name,
"ibd");
2382 true,
false, table->
space,
2386 if (err != DB_SUCCESS) {
2398 dict_load_columns(table, heap);
2418 err = dict_load_indexes(table, heap, index_load_err);
2423 if (!srv_load_corrupted) {
2424 fprintf(stderr,
"InnoDB: Error: Load table ");
2426 fprintf(stderr,
" failed, the table has corrupted"
2427 " clustered indexes. Turn on"
2428 " 'innodb_force_load_corrupted'"
2436 clust_index = dict_table_get_first_index(table);
2454 }
else if (err == DB_SUCCESS) {
2458 if (err != DB_SUCCESS) {
2460 "Load table '%s' failed, the table has missing "
2461 "foreign key indexes. Turn off "
2462 "'foreign_key_checks' and try again.",
2475 index = dict_table_get_first_index(table);
2502 if (table && table->fts) {
2525 table_id_t table_id,
2554 sys_table_ids = dict_table_get_next_index(
2555 dict_table_get_first_index(sys_tables));
2561 dfield = dtuple_get_nth_field(tuple, 0);
2569 btr_pcur_open_on_user_rec(sys_table_ids, tuple, PAGE_CUR_GE,
2573 rec = btr_pcur_get_rec(&pcur);
2580 field = rec_get_nth_field_old(
2581 rec, DICT_FLD__SYS_TABLE_IDS__ID, &len);
2598 field = rec_get_nth_field_old(rec,
2599 DICT_FLD__SYS_TABLE_IDS__NAME, &len);
2603 heap, (
char*) field, len),
2649 dict_load_foreign_cols(
2667 id_len = strlen(foreign->
id);
2671 foreign->
n_fields *
sizeof(
void*)));
2675 foreign->
n_fields *
sizeof(
void*)));
2685 dfield = dtuple_get_nth_field(tuple, 0);
2690 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
2692 for (i = 0; i < foreign->
n_fields; i++) {
2694 rec = btr_pcur_get_rec(&pcur);
2699 field = rec_get_nth_field_old(
2700 rec, DICT_FLD__SYS_FOREIGN_COLS__ID, &len);
2702 if (len != id_len ||
ut_memcmp(foreign->
id, field, len) != 0) {
2705 const rec_t* for_col_name;
2706 ulint for_col_name_len;
2707 const rec_t* ref_col_name;
2708 ulint ref_col_name_len;
2710 pos = rec_get_nth_field_old(
2711 rec, DICT_FLD__SYS_FOREIGN_COLS__POS,
2714 for_col_name = rec_get_nth_field_old(
2715 rec, DICT_FLD__SYS_FOREIGN_COLS__FOR_COL_NAME,
2718 ref_col_name = rec_get_nth_field_old(
2719 rec, DICT_FLD__SYS_FOREIGN_COLS__REF_COL_NAME,
2723 "Unable to load columns names for foreign "
2724 "key '%s' because it was not found in "
2725 "InnoDB internal table SYS_FOREIGN_COLS. The "
2726 "closest entry we found is: "
2727 "(ID='%.*s', POS=%lu, FOR_COL_NAME='%.*s', "
2728 "REF_COL_NAME='%.*s')",
2732 (
int) for_col_name_len, for_col_name,
2733 (
int) ref_col_name_len, ref_col_name);
2738 field = rec_get_nth_field_old(
2739 rec, DICT_FLD__SYS_FOREIGN_COLS__POS, &len);
2743 field = rec_get_nth_field_old(
2744 rec, DICT_FLD__SYS_FOREIGN_COLS__FOR_COL_NAME, &len);
2746 foreign->
heap, (
char*) field, len);
2748 field = rec_get_nth_field_old(
2749 rec, DICT_FLD__SYS_FOREIGN_COLS__REF_COL_NAME, &len);
2751 foreign->
heap, (
char*) field, len);
2763 static __attribute__((nonnull(1), warn_unused_result))
2770 const
char** col_names,
2773 bool check_recursive,
2777 bool check_charsets,
2793 ulint n_fields_and_type;
2801 id_len = strlen(
id);
2813 dfield = dtuple_get_nth_field(tuple, 0);
2818 btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
2820 rec = btr_pcur_get_rec(&pcur);
2827 "InnoDB: Error: cannot load foreign constraint "
2828 "%s: could not find the relevant record in "
2829 "SYS_FOREIGN\n",
id);
2838 field = rec_get_nth_field_old(rec, DICT_FLD__SYS_FOREIGN__ID, &len);
2841 if (len != id_len ||
ut_memcmp(
id, field, len) != 0) {
2844 "InnoDB: Error: cannot load foreign constraint "
2845 "%s: found %.*s instead in SYS_FOREIGN\n",
2846 id, (
int) len, field);
2863 rec_get_nth_field_old(
2864 rec, DICT_FLD__SYS_FOREIGN__N_COLS, &len));
2870 foreign->
type = (
unsigned int) (n_fields_and_type >> 24);
2871 foreign->
n_fields = (
unsigned int) (n_fields_and_type & 0x3FFUL);
2875 field = rec_get_nth_field_old(
2876 rec, DICT_FLD__SYS_FOREIGN__FOR_NAME, &len);
2879 foreign->
heap, (
char*) field, len);
2882 field = rec_get_nth_field_old(
2883 rec, DICT_FLD__SYS_FOREIGN__REF_NAME, &len);
2885 foreign->
heap, (
char*) field, len);
2891 dict_load_foreign_cols(foreign);
2929 if (for_table && ref_table && check_recursive) {
2965 const char* table_name,
2966 const char** col_names,
2968 bool check_recursive,
2971 bool check_charsets,
2975 ulint tuple_buf[(DTUPLE_EST_ALLOC(1) +
sizeof(ulint) - 1)
2992 if (sys_foreign == NULL) {
2996 "InnoDB: Error: no foreign key system tables"
2997 " in the database\n");
3008 sec_index = dict_table_get_next_index(
3009 dict_table_get_first_index(sys_foreign));
3014 dfield = dtuple_get_nth_field(tuple, 0);
3019 btr_pcur_open_on_user_rec(sec_index, tuple, PAGE_CUR_GE,
3022 rec = btr_pcur_get_rec(&pcur);
3027 goto load_next_index;
3033 field = rec_get_nth_field_old(
3034 rec, DICT_FLD__SYS_FOREIGN_FOR_NAME__NAME, &len);
3041 dfield_get_type(dfield)->prtype,
3042 static_cast<const byte*>(
3043 dfield_get_data(dfield)),
3047 goto load_next_index;
3062 && (0 !=
ut_memcmp(field, table_name, len))) {
3067 field = rec_get_nth_field_old(
3068 rec, DICT_FLD__SYS_FOREIGN_FOR_NAME__ID, &len);
3075 memcpy(fk_id, field, len);
3084 err = dict_load_foreign(fk_id, col_names,
3085 check_recursive, check_charsets, ignore_err);
3087 if (err != DB_SUCCESS) {
3105 sec_index = dict_table_get_next_index(sec_index);
3107 if (sec_index != NULL) {
3114 check_recursive = FALSE;