222
229
/************************************************************************
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
/************************************************************************
223
293
In a crash recovery we already have all the tablespace objects created.
224
294
This function compares the space id information in the InnoDB data dictionary
225
295
to what we already read with fil_load_single_table_tablespaces().
227
297
In a normal startup, we create the tablespace objects for every table in
228
298
InnoDB's data dictionary, if the corresponding .ibd file exists.
229
299
We also scan the biggest space id, and store it to fil_system. */
232
302
dict_check_tablespaces_and_store_max_id(
233
303
/*====================================*/
279
field = rec_get_nth_field_old(rec, 0, &len);
281
346
if (!rec_get_deleted_flag(rec, 0)) {
283
348
/* We found one */
285
char* name = mem_strdupl((char*) field, len);
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",
287
375
field = rec_get_nth_field_old(rec, 9, &len);
372
460
rec = btr_pcur_get_rec(&pcur);
374
ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr));
462
ut_a(btr_pcur_is_on_user_rec(&pcur));
376
464
ut_a(!rec_get_deleted_flag(rec, 0));
405
493
prtype = dtype_form_prtype(
407
DATA_DRIZZLE_BINARY_CHARSET_COLL);
495
DATA_MYSQL_BINARY_CHARSET_COLL);
409
497
/* Use the default charset for
410
498
other than binary columns. */
432
520
/************************************************************************
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
/************************************************************************
452
521
Loads definitions for index fields. */
455
524
dict_load_fields(
456
525
/*=============*/
457
dict_table_t* table, /* in: table */
458
526
dict_index_t* index, /* in: index whose fields to load */
459
527
mem_heap_t* heap) /* in: memory heap for temporary storage */
496
564
rec = btr_pcur_get_rec(&pcur);
498
ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr));
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. */
499
572
if (rec_get_deleted_flag(rec, 0)) {
500
dict_load_report_deleted_index(table->name, i);
503
577
field = rec_get_nth_field_old(rec, 0, &len);
505
ut_a(ut_memcmp(buf, field, len) == 0);
507
580
field = rec_get_nth_field_old(rec, 1, &len);
606
680
btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
607
681
BTR_SEARCH_LEAF, &pcur, &mtr);
609
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)) {
683
if (!btr_pcur_is_on_user_rec(&pcur)) {
619
693
if (ut_memcmp(buf, field, len) != 0) {
623
if (rec_get_deleted_flag(rec, 0)) {
624
dict_load_report_deleted_index(table->name,
627
error = DB_CORRUPTION;
695
} else if (rec_get_deleted_flag(rec, 0)) {
696
/* Skip delete marked records */
631
700
field = rec_get_nth_field_old(rec, 1, &len);
675
744
} else if ((type & DICT_CLUSTERED) == 0
676
745
&& NULL == dict_table_get_first_index(table)) {
679
"InnoDB: Error: trying to load index %s"
681
"InnoDB: but the first index"
682
" is not clustered!\n",
683
name_buf, table->name);
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);
685
755
error = DB_CORRUPTION;
698
768
space, type, n_fields);
701
dict_load_fields(table, index, heap);
702
dict_index_add_to_cache(table, index, page_no);
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)) {
705
785
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
767
847
BTR_SEARCH_LEAF, &pcur, &mtr);
768
848
rec = btr_pcur_get_rec(&pcur);
770
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)
850
if (!btr_pcur_is_on_user_rec(&pcur)
771
851
|| rec_get_deleted_flag(rec, 0)) {
794
874
/* Check if the tablespace exists and has the right name */
795
875
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",
796
892
if (fil_space_for_table_exists_in_mem(space, name, FALSE,
798
894
/* Ok; (if we did a crash recovery then the tablespace
809
905
" Retrying an open.\n",
810
906
name, (ulong)space);
811
907
/* Try to open the tablespace */
812
if (!fil_open_single_table_tablespace(TRUE,
908
if (!fil_open_single_table_tablespace(
909
TRUE, space, flags, name)) {
814
910
/* We failed to find a sensible tablespace
817
913
ibd_file_missing = TRUE;
822
920
ut_a(name_of_col_is(sys_tables, sys_index, 4, "N_COLS"));
824
922
field = rec_get_nth_field_old(rec, 4, &len);
825
923
n_cols = mach_read_from_4(field);
829
925
/* The high-order bit of N_COLS is the "compact format" flag. */
830
926
if (n_cols & 0x80000000UL) {
831
927
flags |= DICT_TF_COMPACT;
841
937
field = rec_get_nth_field_old(rec, 3, &len);
842
938
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));
853
940
btr_pcur_close(&pcur);
854
941
mtr_commit(&mtr);
860
947
mem_heap_empty(heap);
862
949
err = dict_load_indexes(table, heap);
950
#ifndef UNIV_HOTBACKUP
864
951
/* If the force recovery flag is set, we open the table irrespective
865
952
of the error condition, since the user may want to dump data from the
866
953
clustered index. However we load the foreign key information only if
871
958
} else if (err == DB_SUCCESS) {
872
959
err = dict_load_foreigns(table->name, TRUE);
875
962
if (err != DB_SUCCESS && table != NULL) {
877
964
mutex_enter(&dict_foreign_err_mutex);
950
1038
BTR_SEARCH_LEAF, &pcur, &mtr);
951
1039
rec = btr_pcur_get_rec(&pcur);
953
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)
1041
if (!btr_pcur_is_on_user_rec(&pcur)
954
1042
|| rec_get_deleted_flag(rec, 0)) {
1059
1148
rec = btr_pcur_get_rec(&pcur);
1061
ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr));
1150
ut_a(btr_pcur_is_on_user_rec(&pcur));
1062
1151
ut_a(!rec_get_deleted_flag(rec, 0));
1064
1153
field = rec_get_nth_field_old(rec, 0, &len);
1129
1218
BTR_SEARCH_LEAF, &pcur, &mtr);
1130
1219
rec = btr_pcur_get_rec(&pcur);
1132
if (!btr_pcur_is_on_user_rec(&pcur, &mtr)
1221
if (!btr_pcur_is_on_user_rec(&pcur)
1133
1222
|| rec_get_deleted_flag(rec, 0)) {
1134
1223
/* Not found */