~drizzle-developers/ubuntu/karmic/drizzle/ppa

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2010-11-24 18:44:57 UTC
  • mfrom: (1308.1.31 trunk)
  • Revision ID: mordred@inaugust.com-20101124184457-qd6jvoe2wgnvl3yq
Tags: 2010.11.04-0ubuntu1~karmic1
* New upstream release.
* Turn off -Werror for packaging builds. (Closes: #602662)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2010, 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
51
51
dtuple_t*
52
52
dict_create_sys_tables_tuple(
53
53
/*=========================*/
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 */
 
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 */
57
58
{
58
59
        dict_table_t*   sys_tables;
59
60
        dtuple_t*       entry;
60
61
        dfield_t*       dfield;
61
62
        byte*           ptr;
62
63
 
63
 
        ut_ad(table && heap);
 
64
        ut_ad(table);
 
65
        ut_ad(heap);
64
66
 
65
67
        sys_tables = dict_sys->sys_tables;
66
68
 
69
71
        dict_table_copy_types(entry, sys_tables);
70
72
 
71
73
        /* 0: NAME -----------------------------*/
72
 
        dfield = dtuple_get_nth_field(entry, 0);
 
74
        dfield = dtuple_get_nth_field(entry, 0/*NAME*/);
73
75
 
74
76
        dfield_set_data(dfield, table->name, ut_strlen(table->name));
75
77
        /* 3: ID -------------------------------*/
76
 
        dfield = dtuple_get_nth_field(entry, 1);
 
78
        dfield = dtuple_get_nth_field(entry, 1/*ID*/);
77
79
 
78
80
        ptr = mem_heap_alloc(heap, 8);
79
81
        mach_write_to_8(ptr, table->id);
80
82
 
81
83
        dfield_set_data(dfield, ptr, 8);
82
84
        /* 4: N_COLS ---------------------------*/
83
 
        dfield = dtuple_get_nth_field(entry, 2);
 
85
        dfield = dtuple_get_nth_field(entry, 2/*N_COLS*/);
84
86
 
85
87
#if DICT_TF_COMPACT != 1
86
88
#error
91
93
                        | ((table->flags & DICT_TF_COMPACT) << 31));
92
94
        dfield_set_data(dfield, ptr, 4);
93
95
        /* 5: TYPE -----------------------------*/
94
 
        dfield = dtuple_get_nth_field(entry, 3);
 
96
        dfield = dtuple_get_nth_field(entry, 3/*TYPE*/);
95
97
 
96
98
        ptr = mem_heap_alloc(heap, 4);
97
99
        if (table->flags & (~DICT_TF_COMPACT & ~(~0 << DICT_TF_BITS))) {
107
109
 
108
110
        dfield_set_data(dfield, ptr, 4);
109
111
        /* 6: MIX_ID (obsolete) ---------------------------*/
110
 
        dfield = dtuple_get_nth_field(entry, 4);
 
112
        dfield = dtuple_get_nth_field(entry, 4/*MIX_ID*/);
111
113
 
112
114
        ptr = mem_heap_zalloc(heap, 8);
113
115
 
114
116
        dfield_set_data(dfield, ptr, 8);
115
117
        /* 7: MIX_LEN (additional flags) --------------------------*/
116
118
 
117
 
        dfield = dtuple_get_nth_field(entry, 5);
 
119
        dfield = dtuple_get_nth_field(entry, 5/*MIX_LEN*/);
118
120
 
119
121
        ptr = mem_heap_alloc(heap, 4);
120
122
        mach_write_to_4(ptr, table->flags >> DICT_TF2_SHIFT);
121
123
 
122
124
        dfield_set_data(dfield, ptr, 4);
123
125
        /* 8: CLUSTER_NAME ---------------------*/
124
 
        dfield = dtuple_get_nth_field(entry, 6);
 
126
        dfield = dtuple_get_nth_field(entry, 6/*CLUSTER_NAME*/);
125
127
        dfield_set_null(dfield); /* not supported */
126
128
 
127
129
        /* 9: SPACE ----------------------------*/
128
 
        dfield = dtuple_get_nth_field(entry, 7);
 
130
        dfield = dtuple_get_nth_field(entry, 7/*SPACE*/);
129
131
 
130
132
        ptr = mem_heap_alloc(heap, 4);
131
133
        mach_write_to_4(ptr, table->space);
144
146
dtuple_t*
145
147
dict_create_sys_columns_tuple(
146
148
/*==========================*/
147
 
        dict_table_t*   table,  /*!< in: table */
148
 
        ulint           i,      /*!< in: column number */
149
 
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
150
 
                                the built tuple is allocated */
 
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 */
151
154
{
152
155
        dict_table_t*           sys_columns;
153
156
        dtuple_t*               entry;
154
157
        const dict_col_t*       column;
155
158
        dfield_t*               dfield;
156
159
        byte*                   ptr;
157
 
        const char*     col_name;
 
160
        const char*             col_name;
158
161
 
159
 
        ut_ad(table && heap);
 
162
        ut_ad(table);
 
163
        ut_ad(heap);
160
164
 
161
165
        column = dict_table_get_nth_col(table, i);
162
166
 
167
171
        dict_table_copy_types(entry, sys_columns);
168
172
 
169
173
        /* 0: TABLE_ID -----------------------*/
170
 
        dfield = dtuple_get_nth_field(entry, 0);
 
174
        dfield = dtuple_get_nth_field(entry, 0/*TABLE_ID*/);
171
175
 
172
176
        ptr = mem_heap_alloc(heap, 8);
173
177
        mach_write_to_8(ptr, table->id);
174
178
 
175
179
        dfield_set_data(dfield, ptr, 8);
176
180
        /* 1: POS ----------------------------*/
177
 
        dfield = dtuple_get_nth_field(entry, 1);
 
181
        dfield = dtuple_get_nth_field(entry, 1/*POS*/);
178
182
 
179
183
        ptr = mem_heap_alloc(heap, 4);
180
184
        mach_write_to_4(ptr, i);
181
185
 
182
186
        dfield_set_data(dfield, ptr, 4);
183
187
        /* 4: NAME ---------------------------*/
184
 
        dfield = dtuple_get_nth_field(entry, 2);
 
188
        dfield = dtuple_get_nth_field(entry, 2/*NAME*/);
185
189
 
186
190
        col_name = dict_table_get_col_name(table, i);
187
191
        dfield_set_data(dfield, col_name, ut_strlen(col_name));
188
192
        /* 5: MTYPE --------------------------*/
189
 
        dfield = dtuple_get_nth_field(entry, 3);
 
193
        dfield = dtuple_get_nth_field(entry, 3/*MTYPE*/);
190
194
 
191
195
        ptr = mem_heap_alloc(heap, 4);
192
196
        mach_write_to_4(ptr, column->mtype);
193
197
 
194
198
        dfield_set_data(dfield, ptr, 4);
195
199
        /* 6: PRTYPE -------------------------*/
196
 
        dfield = dtuple_get_nth_field(entry, 4);
 
200
        dfield = dtuple_get_nth_field(entry, 4/*PRTYPE*/);
197
201
 
198
202
        ptr = mem_heap_alloc(heap, 4);
199
203
        mach_write_to_4(ptr, column->prtype);
200
204
 
201
205
        dfield_set_data(dfield, ptr, 4);
202
206
        /* 7: LEN ----------------------------*/
203
 
        dfield = dtuple_get_nth_field(entry, 5);
 
207
        dfield = dtuple_get_nth_field(entry, 5/*LEN*/);
204
208
 
205
209
        ptr = mem_heap_alloc(heap, 4);
206
210
        mach_write_to_4(ptr, column->len);
207
211
 
208
212
        dfield_set_data(dfield, ptr, 4);
209
213
        /* 8: PREC ---------------------------*/
210
 
        dfield = dtuple_get_nth_field(entry, 6);
 
214
        dfield = dtuple_get_nth_field(entry, 6/*PREC*/);
211
215
 
212
216
        ptr = mem_heap_alloc(heap, 4);
213
217
        mach_write_to_4(ptr, 0/* unused */);
235
239
        const char*     path_or_name;
236
240
        ibool           is_path;
237
241
        mtr_t           mtr;
 
242
        ulint           space = 0;
238
243
 
239
244
        ut_ad(mutex_own(&(dict_sys->mutex)));
240
245
 
241
246
        table = node->table;
242
247
 
243
 
        table->id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
 
248
        dict_hdr_get_new_id(&table->id, NULL,
 
249
                            srv_file_per_table ? &space : NULL);
244
250
 
245
251
        thr_get_trx(thr)->table_id = table->id;
246
252
 
247
253
        if (srv_file_per_table) {
 
254
                if (UNIV_UNLIKELY(space == ULINT_UNDEFINED)) {
 
255
                        return(DB_ERROR);
 
256
                }
 
257
 
248
258
                /* We create a new single-table tablespace for the table.
249
259
                We initially let it be 4 pages:
250
260
                - page 0 is the fsp header and an extent descriptor page,
253
263
                - page 3 will contain the root of the clustered index of the
254
264
                table we create here. */
255
265
 
256
 
                ulint   space = 0;      /* reset to zero for the call below */
257
 
 
258
266
                if (table->dir_path_of_temp_table) {
259
267
                        /* We place tables created with CREATE TEMPORARY
260
268
                        TABLE in the tmp dir of mysqld server */
272
280
 
273
281
                flags = table->flags & ~(~0 << DICT_TF_BITS);
274
282
                error = fil_create_new_single_table_tablespace(
275
 
                        &space, path_or_name, is_path,
 
283
                        space, path_or_name, is_path,
276
284
                        flags == DICT_TF_COMPACT ? 0 : flags,
277
285
                        FIL_IBD_FILE_INITIAL_SIZE);
278
286
                table->space = (unsigned int) space;
325
333
dtuple_t*
326
334
dict_create_sys_indexes_tuple(
327
335
/*==========================*/
328
 
        dict_index_t*   index,  /*!< in: index */
329
 
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
330
 
                                the built tuple is allocated */
 
336
        const dict_index_t*     index,  /*!< in: index */
 
337
        mem_heap_t*             heap)   /*!< in: memory heap from
 
338
                                        which the memory for the built
 
339
                                        tuple is allocated */
331
340
{
332
341
        dict_table_t*   sys_indexes;
333
342
        dict_table_t*   table;
336
345
        byte*           ptr;
337
346
 
338
347
        ut_ad(mutex_own(&(dict_sys->mutex)));
339
 
        ut_ad(index && heap);
 
348
        ut_ad(index);
 
349
        ut_ad(heap);
340
350
 
341
351
        sys_indexes = dict_sys->sys_indexes;
342
352
 
347
357
        dict_table_copy_types(entry, sys_indexes);
348
358
 
349
359
        /* 0: TABLE_ID -----------------------*/
350
 
        dfield = dtuple_get_nth_field(entry, 0);
 
360
        dfield = dtuple_get_nth_field(entry, 0/*TABLE_ID*/);
351
361
 
352
362
        ptr = mem_heap_alloc(heap, 8);
353
363
        mach_write_to_8(ptr, table->id);
354
364
 
355
365
        dfield_set_data(dfield, ptr, 8);
356
366
        /* 1: ID ----------------------------*/
357
 
        dfield = dtuple_get_nth_field(entry, 1);
 
367
        dfield = dtuple_get_nth_field(entry, 1/*ID*/);
358
368
 
359
369
        ptr = mem_heap_alloc(heap, 8);
360
370
        mach_write_to_8(ptr, index->id);
361
371
 
362
372
        dfield_set_data(dfield, ptr, 8);
363
373
        /* 4: NAME --------------------------*/
364
 
        dfield = dtuple_get_nth_field(entry, 2);
 
374
        dfield = dtuple_get_nth_field(entry, 2/*NAME*/);
365
375
 
366
376
        dfield_set_data(dfield, index->name, ut_strlen(index->name));
367
377
        /* 5: N_FIELDS ----------------------*/
368
 
        dfield = dtuple_get_nth_field(entry, 3);
 
378
        dfield = dtuple_get_nth_field(entry, 3/*N_FIELDS*/);
369
379
 
370
380
        ptr = mem_heap_alloc(heap, 4);
371
381
        mach_write_to_4(ptr, index->n_fields);
372
382
 
373
383
        dfield_set_data(dfield, ptr, 4);
374
384
        /* 6: TYPE --------------------------*/
375
 
        dfield = dtuple_get_nth_field(entry, 4);
 
385
        dfield = dtuple_get_nth_field(entry, 4/*TYPE*/);
376
386
 
377
387
        ptr = mem_heap_alloc(heap, 4);
378
388
        mach_write_to_4(ptr, index->type);
384
394
#error "DICT_SYS_INDEXES_SPACE_NO_FIELD != 7"
385
395
#endif
386
396
 
387
 
        dfield = dtuple_get_nth_field(entry, 5);
 
397
        dfield = dtuple_get_nth_field(entry, 5/*SPACE*/);
388
398
 
389
399
        ptr = mem_heap_alloc(heap, 4);
390
400
        mach_write_to_4(ptr, index->space);
396
406
#error "DICT_SYS_INDEXES_PAGE_NO_FIELD != 8"
397
407
#endif
398
408
 
399
 
        dfield = dtuple_get_nth_field(entry, 6);
 
409
        dfield = dtuple_get_nth_field(entry, 6/*PAGE_NO*/);
400
410
 
401
411
        ptr = mem_heap_alloc(heap, 4);
402
412
        mach_write_to_4(ptr, FIL_NULL);
415
425
dtuple_t*
416
426
dict_create_sys_fields_tuple(
417
427
/*=========================*/
418
 
        dict_index_t*   index,  /*!< in: index */
419
 
        ulint           i,      /*!< in: field number */
420
 
        mem_heap_t*     heap)   /*!< in: memory heap from which the memory for
421
 
                                the built tuple is allocated */
 
428
        const dict_index_t*     index,  /*!< in: index */
 
429
        ulint                   i,      /*!< in: field number */
 
430
        mem_heap_t*             heap)   /*!< in: memory heap from
 
431
                                        which the memory for the built
 
432
                                        tuple is allocated */
422
433
{
423
434
        dict_table_t*   sys_fields;
424
435
        dtuple_t*       entry;
428
439
        ibool           index_contains_column_prefix_field      = FALSE;
429
440
        ulint           j;
430
441
 
431
 
        ut_ad(index && heap);
 
442
        ut_ad(index);
 
443
        ut_ad(heap);
432
444
 
433
445
        for (j = 0; j < index->n_fields; j++) {
434
446
                if (dict_index_get_nth_field(index, j)->prefix_len > 0) {
446
458
        dict_table_copy_types(entry, sys_fields);
447
459
 
448
460
        /* 0: INDEX_ID -----------------------*/
449
 
        dfield = dtuple_get_nth_field(entry, 0);
 
461
        dfield = dtuple_get_nth_field(entry, 0/*INDEX_ID*/);
450
462
 
451
463
        ptr = mem_heap_alloc(heap, 8);
452
464
        mach_write_to_8(ptr, index->id);
454
466
        dfield_set_data(dfield, ptr, 8);
455
467
        /* 1: POS + PREFIX LENGTH ----------------------------*/
456
468
 
457
 
        dfield = dtuple_get_nth_field(entry, 1);
 
469
        dfield = dtuple_get_nth_field(entry, 1/*POS*/);
458
470
 
459
471
        ptr = mem_heap_alloc(heap, 4);
460
472
 
474
486
 
475
487
        dfield_set_data(dfield, ptr, 4);
476
488
        /* 4: COL_NAME -------------------------*/
477
 
        dfield = dtuple_get_nth_field(entry, 2);
 
489
        dfield = dtuple_get_nth_field(entry, 2/*COL_NAME*/);
478
490
 
479
491
        dfield_set_data(dfield, field->name,
480
492
                        ut_strlen(field->name));
553
565
        ut_ad((UT_LIST_GET_LEN(table->indexes) > 0)
554
566
              || dict_index_is_clust(index));
555
567
 
556
 
        index->id = dict_hdr_get_new_id(DICT_HDR_INDEX_ID);
 
568
        dict_hdr_get_new_id(NULL, &index->id, NULL);
557
569
 
558
570
        /* Inherit the space id from the table; we store all indexes of a
559
571
        table in the same tablespace */
605
617
        dict_table_t*   sys_indexes;
606
618
        dict_table_t*   table;
607
619
        dtuple_t*       search_tuple;
 
620
        ulint           zip_size;
608
621
        btr_pcur_t      pcur;
609
622
        mtr_t           mtr;
610
623
 
629
642
 
630
643
        btr_pcur_move_to_next_user_rec(&pcur, &mtr);
631
644
 
632
 
        node->page_no = btr_create(index->type, index->space,
633
 
                                   dict_table_zip_size(index->table),
 
645
        zip_size = dict_table_zip_size(index->table);
 
646
 
 
647
        node->page_no = btr_create(index->type, index->space, zip_size,
634
648
                                   index->id, index, &mtr);
635
649
        /* printf("Created a new index tree in space %lu root page %lu\n",
636
650
        index->space, index->page_no); */
1095
1109
 
1096
1110
                dulint  index_id = node->index->id;
1097
1111
 
1098
 
                err = dict_index_add_to_cache(node->table, node->index,
1099
 
                                              FIL_NULL, TRUE);
 
1112
                err = dict_index_add_to_cache(
 
1113
                        node->table, node->index, FIL_NULL,
 
1114
                        trx_is_strict(trx)
 
1115
                        || dict_table_get_format(node->table)
 
1116
                        >= DICT_TF_FORMAT_ZIP);
1100
1117
 
1101
1118
                node->index = dict_index_get_if_in_cache_low(index_id);
1102
1119
                ut_a(!node->index == (err != DB_SUCCESS));