229
222
/************************************************************************
230
Determine the flags of a table described in SYS_TABLES. */
233
dict_sys_tables_get_flags(
234
/*======================*/
235
/* out: compressed page size in kilobytes;
236
or 0 if the tablespace is uncompressed,
237
ULINT_UNDEFINED on error */
238
const rec_t* rec) /* in: a record of SYS_TABLES */
245
field = rec_get_nth_field_old(rec, 5, &len);
248
flags = mach_read_from_4(field);
250
if (UNIV_LIKELY(flags == DICT_TABLE_ORDINARY)) {
254
field = rec_get_nth_field_old(rec, 4, &len);
255
n_cols = mach_read_from_4(field);
257
if (UNIV_UNLIKELY(!(n_cols & 0x80000000UL))) {
258
/* New file formats require ROW_FORMAT=COMPACT. */
259
return(ULINT_UNDEFINED);
262
switch (flags & (DICT_TF_FORMAT_MASK | DICT_TF_COMPACT)) {
264
case DICT_TF_FORMAT_51 << DICT_TF_FORMAT_SHIFT:
265
case DICT_TF_FORMAT_51 << DICT_TF_FORMAT_SHIFT | DICT_TF_COMPACT:
266
/* flags should be DICT_TABLE_ORDINARY,
267
or DICT_TF_FORMAT_MASK should be nonzero. */
268
return(ULINT_UNDEFINED);
270
case DICT_TF_FORMAT_ZIP << DICT_TF_FORMAT_SHIFT | DICT_TF_COMPACT:
271
#if DICT_TF_FORMAT_MAX > DICT_TF_FORMAT_ZIP
272
# error "missing case labels for DICT_TF_FORMAT_ZIP .. DICT_TF_FORMAT_MAX"
274
/* We support this format. */
278
if (UNIV_UNLIKELY((flags & DICT_TF_ZSSIZE_MASK)
279
> (DICT_TF_ZSSIZE_MAX << DICT_TF_ZSSIZE_SHIFT))) {
280
/* Unsupported compressed page size. */
281
return(ULINT_UNDEFINED);
284
if (UNIV_UNLIKELY(flags & (~0 << DICT_TF_BITS))) {
285
/* Some unused bits are set. */
286
return(ULINT_UNDEFINED);
292
/************************************************************************
293
223
In a crash recovery we already have all the tablespace objects created.
294
224
This function compares the space id information in the InnoDB data dictionary
295
225
to what we already read with fil_load_single_table_tablespaces().
297
227
In a normal startup, we create the tablespace objects for every table in
298
228
InnoDB's data dictionary, if the corresponding .ibd file exists.
299
229
We also scan the biggest space id, and store it to fil_system. */
302
232
dict_check_tablespaces_and_store_max_id(
303
233
/*====================================*/
279
field = rec_get_nth_field_old(rec, 0, &len);
346
281
if (!rec_get_deleted_flag(rec, 0)) {
348
283
/* We found one */
355
field = rec_get_nth_field_old(rec, 0, &len);
356
name = mem_strdupl((char*) field, len);
358
flags = dict_sys_tables_get_flags(rec);
359
if (UNIV_UNLIKELY(flags == ULINT_UNDEFINED)) {
361
field = rec_get_nth_field_old(rec, 5, &len);
362
flags = mach_read_from_4(field);
364
ut_print_timestamp(stderr);
365
fputs(" InnoDB: Error: table ", stderr);
366
ut_print_filename(stderr, name);
368
"InnoDB: in InnoDB data dictionary"
369
" has unknown type %lx.\n",
285
char* name = mem_strdupl((char*) field, len);
375
287
field = rec_get_nth_field_old(rec, 9, &len);
460
372
rec = btr_pcur_get_rec(&pcur);
462
ut_a(btr_pcur_is_on_user_rec(&pcur));
374
ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr));
464
376
ut_a(!rec_get_deleted_flag(rec, 0));
493
405
prtype = dtype_form_prtype(
495
DATA_MYSQL_BINARY_CHARSET_COLL);
407
DATA_DRIZZLE_BINARY_CHARSET_COLL);
497
409
/* Use the default charset for
498
410
other than binary columns. */
520
432
/************************************************************************
433
Report that an index field or index for a table has been delete marked. */
436
dict_load_report_deleted_index(
437
/*===========================*/
438
const char* name, /* in: table name */
439
ulint field) /* in: index field, or ULINT_UNDEFINED */
441
fprintf(stderr, "InnoDB: Error: data dictionary entry"
442
" for table %s is corrupt!\n", name);
443
if (field != ULINT_UNDEFINED) {
445
"InnoDB: Index field %lu is delete marked.\n", field);
447
fputs("InnoDB: An index is delete marked.\n", stderr);
451
/************************************************************************
521
452
Loads definitions for index fields. */
524
455
dict_load_fields(
525
456
/*=============*/
457
dict_table_t* table, /* in: table */
526
458
dict_index_t* index, /* in: index whose fields to load */
527
459
mem_heap_t* heap) /* in: memory heap for temporary storage */
564
496
rec = btr_pcur_get_rec(&pcur);
566
ut_a(btr_pcur_is_on_user_rec(&pcur));
568
/* There could be delete marked records in SYS_FIELDS
569
because SYS_FIELDS.INDEX_ID can be updated
570
by ALTER TABLE ADD INDEX. */
498
ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr));
572
499
if (rec_get_deleted_flag(rec, 0)) {
500
dict_load_report_deleted_index(table->name, i);
577
503
field = rec_get_nth_field_old(rec, 0, &len);
505
ut_a(ut_memcmp(buf, field, len) == 0);
580
507
field = rec_get_nth_field_old(rec, 1, &len);
680
606
btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
681
607
BTR_SEARCH_LEAF, &pcur, &mtr);
683
if (!btr_pcur_is_on_user_rec(&pcur)) {
609
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)) {
693
619
if (ut_memcmp(buf, field, len) != 0) {
695
} else if (rec_get_deleted_flag(rec, 0)) {
696
/* Skip delete marked records */
623
if (rec_get_deleted_flag(rec, 0)) {
624
dict_load_report_deleted_index(table->name,
627
error = DB_CORRUPTION;
700
631
field = rec_get_nth_field_old(rec, 1, &len);
744
675
} else if ((type & DICT_CLUSTERED) == 0
745
676
&& NULL == dict_table_get_first_index(table)) {
747
fputs("InnoDB: Error: trying to load index ",
749
ut_print_name(stderr, NULL, FALSE, name_buf);
750
fputs(" for table ", stderr);
751
ut_print_name(stderr, NULL, TRUE, table->name);
752
fputs("\nInnoDB: but the first index"
753
" is not clustered!\n", stderr);
679
"InnoDB: Error: trying to load index %s"
681
"InnoDB: but the first index"
682
" is not clustered!\n",
683
name_buf, table->name);
755
685
error = DB_CORRUPTION;
768
698
space, type, n_fields);
771
dict_load_fields(index, heap);
772
error = dict_index_add_to_cache(table, index, page_no);
773
/* The data dictionary tables should never contain
774
invalid index definitions. If we ignored this error
775
and simply did not load this index definition, the
776
.frm file would disagree with the index definitions
778
if (UNIV_UNLIKELY(error != DB_SUCCESS)) {
701
dict_load_fields(table, index, heap);
702
dict_index_add_to_cache(table, index, page_no);
785
705
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
847
767
BTR_SEARCH_LEAF, &pcur, &mtr);
848
768
rec = btr_pcur_get_rec(&pcur);
850
if (!btr_pcur_is_on_user_rec(&pcur)
770
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)
851
771
|| rec_get_deleted_flag(rec, 0)) {
874
794
/* Check if the tablespace exists and has the right name */
875
795
if (space != 0) {
876
flags = dict_sys_tables_get_flags(rec);
878
if (UNIV_UNLIKELY(flags == ULINT_UNDEFINED)) {
879
field = rec_get_nth_field_old(rec, 5, &len);
880
flags = mach_read_from_4(field);
882
ut_print_timestamp(stderr);
883
fputs(" InnoDB: Error: table ", stderr);
884
ut_print_filename(stderr, name);
886
"InnoDB: in InnoDB data dictionary"
887
" has unknown type %lx.\n",
892
796
if (fil_space_for_table_exists_in_mem(space, name, FALSE,
894
798
/* Ok; (if we did a crash recovery then the tablespace
905
809
" Retrying an open.\n",
906
810
name, (ulong)space);
907
811
/* Try to open the tablespace */
908
if (!fil_open_single_table_tablespace(
909
TRUE, space, flags, name)) {
812
if (!fil_open_single_table_tablespace(TRUE,
910
814
/* We failed to find a sensible tablespace
913
817
ibd_file_missing = TRUE;
920
822
ut_a(name_of_col_is(sys_tables, sys_index, 4, "N_COLS"));
922
824
field = rec_get_nth_field_old(rec, 4, &len);
923
825
n_cols = mach_read_from_4(field);
925
829
/* The high-order bit of N_COLS is the "compact format" flag. */
926
830
if (n_cols & 0x80000000UL) {
927
831
flags |= DICT_TF_COMPACT;
937
841
field = rec_get_nth_field_old(rec, 3, &len);
938
842
table->id = mach_read_from_8(field);
844
field = rec_get_nth_field_old(rec, 5, &len);
845
if (UNIV_UNLIKELY(mach_read_from_4(field) != DICT_TABLE_ORDINARY)) {
846
ut_print_timestamp(stderr);
848
" InnoDB: table %s: unknown table type %lu\n",
849
name, (ulong) mach_read_from_4(field));
940
853
btr_pcur_close(&pcur);
941
854
mtr_commit(&mtr);
947
860
mem_heap_empty(heap);
949
862
err = dict_load_indexes(table, heap);
950
#ifndef UNIV_HOTBACKUP
951
864
/* If the force recovery flag is set, we open the table irrespective
952
865
of the error condition, since the user may want to dump data from the
953
866
clustered index. However we load the foreign key information only if
958
871
} else if (err == DB_SUCCESS) {
959
872
err = dict_load_foreigns(table->name, TRUE);
962
875
if (err != DB_SUCCESS && table != NULL) {
964
877
mutex_enter(&dict_foreign_err_mutex);
1038
950
BTR_SEARCH_LEAF, &pcur, &mtr);
1039
951
rec = btr_pcur_get_rec(&pcur);
1041
if (!btr_pcur_is_on_user_rec(&pcur)
953
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)
1042
954
|| rec_get_deleted_flag(rec, 0)) {
1148
1059
rec = btr_pcur_get_rec(&pcur);
1150
ut_a(btr_pcur_is_on_user_rec(&pcur));
1061
ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr));
1151
1062
ut_a(!rec_get_deleted_flag(rec, 0));
1153
1064
field = rec_get_nth_field_old(rec, 0, &len);
1218
1129
BTR_SEARCH_LEAF, &pcur, &mtr);
1219
1130
rec = btr_pcur_get_rec(&pcur);
1221
if (!btr_pcur_is_on_user_rec(&pcur)
1132
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)
1222
1133
|| rec_get_deleted_flag(rec, 0)) {
1223
1134
/* Not found */