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