You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1407 lines
35 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /******************************************************
  2. Loads to the memory cache database object definitions
  3. from dictionary tables
  4. (c) 1996 Innobase Oy
  5. Created 4/24/1996 Heikki Tuuri
  6. *******************************************************/
  7. #include "dict0load.h"
  8. #ifndef UNIV_HOTBACKUP
  9. #include "mysql_version.h"
  10. #endif /* !UNIV_HOTBACKUP */
  11. #ifdef UNIV_NONINL
  12. #include "dict0load.ic"
  13. #endif
  14. #include "btr0pcur.h"
  15. #include "btr0btr.h"
  16. #include "page0page.h"
  17. #include "mach0data.h"
  18. #include "dict0dict.h"
  19. #include "dict0boot.h"
  20. #include "rem0cmp.h"
  21. #include "srv0start.h"
  22. #include "srv0srv.h"
  23. /********************************************************************
  24. Returns TRUE if index's i'th column's name is 'name' .*/
  25. static
  26. ibool
  27. name_of_col_is(
  28. /*===========*/
  29. /* out: */
  30. dict_table_t* table, /* in: table */
  31. dict_index_t* index, /* in: index */
  32. ulint i, /* in: */
  33. const char* name) /* in: name to compare to */
  34. {
  35. ulint tmp = dict_col_get_no(dict_field_get_col(
  36. dict_index_get_nth_field(
  37. index, i)));
  38. return(strcmp(name, dict_table_get_col_name(table, tmp)) == 0);
  39. }
  40. /************************************************************************
  41. Finds the first table name in the given database. */
  42. char*
  43. dict_get_first_table_name_in_db(
  44. /*============================*/
  45. /* out, own: table name, NULL if
  46. does not exist; the caller must
  47. free the memory in the string! */
  48. const char* name) /* in: database name which ends in '/' */
  49. {
  50. dict_table_t* sys_tables;
  51. btr_pcur_t pcur;
  52. dict_index_t* sys_index;
  53. dtuple_t* tuple;
  54. mem_heap_t* heap;
  55. dfield_t* dfield;
  56. const rec_t* rec;
  57. const byte* field;
  58. ulint len;
  59. mtr_t mtr;
  60. ut_ad(mutex_own(&(dict_sys->mutex)));
  61. heap = mem_heap_create(1000);
  62. mtr_start(&mtr);
  63. sys_tables = dict_table_get_low("SYS_TABLES");
  64. sys_index = UT_LIST_GET_FIRST(sys_tables->indexes);
  65. ut_a(!dict_table_is_comp(sys_tables));
  66. tuple = dtuple_create(heap, 1);
  67. dfield = dtuple_get_nth_field(tuple, 0);
  68. dfield_set_data(dfield, name, ut_strlen(name));
  69. dict_index_copy_types(tuple, sys_index, 1);
  70. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  71. BTR_SEARCH_LEAF, &pcur, &mtr);
  72. loop:
  73. rec = btr_pcur_get_rec(&pcur);
  74. if (!btr_pcur_is_on_user_rec(&pcur)) {
  75. /* Not found */
  76. btr_pcur_close(&pcur);
  77. mtr_commit(&mtr);
  78. mem_heap_free(heap);
  79. return(NULL);
  80. }
  81. field = rec_get_nth_field_old(rec, 0, &len);
  82. if (len < strlen(name)
  83. || ut_memcmp(name, field, strlen(name)) != 0) {
  84. /* Not found */
  85. btr_pcur_close(&pcur);
  86. mtr_commit(&mtr);
  87. mem_heap_free(heap);
  88. return(NULL);
  89. }
  90. if (!rec_get_deleted_flag(rec, 0)) {
  91. /* We found one */
  92. char* table_name = mem_strdupl((char*) field, len);
  93. btr_pcur_close(&pcur);
  94. mtr_commit(&mtr);
  95. mem_heap_free(heap);
  96. return(table_name);
  97. }
  98. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  99. goto loop;
  100. }
  101. /************************************************************************
  102. Prints to the standard output information on all tables found in the data
  103. dictionary system table. */
  104. void
  105. dict_print(void)
  106. /*============*/
  107. {
  108. dict_table_t* sys_tables;
  109. dict_index_t* sys_index;
  110. dict_table_t* table;
  111. btr_pcur_t pcur;
  112. const rec_t* rec;
  113. const byte* field;
  114. ulint len;
  115. mtr_t mtr;
  116. /* Enlarge the fatal semaphore wait timeout during the InnoDB table
  117. monitor printout */
  118. mutex_enter(&kernel_mutex);
  119. srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */
  120. mutex_exit(&kernel_mutex);
  121. mutex_enter(&(dict_sys->mutex));
  122. mtr_start(&mtr);
  123. sys_tables = dict_table_get_low("SYS_TABLES");
  124. sys_index = UT_LIST_GET_FIRST(sys_tables->indexes);
  125. btr_pcur_open_at_index_side(TRUE, sys_index, BTR_SEARCH_LEAF, &pcur,
  126. TRUE, &mtr);
  127. loop:
  128. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  129. rec = btr_pcur_get_rec(&pcur);
  130. if (!btr_pcur_is_on_user_rec(&pcur)) {
  131. /* end of index */
  132. btr_pcur_close(&pcur);
  133. mtr_commit(&mtr);
  134. mutex_exit(&(dict_sys->mutex));
  135. /* Restore the fatal semaphore wait timeout */
  136. mutex_enter(&kernel_mutex);
  137. srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */
  138. mutex_exit(&kernel_mutex);
  139. return;
  140. }
  141. field = rec_get_nth_field_old(rec, 0, &len);
  142. if (!rec_get_deleted_flag(rec, 0)) {
  143. /* We found one */
  144. char* table_name = mem_strdupl((char*) field, len);
  145. btr_pcur_store_position(&pcur, &mtr);
  146. mtr_commit(&mtr);
  147. table = dict_table_get_low(table_name);
  148. mem_free(table_name);
  149. if (table == NULL) {
  150. fputs("InnoDB: Failed to load table ", stderr);
  151. ut_print_namel(stderr, NULL, TRUE, (char*) field, len);
  152. putc('\n', stderr);
  153. } else {
  154. /* The table definition was corrupt if there
  155. is no index */
  156. if (dict_table_get_first_index(table)) {
  157. dict_update_statistics_low(table, TRUE);
  158. }
  159. dict_table_print_low(table);
  160. }
  161. mtr_start(&mtr);
  162. btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
  163. }
  164. goto loop;
  165. }
  166. /************************************************************************
  167. Determine the compressed page size of a table described in SYS_TABLES. */
  168. static
  169. ulint
  170. dict_sys_tables_get_zip_size(
  171. /*=========================*/
  172. /* out: compressed page size in kilobytes;
  173. or 0 if the tablespace is uncompressed,
  174. ULINT_UNDEFINED on error */
  175. const rec_t* rec) /* in: a record of SYS_TABLES */
  176. {
  177. const byte* field;
  178. ulint len;
  179. ulint n_cols;
  180. ulint table_type;
  181. field = rec_get_nth_field_old(rec, 5, &len);
  182. ut_a(len == 4);
  183. table_type = mach_read_from_4(field);
  184. field = rec_get_nth_field_old(rec, 4, &len);
  185. n_cols = mach_read_from_4(field);
  186. if (UNIV_EXPECT(n_cols & 0x80000000UL, 0x80000000UL)
  187. && UNIV_LIKELY(table_type > DICT_TABLE_COMPRESSED_BASE)
  188. && UNIV_LIKELY(table_type
  189. <= DICT_TABLE_COMPRESSED_BASE + 16)) {
  190. return(table_type - DICT_TABLE_COMPRESSED_BASE);
  191. }
  192. if (UNIV_LIKELY(table_type == DICT_TABLE_ORDINARY)) {
  193. return(0);
  194. }
  195. return(ULINT_UNDEFINED);
  196. }
  197. /************************************************************************
  198. In a crash recovery we already have all the tablespace objects created.
  199. This function compares the space id information in the InnoDB data dictionary
  200. to what we already read with fil_load_single_table_tablespaces().
  201. In a normal startup, we create the tablespace objects for every table in
  202. InnoDB's data dictionary, if the corresponding .ibd file exists.
  203. We also scan the biggest space id, and store it to fil_system. */
  204. void
  205. dict_check_tablespaces_and_store_max_id(
  206. /*====================================*/
  207. ibool in_crash_recovery) /* in: are we doing a crash recovery */
  208. {
  209. dict_table_t* sys_tables;
  210. dict_index_t* sys_index;
  211. btr_pcur_t pcur;
  212. const rec_t* rec;
  213. ulint max_space_id = 0;
  214. mtr_t mtr;
  215. mutex_enter(&(dict_sys->mutex));
  216. mtr_start(&mtr);
  217. sys_tables = dict_table_get_low("SYS_TABLES");
  218. sys_index = UT_LIST_GET_FIRST(sys_tables->indexes);
  219. ut_a(!dict_table_is_comp(sys_tables));
  220. btr_pcur_open_at_index_side(TRUE, sys_index, BTR_SEARCH_LEAF, &pcur,
  221. TRUE, &mtr);
  222. loop:
  223. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  224. rec = btr_pcur_get_rec(&pcur);
  225. if (!btr_pcur_is_on_user_rec(&pcur)) {
  226. /* end of index */
  227. btr_pcur_close(&pcur);
  228. mtr_commit(&mtr);
  229. /* We must make the tablespace cache aware of the biggest
  230. known space id */
  231. /* printf("Biggest space id in data dictionary %lu\n",
  232. max_space_id); */
  233. fil_set_max_space_id_if_bigger(max_space_id);
  234. mutex_exit(&(dict_sys->mutex));
  235. return;
  236. }
  237. if (!rec_get_deleted_flag(rec, 0)) {
  238. /* We found one */
  239. const byte* field;
  240. ulint len;
  241. ulint space_id;
  242. ulint zip_size_in_k;
  243. char* name;
  244. field = rec_get_nth_field_old(rec, 0, &len);
  245. name = mem_strdupl((char*) field, len);
  246. zip_size_in_k = dict_sys_tables_get_zip_size(rec);
  247. ut_a(zip_size_in_k != ULINT_UNDEFINED);
  248. field = rec_get_nth_field_old(rec, 9, &len);
  249. ut_a(len == 4);
  250. space_id = mach_read_from_4(field);
  251. btr_pcur_store_position(&pcur, &mtr);
  252. mtr_commit(&mtr);
  253. if (space_id != 0 && in_crash_recovery) {
  254. /* Check that the tablespace (the .ibd file) really
  255. exists; print a warning to the .err log if not */
  256. fil_space_for_table_exists_in_mem(space_id, name,
  257. FALSE, TRUE, TRUE);
  258. }
  259. if (space_id != 0 && !in_crash_recovery) {
  260. /* It is a normal database startup: create the space
  261. object and check that the .ibd file exists. */
  262. fil_open_single_table_tablespace(FALSE, space_id,
  263. zip_size_in_k * 1024,
  264. name);
  265. }
  266. mem_free(name);
  267. if (space_id > max_space_id) {
  268. max_space_id = space_id;
  269. }
  270. mtr_start(&mtr);
  271. btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
  272. }
  273. goto loop;
  274. }
  275. /************************************************************************
  276. Loads definitions for table columns. */
  277. static
  278. void
  279. dict_load_columns(
  280. /*==============*/
  281. dict_table_t* table, /* in: table */
  282. mem_heap_t* heap) /* in: memory heap for temporary storage */
  283. {
  284. dict_table_t* sys_columns;
  285. dict_index_t* sys_index;
  286. btr_pcur_t pcur;
  287. dtuple_t* tuple;
  288. dfield_t* dfield;
  289. const rec_t* rec;
  290. const byte* field;
  291. ulint len;
  292. byte* buf;
  293. char* name;
  294. ulint mtype;
  295. ulint prtype;
  296. ulint col_len;
  297. ulint i;
  298. mtr_t mtr;
  299. ut_ad(mutex_own(&(dict_sys->mutex)));
  300. mtr_start(&mtr);
  301. sys_columns = dict_table_get_low("SYS_COLUMNS");
  302. sys_index = UT_LIST_GET_FIRST(sys_columns->indexes);
  303. ut_a(!dict_table_is_comp(sys_columns));
  304. tuple = dtuple_create(heap, 1);
  305. dfield = dtuple_get_nth_field(tuple, 0);
  306. buf = mem_heap_alloc(heap, 8);
  307. mach_write_to_8(buf, table->id);
  308. dfield_set_data(dfield, buf, 8);
  309. dict_index_copy_types(tuple, sys_index, 1);
  310. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  311. BTR_SEARCH_LEAF, &pcur, &mtr);
  312. for (i = 0; i + DATA_N_SYS_COLS < (ulint) table->n_cols; i++) {
  313. rec = btr_pcur_get_rec(&pcur);
  314. ut_a(btr_pcur_is_on_user_rec(&pcur));
  315. ut_a(!rec_get_deleted_flag(rec, 0));
  316. field = rec_get_nth_field_old(rec, 0, &len);
  317. ut_ad(len == 8);
  318. ut_a(ut_dulint_cmp(table->id, mach_read_from_8(field)) == 0);
  319. field = rec_get_nth_field_old(rec, 1, &len);
  320. ut_ad(len == 4);
  321. ut_a(i == mach_read_from_4(field));
  322. ut_a(name_of_col_is(sys_columns, sys_index, 4, "NAME"));
  323. field = rec_get_nth_field_old(rec, 4, &len);
  324. name = mem_heap_strdupl(heap, (char*) field, len);
  325. field = rec_get_nth_field_old(rec, 5, &len);
  326. mtype = mach_read_from_4(field);
  327. field = rec_get_nth_field_old(rec, 6, &len);
  328. prtype = mach_read_from_4(field);
  329. if (dtype_get_charset_coll(prtype) == 0
  330. && dtype_is_string_type(mtype)) {
  331. /* The table was created with < 4.1.2. */
  332. if (dtype_is_binary_string_type(mtype, prtype)) {
  333. /* Use the binary collation for
  334. string columns of binary type. */
  335. prtype = dtype_form_prtype(
  336. prtype,
  337. DATA_MYSQL_BINARY_CHARSET_COLL);
  338. } else {
  339. /* Use the default charset for
  340. other than binary columns. */
  341. prtype = dtype_form_prtype(
  342. prtype,
  343. data_mysql_default_charset_coll);
  344. }
  345. }
  346. field = rec_get_nth_field_old(rec, 7, &len);
  347. col_len = mach_read_from_4(field);
  348. ut_a(name_of_col_is(sys_columns, sys_index, 8, "PREC"));
  349. dict_mem_table_add_col(table, heap, name,
  350. mtype, prtype, col_len);
  351. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  352. }
  353. btr_pcur_close(&pcur);
  354. mtr_commit(&mtr);
  355. }
  356. /************************************************************************
  357. Loads definitions for index fields. */
  358. static
  359. void
  360. dict_load_fields(
  361. /*=============*/
  362. dict_index_t* index, /* in: index whose fields to load */
  363. mem_heap_t* heap) /* in: memory heap for temporary storage */
  364. {
  365. dict_table_t* sys_fields;
  366. dict_index_t* sys_index;
  367. btr_pcur_t pcur;
  368. dtuple_t* tuple;
  369. dfield_t* dfield;
  370. ulint pos_and_prefix_len;
  371. ulint prefix_len;
  372. const rec_t* rec;
  373. const byte* field;
  374. ulint len;
  375. byte* buf;
  376. ulint i;
  377. mtr_t mtr;
  378. ut_ad(mutex_own(&(dict_sys->mutex)));
  379. mtr_start(&mtr);
  380. sys_fields = dict_table_get_low("SYS_FIELDS");
  381. sys_index = UT_LIST_GET_FIRST(sys_fields->indexes);
  382. ut_a(!dict_table_is_comp(sys_fields));
  383. tuple = dtuple_create(heap, 1);
  384. dfield = dtuple_get_nth_field(tuple, 0);
  385. buf = mem_heap_alloc(heap, 8);
  386. mach_write_to_8(buf, index->id);
  387. dfield_set_data(dfield, buf, 8);
  388. dict_index_copy_types(tuple, sys_index, 1);
  389. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  390. BTR_SEARCH_LEAF, &pcur, &mtr);
  391. for (i = 0; i < index->n_fields; i++) {
  392. rec = btr_pcur_get_rec(&pcur);
  393. ut_a(btr_pcur_is_on_user_rec(&pcur));
  394. /* There could be delete marked records in SYS_FIELDS
  395. because SYS_FIELDS.INDEX_ID can be updated
  396. by ALTER TABLE ADD INDEX. */
  397. if (rec_get_deleted_flag(rec, 0)) {
  398. goto next_rec;
  399. }
  400. field = rec_get_nth_field_old(rec, 0, &len);
  401. ut_ad(len == 8);
  402. field = rec_get_nth_field_old(rec, 1, &len);
  403. ut_a(len == 4);
  404. /* The next field stores the field position in the index
  405. and a possible column prefix length if the index field
  406. does not contain the whole column. The storage format is
  407. like this: if there is at least one prefix field in the index,
  408. then the HIGH 2 bytes contain the field number (== i) and the
  409. low 2 bytes the prefix length for the field. Otherwise the
  410. field number (== i) is contained in the 2 LOW bytes. */
  411. pos_and_prefix_len = mach_read_from_4(field);
  412. ut_a((pos_and_prefix_len & 0xFFFFUL) == i
  413. || (pos_and_prefix_len & 0xFFFF0000UL) == (i << 16));
  414. if ((i == 0 && pos_and_prefix_len > 0)
  415. || (pos_and_prefix_len & 0xFFFF0000UL) > 0) {
  416. prefix_len = pos_and_prefix_len & 0xFFFFUL;
  417. } else {
  418. prefix_len = 0;
  419. }
  420. ut_a(name_of_col_is(sys_fields, sys_index, 4, "COL_NAME"));
  421. field = rec_get_nth_field_old(rec, 4, &len);
  422. dict_mem_index_add_field(index,
  423. mem_heap_strdupl(heap,
  424. (char*) field, len),
  425. prefix_len);
  426. next_rec:
  427. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  428. }
  429. btr_pcur_close(&pcur);
  430. mtr_commit(&mtr);
  431. }
  432. /************************************************************************
  433. Loads definitions for table indexes. Adds them to the data dictionary
  434. cache. */
  435. static
  436. ulint
  437. dict_load_indexes(
  438. /*==============*/
  439. /* out: DB_SUCCESS if ok, DB_CORRUPTION
  440. if corruption of dictionary table or
  441. DB_UNSUPPORTED if table has unknown index
  442. type */
  443. dict_table_t* table, /* in: table */
  444. mem_heap_t* heap) /* in: memory heap for temporary storage */
  445. {
  446. dict_table_t* sys_indexes;
  447. dict_index_t* sys_index;
  448. dict_index_t* index;
  449. btr_pcur_t pcur;
  450. dtuple_t* tuple;
  451. dfield_t* dfield;
  452. const rec_t* rec;
  453. const byte* field;
  454. ulint len;
  455. ulint name_len;
  456. char* name_buf;
  457. ulint type;
  458. ulint space;
  459. ulint page_no;
  460. ulint n_fields;
  461. byte* buf;
  462. ibool is_sys_table;
  463. dulint id;
  464. mtr_t mtr;
  465. ulint error = DB_SUCCESS;
  466. ut_ad(mutex_own(&(dict_sys->mutex)));
  467. if ((ut_dulint_get_high(table->id) == 0)
  468. && (ut_dulint_get_low(table->id) < DICT_HDR_FIRST_ID)) {
  469. is_sys_table = TRUE;
  470. } else {
  471. is_sys_table = FALSE;
  472. }
  473. mtr_start(&mtr);
  474. sys_indexes = dict_table_get_low("SYS_INDEXES");
  475. sys_index = UT_LIST_GET_FIRST(sys_indexes->indexes);
  476. ut_a(!dict_table_is_comp(sys_indexes));
  477. tuple = dtuple_create(heap, 1);
  478. dfield = dtuple_get_nth_field(tuple, 0);
  479. buf = mem_heap_alloc(heap, 8);
  480. mach_write_to_8(buf, table->id);
  481. dfield_set_data(dfield, buf, 8);
  482. dict_index_copy_types(tuple, sys_index, 1);
  483. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  484. BTR_SEARCH_LEAF, &pcur, &mtr);
  485. for (;;) {
  486. if (!btr_pcur_is_on_user_rec(&pcur)) {
  487. break;
  488. }
  489. rec = btr_pcur_get_rec(&pcur);
  490. field = rec_get_nth_field_old(rec, 0, &len);
  491. ut_ad(len == 8);
  492. if (ut_memcmp(buf, field, len) != 0) {
  493. break;
  494. } else if (rec_get_deleted_flag(rec, 0)) {
  495. /* Skip delete marked records */
  496. goto next_rec;
  497. }
  498. field = rec_get_nth_field_old(rec, 1, &len);
  499. ut_ad(len == 8);
  500. id = mach_read_from_8(field);
  501. ut_a(name_of_col_is(sys_indexes, sys_index, 4, "NAME"));
  502. field = rec_get_nth_field_old(rec, 4, &name_len);
  503. name_buf = mem_heap_strdupl(heap, (char*) field, name_len);
  504. field = rec_get_nth_field_old(rec, 5, &len);
  505. n_fields = mach_read_from_4(field);
  506. field = rec_get_nth_field_old(rec, 6, &len);
  507. type = mach_read_from_4(field);
  508. field = rec_get_nth_field_old(rec, 7, &len);
  509. space = mach_read_from_4(field);
  510. ut_a(name_of_col_is(sys_indexes, sys_index, 8, "PAGE_NO"));
  511. field = rec_get_nth_field_old(rec, 8, &len);
  512. page_no = mach_read_from_4(field);
  513. /* We check for unsupported types first, so that the
  514. subsequent checks are relevant for the supported types. */
  515. if (type & ~(DICT_CLUSTERED | DICT_UNIQUE)) {
  516. fprintf(stderr,
  517. "InnoDB: Error: unknown type %lu"
  518. " of index %s of table %s\n",
  519. (ulong) type, name_buf, table->name);
  520. error = DB_UNSUPPORTED;
  521. goto func_exit;
  522. } else if (page_no == FIL_NULL) {
  523. fprintf(stderr,
  524. "InnoDB: Error: trying to load index %s"
  525. " for table %s\n"
  526. "InnoDB: but the index tree has been freed!\n",
  527. name_buf, table->name);
  528. error = DB_CORRUPTION;
  529. goto func_exit;
  530. } else if ((type & DICT_CLUSTERED) == 0
  531. && NULL == dict_table_get_first_index(table)) {
  532. fputs("InnoDB: Error: trying to load index ",
  533. stderr);
  534. ut_print_name(stderr, NULL, FALSE, name_buf);
  535. fputs(" for table ", stderr);
  536. ut_print_name(stderr, NULL, TRUE, table->name);
  537. fputs("\nInnoDB: but the first index"
  538. " is not clustered!\n", stderr);
  539. error = DB_CORRUPTION;
  540. goto func_exit;
  541. } else if (is_sys_table
  542. && ((type & DICT_CLUSTERED)
  543. || ((table == dict_sys->sys_tables)
  544. && (name_len == (sizeof "ID_IND") - 1)
  545. && (0 == ut_memcmp(name_buf,
  546. "ID_IND", name_len))))) {
  547. /* The index was created in memory already at booting
  548. of the database server */
  549. } else {
  550. index = dict_mem_index_create(table->name, name_buf,
  551. space, type, n_fields);
  552. index->id = id;
  553. dict_load_fields(index, heap);
  554. error = dict_index_add_to_cache(table, index, page_no);
  555. /* The data dictionary tables should never contain
  556. invalid index definitions. If we ignored this error
  557. and simply did not load this index definition, the
  558. .frm file would disagree with the index definitions
  559. inside InnoDB. */
  560. if (UNIV_UNLIKELY(error != DB_SUCCESS)) {
  561. goto func_exit;
  562. }
  563. }
  564. next_rec:
  565. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  566. }
  567. func_exit:
  568. btr_pcur_close(&pcur);
  569. mtr_commit(&mtr);
  570. return(error);
  571. }
  572. /************************************************************************
  573. Loads a table definition and also all its index definitions, and also
  574. the cluster definition if the table is a member in a cluster. Also loads
  575. all foreign key constraints where the foreign key is in the table or where
  576. a foreign key references columns in this table. Adds all these to the data
  577. dictionary cache. */
  578. dict_table_t*
  579. dict_load_table(
  580. /*============*/
  581. /* out: table, NULL if does not exist;
  582. if the table is stored in an .ibd file,
  583. but the file does not exist,
  584. then we set the ibd_file_missing flag TRUE
  585. in the table object we return */
  586. const char* name) /* in: table name in the
  587. databasename/tablename format */
  588. {
  589. ibool ibd_file_missing = FALSE;
  590. dict_table_t* table;
  591. dict_table_t* sys_tables;
  592. btr_pcur_t pcur;
  593. dict_index_t* sys_index;
  594. dtuple_t* tuple;
  595. mem_heap_t* heap;
  596. dfield_t* dfield;
  597. const rec_t* rec;
  598. const byte* field;
  599. ulint len;
  600. ulint space;
  601. ulint n_cols;
  602. ulint flags;
  603. ulint err;
  604. ulint zip_size_in_k;
  605. mtr_t mtr;
  606. ut_ad(mutex_own(&(dict_sys->mutex)));
  607. heap = mem_heap_create(32000);
  608. mtr_start(&mtr);
  609. sys_tables = dict_table_get_low("SYS_TABLES");
  610. sys_index = UT_LIST_GET_FIRST(sys_tables->indexes);
  611. ut_a(!dict_table_is_comp(sys_tables));
  612. tuple = dtuple_create(heap, 1);
  613. dfield = dtuple_get_nth_field(tuple, 0);
  614. dfield_set_data(dfield, name, ut_strlen(name));
  615. dict_index_copy_types(tuple, sys_index, 1);
  616. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  617. BTR_SEARCH_LEAF, &pcur, &mtr);
  618. rec = btr_pcur_get_rec(&pcur);
  619. if (!btr_pcur_is_on_user_rec(&pcur)
  620. || rec_get_deleted_flag(rec, 0)) {
  621. /* Not found */
  622. err_exit:
  623. btr_pcur_close(&pcur);
  624. mtr_commit(&mtr);
  625. mem_heap_free(heap);
  626. return(NULL);
  627. }
  628. field = rec_get_nth_field_old(rec, 0, &len);
  629. /* Check if the table name in record is the searched one */
  630. if (len != ut_strlen(name) || ut_memcmp(name, field, len) != 0) {
  631. goto err_exit;
  632. }
  633. ut_a(name_of_col_is(sys_tables, sys_index, 9, "SPACE"));
  634. field = rec_get_nth_field_old(rec, 9, &len);
  635. space = mach_read_from_4(field);
  636. /* Check if the tablespace exists and has the right name */
  637. if (space != 0) {
  638. zip_size_in_k = dict_sys_tables_get_zip_size(rec);
  639. ut_a(zip_size_in_k != ULINT_UNDEFINED);
  640. if (fil_space_for_table_exists_in_mem(space, name, FALSE,
  641. FALSE, FALSE)) {
  642. /* Ok; (if we did a crash recovery then the tablespace
  643. can already be in the memory cache) */
  644. } else {
  645. /* In >= 4.1.9, InnoDB scans the data dictionary also
  646. at a normal mysqld startup. It is an error if the
  647. space object does not exist in memory. */
  648. ut_print_timestamp(stderr);
  649. fprintf(stderr,
  650. " InnoDB: error: space object of table %s,\n"
  651. "InnoDB: space id %lu did not exist in memory."
  652. " Retrying an open.\n",
  653. name, (ulong)space);
  654. /* Try to open the tablespace */
  655. if (!fil_open_single_table_tablespace(
  656. TRUE, space, zip_size_in_k << 10, name)) {
  657. /* We failed to find a sensible tablespace
  658. file */
  659. ibd_file_missing = TRUE;
  660. }
  661. }
  662. } else {
  663. zip_size_in_k = 0;
  664. }
  665. ut_a(name_of_col_is(sys_tables, sys_index, 4, "N_COLS"));
  666. field = rec_get_nth_field_old(rec, 4, &len);
  667. n_cols = mach_read_from_4(field);
  668. flags = zip_size_in_k << DICT_TF_COMPRESSED_SHIFT;
  669. /* The high-order bit of N_COLS is the "compact format" flag. */
  670. if (n_cols & 0x80000000UL) {
  671. flags |= DICT_TF_COMPACT;
  672. }
  673. table = dict_mem_table_create(name, space, n_cols & ~0x80000000UL,
  674. flags);
  675. table->ibd_file_missing = (unsigned int) ibd_file_missing;
  676. ut_a(name_of_col_is(sys_tables, sys_index, 3, "ID"));
  677. field = rec_get_nth_field_old(rec, 3, &len);
  678. table->id = mach_read_from_8(field);
  679. zip_size_in_k = dict_sys_tables_get_zip_size(rec);
  680. if (UNIV_UNLIKELY(zip_size_in_k == ULINT_UNDEFINED)) {
  681. field = rec_get_nth_field_old(rec, 5, &len);
  682. ut_print_timestamp(stderr);
  683. fprintf(stderr,
  684. " InnoDB: table %s: unknown table type %lu\n",
  685. name, (ulong) mach_read_from_4(field));
  686. goto err_exit;
  687. }
  688. btr_pcur_close(&pcur);
  689. mtr_commit(&mtr);
  690. dict_load_columns(table, heap);
  691. dict_table_add_to_cache(table, heap);
  692. mem_heap_empty(heap);
  693. err = dict_load_indexes(table, heap);
  694. #ifndef UNIV_HOTBACKUP
  695. /* If the force recovery flag is set, we open the table irrespective
  696. of the error condition, since the user may want to dump data from the
  697. clustered index. However we load the foreign key information only if
  698. all indexes were loaded. */
  699. if (err != DB_SUCCESS && !srv_force_recovery) {
  700. dict_mem_table_free(table);
  701. table = NULL;
  702. } else if (err == DB_SUCCESS) {
  703. err = dict_load_foreigns(table->name, TRUE);
  704. }
  705. # if 0
  706. if (err != DB_SUCCESS && table != NULL) {
  707. mutex_enter(&dict_foreign_err_mutex);
  708. ut_print_timestamp(stderr);
  709. fprintf(stderr,
  710. " InnoDB: Error: could not make a foreign key"
  711. " definition to match\n"
  712. "InnoDB: the foreign key table"
  713. " or the referenced table!\n"
  714. "InnoDB: The data dictionary of InnoDB is corrupt."
  715. " You may need to drop\n"
  716. "InnoDB: and recreate the foreign key table"
  717. " or the referenced table.\n"
  718. "InnoDB: Submit a detailed bug report"
  719. " to http://bugs.mysql.com\n"
  720. "InnoDB: Latest foreign key error printout:\n%s\n",
  721. dict_foreign_err_buf);
  722. mutex_exit(&dict_foreign_err_mutex);
  723. }
  724. # endif /* 0 */
  725. #endif /* !UNIV_HOTBACKUP */
  726. mem_heap_free(heap);
  727. return(table);
  728. }
  729. /***************************************************************************
  730. Loads a table object based on the table id. */
  731. dict_table_t*
  732. dict_load_table_on_id(
  733. /*==================*/
  734. /* out: table; NULL if table does not exist */
  735. dulint table_id) /* in: table id */
  736. {
  737. byte id_buf[8];
  738. btr_pcur_t pcur;
  739. mem_heap_t* heap;
  740. dtuple_t* tuple;
  741. dfield_t* dfield;
  742. dict_index_t* sys_table_ids;
  743. dict_table_t* sys_tables;
  744. const rec_t* rec;
  745. const byte* field;
  746. ulint len;
  747. dict_table_t* table;
  748. mtr_t mtr;
  749. ut_ad(mutex_own(&(dict_sys->mutex)));
  750. /* NOTE that the operation of this function is protected by
  751. the dictionary mutex, and therefore no deadlocks can occur
  752. with other dictionary operations. */
  753. mtr_start(&mtr);
  754. /*---------------------------------------------------*/
  755. /* Get the secondary index based on ID for table SYS_TABLES */
  756. sys_tables = dict_sys->sys_tables;
  757. sys_table_ids = dict_table_get_next_index(
  758. dict_table_get_first_index(sys_tables));
  759. ut_a(!dict_table_is_comp(sys_tables));
  760. heap = mem_heap_create(256);
  761. tuple = dtuple_create(heap, 1);
  762. dfield = dtuple_get_nth_field(tuple, 0);
  763. /* Write the table id in byte format to id_buf */
  764. mach_write_to_8(id_buf, table_id);
  765. dfield_set_data(dfield, id_buf, 8);
  766. dict_index_copy_types(tuple, sys_table_ids, 1);
  767. btr_pcur_open_on_user_rec(sys_table_ids, tuple, PAGE_CUR_GE,
  768. BTR_SEARCH_LEAF, &pcur, &mtr);
  769. rec = btr_pcur_get_rec(&pcur);
  770. if (!btr_pcur_is_on_user_rec(&pcur)
  771. || rec_get_deleted_flag(rec, 0)) {
  772. /* Not found */
  773. btr_pcur_close(&pcur);
  774. mtr_commit(&mtr);
  775. mem_heap_free(heap);
  776. return(NULL);
  777. }
  778. /*---------------------------------------------------*/
  779. /* Now we have the record in the secondary index containing the
  780. table ID and NAME */
  781. rec = btr_pcur_get_rec(&pcur);
  782. field = rec_get_nth_field_old(rec, 0, &len);
  783. ut_ad(len == 8);
  784. /* Check if the table id in record is the one searched for */
  785. if (ut_dulint_cmp(table_id, mach_read_from_8(field)) != 0) {
  786. btr_pcur_close(&pcur);
  787. mtr_commit(&mtr);
  788. mem_heap_free(heap);
  789. return(NULL);
  790. }
  791. /* Now we get the table name from the record */
  792. field = rec_get_nth_field_old(rec, 1, &len);
  793. /* Load the table definition to memory */
  794. table = dict_load_table(mem_heap_strdupl(heap, (char*) field, len));
  795. btr_pcur_close(&pcur);
  796. mtr_commit(&mtr);
  797. mem_heap_free(heap);
  798. return(table);
  799. }
  800. /************************************************************************
  801. This function is called when the database is booted. Loads system table
  802. index definitions except for the clustered index which is added to the
  803. dictionary cache at booting before calling this function. */
  804. void
  805. dict_load_sys_table(
  806. /*================*/
  807. dict_table_t* table) /* in: system table */
  808. {
  809. mem_heap_t* heap;
  810. ut_ad(mutex_own(&(dict_sys->mutex)));
  811. heap = mem_heap_create(1000);
  812. dict_load_indexes(table, heap);
  813. mem_heap_free(heap);
  814. }
  815. #ifndef UNIV_HOTBACKUP
  816. /************************************************************************
  817. Loads foreign key constraint col names (also for the referenced table). */
  818. static
  819. void
  820. dict_load_foreign_cols(
  821. /*===================*/
  822. const char* id, /* in: foreign constraint id as a
  823. null-terminated string */
  824. dict_foreign_t* foreign)/* in: foreign constraint object */
  825. {
  826. dict_table_t* sys_foreign_cols;
  827. dict_index_t* sys_index;
  828. btr_pcur_t pcur;
  829. dtuple_t* tuple;
  830. dfield_t* dfield;
  831. const rec_t* rec;
  832. const byte* field;
  833. ulint len;
  834. ulint i;
  835. mtr_t mtr;
  836. ut_ad(mutex_own(&(dict_sys->mutex)));
  837. foreign->foreign_col_names = mem_heap_alloc(
  838. foreign->heap, foreign->n_fields * sizeof(void*));
  839. foreign->referenced_col_names = mem_heap_alloc(
  840. foreign->heap, foreign->n_fields * sizeof(void*));
  841. mtr_start(&mtr);
  842. sys_foreign_cols = dict_table_get_low("SYS_FOREIGN_COLS");
  843. sys_index = UT_LIST_GET_FIRST(sys_foreign_cols->indexes);
  844. ut_a(!dict_table_is_comp(sys_foreign_cols));
  845. tuple = dtuple_create(foreign->heap, 1);
  846. dfield = dtuple_get_nth_field(tuple, 0);
  847. dfield_set_data(dfield, id, ut_strlen(id));
  848. dict_index_copy_types(tuple, sys_index, 1);
  849. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  850. BTR_SEARCH_LEAF, &pcur, &mtr);
  851. for (i = 0; i < foreign->n_fields; i++) {
  852. rec = btr_pcur_get_rec(&pcur);
  853. ut_a(btr_pcur_is_on_user_rec(&pcur));
  854. ut_a(!rec_get_deleted_flag(rec, 0));
  855. field = rec_get_nth_field_old(rec, 0, &len);
  856. ut_a(len == ut_strlen(id));
  857. ut_a(ut_memcmp(id, field, len) == 0);
  858. field = rec_get_nth_field_old(rec, 1, &len);
  859. ut_a(len == 4);
  860. ut_a(i == mach_read_from_4(field));
  861. field = rec_get_nth_field_old(rec, 4, &len);
  862. foreign->foreign_col_names[i] = mem_heap_strdupl(
  863. foreign->heap, (char*) field, len);
  864. field = rec_get_nth_field_old(rec, 5, &len);
  865. foreign->referenced_col_names[i] = mem_heap_strdupl(
  866. foreign->heap, (char*) field, len);
  867. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  868. }
  869. btr_pcur_close(&pcur);
  870. mtr_commit(&mtr);
  871. }
  872. /***************************************************************************
  873. Loads a foreign key constraint to the dictionary cache. */
  874. static
  875. ulint
  876. dict_load_foreign(
  877. /*==============*/
  878. /* out: DB_SUCCESS or error code */
  879. const char* id, /* in: foreign constraint id as a
  880. null-terminated string */
  881. ibool check_charsets)
  882. /* in: TRUE=check charset compatibility */
  883. {
  884. dict_foreign_t* foreign;
  885. dict_table_t* sys_foreign;
  886. btr_pcur_t pcur;
  887. dict_index_t* sys_index;
  888. dtuple_t* tuple;
  889. mem_heap_t* heap2;
  890. dfield_t* dfield;
  891. const rec_t* rec;
  892. const byte* field;
  893. ulint len;
  894. ulint n_fields_and_type;
  895. mtr_t mtr;
  896. ut_ad(mutex_own(&(dict_sys->mutex)));
  897. heap2 = mem_heap_create(1000);
  898. mtr_start(&mtr);
  899. sys_foreign = dict_table_get_low("SYS_FOREIGN");
  900. sys_index = UT_LIST_GET_FIRST(sys_foreign->indexes);
  901. ut_a(!dict_table_is_comp(sys_foreign));
  902. tuple = dtuple_create(heap2, 1);
  903. dfield = dtuple_get_nth_field(tuple, 0);
  904. dfield_set_data(dfield, id, ut_strlen(id));
  905. dict_index_copy_types(tuple, sys_index, 1);
  906. btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
  907. BTR_SEARCH_LEAF, &pcur, &mtr);
  908. rec = btr_pcur_get_rec(&pcur);
  909. if (!btr_pcur_is_on_user_rec(&pcur)
  910. || rec_get_deleted_flag(rec, 0)) {
  911. /* Not found */
  912. fprintf(stderr,
  913. "InnoDB: Error A: cannot load foreign constraint %s\n",
  914. id);
  915. btr_pcur_close(&pcur);
  916. mtr_commit(&mtr);
  917. mem_heap_free(heap2);
  918. return(DB_ERROR);
  919. }
  920. field = rec_get_nth_field_old(rec, 0, &len);
  921. /* Check if the id in record is the searched one */
  922. if (len != ut_strlen(id) || ut_memcmp(id, field, len) != 0) {
  923. fprintf(stderr,
  924. "InnoDB: Error B: cannot load foreign constraint %s\n",
  925. id);
  926. btr_pcur_close(&pcur);
  927. mtr_commit(&mtr);
  928. mem_heap_free(heap2);
  929. return(DB_ERROR);
  930. }
  931. /* Read the table names and the number of columns associated
  932. with the constraint */
  933. mem_heap_free(heap2);
  934. foreign = dict_mem_foreign_create();
  935. n_fields_and_type = mach_read_from_4(
  936. rec_get_nth_field_old(rec, 5, &len));
  937. ut_a(len == 4);
  938. /* We store the type in the bits 24..29 of n_fields_and_type. */
  939. foreign->type = (unsigned int) (n_fields_and_type >> 24);
  940. foreign->n_fields = (unsigned int) (n_fields_and_type & 0x3FFUL);
  941. foreign->id = mem_heap_strdup(foreign->heap, id);
  942. field = rec_get_nth_field_old(rec, 3, &len);
  943. foreign->foreign_table_name = mem_heap_strdupl(
  944. foreign->heap, (char*) field, len);
  945. field = rec_get_nth_field_old(rec, 4, &len);
  946. foreign->referenced_table_name = mem_heap_strdupl(
  947. foreign->heap, (char*) field, len);
  948. btr_pcur_close(&pcur);
  949. mtr_commit(&mtr);
  950. dict_load_foreign_cols(id, foreign);
  951. /* If the foreign table is not yet in the dictionary cache, we
  952. have to load it so that we are able to make type comparisons
  953. in the next function call. */
  954. dict_table_get_low(foreign->foreign_table_name);
  955. /* Note that there may already be a foreign constraint object in
  956. the dictionary cache for this constraint: then the following
  957. call only sets the pointers in it to point to the appropriate table
  958. and index objects and frees the newly created object foreign.
  959. Adding to the cache should always succeed since we are not creating
  960. a new foreign key constraint but loading one from the data
  961. dictionary. */
  962. return(dict_foreign_add_to_cache(foreign, check_charsets));
  963. }
  964. /***************************************************************************
  965. Loads foreign key constraints where the table is either the foreign key
  966. holder or where the table is referenced by a foreign key. Adds these
  967. constraints to the data dictionary. Note that we know that the dictionary
  968. cache already contains all constraints where the other relevant table is
  969. already in the dictionary cache. */
  970. ulint
  971. dict_load_foreigns(
  972. /*===============*/
  973. /* out: DB_SUCCESS or error code */
  974. const char* table_name, /* in: table name */
  975. ibool check_charsets) /* in: TRUE=check charset
  976. compatibility */
  977. {
  978. btr_pcur_t pcur;
  979. mem_heap_t* heap;
  980. dtuple_t* tuple;
  981. dfield_t* dfield;
  982. dict_index_t* sec_index;
  983. dict_table_t* sys_foreign;
  984. const rec_t* rec;
  985. const byte* field;
  986. ulint len;
  987. char* id ;
  988. ulint err;
  989. mtr_t mtr;
  990. ut_ad(mutex_own(&(dict_sys->mutex)));
  991. sys_foreign = dict_table_get_low("SYS_FOREIGN");
  992. if (sys_foreign == NULL) {
  993. /* No foreign keys defined yet in this database */
  994. fprintf(stderr,
  995. "InnoDB: Error: no foreign key system tables"
  996. " in the database\n");
  997. return(DB_ERROR);
  998. }
  999. ut_a(!dict_table_is_comp(sys_foreign));
  1000. mtr_start(&mtr);
  1001. /* Get the secondary index based on FOR_NAME from table
  1002. SYS_FOREIGN */
  1003. sec_index = dict_table_get_next_index(
  1004. dict_table_get_first_index(sys_foreign));
  1005. start_load:
  1006. heap = mem_heap_create(256);
  1007. tuple = dtuple_create(heap, 1);
  1008. dfield = dtuple_get_nth_field(tuple, 0);
  1009. dfield_set_data(dfield, table_name, ut_strlen(table_name));
  1010. dict_index_copy_types(tuple, sec_index, 1);
  1011. btr_pcur_open_on_user_rec(sec_index, tuple, PAGE_CUR_GE,
  1012. BTR_SEARCH_LEAF, &pcur, &mtr);
  1013. loop:
  1014. rec = btr_pcur_get_rec(&pcur);
  1015. if (!btr_pcur_is_on_user_rec(&pcur)) {
  1016. /* End of index */
  1017. goto load_next_index;
  1018. }
  1019. /* Now we have the record in the secondary index containing a table
  1020. name and a foreign constraint ID */
  1021. rec = btr_pcur_get_rec(&pcur);
  1022. field = rec_get_nth_field_old(rec, 0, &len);
  1023. /* Check if the table name in the record is the one searched for; the
  1024. following call does the comparison in the latin1_swedish_ci
  1025. charset-collation, in a case-insensitive way. */
  1026. if (0 != cmp_data_data(dfield_get_type(dfield)->mtype,
  1027. dfield_get_type(dfield)->prtype,
  1028. dfield_get_data(dfield), dfield_get_len(dfield),
  1029. field, len)) {
  1030. goto load_next_index;
  1031. }
  1032. /* Since table names in SYS_FOREIGN are stored in a case-insensitive
  1033. order, we have to check that the table name matches also in a binary
  1034. string comparison. On Unix, MySQL allows table names that only differ
  1035. in character case. */
  1036. if (0 != ut_memcmp(field, table_name, len)) {
  1037. goto next_rec;
  1038. }
  1039. if (rec_get_deleted_flag(rec, 0)) {
  1040. goto next_rec;
  1041. }
  1042. /* Now we get a foreign key constraint id */
  1043. field = rec_get_nth_field_old(rec, 1, &len);
  1044. id = mem_heap_strdupl(heap, (char*) field, len);
  1045. btr_pcur_store_position(&pcur, &mtr);
  1046. mtr_commit(&mtr);
  1047. /* Load the foreign constraint definition to the dictionary cache */
  1048. err = dict_load_foreign(id, check_charsets);
  1049. if (err != DB_SUCCESS) {
  1050. btr_pcur_close(&pcur);
  1051. mem_heap_free(heap);
  1052. return(err);
  1053. }
  1054. mtr_start(&mtr);
  1055. btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
  1056. next_rec:
  1057. btr_pcur_move_to_next_user_rec(&pcur, &mtr);
  1058. goto loop;
  1059. load_next_index:
  1060. btr_pcur_close(&pcur);
  1061. mtr_commit(&mtr);
  1062. mem_heap_free(heap);
  1063. sec_index = dict_table_get_next_index(sec_index);
  1064. if (sec_index != NULL) {
  1065. mtr_start(&mtr);
  1066. goto start_load;
  1067. }
  1068. return(DB_SUCCESS);
  1069. }
  1070. #endif /* !UNIV_HOTBACKUP */