50
50
entry = dtuple_create(heap, 8 + DATA_N_SYS_COLS);
52
dict_table_copy_types(entry, sys_tables);
52
54
/* 0: NAME -----------------------------*/
53
55
dfield = dtuple_get_nth_field(entry, 0);
75
77
dfield = dtuple_get_nth_field(entry, 3);
77
79
ptr = mem_heap_alloc(heap, 4);
78
mach_write_to_4(ptr, DICT_TABLE_ORDINARY);
80
if (table->flags & ~DICT_TF_COMPACT) {
81
ut_a(table->flags & DICT_TF_COMPACT);
82
ut_a(dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP);
83
ut_a((table->flags & DICT_TF_ZSSIZE_MASK)
84
<= (DICT_TF_ZSSIZE_MAX << DICT_TF_ZSSIZE_SHIFT));
85
ut_a(!(table->flags & (~0 << DICT_TF_BITS)));
86
mach_write_to_4(ptr, table->flags);
88
mach_write_to_4(ptr, DICT_TABLE_ORDINARY);
80
91
dfield_set_data(dfield, ptr, 4);
81
92
/* 6: MIX_ID (obsolete) ---------------------------*/
82
93
dfield = dtuple_get_nth_field(entry, 4);
84
ptr = mem_heap_alloc(heap, 8);
95
ptr = mem_heap_zalloc(heap, 8);
87
97
dfield_set_data(dfield, ptr, 8);
88
98
/* 7: MIX_LEN (obsolete) --------------------------*/
90
100
dfield = dtuple_get_nth_field(entry, 5);
92
ptr = mem_heap_alloc(heap, 4);
102
ptr = mem_heap_zalloc(heap, 4);
95
104
dfield_set_data(dfield, ptr, 4);
96
105
/* 8: CLUSTER_NAME ---------------------*/
97
106
dfield = dtuple_get_nth_field(entry, 6);
98
dfield_set_data(dfield, NULL, UNIV_SQL_NULL); /* not supported */
107
dfield_set_null(dfield); /* not supported */
100
109
/* 9: SPACE ----------------------------*/
101
110
dfield = dtuple_get_nth_field(entry, 7);
106
115
dfield_set_data(dfield, ptr, 4);
107
116
/*----------------------------------*/
109
dict_table_copy_types(entry, sys_tables);
140
147
entry = dtuple_create(heap, 7 + DATA_N_SYS_COLS);
149
dict_table_copy_types(entry, sys_columns);
142
151
/* 0: TABLE_ID -----------------------*/
143
152
dfield = dtuple_get_nth_field(entry, 0);
188
197
dfield_set_data(dfield, ptr, 4);
189
198
/*---------------------------------*/
191
dict_table_copy_types(entry, sys_columns);
260
ut_ad(dict_table_get_format(table) <= DICT_TF_FORMAT_MAX);
261
ut_ad(!dict_table_zip_size(table)
262
|| dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP);
253
264
error = fil_create_new_single_table_tablespace(
254
265
&space, path_or_name, is_path,
266
table->flags == DICT_TF_COMPACT ? 0 : table->flags,
255
267
FIL_IBD_FILE_INITIAL_SIZE);
256
268
table->space = (unsigned int) space;
265
277
fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr);
267
279
mtr_commit(&mtr);
281
/* Create in the system tablespace: disallow new features */
282
table->flags &= DICT_TF_COMPACT;
270
285
row = dict_create_sys_tables_tuple(table, node->heap);
320
335
entry = dtuple_create(heap, 7 + DATA_N_SYS_COLS);
337
dict_table_copy_types(entry, sys_indexes);
322
339
/* 0: TABLE_ID -----------------------*/
323
340
dfield = dtuple_get_nth_field(entry, 0);
377
394
dfield_set_data(dfield, ptr, 4);
378
395
/*--------------------------------*/
380
dict_table_copy_types(entry, sys_indexes);
418
434
entry = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
436
dict_table_copy_types(entry, sys_fields);
420
438
/* 0: INDEX_ID -----------------------*/
421
439
dfield = dtuple_get_nth_field(entry, 0);
465
481
dict_create_search_tuple(
466
482
/*=====================*/
467
483
/* out: the tuple for search */
468
dtuple_t* tuple, /* in: the tuple inserted in the SYS_INDEXES
484
const dtuple_t* tuple, /* in: the tuple inserted in the SYS_INDEXES
470
486
mem_heap_t* heap) /* in: memory heap from which the memory for
471
487
the built tuple is allocated */
473
489
dtuple_t* search_tuple;
490
const dfield_t* field1;
475
491
dfield_t* field2;
477
493
ut_ad(tuple && heap);
525
541
node->table = table;
527
543
ut_ad((UT_LIST_GET_LEN(table->indexes) > 0)
528
|| (index->type & DICT_CLUSTERED));
544
|| dict_index_is_clust(index));
530
index->id = dict_hdr_get_new_id(DICT_HDR_INDEX_ID);
546
/* For fast index creation we have already allocated an index id
547
for this index so that we could write an UNDO log record for it.*/
548
if (ut_dulint_is_zero(index->id)) {
549
index->id = dict_hdr_get_new_id(DICT_HDR_INDEX_ID);
532
552
/* Inherit the space id from the table; we store all indexes of a
533
553
table in the same tablespace */
540
560
ins_node_set_new_row(node->ind_def, row);
562
#ifdef ROW_MERGE_IS_INDEX_USABLE
563
/* Note that the index was created by this transaction. */
564
index->trx_id = trx->id;
565
#endif /* ROW_MERGE_IS_INDEX_USABLE */
542
567
return(DB_SUCCESS);
601
626
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
603
node->page_no = btr_create(index->type, index->space, index->id,
604
dict_table_is_comp(table), &mtr);
628
node->page_no = btr_create(index->type, index->space,
629
dict_table_zip_size(index->table),
630
index->id, index, &mtr);
605
631
/* printf("Created a new index tree in space %lu root page %lu\n",
606
632
index->space, index->page_no); */
622
648
/***********************************************************************
623
649
Drops the index tree associated with a row in SYS_INDEXES table. */
626
652
dict_drop_index_tree(
627
653
/*=================*/
628
rec_t* rec, /* in: record in the clustered index of SYS_INDEXES
654
rec_t* rec, /* in/out: record in the clustered index
655
of SYS_INDEXES table */
630
656
mtr_t* mtr) /* in: mtr having the latch on the record page */
637
664
ut_ad(mutex_own(&(dict_sys->mutex)));
638
665
ut_a(!dict_table_is_comp(dict_sys->sys_indexes));
656
683
space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
684
zip_size = fil_space_get_zip_size(space);
658
if (!fil_tablespace_exists_in_mem(space)) {
686
if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
659
687
/* It is a single table tablespace and the .ibd file is
660
688
missing: do nothing */
665
693
/* We free all the pages but the root page first; this operation
666
694
may span several mini-transactions */
668
btr_free_but_not_root(space, root_page_no);
696
btr_free_but_not_root(space, zip_size, root_page_no);
670
698
/* Then we free the root page in the same mini-transaction where
671
699
we write FIL_NULL to the appropriate field in the SYS_INDEXES
674
702
/* printf("Dropping index tree in space %lu root page %lu\n", space,
675
703
root_page_no); */
676
btr_free_root(space, root_page_no, mtr);
704
btr_free_root(space, zip_size, root_page_no, mtr);
678
706
page_rec_write_index_page_no(rec,
679
707
DICT_SYS_INDEXES_PAGE_NO_FIELD,
683
711
/***********************************************************************
684
712
Truncates the index tree associated with a row in SYS_INDEXES table. */
687
715
dict_truncate_index_tree(
688
716
/*=====================*/
689
717
/* out: new root page number, or
690
718
FIL_NULL on failure */
691
719
dict_table_t* table, /* in: the table the index belongs to */
720
ulint space, /* in: 0=truncate,
721
nonzero=create the index tree in the
692
723
btr_pcur_t* pcur, /* in/out: persistent cursor pointing to
693
724
record in the clustered index of
694
725
SYS_INDEXES table. The cursor may be
717
748
root_page_no = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
719
if (root_page_no == FIL_NULL) {
750
if (drop && root_page_no == FIL_NULL) {
720
751
/* The tree has been freed. */
722
753
ut_print_timestamp(stderr);
723
754
fprintf(stderr, " InnoDB: Trying to TRUNCATE"
724
755
" a missing index of table %s!\n", table->name);
728
759
ptr = rec_get_nth_field_old(rec,
733
space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
735
if (!fil_tablespace_exists_in_mem(space)) {
765
space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
768
zip_size = fil_space_get_zip_size(space);
770
if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
736
771
/* It is a single table tablespace and the .ibd file is
737
772
missing: do nothing */
752
787
index_id = mach_read_from_8(ptr);
754
794
/* We free all the pages but the root page first; this operation
755
795
may span several mini-transactions */
757
btr_free_but_not_root(space, root_page_no);
797
btr_free_but_not_root(space, zip_size, root_page_no);
759
799
/* Then we free the root page in the same mini-transaction where
760
800
we create the b-tree and write its new root page number to the
761
801
appropriate field in the SYS_INDEXES record: this mini-transaction
762
802
marks the B-tree totally truncated */
764
comp = page_is_comp(btr_page_get(space, root_page_no, RW_X_LATCH,
804
btr_page_get(space, zip_size, root_page_no, RW_X_LATCH, mtr);
767
btr_free_root(space, root_page_no, mtr);
806
btr_free_root(space, zip_size, root_page_no, mtr);
768
808
/* We will temporarily write FIL_NULL to the PAGE_NO field
769
809
in SYS_INDEXES, so that the database will not get into an
770
810
inconsistent state in case it crashes between the mtr_commit()
787
827
index = UT_LIST_GET_NEXT(indexes, index)) {
788
828
if (!ut_dulint_cmp(index->id, index_id)) {
829
root_page_no = btr_create(type, space, zip_size,
830
index_id, index, mtr);
831
index->page = (unsigned int) root_page_no;
832
return(root_page_no);
793
root_page_no = btr_create(type, space, index_id, comp, mtr);
795
index->page = (unsigned int) root_page_no;
797
ut_print_timestamp(stderr);
799
" InnoDB: Index %lu %lu of table %s is missing\n"
800
"InnoDB: from the data dictionary during TRUNCATE!\n",
801
ut_dulint_get_high(index_id),
802
ut_dulint_get_low(index_id),
836
ut_print_timestamp(stderr);
838
" InnoDB: Index %lu %lu of table %s is missing\n"
839
"InnoDB: from the data dictionary during TRUNCATE!\n",
840
ut_dulint_get_high(index_id),
841
ut_dulint_get_low(index_id),
806
return(root_page_no);
809
847
/*************************************************************************
810
848
Creates a table create graph. */
813
851
tab_create_graph_create(
814
852
/*====================*/
1049
node->state = INDEX_CREATE_INDEX_TREE;
1087
node->state = INDEX_ADD_TO_CACHE;
1091
if (node->state == INDEX_ADD_TO_CACHE) {
1093
dulint index_id = node->index->id;
1095
err = dict_index_add_to_cache(node->table, node->index,
1098
node->index = dict_index_get_if_in_cache_low(index_id);
1099
ut_a(!node->index == (err != DB_SUCCESS));
1101
if (err != DB_SUCCESS) {
1106
node->state = INDEX_CREATE_INDEX_TREE;
1053
1109
if (node->state == INDEX_CREATE_INDEX_TREE) {
1055
1111
err = dict_create_index_tree_step(node);
1057
1113
if (err != DB_SUCCESS) {
1114
dict_index_remove_from_cache(node->table, node->index);
1059
1117
goto function_exit;
1120
node->index->page = node->page_no;
1062
1121
node->state = INDEX_COMMIT_WORK;
1068
1127
(CREATE INDEX does NOT currently do an implicit commit of
1069
1128
the current transaction) */
1071
node->state = INDEX_ADD_TO_CACHE;
1130
node->state = INDEX_CREATE_INDEX_TREE;
1073
1132
/* thr->run_node = node->commit_node;
1075
1134
return(thr); */
1078
if (node->state == INDEX_ADD_TO_CACHE) {
1080
dict_index_add_to_cache(node->table, node->index,
1087
1138
trx->error_state = err;
1157
#ifndef UNIV_HOTBACKUP
1106
1158
/********************************************************************
1107
1159
Creates the foreign key constraints system tables inside InnoDB
1108
1160
at database creation or database start if they are not found or are
1109
1161
not of the right form. */
1112
1164
dict_create_or_check_foreign_constraint_tables(void)
1113
1165
/*================================================*/
1252
1304
ut_print_name(ef, trx, TRUE, table->name);
1253
1305
fputs(".\nA foreign key constraint of name ", ef);
1254
ut_print_name(ef, trx, FALSE, foreign->id);
1306
ut_print_name(ef, trx, TRUE, foreign->id);
1255
1307
fputs("\nalready exists."
1256
" (Note that internally InnoDB adds 'databasename/'\n"
1257
"in front of the user-defined constraint name).\n",
1259
fputs("Note that InnoDB's FOREIGN KEY system tables store\n"
1308
" (Note that internally InnoDB adds 'databasename'\n"
1309
"in front of the user-defined constraint name.)\n"
1310
"Note that InnoDB's FOREIGN KEY system tables store\n"
1260
1311
"constraint names as case-insensitive, with the\n"
1261
1312
"MySQL standard latin1_swedish_ci collation. If you\n"
1262
1313
"create tables or databases whose names differ only in\n"
1404
1455
/************************************************************************
1405
1456
Adds foreign key definitions to data dictionary tables in the database. */
1408
1459
dict_create_add_foreigns_to_dictionary(
1409
1460
/*===================================*/