~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
Data dictionary system
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 1/8/1996 Heikki Tuuri
 
7
***********************************************************************/
 
8
 
 
9
#include "dict0load.h"
 
10
#include "rem0types.h"
 
11
#include "data0type.h"
 
12
 
 
13
/*************************************************************************
 
14
Gets the column data type. */
 
15
UNIV_INLINE
 
16
void
 
17
dict_col_copy_type(
 
18
/*===============*/
 
19
        const dict_col_t*       col,    /* in: column */
 
20
        dtype_t*                type)   /* out: data type */
 
21
{
 
22
        ut_ad(col && type);
 
23
 
 
24
        type->mtype = col->mtype;
 
25
        type->prtype = col->prtype;
 
26
        type->len = col->len;
 
27
        type->mbminlen = col->mbminlen;
 
28
        type->mbmaxlen = col->mbmaxlen;
 
29
}
 
30
 
 
31
#ifdef UNIV_DEBUG
 
32
/*************************************************************************
 
33
Assert that a column and a data type match. */
 
34
UNIV_INLINE
 
35
ibool
 
36
dict_col_type_assert_equal(
 
37
/*=======================*/
 
38
                                        /* out: TRUE */
 
39
        const dict_col_t*       col,    /* in: column */
 
40
        const dtype_t*          type)   /* in: data type */
 
41
{
 
42
        ut_ad(col);
 
43
        ut_ad(type);
 
44
 
 
45
        ut_ad(col->mtype == type->mtype);
 
46
        ut_ad(col->prtype == type->prtype);
 
47
        ut_ad(col->len == type->len);
 
48
        ut_ad(col->mbminlen == type->mbminlen);
 
49
        ut_ad(col->mbmaxlen == type->mbmaxlen);
 
50
 
 
51
        return(TRUE);
 
52
}
 
53
#endif /* UNIV_DEBUG */
 
54
 
 
55
/***************************************************************************
 
56
Returns the minimum size of the column. */
 
57
UNIV_INLINE
 
58
ulint
 
59
dict_col_get_min_size(
 
60
/*==================*/
 
61
                                        /* out: minimum size */
 
62
        const dict_col_t*       col)    /* in: column */
 
63
{
 
64
        return(dtype_get_min_size_low(col->mtype, col->prtype, col->len,
 
65
                                      col->mbminlen, col->mbmaxlen));
 
66
}
 
67
/***************************************************************************
 
68
Returns the maximum size of the column. */
 
69
UNIV_INLINE
 
70
ulint
 
71
dict_col_get_max_size(
 
72
/*==================*/
 
73
                                        /* out: maximum size */
 
74
        const dict_col_t*       col)    /* in: column */
 
75
{
 
76
        return(dtype_get_max_size_low(col->mtype, col->len));
 
77
}
 
78
/***************************************************************************
 
79
Returns the size of a fixed size column, 0 if not a fixed size column. */
 
80
UNIV_INLINE
 
81
ulint
 
82
dict_col_get_fixed_size(
 
83
/*====================*/
 
84
                                        /* out: fixed size, or 0 */
 
85
        const dict_col_t*       col)    /* in: column */
 
86
{
 
87
        return(dtype_get_fixed_size_low(col->mtype, col->prtype, col->len,
 
88
                                        col->mbminlen, col->mbmaxlen));
 
89
}
 
90
/***************************************************************************
 
91
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
 
92
For fixed length types it is the fixed length of the type, otherwise 0. */
 
93
UNIV_INLINE
 
94
ulint
 
95
dict_col_get_sql_null_size(
 
96
/*=======================*/
 
97
                                        /* out: SQL null storage size
 
98
                                        in ROW_FORMAT=REDUNDANT */
 
99
        const dict_col_t*       col)    /* in: column */
 
100
{
 
101
        return(dict_col_get_fixed_size(col));
 
102
}
 
103
 
 
104
/*************************************************************************
 
105
Gets the column number. */
 
106
UNIV_INLINE
 
107
ulint
 
108
dict_col_get_no(
 
109
/*============*/
 
110
        const dict_col_t*       col)
 
111
{
 
112
        ut_ad(col);
 
113
 
 
114
        return(col->ind);
 
115
}
 
116
 
 
117
/*************************************************************************
 
118
Gets the column position in the clustered index. */
 
119
UNIV_INLINE
 
120
ulint
 
121
dict_col_get_clust_pos(
 
122
/*===================*/
 
123
        const dict_col_t*       col,            /* in: table column */
 
124
        const dict_index_t*     clust_index)    /* in: clustered index */
 
125
{
 
126
        ulint   i;
 
127
 
 
128
        ut_ad(col);
 
129
        ut_ad(clust_index);
 
130
        ut_ad(dict_index_is_clust(clust_index));
 
131
 
 
132
        for (i = 0; i < clust_index->n_def; i++) {
 
133
                const dict_field_t*     field = &clust_index->fields[i];
 
134
 
 
135
                if (!field->prefix_len && field->col == col) {
 
136
                        return(i);
 
137
                }
 
138
        }
 
139
 
 
140
        return(ULINT_UNDEFINED);
 
141
}
 
142
 
 
143
#ifdef UNIV_DEBUG
 
144
/************************************************************************
 
145
Gets the first index on the table (the clustered index). */
 
146
UNIV_INLINE
 
147
dict_index_t*
 
148
dict_table_get_first_index(
 
149
/*=======================*/
 
150
                                        /* out: index, NULL if none exists */
 
151
        const dict_table_t*     table)  /* in: table */
 
152
{
 
153
        ut_ad(table);
 
154
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
155
 
 
156
        return(UT_LIST_GET_FIRST(((dict_table_t*) table)->indexes));
 
157
}
 
158
 
 
159
/************************************************************************
 
160
Gets the next index on the table. */
 
161
UNIV_INLINE
 
162
dict_index_t*
 
163
dict_table_get_next_index(
 
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));
 
220
}
 
221
 
 
222
/************************************************************************
 
223
Gets the number of user-defined columns in a table in the dictionary
 
224
cache. */
 
225
UNIV_INLINE
 
226
ulint
 
227
dict_table_get_n_user_cols(
 
228
/*=======================*/
 
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 */
 
233
{
 
234
        ut_ad(table);
 
235
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
236
 
 
237
        return(table->n_cols - DATA_N_SYS_COLS);
 
238
}
 
239
 
 
240
/************************************************************************
 
241
Gets the number of system columns in a table in the dictionary cache. */
 
242
UNIV_INLINE
 
243
ulint
 
244
dict_table_get_n_sys_cols(
 
245
/*======================*/
 
246
                                        /* out: number of system (e.g.,
 
247
                                        ROW_ID) columns of a table */
 
248
        const dict_table_t*     table __attribute__((unused)))  /* in: table */
 
249
{
 
250
        ut_ad(table);
 
251
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
252
        ut_ad(table->cached);
 
253
 
 
254
        return(DATA_N_SYS_COLS);
 
255
}
 
256
 
 
257
/************************************************************************
 
258
Gets the number of all columns (also system) in a table in the dictionary
 
259
cache. */
 
260
UNIV_INLINE
 
261
ulint
 
262
dict_table_get_n_cols(
 
263
/*==================*/
 
264
                                        /* out: number of columns of a table */
 
265
        const dict_table_t*     table)  /* in: table */
 
266
{
 
267
        ut_ad(table);
 
268
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
269
 
 
270
        return(table->n_cols);
 
271
}
 
272
 
 
273
#ifdef UNIV_DEBUG
 
274
/************************************************************************
 
275
Gets the nth column of a table. */
 
276
UNIV_INLINE
 
277
dict_col_t*
 
278
dict_table_get_nth_col(
 
279
/*===================*/
 
280
                                        /* out: pointer to column object */
 
281
        const dict_table_t*     table,  /* in: table */
 
282
        ulint                   pos)    /* in: position of column */
 
283
{
 
284
        ut_ad(table);
 
285
        ut_ad(pos < table->n_def);
 
286
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
287
 
 
288
        return((dict_col_t*) (table->cols) + pos);
 
289
}
 
290
 
 
291
/************************************************************************
 
292
Gets the given system column of a table. */
 
293
UNIV_INLINE
 
294
dict_col_t*
 
295
dict_table_get_sys_col(
 
296
/*===================*/
 
297
                                        /* out: pointer to column object */
 
298
        const dict_table_t*     table,  /* in: table */
 
299
        ulint                   sys)    /* in: DATA_ROW_ID, ... */
 
300
{
 
301
        dict_col_t*     col;
 
302
 
 
303
        ut_ad(table);
 
304
        ut_ad(sys < DATA_N_SYS_COLS);
 
305
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
306
 
 
307
        col = dict_table_get_nth_col(table, table->n_cols
 
308
                                     - DATA_N_SYS_COLS + sys);
 
309
        ut_ad(col->mtype == DATA_SYS);
 
310
        ut_ad(col->prtype == (sys | DATA_NOT_NULL));
 
311
 
 
312
        return(col);
 
313
}
 
314
#endif /* UNIV_DEBUG */
 
315
 
 
316
/************************************************************************
 
317
Gets the given system column number of a table. */
 
318
UNIV_INLINE
 
319
ulint
 
320
dict_table_get_sys_col_no(
 
321
/*======================*/
 
322
                                        /* out: column number */
 
323
        const dict_table_t*     table,  /* in: table */
 
324
        ulint                   sys)    /* in: DATA_ROW_ID, ... */
 
325
{
 
326
        ut_ad(table);
 
327
        ut_ad(sys < DATA_N_SYS_COLS);
 
328
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
 
329
 
 
330
        return(table->n_cols - DATA_N_SYS_COLS + sys);
 
331
}
 
332
 
 
333
/************************************************************************
 
334
Check whether the table uses the compact page format. */
 
335
UNIV_INLINE
 
336
ibool
 
337
dict_table_is_comp(
 
338
/*===============*/
 
339
                                        /* out: TRUE if table uses the
 
340
                                        compact page format */
 
341
        const dict_table_t*     table)  /* in: table */
 
342
{
 
343
        ut_ad(table);
 
344
 
 
345
#if DICT_TF_COMPACT != TRUE
 
346
#error
 
347
#endif
 
348
 
 
349
        return(UNIV_LIKELY(table->flags & DICT_TF_COMPACT));
 
350
}
 
351
 
 
352
/************************************************************************
 
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
Gets the number of fields in the internal representation of an index,
 
420
including fields added by the dictionary system. */
 
421
UNIV_INLINE
 
422
ulint
 
423
dict_index_get_n_fields(
 
424
/*====================*/
 
425
                                        /* out: number of fields */
 
426
        const dict_index_t*     index)  /* in: an internal
 
427
                                        representation of index (in
 
428
                                        the dictionary cache) */
 
429
{
 
430
        ut_ad(index);
 
431
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
432
 
 
433
        return(index->n_fields);
 
434
}
 
435
 
 
436
/************************************************************************
 
437
Gets the number of fields in the internal representation of an index
 
438
that uniquely determine the position of an index entry in the index, if
 
439
we do not take multiversioning into account: in the B-tree use the value
 
440
returned by dict_index_get_n_unique_in_tree. */
 
441
UNIV_INLINE
 
442
ulint
 
443
dict_index_get_n_unique(
 
444
/*====================*/
 
445
                                        /* out: number of fields */
 
446
        const dict_index_t*     index)  /* in: an internal representation
 
447
                                        of index (in the dictionary cache) */
 
448
{
 
449
        ut_ad(index);
 
450
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
451
        ut_ad(index->cached);
 
452
 
 
453
        return(index->n_uniq);
 
454
}
 
455
 
 
456
/************************************************************************
 
457
Gets the number of fields in the internal representation of an index
 
458
which uniquely determine the position of an index entry in the index, if
 
459
we also take multiversioning into account. */
 
460
UNIV_INLINE
 
461
ulint
 
462
dict_index_get_n_unique_in_tree(
 
463
/*============================*/
 
464
                                        /* out: number of fields */
 
465
        const dict_index_t*     index)  /* in: an internal representation
 
466
                                        of index (in the dictionary cache) */
 
467
{
 
468
        ut_ad(index);
 
469
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
470
        ut_ad(index->cached);
 
471
 
 
472
        if (dict_index_is_clust(index)) {
 
473
 
 
474
                return(dict_index_get_n_unique(index));
 
475
        }
 
476
 
 
477
        return(dict_index_get_n_fields(index));
 
478
}
 
479
 
 
480
/************************************************************************
 
481
Gets the number of user-defined ordering fields in the index. In the internal
 
482
representation of clustered indexes we add the row id to the ordering fields
 
483
to make a clustered index unique, but this function returns the number of
 
484
fields the user defined in the index as ordering fields. */
 
485
UNIV_INLINE
 
486
ulint
 
487
dict_index_get_n_ordering_defined_by_user(
 
488
/*======================================*/
 
489
                                        /* out: number of fields */
 
490
        const dict_index_t*     index)  /* in: an internal representation
 
491
                                        of index (in the dictionary cache) */
 
492
{
 
493
        return(index->n_user_defined_cols);
 
494
}
 
495
 
 
496
#ifdef UNIV_DEBUG
 
497
/************************************************************************
 
498
Gets the nth field of an index. */
 
499
UNIV_INLINE
 
500
dict_field_t*
 
501
dict_index_get_nth_field(
 
502
/*=====================*/
 
503
                                        /* out: pointer to field object */
 
504
        const dict_index_t*     index,  /* in: index */
 
505
        ulint                   pos)    /* in: position of field */
 
506
{
 
507
        ut_ad(index);
 
508
        ut_ad(pos < index->n_def);
 
509
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
510
 
 
511
        return((dict_field_t*) (index->fields) + pos);
 
512
}
 
513
#endif /* UNIV_DEBUG */
 
514
 
 
515
/************************************************************************
 
516
Returns the position of a system column in an index. */
 
517
UNIV_INLINE
 
518
ulint
 
519
dict_index_get_sys_col_pos(
 
520
/*=======================*/
 
521
                                        /* out: position,
 
522
                                        ULINT_UNDEFINED if not contained */
 
523
        const dict_index_t*     index,  /* in: index */
 
524
        ulint                   type)   /* in: DATA_ROW_ID, ... */
 
525
{
 
526
        ut_ad(index);
 
527
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
528
        ut_ad(!(index->type & DICT_UNIVERSAL));
 
529
 
 
530
        if (dict_index_is_clust(index)) {
 
531
 
 
532
                return(dict_col_get_clust_pos(
 
533
                               dict_table_get_sys_col(index->table, type),
 
534
                               index));
 
535
        }
 
536
 
 
537
        return(dict_index_get_nth_col_pos(
 
538
                       index, dict_table_get_sys_col_no(index->table, type)));
 
539
}
 
540
 
 
541
/*************************************************************************
 
542
Gets the field column. */
 
543
UNIV_INLINE
 
544
const dict_col_t*
 
545
dict_field_get_col(
 
546
/*===============*/
 
547
        const dict_field_t*     field)
 
548
{
 
549
        ut_ad(field);
 
550
 
 
551
        return(field->col);
 
552
}
 
553
 
 
554
/************************************************************************
 
555
Gets pointer to the nth column in an index. */
 
556
UNIV_INLINE
 
557
const dict_col_t*
 
558
dict_index_get_nth_col(
 
559
/*===================*/
 
560
                                        /* out: column */
 
561
        const dict_index_t*     index,  /* in: index */
 
562
        ulint                   pos)    /* in: position of the field */
 
563
{
 
564
        return(dict_field_get_col(dict_index_get_nth_field(index, pos)));
 
565
}
 
566
 
 
567
/************************************************************************
 
568
Gets the column number the nth field in an index. */
 
569
UNIV_INLINE
 
570
ulint
 
571
dict_index_get_nth_col_no(
 
572
/*======================*/
 
573
                                        /* out: column number */
 
574
        const dict_index_t*     index,  /* in: index */
 
575
        ulint                   pos)    /* in: position of the field */
 
576
{
 
577
        return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
 
578
}
 
579
 
 
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
/*************************************************************************
 
601
Gets the space id of the root of the index tree. */
 
602
UNIV_INLINE
 
603
ulint
 
604
dict_index_get_space(
 
605
/*=================*/
 
606
                                        /* out: space id */
 
607
        const dict_index_t*     index)  /* in: index */
 
608
{
 
609
        ut_ad(index);
 
610
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
611
 
 
612
        return(index->space);
 
613
}
 
614
 
 
615
/*************************************************************************
 
616
Sets the space id of the root of the index tree. */
 
617
UNIV_INLINE
 
618
void
 
619
dict_index_set_space(
 
620
/*=================*/
 
621
        dict_index_t*   index,  /* in/out: index */
 
622
        ulint           space)  /* in: space id */
 
623
{
 
624
        ut_ad(index);
 
625
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
626
 
 
627
        index->space = space;
 
628
}
 
629
 
 
630
/*************************************************************************
 
631
Gets the page number of the root of the index tree. */
 
632
UNIV_INLINE
 
633
ulint
 
634
dict_index_get_page(
 
635
/*================*/
 
636
                                        /* out: page number */
 
637
        const dict_index_t*     index)  /* in: index */
 
638
{
 
639
        ut_ad(index);
 
640
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
641
 
 
642
        return(index->page);
 
643
}
 
644
 
 
645
/*************************************************************************
 
646
Sets the page number of the root of index tree. */
 
647
UNIV_INLINE
 
648
void
 
649
dict_index_set_page(
 
650
/*================*/
 
651
        dict_index_t*   index,  /* in/out: index */
 
652
        ulint           page)   /* in: page number */
 
653
{
 
654
        ut_ad(index);
 
655
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
656
 
 
657
        index->page = page;
 
658
}
 
659
 
 
660
/*************************************************************************
 
661
Gets the type of the index tree. */
 
662
UNIV_INLINE
 
663
ulint
 
664
dict_index_get_type(
 
665
/*================*/
 
666
                                        /* out: type */
 
667
        const dict_index_t*     index)  /* in: index */
 
668
{
 
669
        ut_ad(index);
 
670
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
671
 
 
672
        return(index->type);
 
673
}
 
674
 
 
675
/*************************************************************************
 
676
Gets the read-write lock of the index tree. */
 
677
UNIV_INLINE
 
678
rw_lock_t*
 
679
dict_index_get_lock(
 
680
/*================*/
 
681
                                /* out: read-write lock */
 
682
        dict_index_t*   index)  /* in: index */
 
683
{
 
684
        ut_ad(index);
 
685
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
686
 
 
687
        return(&(index->lock));
 
688
}
 
689
 
 
690
/************************************************************************
 
691
Returns free space reserved for future updates of records. This is
 
692
relevant only in the case of many consecutive inserts, as updates
 
693
which make the records bigger might fragment the index. */
 
694
UNIV_INLINE
 
695
ulint
 
696
dict_index_get_space_reserve(void)
 
697
/*==============================*/
 
698
                                /* out: number of free bytes on page,
 
699
                                reserved for updates */
 
700
{
 
701
        return(UNIV_PAGE_SIZE / 16);
 
702
}
 
703
 
 
704
/**************************************************************************
 
705
Checks if a table is in the dictionary cache. */
 
706
UNIV_INLINE
 
707
dict_table_t*
 
708
dict_table_check_if_in_cache_low(
 
709
/*=============================*/
 
710
                                        /* out: table, NULL if not found */
 
711
        const char*     table_name)     /* in: table name */
 
712
{
 
713
        dict_table_t*   table;
 
714
        ulint           table_fold;
 
715
 
 
716
        ut_ad(table_name);
 
717
        ut_ad(mutex_own(&(dict_sys->mutex)));
 
718
 
 
719
        /* Look for the table name in the hash table */
 
720
        table_fold = ut_fold_string(table_name);
 
721
 
 
722
        HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold,
 
723
                    dict_table_t*, table, !strcmp(table->name, table_name));
 
724
        return(table);
 
725
}
 
726
 
 
727
/**************************************************************************
 
728
Gets a table; loads it to the dictionary cache if necessary. A low-level
 
729
function. */
 
730
UNIV_INLINE
 
731
dict_table_t*
 
732
dict_table_get_low(
 
733
/*===============*/
 
734
                                        /* out: table, NULL if not found */
 
735
        const char*     table_name)     /* in: table name */
 
736
{
 
737
        dict_table_t*   table;
 
738
 
 
739
        ut_ad(table_name);
 
740
        ut_ad(mutex_own(&(dict_sys->mutex)));
 
741
 
 
742
        table = dict_table_check_if_in_cache_low(table_name);
 
743
 
 
744
        if (table == NULL) {
 
745
                table = dict_load_table(table_name);
 
746
        }
 
747
 
 
748
        return(table);
 
749
}
 
750
 
 
751
/**************************************************************************
 
752
Returns a table object based on table id. */
 
753
UNIV_INLINE
 
754
dict_table_t*
 
755
dict_table_get_on_id_low(
 
756
/*=====================*/
 
757
                                /* out: table, NULL if does not exist */
 
758
        dulint  table_id)       /* in: table id */
 
759
{
 
760
        dict_table_t*   table;
 
761
        ulint           fold;
 
762
 
 
763
        ut_ad(mutex_own(&(dict_sys->mutex)));
 
764
 
 
765
        /* Look for the table name in the hash table */
 
766
        fold = ut_fold_dulint(table_id);
 
767
 
 
768
        HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold,
 
769
                    dict_table_t*, table, !ut_dulint_cmp(table->id, table_id));
 
770
        if (table == NULL) {
 
771
                table = dict_load_table_on_id(table_id);
 
772
        }
 
773
 
 
774
        /* TODO: should get the type information from MySQL */
 
775
 
 
776
        return(table);
 
777
}
 
778