~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-02-14 01:56:51 UTC
  • mto: (1273.16.5 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: brian@gaz-20100214015651-ror9j0xu7dccz0ct
Two fixes for "make dist"

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
51
51
dtuple_t*
52
52
dict_create_sys_tables_tuple(
53
53
/*=========================*/
54
 
        const dict_table_t*     table,  /*!< in: table */
55
 
        mem_heap_t*             heap)   /*!< in: memory heap from
56
 
                                        which the memory for the built
57
 
                                        tuple is allocated */
 
54
        dict_table_t*   table,  /*!< in: table */
 
55
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
 
56
                                the built tuple is allocated */
58
57
{
59
58
        dict_table_t*   sys_tables;
60
59
        dtuple_t*       entry;
61
60
        dfield_t*       dfield;
62
61
        byte*           ptr;
63
62
 
64
 
        ut_ad(table);
65
 
        ut_ad(heap);
 
63
        ut_ad(table && heap);
66
64
 
67
65
        sys_tables = dict_sys->sys_tables;
68
66
 
71
69
        dict_table_copy_types(entry, sys_tables);
72
70
 
73
71
        /* 0: NAME -----------------------------*/
74
 
        dfield = dtuple_get_nth_field(entry, 0/*NAME*/);
 
72
        dfield = dtuple_get_nth_field(entry, 0);
75
73
 
76
74
        dfield_set_data(dfield, table->name, ut_strlen(table->name));
77
75
        /* 3: ID -------------------------------*/
78
 
        dfield = dtuple_get_nth_field(entry, 1/*ID*/);
 
76
        dfield = dtuple_get_nth_field(entry, 1);
79
77
 
80
78
        ptr = mem_heap_alloc(heap, 8);
81
79
        mach_write_to_8(ptr, table->id);
82
80
 
83
81
        dfield_set_data(dfield, ptr, 8);
84
82
        /* 4: N_COLS ---------------------------*/
85
 
        dfield = dtuple_get_nth_field(entry, 2/*N_COLS*/);
 
83
        dfield = dtuple_get_nth_field(entry, 2);
86
84
 
87
85
#if DICT_TF_COMPACT != 1
88
86
#error
93
91
                        | ((table->flags & DICT_TF_COMPACT) << 31));
94
92
        dfield_set_data(dfield, ptr, 4);
95
93
        /* 5: TYPE -----------------------------*/
96
 
        dfield = dtuple_get_nth_field(entry, 3/*TYPE*/);
 
94
        dfield = dtuple_get_nth_field(entry, 3);
97
95
 
98
96
        ptr = mem_heap_alloc(heap, 4);
99
 
        if (table->flags & (~DICT_TF_COMPACT & ~(~0 << DICT_TF_BITS))) {
 
97
        if (table->flags & ~DICT_TF_COMPACT) {
100
98
                ut_a(table->flags & DICT_TF_COMPACT);
101
99
                ut_a(dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP);
102
100
                ut_a((table->flags & DICT_TF_ZSSIZE_MASK)
103
101
                     <= (DICT_TF_ZSSIZE_MAX << DICT_TF_ZSSIZE_SHIFT));
104
 
                ut_a(!(table->flags & (~0 << DICT_TF2_BITS)));
105
 
                mach_write_to_4(ptr, table->flags & ~(~0 << DICT_TF_BITS));
 
102
                ut_a(!(table->flags & (~0 << DICT_TF_BITS)));
 
103
                mach_write_to_4(ptr, table->flags);
106
104
        } else {
107
105
                mach_write_to_4(ptr, DICT_TABLE_ORDINARY);
108
106
        }
109
107
 
110
108
        dfield_set_data(dfield, ptr, 4);
111
109
        /* 6: MIX_ID (obsolete) ---------------------------*/
112
 
        dfield = dtuple_get_nth_field(entry, 4/*MIX_ID*/);
 
110
        dfield = dtuple_get_nth_field(entry, 4);
113
111
 
114
112
        ptr = mem_heap_zalloc(heap, 8);
115
113
 
116
114
        dfield_set_data(dfield, ptr, 8);
117
 
        /* 7: MIX_LEN (additional flags) --------------------------*/
118
 
 
119
 
        dfield = dtuple_get_nth_field(entry, 5/*MIX_LEN*/);
120
 
 
121
 
        ptr = mem_heap_alloc(heap, 4);
122
 
        mach_write_to_4(ptr, table->flags >> DICT_TF2_SHIFT);
 
115
        /* 7: MIX_LEN (obsolete) --------------------------*/
 
116
 
 
117
        dfield = dtuple_get_nth_field(entry, 5);
 
118
 
 
119
        ptr = mem_heap_zalloc(heap, 4);
123
120
 
124
121
        dfield_set_data(dfield, ptr, 4);
125
122
        /* 8: CLUSTER_NAME ---------------------*/
126
 
        dfield = dtuple_get_nth_field(entry, 6/*CLUSTER_NAME*/);
 
123
        dfield = dtuple_get_nth_field(entry, 6);
127
124
        dfield_set_null(dfield); /* not supported */
128
125
 
129
126
        /* 9: SPACE ----------------------------*/
130
 
        dfield = dtuple_get_nth_field(entry, 7/*SPACE*/);
 
127
        dfield = dtuple_get_nth_field(entry, 7);
131
128
 
132
129
        ptr = mem_heap_alloc(heap, 4);
133
130
        mach_write_to_4(ptr, table->space);
146
143
dtuple_t*
147
144
dict_create_sys_columns_tuple(
148
145
/*==========================*/
149
 
        const dict_table_t*     table,  /*!< in: table */
150
 
        ulint                   i,      /*!< in: column number */
151
 
        mem_heap_t*             heap)   /*!< in: memory heap from
152
 
                                        which the memory for the built
153
 
                                        tuple is allocated */
 
146
        dict_table_t*   table,  /*!< in: table */
 
147
        ulint           i,      /*!< in: column number */
 
148
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
 
149
                                the built tuple is allocated */
154
150
{
155
151
        dict_table_t*           sys_columns;
156
152
        dtuple_t*               entry;
157
153
        const dict_col_t*       column;
158
154
        dfield_t*               dfield;
159
155
        byte*                   ptr;
160
 
        const char*             col_name;
 
156
        const char*     col_name;
161
157
 
162
 
        ut_ad(table);
163
 
        ut_ad(heap);
 
158
        ut_ad(table && heap);
164
159
 
165
160
        column = dict_table_get_nth_col(table, i);
166
161
 
171
166
        dict_table_copy_types(entry, sys_columns);
172
167
 
173
168
        /* 0: TABLE_ID -----------------------*/
174
 
        dfield = dtuple_get_nth_field(entry, 0/*TABLE_ID*/);
 
169
        dfield = dtuple_get_nth_field(entry, 0);
175
170
 
176
171
        ptr = mem_heap_alloc(heap, 8);
177
172
        mach_write_to_8(ptr, table->id);
178
173
 
179
174
        dfield_set_data(dfield, ptr, 8);
180
175
        /* 1: POS ----------------------------*/
181
 
        dfield = dtuple_get_nth_field(entry, 1/*POS*/);
 
176
        dfield = dtuple_get_nth_field(entry, 1);
182
177
 
183
178
        ptr = mem_heap_alloc(heap, 4);
184
179
        mach_write_to_4(ptr, i);
185
180
 
186
181
        dfield_set_data(dfield, ptr, 4);
187
182
        /* 4: NAME ---------------------------*/
188
 
        dfield = dtuple_get_nth_field(entry, 2/*NAME*/);
 
183
        dfield = dtuple_get_nth_field(entry, 2);
189
184
 
190
185
        col_name = dict_table_get_col_name(table, i);
191
186
        dfield_set_data(dfield, col_name, ut_strlen(col_name));
192
187
        /* 5: MTYPE --------------------------*/
193
 
        dfield = dtuple_get_nth_field(entry, 3/*MTYPE*/);
 
188
        dfield = dtuple_get_nth_field(entry, 3);
194
189
 
195
190
        ptr = mem_heap_alloc(heap, 4);
196
191
        mach_write_to_4(ptr, column->mtype);
197
192
 
198
193
        dfield_set_data(dfield, ptr, 4);
199
194
        /* 6: PRTYPE -------------------------*/
200
 
        dfield = dtuple_get_nth_field(entry, 4/*PRTYPE*/);
 
195
        dfield = dtuple_get_nth_field(entry, 4);
201
196
 
202
197
        ptr = mem_heap_alloc(heap, 4);
203
198
        mach_write_to_4(ptr, column->prtype);
204
199
 
205
200
        dfield_set_data(dfield, ptr, 4);
206
201
        /* 7: LEN ----------------------------*/
207
 
        dfield = dtuple_get_nth_field(entry, 5/*LEN*/);
 
202
        dfield = dtuple_get_nth_field(entry, 5);
208
203
 
209
204
        ptr = mem_heap_alloc(heap, 4);
210
205
        mach_write_to_4(ptr, column->len);
211
206
 
212
207
        dfield_set_data(dfield, ptr, 4);
213
208
        /* 8: PREC ---------------------------*/
214
 
        dfield = dtuple_get_nth_field(entry, 6/*PREC*/);
 
209
        dfield = dtuple_get_nth_field(entry, 6);
215
210
 
216
211
        ptr = mem_heap_alloc(heap, 4);
217
212
        mach_write_to_4(ptr, 0/* unused */);
235
230
        dict_table_t*   table;
236
231
        dtuple_t*       row;
237
232
        ulint           error;
238
 
        ulint           flags;
239
233
        const char*     path_or_name;
240
234
        ibool           is_path;
241
235
        mtr_t           mtr;
242
 
        ulint           space = 0;
243
 
        ibool           file_per_table;
244
236
 
245
237
        ut_ad(mutex_own(&(dict_sys->mutex)));
246
238
 
247
239
        table = node->table;
248
240
 
249
 
        /* Cache the global variable "srv_file_per_table" to
250
 
        a local variable before using it. Please note
251
 
        "srv_file_per_table" is not under dict_sys mutex
252
 
        protection, and could be changed while executing
253
 
        this function. So better to cache the current value
254
 
        to a local variable, and all future reference to
255
 
        "srv_file_per_table" should use this local variable. */
256
 
        file_per_table = srv_file_per_table;
257
 
 
258
 
        dict_hdr_get_new_id(&table->id, NULL, NULL);
 
241
        table->id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
259
242
 
260
243
        thr_get_trx(thr)->table_id = table->id;
261
244
 
262
 
        if (file_per_table) {
263
 
                /* Get a new space id if srv_file_per_table is set */
264
 
                dict_hdr_get_new_id(NULL, NULL, &space);
265
 
 
266
 
                if (UNIV_UNLIKELY(space == ULINT_UNDEFINED)) {
267
 
                        return(DB_ERROR);
268
 
                }
269
 
 
 
245
        if (srv_file_per_table) {
270
246
                /* We create a new single-table tablespace for the table.
271
247
                We initially let it be 4 pages:
272
248
                - page 0 is the fsp header and an extent descriptor page,
275
251
                - page 3 will contain the root of the clustered index of the
276
252
                table we create here. */
277
253
 
 
254
                ulint   space = 0;      /* reset to zero for the call below */
 
255
 
278
256
                if (table->dir_path_of_temp_table) {
279
257
                        /* We place tables created with CREATE TEMPORARY
280
258
                        TABLE in the tmp dir of mysqld server */
290
268
                ut_ad(!dict_table_zip_size(table)
291
269
                      || dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP);
292
270
 
293
 
                flags = table->flags & ~(~0 << DICT_TF_BITS);
294
271
                error = fil_create_new_single_table_tablespace(
295
 
                        space, path_or_name, is_path,
296
 
                        flags == DICT_TF_COMPACT ? 0 : flags,
 
272
                        &space, path_or_name, is_path,
 
273
                        table->flags == DICT_TF_COMPACT ? 0 : table->flags,
297
274
                        FIL_IBD_FILE_INITIAL_SIZE);
298
275
                table->space = (unsigned int) space;
299
276
 
309
286
                mtr_commit(&mtr);
310
287
        } else {
311
288
                /* Create in the system tablespace: disallow new features */
312
 
                table->flags &= (~0 << DICT_TF_BITS) | DICT_TF_COMPACT;
 
289
                table->flags &= DICT_TF_COMPACT;
313
290
        }
314
291
 
315
292
        row = dict_create_sys_tables_tuple(table, node->heap);
345
322
dtuple_t*
346
323
dict_create_sys_indexes_tuple(
347
324
/*==========================*/
348
 
        const dict_index_t*     index,  /*!< in: index */
349
 
        mem_heap_t*             heap)   /*!< in: memory heap from
350
 
                                        which the memory for the built
351
 
                                        tuple is allocated */
 
325
        dict_index_t*   index,  /*!< in: index */
 
326
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
 
327
                                the built tuple is allocated */
352
328
{
353
329
        dict_table_t*   sys_indexes;
354
330
        dict_table_t*   table;
357
333
        byte*           ptr;
358
334
 
359
335
        ut_ad(mutex_own(&(dict_sys->mutex)));
360
 
        ut_ad(index);
361
 
        ut_ad(heap);
 
336
        ut_ad(index && heap);
362
337
 
363
338
        sys_indexes = dict_sys->sys_indexes;
364
339
 
369
344
        dict_table_copy_types(entry, sys_indexes);
370
345
 
371
346
        /* 0: TABLE_ID -----------------------*/
372
 
        dfield = dtuple_get_nth_field(entry, 0/*TABLE_ID*/);
 
347
        dfield = dtuple_get_nth_field(entry, 0);
373
348
 
374
349
        ptr = mem_heap_alloc(heap, 8);
375
350
        mach_write_to_8(ptr, table->id);
376
351
 
377
352
        dfield_set_data(dfield, ptr, 8);
378
353
        /* 1: ID ----------------------------*/
379
 
        dfield = dtuple_get_nth_field(entry, 1/*ID*/);
 
354
        dfield = dtuple_get_nth_field(entry, 1);
380
355
 
381
356
        ptr = mem_heap_alloc(heap, 8);
382
357
        mach_write_to_8(ptr, index->id);
383
358
 
384
359
        dfield_set_data(dfield, ptr, 8);
385
360
        /* 4: NAME --------------------------*/
386
 
        dfield = dtuple_get_nth_field(entry, 2/*NAME*/);
 
361
        dfield = dtuple_get_nth_field(entry, 2);
387
362
 
388
363
        dfield_set_data(dfield, index->name, ut_strlen(index->name));
389
364
        /* 5: N_FIELDS ----------------------*/
390
 
        dfield = dtuple_get_nth_field(entry, 3/*N_FIELDS*/);
 
365
        dfield = dtuple_get_nth_field(entry, 3);
391
366
 
392
367
        ptr = mem_heap_alloc(heap, 4);
393
368
        mach_write_to_4(ptr, index->n_fields);
394
369
 
395
370
        dfield_set_data(dfield, ptr, 4);
396
371
        /* 6: TYPE --------------------------*/
397
 
        dfield = dtuple_get_nth_field(entry, 4/*TYPE*/);
 
372
        dfield = dtuple_get_nth_field(entry, 4);
398
373
 
399
374
        ptr = mem_heap_alloc(heap, 4);
400
375
        mach_write_to_4(ptr, index->type);
406
381
#error "DICT_SYS_INDEXES_SPACE_NO_FIELD != 7"
407
382
#endif
408
383
 
409
 
        dfield = dtuple_get_nth_field(entry, 5/*SPACE*/);
 
384
        dfield = dtuple_get_nth_field(entry, 5);
410
385
 
411
386
        ptr = mem_heap_alloc(heap, 4);
412
387
        mach_write_to_4(ptr, index->space);
418
393
#error "DICT_SYS_INDEXES_PAGE_NO_FIELD != 8"
419
394
#endif
420
395
 
421
 
        dfield = dtuple_get_nth_field(entry, 6/*PAGE_NO*/);
 
396
        dfield = dtuple_get_nth_field(entry, 6);
422
397
 
423
398
        ptr = mem_heap_alloc(heap, 4);
424
399
        mach_write_to_4(ptr, FIL_NULL);
437
412
dtuple_t*
438
413
dict_create_sys_fields_tuple(
439
414
/*=========================*/
440
 
        const dict_index_t*     index,  /*!< in: index */
441
 
        ulint                   i,      /*!< in: field number */
442
 
        mem_heap_t*             heap)   /*!< in: memory heap from
443
 
                                        which the memory for the built
444
 
                                        tuple is allocated */
 
415
        dict_index_t*   index,  /*!< in: index */
 
416
        ulint           i,      /*!< in: field number */
 
417
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
 
418
                                the built tuple is allocated */
445
419
{
446
420
        dict_table_t*   sys_fields;
447
421
        dtuple_t*       entry;
451
425
        ibool           index_contains_column_prefix_field      = FALSE;
452
426
        ulint           j;
453
427
 
454
 
        ut_ad(index);
455
 
        ut_ad(heap);
 
428
        ut_ad(index && heap);
456
429
 
457
430
        for (j = 0; j < index->n_fields; j++) {
458
431
                if (dict_index_get_nth_field(index, j)->prefix_len > 0) {
470
443
        dict_table_copy_types(entry, sys_fields);
471
444
 
472
445
        /* 0: INDEX_ID -----------------------*/
473
 
        dfield = dtuple_get_nth_field(entry, 0/*INDEX_ID*/);
 
446
        dfield = dtuple_get_nth_field(entry, 0);
474
447
 
475
448
        ptr = mem_heap_alloc(heap, 8);
476
449
        mach_write_to_8(ptr, index->id);
478
451
        dfield_set_data(dfield, ptr, 8);
479
452
        /* 1: POS + PREFIX LENGTH ----------------------------*/
480
453
 
481
 
        dfield = dtuple_get_nth_field(entry, 1/*POS*/);
 
454
        dfield = dtuple_get_nth_field(entry, 1);
482
455
 
483
456
        ptr = mem_heap_alloc(heap, 4);
484
457
 
498
471
 
499
472
        dfield_set_data(dfield, ptr, 4);
500
473
        /* 4: COL_NAME -------------------------*/
501
 
        dfield = dtuple_get_nth_field(entry, 2/*COL_NAME*/);
 
474
        dfield = dtuple_get_nth_field(entry, 2);
502
475
 
503
476
        dfield_set_data(dfield, field->name,
504
477
                        ut_strlen(field->name));
577
550
        ut_ad((UT_LIST_GET_LEN(table->indexes) > 0)
578
551
              || dict_index_is_clust(index));
579
552
 
580
 
        dict_hdr_get_new_id(NULL, &index->id, NULL);
 
553
        index->id = dict_hdr_get_new_id(DICT_HDR_INDEX_ID);
581
554
 
582
555
        /* Inherit the space id from the table; we store all indexes of a
583
556
        table in the same tablespace */
590
563
        ins_node_set_new_row(node->ind_def, row);
591
564
 
592
565
        /* Note that the index was created by this transaction. */
593
 
        index->trx_id = trx->id;
 
566
        index->trx_id = (ib_uint64_t) ut_conv_dulint_to_longlong(trx->id);
594
567
 
595
568
        return(DB_SUCCESS);
596
569
}
627
600
{
628
601
        dict_index_t*   index;
629
602
        dict_table_t*   sys_indexes;
 
603
        dict_table_t*   table;
630
604
        dtuple_t*       search_tuple;
631
 
        ulint           zip_size;
632
605
        btr_pcur_t      pcur;
633
606
        mtr_t           mtr;
634
607
 
635
608
        ut_ad(mutex_own(&(dict_sys->mutex)));
636
609
 
637
610
        index = node->index;
 
611
        table = node->table;
638
612
 
639
613
        sys_indexes = dict_sys->sys_indexes;
640
614
 
652
626
 
653
627
        btr_pcur_move_to_next_user_rec(&pcur, &mtr);
654
628
 
655
 
        zip_size = dict_table_zip_size(index->table);
656
 
 
657
 
        node->page_no = btr_create(index->type, index->space, zip_size,
 
629
        node->page_no = btr_create(index->type, index->space,
 
630
                                   dict_table_zip_size(index->table),
658
631
                                   index->id, index, &mtr);
659
632
        /* printf("Created a new index tree in space %lu root page %lu\n",
660
633
        index->space, index->page_no); */
759
732
        ibool           drop = !space;
760
733
        ulint           zip_size;
761
734
        ulint           type;
762
 
        index_id_t      index_id;
 
735
        dulint          index_id;
763
736
        rec_t*          rec;
764
737
        const byte*     ptr;
765
738
        ulint           len;
852
825
        for (index = UT_LIST_GET_FIRST(table->indexes);
853
826
             index;
854
827
             index = UT_LIST_GET_NEXT(indexes, index)) {
855
 
                if (index->id == index_id) {
 
828
                if (!ut_dulint_cmp(index->id, index_id)) {
856
829
                        root_page_no = btr_create(type, space, zip_size,
857
830
                                                  index_id, index, mtr);
858
831
                        index->page = (unsigned int) root_page_no;
862
835
 
863
836
        ut_print_timestamp(stderr);
864
837
        fprintf(stderr,
865
 
                "  InnoDB: Index %llu of table %s is missing\n"
 
838
                "  InnoDB: Index %lu %lu of table %s is missing\n"
866
839
                "InnoDB: from the data dictionary during TRUNCATE!\n",
867
 
                (ullint) index_id,
 
840
                ut_dulint_get_high(index_id),
 
841
                ut_dulint_get_low(index_id),
868
842
                table->name);
869
843
 
870
844
        return(FIL_NULL);
1116
1090
 
1117
1091
        if (node->state == INDEX_ADD_TO_CACHE) {
1118
1092
 
1119
 
                index_id_t      index_id = node->index->id;
 
1093
                dulint  index_id = node->index->id;
1120
1094
 
1121
 
                err = dict_index_add_to_cache(
1122
 
                        node->table, node->index, FIL_NULL,
1123
 
                        trx_is_strict(trx)
1124
 
                        || dict_table_get_format(node->table)
1125
 
                        >= DICT_TF_FORMAT_ZIP);
 
1095
                err = dict_index_add_to_cache(node->table, node->index,
 
1096
                                              FIL_NULL, TRUE);
1126
1097
 
1127
1098
                node->index = dict_index_get_if_in_cache_low(index_id);
1128
1099
                ut_a(!node->index == (err != DB_SUCCESS));