~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/dict0dict.ic

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
***********************************************************************/
8
8
 
9
9
#include "dict0load.h"
 
10
#include "trx0undo.h"
 
11
#include "trx0sys.h"
10
12
#include "rem0types.h"
11
13
#include "data0type.h"
12
14
 
126
128
        ulint   i;
127
129
 
128
130
        ut_ad(col);
129
 
        ut_ad(clust_index);
130
 
        ut_ad(dict_index_is_clust(clust_index));
 
131
        ut_ad(clust_index && clust_index->type & DICT_CLUSTERED);
131
132
 
132
133
        for (i = 0; i < clust_index->n_def; i++) {
133
134
                const dict_field_t*     field = &clust_index->fields[i];
140
141
        return(ULINT_UNDEFINED);
141
142
}
142
143
 
143
 
#ifdef UNIV_DEBUG
144
144
/************************************************************************
145
145
Gets the first index on the table (the clustered index). */
146
146
UNIV_INLINE
147
147
dict_index_t*
148
148
dict_table_get_first_index(
149
149
/*=======================*/
150
 
                                        /* out: index, NULL if none exists */
151
 
        const dict_table_t*     table)  /* in: table */
 
150
                                /* out: index, NULL if none exists */
 
151
        dict_table_t*   table)  /* in: table */
152
152
{
153
153
        ut_ad(table);
154
154
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
155
155
 
156
 
        return(UT_LIST_GET_FIRST(((dict_table_t*) table)->indexes));
 
156
        return(UT_LIST_GET_FIRST(table->indexes));
157
157
}
158
158
 
159
159
/************************************************************************
162
162
dict_index_t*
163
163
dict_table_get_next_index(
164
164
/*======================*/
165
 
                                        /* out: index, NULL if none left */
166
 
        const dict_index_t*     index)  /* in: index */
167
 
{
168
 
        ut_ad(index);
169
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
170
 
 
171
 
        return(UT_LIST_GET_NEXT(indexes, (dict_index_t*) index));
172
 
}
173
 
#endif /* UNIV_DEBUG */
174
 
 
175
 
/************************************************************************
176
 
Check whether the index is the clustered index. */
177
 
UNIV_INLINE
178
 
ulint
179
 
dict_index_is_clust(
180
 
/*================*/
181
 
                                        /* out: nonzero for clustered index,
182
 
                                        zero for other indexes */
183
 
        const dict_index_t*     index)  /* in: index */
184
 
{
185
 
        ut_ad(index);
186
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
187
 
 
188
 
        return(UNIV_UNLIKELY(index->type & DICT_CLUSTERED));
189
 
}
190
 
/************************************************************************
191
 
Check whether the index is unique. */
192
 
UNIV_INLINE
193
 
ulint
194
 
dict_index_is_unique(
195
 
/*=================*/
196
 
                                        /* out: nonzero for unique index,
197
 
                                        zero for other indexes */
198
 
        const dict_index_t*     index)  /* in: index */
199
 
{
200
 
        ut_ad(index);
201
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
202
 
 
203
 
        return(UNIV_UNLIKELY(index->type & DICT_UNIQUE));
204
 
}
205
 
 
206
 
/************************************************************************
207
 
Check whether the index is the insert buffer tree. */
208
 
UNIV_INLINE
209
 
ulint
210
 
dict_index_is_ibuf(
211
 
/*===============*/
212
 
                                        /* out: nonzero for insert buffer,
213
 
                                        zero for other indexes */
214
 
        const dict_index_t*     index)  /* in: index */
215
 
{
216
 
        ut_ad(index);
217
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
218
 
 
219
 
        return(UNIV_UNLIKELY(index->type & DICT_IBUF));
 
165
                                /* out: index, NULL if none left */
 
166
        dict_index_t*   index)  /* in: index */
 
167
{
 
168
        ut_ad(index);
 
169
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
170
 
 
171
        return(UT_LIST_GET_NEXT(indexes, index));
220
172
}
221
173
 
222
174
/************************************************************************
226
178
ulint
227
179
dict_table_get_n_user_cols(
228
180
/*=======================*/
229
 
                                        /* out: number of user-defined
230
 
                                        (e.g., not ROW_ID)
231
 
                                        columns of a table */
232
 
        const dict_table_t*     table)  /* in: table */
 
181
                                /* out: number of user-defined (e.g., not
 
182
                                ROW_ID) columns of a table */
 
183
        dict_table_t*   table)  /* in: table */
233
184
{
234
185
        ut_ad(table);
235
186
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
243
194
ulint
244
195
dict_table_get_n_sys_cols(
245
196
/*======================*/
246
 
                                        /* out: number of system (e.g.,
247
 
                                        ROW_ID) columns of a table */
248
 
        const dict_table_t*     table __attribute__((unused)))  /* in: table */
 
197
                                /* out: number of system (e.g.,
 
198
                                ROW_ID) columns of a table */
 
199
        dict_table_t*   table __attribute__((unused)))  /* in: table */
249
200
{
250
201
        ut_ad(table);
251
202
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
261
212
ulint
262
213
dict_table_get_n_cols(
263
214
/*==================*/
264
 
                                        /* out: number of columns of a table */
265
 
        const dict_table_t*     table)  /* in: table */
 
215
                                /* out: number of columns of a table */
 
216
        dict_table_t*   table)  /* in: table */
266
217
{
267
218
        ut_ad(table);
268
219
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
270
221
        return(table->n_cols);
271
222
}
272
223
 
273
 
#ifdef UNIV_DEBUG
274
224
/************************************************************************
275
225
Gets the nth column of a table. */
276
226
UNIV_INLINE
277
 
dict_col_t*
 
227
const dict_col_t*
278
228
dict_table_get_nth_col(
279
229
/*===================*/
280
230
                                        /* out: pointer to column object */
285
235
        ut_ad(pos < table->n_def);
286
236
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
287
237
 
288
 
        return((dict_col_t*) (table->cols) + pos);
 
238
        return((table->cols) + pos);
289
239
}
290
240
 
291
241
/************************************************************************
292
242
Gets the given system column of a table. */
293
243
UNIV_INLINE
294
 
dict_col_t*
 
244
const dict_col_t*
295
245
dict_table_get_sys_col(
296
246
/*===================*/
297
247
                                        /* out: pointer to column object */
298
248
        const dict_table_t*     table,  /* in: table */
299
249
        ulint                   sys)    /* in: DATA_ROW_ID, ... */
300
250
{
301
 
        dict_col_t*     col;
 
251
        const dict_col_t*       col;
302
252
 
303
253
        ut_ad(table);
304
254
        ut_ad(sys < DATA_N_SYS_COLS);
311
261
 
312
262
        return(col);
313
263
}
314
 
#endif /* UNIV_DEBUG */
315
264
 
316
265
/************************************************************************
317
266
Gets the given system column number of a table. */
319
268
ulint
320
269
dict_table_get_sys_col_no(
321
270
/*======================*/
322
 
                                        /* out: column number */
323
 
        const dict_table_t*     table,  /* in: table */
324
 
        ulint                   sys)    /* in: DATA_ROW_ID, ... */
 
271
                                /* out: column number */
 
272
        dict_table_t*   table,  /* in: table */
 
273
        ulint           sys)    /* in: DATA_ROW_ID, ... */
325
274
{
326
275
        ut_ad(table);
327
276
        ut_ad(sys < DATA_N_SYS_COLS);
350
299
}
351
300
 
352
301
/************************************************************************
353
 
Determine the file format of a table. */
354
 
UNIV_INLINE
355
 
ulint
356
 
dict_table_get_format(
357
 
/*==================*/
358
 
                                        /* out: file format version */
359
 
        const dict_table_t*     table)  /* in: table */
360
 
{
361
 
        ut_ad(table);
362
 
 
363
 
        return((table->flags & DICT_TF_FORMAT_MASK) >> DICT_TF_FORMAT_SHIFT);
364
 
}
365
 
 
366
 
/************************************************************************
367
 
Determine the file format of a table. */
368
 
UNIV_INLINE
369
 
void
370
 
dict_table_set_format(
371
 
/*==================*/
372
 
        dict_table_t*   table,  /* in/out: table */
373
 
        ulint           format) /* in: file format version */
374
 
{
375
 
        ut_ad(table);
376
 
 
377
 
        table->flags = (table->flags & ~DICT_TF_FORMAT_MASK)
378
 
                | (format << DICT_TF_FORMAT_SHIFT);
379
 
}
380
 
 
381
 
/************************************************************************
382
 
Extract the compressed page size from table flags. */
383
 
UNIV_INLINE
384
 
ulint
385
 
dict_table_flags_to_zip_size(
386
 
/*=========================*/
387
 
                        /* out: compressed page size,
388
 
                        or 0 if not compressed */
389
 
        ulint   flags)  /* in: flags */
390
 
{
391
 
        ulint   zip_size = flags & DICT_TF_ZSSIZE_MASK;
392
 
 
393
 
        if (UNIV_UNLIKELY(zip_size)) {
394
 
                zip_size = ((PAGE_ZIP_MIN_SIZE >> 1)
395
 
                         << (zip_size >> DICT_TF_ZSSIZE_SHIFT));
396
 
 
397
 
                ut_ad(zip_size <= UNIV_PAGE_SIZE);
398
 
        }
399
 
 
400
 
        return(zip_size);
401
 
}
402
 
 
403
 
/************************************************************************
404
 
Check whether the table uses the compressed compact page format. */
405
 
UNIV_INLINE
406
 
ulint
407
 
dict_table_zip_size(
408
 
/*================*/
409
 
                                        /* out: compressed page size,
410
 
                                        or 0 if not compressed */
411
 
        const dict_table_t*     table)  /* in: table */
412
 
{
413
 
        ut_ad(table);
414
 
 
415
 
        return(dict_table_flags_to_zip_size(table->flags));
416
 
}
417
 
 
418
 
/************************************************************************
419
302
Gets the number of fields in the internal representation of an index,
420
303
including fields added by the dictionary system. */
421
304
UNIV_INLINE
422
305
ulint
423
306
dict_index_get_n_fields(
424
307
/*====================*/
425
 
                                        /* out: number of fields */
426
 
        const dict_index_t*     index)  /* in: an internal
427
 
                                        representation of index (in
428
 
                                        the dictionary cache) */
 
308
                                /* out: number of fields */
 
309
        dict_index_t*   index)  /* in: an internal representation of index
 
310
                                (in the dictionary cache) */
429
311
{
430
312
        ut_ad(index);
431
313
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
442
324
ulint
443
325
dict_index_get_n_unique(
444
326
/*====================*/
445
 
                                        /* out: number of fields */
446
 
        const dict_index_t*     index)  /* in: an internal representation
447
 
                                        of index (in the dictionary cache) */
 
327
                                /* out: number of fields */
 
328
        dict_index_t*   index)  /* in: an internal representation of index
 
329
                                (in the dictionary cache) */
448
330
{
449
331
        ut_ad(index);
450
332
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
461
343
ulint
462
344
dict_index_get_n_unique_in_tree(
463
345
/*============================*/
464
 
                                        /* out: number of fields */
465
 
        const dict_index_t*     index)  /* in: an internal representation
466
 
                                        of index (in the dictionary cache) */
 
346
                                /* out: number of fields */
 
347
        dict_index_t*   index)  /* in: an internal representation of index
 
348
                                (in the dictionary cache) */
467
349
{
468
350
        ut_ad(index);
469
351
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
470
352
        ut_ad(index->cached);
471
353
 
472
 
        if (dict_index_is_clust(index)) {
 
354
        if (index->type & DICT_CLUSTERED) {
473
355
 
474
356
                return(dict_index_get_n_unique(index));
475
357
        }
486
368
ulint
487
369
dict_index_get_n_ordering_defined_by_user(
488
370
/*======================================*/
489
 
                                        /* out: number of fields */
490
 
        const dict_index_t*     index)  /* in: an internal representation
491
 
                                        of index (in the dictionary cache) */
 
371
                                /* out: number of fields */
 
372
        dict_index_t*   index)  /* in: an internal representation of index
 
373
                                (in the dictionary cache) */
492
374
{
493
375
        return(index->n_user_defined_cols);
494
376
}
495
377
 
496
 
#ifdef UNIV_DEBUG
497
378
/************************************************************************
498
379
Gets the nth field of an index. */
499
380
UNIV_INLINE
502
383
/*=====================*/
503
384
                                        /* out: pointer to field object */
504
385
        const dict_index_t*     index,  /* in: index */
505
 
        ulint                   pos)    /* in: position of field */
 
386
        ulint                   pos)    /* in: position of field */
506
387
{
507
388
        ut_ad(index);
508
389
        ut_ad(pos < index->n_def);
509
390
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
510
391
 
511
 
        return((dict_field_t*) (index->fields) + pos);
 
392
        return((index->fields) + pos);
512
393
}
513
 
#endif /* UNIV_DEBUG */
514
394
 
515
395
/************************************************************************
516
396
Returns the position of a system column in an index. */
518
398
ulint
519
399
dict_index_get_sys_col_pos(
520
400
/*=======================*/
521
 
                                        /* out: position,
522
 
                                        ULINT_UNDEFINED if not contained */
523
 
        const dict_index_t*     index,  /* in: index */
524
 
        ulint                   type)   /* in: DATA_ROW_ID, ... */
 
401
                                /* out: position, ULINT_UNDEFINED if not
 
402
                                contained */
 
403
        dict_index_t*   index,  /* in: index */
 
404
        ulint           type)   /* in: DATA_ROW_ID, ... */
525
405
{
526
406
        ut_ad(index);
527
407
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
528
408
        ut_ad(!(index->type & DICT_UNIVERSAL));
529
409
 
530
 
        if (dict_index_is_clust(index)) {
 
410
        if (index->type & DICT_CLUSTERED) {
531
411
 
532
412
                return(dict_col_get_clust_pos(
533
413
                               dict_table_get_sys_col(index->table, type),
577
457
        return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
578
458
}
579
459
 
580
 
/************************************************************************
581
 
Returns the minimum data size of an index record. */
582
 
UNIV_INLINE
583
 
ulint
584
 
dict_index_get_min_size(
585
 
/*====================*/
586
 
                                        /* out: minimum data size in bytes */
587
 
        const dict_index_t*     index)  /* in: index */
588
 
{
589
 
        ulint   n       = dict_index_get_n_fields(index);
590
 
        ulint   size    = 0;
591
 
 
592
 
        while (n--) {
593
 
                size += dict_col_get_min_size(dict_index_get_nth_col(index,
594
 
                                                                     n));
595
 
        }
596
 
 
597
 
        return(size);
598
 
}
599
 
 
600
460
/*************************************************************************
601
461
Gets the space id of the root of the index tree. */
602
462
UNIV_INLINE
603
463
ulint
604
464
dict_index_get_space(
605
465
/*=================*/
606
 
                                        /* out: space id */
607
 
        const dict_index_t*     index)  /* in: index */
 
466
                                /* out: space id */
 
467
        dict_index_t*   index)  /* in: index */
608
468
{
609
469
        ut_ad(index);
610
470
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
618
478
void
619
479
dict_index_set_space(
620
480
/*=================*/
621
 
        dict_index_t*   index,  /* in/out: index */
 
481
        dict_index_t*   index,  /* in: index */
622
482
        ulint           space)  /* in: space id */
623
483
{
624
484
        ut_ad(index);
633
493
ulint
634
494
dict_index_get_page(
635
495
/*================*/
636
 
                                        /* out: page number */
637
 
        const dict_index_t*     index)  /* in: index */
 
496
                                /* out: page number */
 
497
        dict_index_t*   index)  /* in: index */
638
498
{
639
499
        ut_ad(index);
640
500
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
648
508
void
649
509
dict_index_set_page(
650
510
/*================*/
651
 
        dict_index_t*   index,  /* in/out: index */
 
511
        dict_index_t*   index,  /* in: index */
652
512
        ulint           page)   /* in: page number */
653
513
{
654
514
        ut_ad(index);
663
523
ulint
664
524
dict_index_get_type(
665
525
/*================*/
666
 
                                        /* out: type */
667
 
        const dict_index_t*     index)  /* in: index */
 
526
                                /* out: type */
 
527
        dict_index_t*   index)  /* in: index */
668
528
{
669
529
        ut_ad(index);
670
530
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
719
579
        /* Look for the table name in the hash table */
720
580
        table_fold = ut_fold_string(table_name);
721
581
 
722
 
        HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold,
723
 
                    dict_table_t*, table, !strcmp(table->name, table_name));
 
582
        HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold, table,
 
583
                    ut_strcmp(table->name, table_name) == 0);
724
584
        return(table);
725
585
}
726
586
 
765
625
        /* Look for the table name in the hash table */
766
626
        fold = ut_fold_dulint(table_id);
767
627
 
768
 
        HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold,
769
 
                    dict_table_t*, table, !ut_dulint_cmp(table->id, table_id));
 
628
        HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold, table,
 
629
                    ut_dulint_cmp(table->id, table_id) == 0);
770
630
        if (table == NULL) {
771
631
                table = dict_load_table_on_id(table_id);
772
632
        }
776
636
        return(table);
777
637
}
778
638
 
 
639
/**************************************************************************
 
640
Returns an index object. */
 
641
UNIV_INLINE
 
642
dict_index_t*
 
643
dict_table_get_index(
 
644
/*=================*/
 
645
                                /* out: index, NULL if does not exist */
 
646
        dict_table_t*   table,  /* in: table */
 
647
        const char*     name)   /* in: index name */
 
648
{
 
649
        dict_index_t*   index   = NULL;
 
650
 
 
651
        index = dict_table_get_first_index(table);
 
652
 
 
653
        while (index != NULL) {
 
654
                if (ut_strcmp(name, index->name) == 0) {
 
655
 
 
656
                        break;
 
657
                }
 
658
 
 
659
                index = dict_table_get_next_index(index);
 
660
        }
 
661
 
 
662
        return(index);
 
663
}