~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/dict/dict0crea.c

  • Committer: Monty Taylor
  • Date: 2008-08-04 19:37:18 UTC
  • mto: (261.2.2 codestyle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804193718-f0rz13uli4429ozb
Changed gettext_noop() to N_()

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
        entry = dtuple_create(heap, 8 + DATA_N_SYS_COLS);
51
51
 
52
 
        dict_table_copy_types(entry, sys_tables);
53
 
 
54
52
        /* 0: NAME -----------------------------*/
55
53
        dfield = dtuple_get_nth_field(entry, 0);
56
54
 
77
75
        dfield = dtuple_get_nth_field(entry, 3);
78
76
 
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);
87
 
        } else {
88
 
                mach_write_to_4(ptr, DICT_TABLE_ORDINARY);
89
 
        }
 
78
        mach_write_to_4(ptr, DICT_TABLE_ORDINARY);
90
79
 
91
80
        dfield_set_data(dfield, ptr, 4);
92
81
        /* 6: MIX_ID (obsolete) ---------------------------*/
93
82
        dfield = dtuple_get_nth_field(entry, 4);
94
83
 
95
 
        ptr = mem_heap_zalloc(heap, 8);
 
84
        ptr = mem_heap_alloc(heap, 8);
 
85
        memset(ptr, 0, 8);
96
86
 
97
87
        dfield_set_data(dfield, ptr, 8);
98
88
        /* 7: MIX_LEN (obsolete) --------------------------*/
99
89
 
100
90
        dfield = dtuple_get_nth_field(entry, 5);
101
91
 
102
 
        ptr = mem_heap_zalloc(heap, 4);
 
92
        ptr = mem_heap_alloc(heap, 4);
 
93
        memset(ptr, 0, 4);
103
94
 
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 */
108
99
 
109
100
        /* 9: SPACE ----------------------------*/
110
101
        dfield = dtuple_get_nth_field(entry, 7);
115
106
        dfield_set_data(dfield, ptr, 4);
116
107
        /*----------------------------------*/
117
108
 
 
109
        dict_table_copy_types(entry, sys_tables);
 
110
 
118
111
        return(entry);
119
112
}
120
113
 
146
139
 
147
140
        entry = dtuple_create(heap, 7 + DATA_N_SYS_COLS);
148
141
 
149
 
        dict_table_copy_types(entry, sys_columns);
150
 
 
151
142
        /* 0: TABLE_ID -----------------------*/
152
143
        dfield = dtuple_get_nth_field(entry, 0);
153
144
 
197
188
        dfield_set_data(dfield, ptr, 4);
198
189
        /*---------------------------------*/
199
190
 
 
191
        dict_table_copy_types(entry, sys_columns);
 
192
 
200
193
        return(entry);
201
194
}
202
195
 
257
250
                        is_path = FALSE;
258
251
                }
259
252
 
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);
263
 
 
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;
269
257
 
277
265
                fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr);
278
266
 
279
267
                mtr_commit(&mtr);
280
 
        } else {
281
 
                /* Create in the system tablespace: disallow new features */
282
 
                table->flags &= DICT_TF_COMPACT;
283
268
        }
284
269
 
285
270
        row = dict_create_sys_tables_tuple(table, node->heap);
334
319
 
335
320
        entry = dtuple_create(heap, 7 + DATA_N_SYS_COLS);
336
321
 
337
 
        dict_table_copy_types(entry, sys_indexes);
338
 
 
339
322
        /* 0: TABLE_ID -----------------------*/
340
323
        dfield = dtuple_get_nth_field(entry, 0);
341
324
 
394
377
        dfield_set_data(dfield, ptr, 4);
395
378
        /*--------------------------------*/
396
379
 
 
380
        dict_table_copy_types(entry, sys_indexes);
 
381
 
397
382
        return(entry);
398
383
}
399
384
 
423
408
        for (j = 0; j < index->n_fields; j++) {
424
409
                if (dict_index_get_nth_field(index, j)->prefix_len > 0) {
425
410
                        index_contains_column_prefix_field = TRUE;
426
 
                        break;
427
411
                }
428
412
        }
429
413
 
433
417
 
434
418
        entry = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
435
419
 
436
 
        dict_table_copy_types(entry, sys_fields);
437
 
 
438
420
        /* 0: INDEX_ID -----------------------*/
439
421
        dfield = dtuple_get_nth_field(entry, 0);
440
422
 
470
452
                        ut_strlen(field->name));
471
453
        /*---------------------------------*/
472
454
 
 
455
        dict_table_copy_types(entry, sys_fields);
 
456
 
473
457
        return(entry);
474
458
}
475
459
 
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
485
469
                                table */
486
470
        mem_heap_t*     heap)   /* in: memory heap from which the memory for
487
471
                                the built tuple is allocated */
488
472
{
489
473
        dtuple_t*       search_tuple;
490
 
        const dfield_t* field1;
 
474
        dfield_t*       field1;
491
475
        dfield_t*       field2;
492
476
 
493
477
        ut_ad(tuple && heap);
541
525
        node->table = table;
542
526
 
543
527
        ut_ad((UT_LIST_GET_LEN(table->indexes) > 0)
544
 
              || dict_index_is_clust(index));
 
528
              || (index->type & DICT_CLUSTERED));
545
529
 
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);
550
 
        }
 
530
        index->id = dict_hdr_get_new_id(DICT_HDR_INDEX_ID);
551
531
 
552
532
        /* Inherit the space id from the table; we store all indexes of a
553
533
        table in the same tablespace */
559
539
 
560
540
        ins_node_set_new_row(node->ind_def, row);
561
541
 
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 */
566
 
 
567
542
        return(DB_SUCCESS);
568
543
}
569
544
 
625
600
 
626
601
        btr_pcur_move_to_next_user_rec(&pcur, &mtr);
627
602
 
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); */
633
607
 
647
621
 
648
622
/***********************************************************************
649
623
Drops the index tree associated with a row in SYS_INDEXES table. */
650
 
UNIV_INTERN
 
624
 
651
625
void
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
 
629
                        table */
656
630
        mtr_t*  mtr)    /* in: mtr having the latch on the record page */
657
631
{
658
 
        ulint           root_page_no;
659
 
        ulint           space;
660
 
        ulint           zip_size;
661
 
        const byte*     ptr;
662
 
        ulint           len;
 
632
        ulint   root_page_no;
 
633
        ulint   space;
 
634
        byte*   ptr;
 
635
        ulint   len;
663
636
 
664
637
        ut_ad(mutex_own(&(dict_sys->mutex)));
665
638
        ut_a(!dict_table_is_comp(dict_sys->sys_indexes));
681
654
        ut_ad(len == 4);
682
655
 
683
656
        space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
684
 
        zip_size = fil_space_get_zip_size(space);
685
657
 
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 */
689
661
 
693
665
        /* We free all the pages but the root page first; this operation
694
666
        may span several mini-transactions */
695
667
 
696
 
        btr_free_but_not_root(space, zip_size, root_page_no);
 
668
        btr_free_but_not_root(space, root_page_no);
697
669
 
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
701
673
 
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);
705
677
 
706
678
        page_rec_write_index_page_no(rec,
707
679
                                     DICT_SYS_INDEXES_PAGE_NO_FIELD,
710
682
 
711
683
/***********************************************************************
712
684
Truncates the index tree associated with a row in SYS_INDEXES table. */
713
 
UNIV_INTERN
 
685
 
714
686
ulint
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
722
 
                                given tablespace */
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
729
698
                                committed and restarted in this call. */
730
699
{
731
700
        ulint           root_page_no;
732
 
        ibool           drop = !space;
733
 
        ulint           zip_size;
 
701
        ulint           space;
734
702
        ulint           type;
735
703
        dulint          index_id;
736
704
        rec_t*          rec;
737
 
        const byte*     ptr;
 
705
        byte*           ptr;
738
706
        ulint           len;
 
707
        ulint           comp;
739
708
        dict_index_t*   index;
740
709
 
741
710
        ut_ad(mutex_own(&(dict_sys->mutex)));
747
716
 
748
717
        root_page_no = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
749
718
 
750
 
        if (drop && root_page_no == FIL_NULL) {
 
719
        if (root_page_no == FIL_NULL) {
751
720
                /* The tree has been freed. */
752
721
 
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);
756
 
                drop = FALSE;
 
725
                return(FIL_NULL);
757
726
        }
758
727
 
759
728
        ptr = rec_get_nth_field_old(rec,
761
730
 
762
731
        ut_ad(len == 4);
763
732
 
764
 
        if (drop) {
765
 
                space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
766
 
        }
767
 
 
768
 
        zip_size = fil_space_get_zip_size(space);
769
 
 
770
 
        if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
 
733
        space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
 
734
 
 
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 */
773
738
 
786
751
        ut_ad(len == 8);
787
752
        index_id = mach_read_from_8(ptr);
788
753
 
789
 
        if (!drop) {
790
 
 
791
 
                goto create;
792
 
        }
793
 
 
794
754
        /* We free all the pages but the root page first; this operation
795
755
        may span several mini-transactions */
796
756
 
797
 
        btr_free_but_not_root(space, zip_size, root_page_no);
 
757
        btr_free_but_not_root(space, root_page_no);
798
758
 
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 */
803
763
 
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,
 
765
                                         mtr));
805
766
 
806
 
        btr_free_root(space, zip_size, root_page_no, mtr);
807
 
create:
 
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()
826
786
             index;
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);
 
789
                        break;
833
790
                }
834
791
        }
835
792
 
836
 
        ut_print_timestamp(stderr);
837
 
        fprintf(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),
842
 
                table->name);
 
793
        root_page_no = btr_create(type, space, index_id, comp, mtr);
 
794
        if (index) {
 
795
                index->page = (unsigned int) root_page_no;
 
796
        } else {
 
797
                ut_print_timestamp(stderr);
 
798
                fprintf(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),
 
803
                        table->name);
 
804
        }
843
805
 
844
 
        return(FIL_NULL);
 
806
        return(root_page_no);
845
807
}
846
808
 
847
809
/*************************************************************************
848
810
Creates a table create graph. */
849
 
UNIV_INTERN
 
811
 
850
812
tab_node_t*
851
813
tab_create_graph_create(
852
814
/*====================*/
882
844
 
883
845
/*************************************************************************
884
846
Creates an index create graph. */
885
 
UNIV_INTERN
 
847
 
886
848
ind_node_t*
887
849
ind_create_graph_create(
888
850
/*====================*/
919
881
 
920
882
/***************************************************************
921
883
Creates a table. This is a high-level function used in SQL execution graphs. */
922
 
UNIV_INTERN
 
884
 
923
885
que_thr_t*
924
886
dict_create_table_step(
925
887
/*===================*/
1026
988
/***************************************************************
1027
989
Creates an index. This is a high-level function used in SQL execution
1028
990
graphs. */
1029
 
UNIV_INTERN
 
991
 
1030
992
que_thr_t*
1031
993
dict_create_index_step(
1032
994
/*===================*/
1084
1046
 
1085
1047
                        return(thr);
1086
1048
                } else {
1087
 
                        node->state = INDEX_ADD_TO_CACHE;
1088
 
                }
1089
 
        }
1090
 
 
1091
 
        if (node->state == INDEX_ADD_TO_CACHE) {
1092
 
 
1093
 
                dulint  index_id = node->index->id;
1094
 
 
1095
 
                err = dict_index_add_to_cache(node->table, node->index,
1096
 
                                              FIL_NULL);
1097
 
 
1098
 
                node->index = dict_index_get_if_in_cache_low(index_id);
1099
 
                ut_a(!node->index == (err != DB_SUCCESS));
1100
 
 
1101
 
                if (err != DB_SUCCESS) {
1102
 
 
1103
 
                        goto function_exit;
1104
 
                }
1105
 
 
1106
 
                node->state = INDEX_CREATE_INDEX_TREE;
 
1049
                        node->state = INDEX_CREATE_INDEX_TREE;
 
1050
                }
1107
1051
        }
1108
1052
 
1109
1053
        if (node->state == INDEX_CREATE_INDEX_TREE) {
1111
1055
                err = dict_create_index_tree_step(node);
1112
1056
 
1113
1057
                if (err != DB_SUCCESS) {
1114
 
                        dict_index_remove_from_cache(node->table, node->index);
1115
 
                        node->index = NULL;
1116
1058
 
1117
1059
                        goto function_exit;
1118
1060
                }
1119
1061
 
1120
 
                node->index->page = node->page_no;
1121
1062
                node->state = INDEX_COMMIT_WORK;
1122
1063
        }
1123
1064
 
1127
1068
                (CREATE INDEX does NOT currently do an implicit commit of
1128
1069
                the current transaction) */
1129
1070
 
1130
 
                node->state = INDEX_CREATE_INDEX_TREE;
 
1071
                node->state = INDEX_ADD_TO_CACHE;
1131
1072
 
1132
1073
                /* thr->run_node = node->commit_node;
1133
1074
 
1134
1075
                return(thr); */
1135
1076
        }
1136
1077
 
 
1078
        if (node->state == INDEX_ADD_TO_CACHE) {
 
1079
 
 
1080
                dict_index_add_to_cache(node->table, node->index,
 
1081
                                        node->page_no);
 
1082
 
 
1083
                err = DB_SUCCESS;
 
1084
        }
 
1085
 
1137
1086
function_exit:
1138
1087
        trx->error_state = err;
1139
1088
 
1154
1103
        return(thr);
1155
1104
}
1156
1105
 
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. */
1162
 
UNIV_INTERN
 
1110
 
1163
1111
ulint
1164
1112
dict_create_or_check_foreign_constraint_tables(void)
1165
1113
/*================================================*/
1279
1227
 
1280
1228
/********************************************************************
1281
1229
Evaluate the given foreign key SQL statement. */
1282
 
static
1283
 
ulint
 
1230
 
 
1231
static ulint
1284
1232
dict_foreign_eval_sql(
1285
1233
/*==================*/
1286
1234
                                /* out: error code or DB_SUCCESS */
1303
1251
                      ef);
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",
 
1258
                      ef);
 
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"
1454
1403
 
1455
1404
/************************************************************************
1456
1405
Adds foreign key definitions to data dictionary tables in the database. */
1457
 
UNIV_INTERN
 
1406
 
1458
1407
ulint
1459
1408
dict_create_add_foreigns_to_dictionary(
1460
1409
/*===================================*/
1499
1448
 
1500
1449
        return(DB_SUCCESS);
1501
1450
}
1502
 
#endif /* !UNIV_HOTBACKUP */