~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Devananda
  • Date: 2009-07-04 01:55:13 UTC
  • mto: (1086.10.1 length-plugin)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: deva@myst-20090704015513-gtqliazxtfm7sdvf
refactored function/length into plugin/length

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
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
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/******************************************************************//**
20
 
@file include/dict0dict.ic
21
 
Data dictionary system
22
 
 
23
 
Created 1/8/1996 Heikki Tuuri
24
 
***********************************************************************/
25
 
 
26
 
#include "data0type.h"
27
 
#ifndef UNIV_HOTBACKUP
28
 
#include "dict0load.h"
29
 
#include "rem0types.h"
30
 
 
31
 
/*********************************************************************//**
32
 
Gets the minimum number of bytes per character.
33
 
@return minimum multi-byte char size, in bytes */
34
 
UNIV_INLINE
35
 
ulint
36
 
dict_col_get_mbminlen(
37
 
/*==================*/
38
 
        const dict_col_t*       col)    /*!< in: column */
39
 
{
40
 
        return(DATA_MBMINLEN(col->mbminmaxlen));
41
 
}
42
 
/*********************************************************************//**
43
 
Gets the maximum number of bytes per character.
44
 
@return maximum multi-byte char size, in bytes */
45
 
UNIV_INLINE
46
 
ulint
47
 
dict_col_get_mbmaxlen(
48
 
/*==================*/
49
 
        const dict_col_t*       col)    /*!< in: column */
50
 
{
51
 
        return(DATA_MBMAXLEN(col->mbminmaxlen));
52
 
}
53
 
/*********************************************************************//**
54
 
Sets the minimum and maximum number of bytes per character. */
55
 
UNIV_INLINE
56
 
void
57
 
dict_col_set_mbminmaxlen(
58
 
/*=====================*/
59
 
        dict_col_t*     col,            /*!< in/out: column */
60
 
        ulint           mbminlen,       /*!< in: minimum multi-byte
61
 
                                        character size, in bytes */
62
 
        ulint           mbmaxlen)       /*!< in: minimum multi-byte
63
 
                                        character size, in bytes */
64
 
{
65
 
        ut_ad(mbminlen < DATA_MBMAX);
66
 
        ut_ad(mbmaxlen < DATA_MBMAX);
67
 
        ut_ad(mbminlen <= mbmaxlen);
68
 
 
69
 
        col->mbminmaxlen = DATA_MBMINMAXLEN(mbminlen, mbmaxlen);
70
 
}
71
 
/*********************************************************************//**
72
 
Gets the column data type. */
73
 
UNIV_INLINE
74
 
void
75
 
dict_col_copy_type(
76
 
/*===============*/
77
 
        const dict_col_t*       col,    /*!< in: column */
78
 
        dtype_t*                type)   /*!< out: data type */
79
 
{
80
 
        ut_ad(col && type);
81
 
 
82
 
        type->mtype = col->mtype;
83
 
        type->prtype = col->prtype;
84
 
        type->len = col->len;
85
 
        type->mbminmaxlen = col->mbminmaxlen;
86
 
}
87
 
#endif /* !UNIV_HOTBACKUP */
88
 
 
89
 
#ifdef UNIV_DEBUG
90
 
/*********************************************************************//**
91
 
Assert that a column and a data type match.
92
 
@return TRUE */
93
 
UNIV_INLINE
94
 
ibool
95
 
dict_col_type_assert_equal(
96
 
/*=======================*/
97
 
        const dict_col_t*       col,    /*!< in: column */
98
 
        const dtype_t*          type)   /*!< in: data type */
99
 
{
100
 
        ut_ad(col);
101
 
        ut_ad(type);
102
 
 
103
 
        ut_ad(col->mtype == type->mtype);
104
 
        ut_ad(col->prtype == type->prtype);
105
 
        ut_ad(col->len == type->len);
106
 
# ifndef UNIV_HOTBACKUP
107
 
        ut_ad(col->mbminmaxlen == type->mbminmaxlen);
108
 
# endif /* !UNIV_HOTBACKUP */
109
 
 
110
 
        return(TRUE);
111
 
}
112
 
#endif /* UNIV_DEBUG */
113
 
 
114
 
#ifndef UNIV_HOTBACKUP
115
 
/***********************************************************************//**
116
 
Returns the minimum size of the column.
117
 
@return minimum size */
118
 
UNIV_INLINE
119
 
ulint
120
 
dict_col_get_min_size(
121
 
/*==================*/
122
 
        const dict_col_t*       col)    /*!< in: column */
123
 
{
124
 
        return(dtype_get_min_size_low(col->mtype, col->prtype, col->len,
125
 
                                      col->mbminmaxlen));
126
 
}
127
 
/***********************************************************************//**
128
 
Returns the maximum size of the column.
129
 
@return maximum size */
130
 
UNIV_INLINE
131
 
ulint
132
 
dict_col_get_max_size(
133
 
/*==================*/
134
 
        const dict_col_t*       col)    /*!< in: column */
135
 
{
136
 
        return(dtype_get_max_size_low(col->mtype, col->len));
137
 
}
138
 
#endif /* !UNIV_HOTBACKUP */
139
 
/***********************************************************************//**
140
 
Returns the size of a fixed size column, 0 if not a fixed size column.
141
 
@return fixed size, or 0 */
142
 
UNIV_INLINE
143
 
ulint
144
 
dict_col_get_fixed_size(
145
 
/*====================*/
146
 
        const dict_col_t*       col,    /*!< in: column */
147
 
        ulint                   comp)   /*!< in: nonzero=ROW_FORMAT=COMPACT  */
148
 
{
149
 
        return(dtype_get_fixed_size_low(col->mtype, col->prtype, col->len,
150
 
                                        col->mbminmaxlen, comp));
151
 
}
152
 
/***********************************************************************//**
153
 
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
154
 
For fixed length types it is the fixed length of the type, otherwise 0.
155
 
@return SQL null storage size in ROW_FORMAT=REDUNDANT */
156
 
UNIV_INLINE
157
 
ulint
158
 
dict_col_get_sql_null_size(
159
 
/*=======================*/
160
 
        const dict_col_t*       col,    /*!< in: column */
161
 
        ulint                   comp)   /*!< in: nonzero=ROW_FORMAT=COMPACT  */
162
 
{
163
 
        return(dict_col_get_fixed_size(col, comp));
164
 
}
165
 
 
166
 
/*********************************************************************//**
167
 
Gets the column number.
168
 
@return col->ind, table column position (starting from 0) */
169
 
UNIV_INLINE
170
 
ulint
171
 
dict_col_get_no(
172
 
/*============*/
173
 
        const dict_col_t*       col)    /*!< in: column */
174
 
{
175
 
        ut_ad(col);
176
 
 
177
 
        return(col->ind);
178
 
}
179
 
 
180
 
/*********************************************************************//**
181
 
Gets the column position in the clustered index. */
182
 
UNIV_INLINE
183
 
ulint
184
 
dict_col_get_clust_pos(
185
 
/*===================*/
186
 
        const dict_col_t*       col,            /*!< in: table column */
187
 
        const dict_index_t*     clust_index)    /*!< in: clustered index */
188
 
{
189
 
        ulint   i;
190
 
 
191
 
        ut_ad(col);
192
 
        ut_ad(clust_index);
193
 
        ut_ad(dict_index_is_clust(clust_index));
194
 
 
195
 
        for (i = 0; i < clust_index->n_def; i++) {
196
 
                const dict_field_t*     field = &clust_index->fields[i];
197
 
 
198
 
                if (!field->prefix_len && field->col == col) {
199
 
                        return(i);
200
 
                }
201
 
        }
202
 
 
203
 
        return(ULINT_UNDEFINED);
204
 
}
205
 
 
206
 
#ifndef UNIV_HOTBACKUP
207
 
#ifdef UNIV_DEBUG
208
 
/********************************************************************//**
209
 
Gets the first index on the table (the clustered index).
210
 
@return index, NULL if none exists */
211
 
UNIV_INLINE
212
 
dict_index_t*
213
 
dict_table_get_first_index(
214
 
/*=======================*/
215
 
        const dict_table_t*     table)  /*!< in: table */
216
 
{
217
 
        ut_ad(table);
218
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
219
 
 
220
 
        return(UT_LIST_GET_FIRST(((dict_table_t*) table)->indexes));
221
 
}
222
 
 
223
 
/********************************************************************//**
224
 
Gets the next index on the table.
225
 
@return index, NULL if none left */
226
 
UNIV_INLINE
227
 
dict_index_t*
228
 
dict_table_get_next_index(
229
 
/*======================*/
230
 
        const dict_index_t*     index)  /*!< in: index */
231
 
{
232
 
        ut_ad(index);
233
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
234
 
 
235
 
        return(UT_LIST_GET_NEXT(indexes, (dict_index_t*) index));
236
 
}
237
 
#endif /* UNIV_DEBUG */
238
 
#endif /* !UNIV_HOTBACKUP */
239
 
 
240
 
/********************************************************************//**
241
 
Check whether the index is the clustered index.
242
 
@return nonzero for clustered index, zero for other indexes */
243
 
UNIV_INLINE
244
 
ulint
245
 
dict_index_is_clust(
246
 
/*================*/
247
 
        const dict_index_t*     index)  /*!< in: index */
248
 
{
249
 
        ut_ad(index);
250
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
251
 
 
252
 
        return(UNIV_UNLIKELY(index->type & DICT_CLUSTERED));
253
 
}
254
 
/********************************************************************//**
255
 
Check whether the index is unique.
256
 
@return nonzero for unique index, zero for other indexes */
257
 
UNIV_INLINE
258
 
ulint
259
 
dict_index_is_unique(
260
 
/*=================*/
261
 
        const dict_index_t*     index)  /*!< in: index */
262
 
{
263
 
        ut_ad(index);
264
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
265
 
 
266
 
        return(UNIV_UNLIKELY(index->type & DICT_UNIQUE));
267
 
}
268
 
 
269
 
/********************************************************************//**
270
 
Check whether the index is the insert buffer tree.
271
 
@return nonzero for insert buffer, zero for other indexes */
272
 
UNIV_INLINE
273
 
ulint
274
 
dict_index_is_ibuf(
275
 
/*===============*/
276
 
        const dict_index_t*     index)  /*!< in: index */
277
 
{
278
 
        ut_ad(index);
279
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
280
 
 
281
 
        return(UNIV_UNLIKELY(index->type & DICT_IBUF));
282
 
}
283
 
 
284
 
/********************************************************************//**
285
 
Check whether the index is a secondary index or the insert buffer tree.
286
 
@return nonzero for insert buffer, zero for other indexes */
287
 
UNIV_INLINE
288
 
ulint
289
 
dict_index_is_sec_or_ibuf(
290
 
/*======================*/
291
 
        const dict_index_t*     index)  /*!< in: index */
292
 
{
293
 
        ulint   type;
294
 
 
295
 
        ut_ad(index);
296
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
297
 
 
298
 
        type = index->type;
299
 
 
300
 
        return(UNIV_LIKELY(!(type & DICT_CLUSTERED) || (type & DICT_IBUF)));
301
 
}
302
 
 
303
 
/********************************************************************//**
304
 
Gets the number of user-defined columns in a table in the dictionary
305
 
cache.
306
 
@return number of user-defined (e.g., not ROW_ID) columns of a table */
307
 
UNIV_INLINE
308
 
ulint
309
 
dict_table_get_n_user_cols(
310
 
/*=======================*/
311
 
        const dict_table_t*     table)  /*!< in: table */
312
 
{
313
 
        ut_ad(table);
314
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
315
 
 
316
 
        return(table->n_cols - DATA_N_SYS_COLS);
317
 
}
318
 
 
319
 
/********************************************************************//**
320
 
Gets the number of system columns in a table in the dictionary cache.
321
 
@return number of system (e.g., ROW_ID) columns of a table */
322
 
UNIV_INLINE
323
 
ulint
324
 
dict_table_get_n_sys_cols(
325
 
/*======================*/
326
 
        const dict_table_t*     table __attribute__((unused)))  /*!< in: table */
327
 
{
328
 
        (void)table;
329
 
        ut_ad(table);
330
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
331
 
        ut_ad(table->cached);
332
 
 
333
 
        return(DATA_N_SYS_COLS);
334
 
}
335
 
 
336
 
/********************************************************************//**
337
 
Gets the number of all columns (also system) in a table in the dictionary
338
 
cache.
339
 
@return number of columns of a table */
340
 
UNIV_INLINE
341
 
ulint
342
 
dict_table_get_n_cols(
343
 
/*==================*/
344
 
        const dict_table_t*     table)  /*!< in: table */
345
 
{
346
 
        ut_ad(table);
347
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
348
 
 
349
 
        return(table->n_cols);
350
 
}
351
 
 
352
 
#ifdef UNIV_DEBUG
353
 
/********************************************************************//**
354
 
Gets the nth column of a table.
355
 
@return pointer to column object */
356
 
UNIV_INLINE
357
 
dict_col_t*
358
 
dict_table_get_nth_col(
359
 
/*===================*/
360
 
        const dict_table_t*     table,  /*!< in: table */
361
 
        ulint                   pos)    /*!< in: position of column */
362
 
{
363
 
        ut_ad(table);
364
 
        ut_ad(pos < table->n_def);
365
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
366
 
 
367
 
        return((dict_col_t*) (table->cols) + pos);
368
 
}
369
 
 
370
 
/********************************************************************//**
371
 
Gets the given system column of a table.
372
 
@return pointer to column object */
373
 
UNIV_INLINE
374
 
dict_col_t*
375
 
dict_table_get_sys_col(
376
 
/*===================*/
377
 
        const dict_table_t*     table,  /*!< in: table */
378
 
        ulint                   sys)    /*!< in: DATA_ROW_ID, ... */
379
 
{
380
 
        dict_col_t*     col;
381
 
 
382
 
        ut_ad(table);
383
 
        ut_ad(sys < DATA_N_SYS_COLS);
384
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
385
 
 
386
 
        col = dict_table_get_nth_col(table, table->n_cols
387
 
                                     - DATA_N_SYS_COLS + sys);
388
 
        ut_ad(col->mtype == DATA_SYS);
389
 
        ut_ad(col->prtype == (sys | DATA_NOT_NULL));
390
 
 
391
 
        return(col);
392
 
}
393
 
#endif /* UNIV_DEBUG */
394
 
 
395
 
/********************************************************************//**
396
 
Gets the given system column number of a table.
397
 
@return column number */
398
 
UNIV_INLINE
399
 
ulint
400
 
dict_table_get_sys_col_no(
401
 
/*======================*/
402
 
        const dict_table_t*     table,  /*!< in: table */
403
 
        ulint                   sys)    /*!< in: DATA_ROW_ID, ... */
404
 
{
405
 
        ut_ad(table);
406
 
        ut_ad(sys < DATA_N_SYS_COLS);
407
 
        ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
408
 
 
409
 
        return(table->n_cols - DATA_N_SYS_COLS + sys);
410
 
}
411
 
 
412
 
/********************************************************************//**
413
 
Check whether the table uses the compact page format.
414
 
@return TRUE if table uses the compact page format */
415
 
UNIV_INLINE
416
 
ibool
417
 
dict_table_is_comp(
418
 
/*===============*/
419
 
        const dict_table_t*     table)  /*!< in: table */
420
 
{
421
 
        ut_ad(table);
422
 
 
423
 
#if DICT_TF_COMPACT != TRUE
424
 
#error
425
 
#endif
426
 
 
427
 
        return(UNIV_LIKELY(table->flags & DICT_TF_COMPACT));
428
 
}
429
 
 
430
 
/********************************************************************//**
431
 
Determine the file format of a table.
432
 
@return file format version */
433
 
UNIV_INLINE
434
 
ulint
435
 
dict_table_get_format(
436
 
/*==================*/
437
 
        const dict_table_t*     table)  /*!< in: table */
438
 
{
439
 
        ut_ad(table);
440
 
 
441
 
        return((table->flags & DICT_TF_FORMAT_MASK) >> DICT_TF_FORMAT_SHIFT);
442
 
}
443
 
 
444
 
/********************************************************************//**
445
 
Determine the file format of a table. */
446
 
UNIV_INLINE
447
 
void
448
 
dict_table_set_format(
449
 
/*==================*/
450
 
        dict_table_t*   table,  /*!< in/out: table */
451
 
        ulint           format) /*!< in: file format version */
452
 
{
453
 
        ut_ad(table);
454
 
 
455
 
        table->flags = (table->flags & ~DICT_TF_FORMAT_MASK)
456
 
                | (format << DICT_TF_FORMAT_SHIFT);
457
 
}
458
 
 
459
 
/********************************************************************//**
460
 
Extract the compressed page size from table flags.
461
 
@return compressed page size, or 0 if not compressed */
462
 
UNIV_INLINE
463
 
ulint
464
 
dict_table_flags_to_zip_size(
465
 
/*=========================*/
466
 
        ulint   flags)  /*!< in: flags */
467
 
{
468
 
        ulint   zip_size = flags & DICT_TF_ZSSIZE_MASK;
469
 
 
470
 
        if (UNIV_UNLIKELY(zip_size)) {
471
 
                zip_size = ((PAGE_ZIP_MIN_SIZE >> 1)
472
 
                         << (zip_size >> DICT_TF_ZSSIZE_SHIFT));
473
 
 
474
 
                ut_ad(zip_size <= UNIV_PAGE_SIZE);
475
 
        }
476
 
 
477
 
        return(zip_size);
478
 
}
479
 
 
480
 
/********************************************************************//**
481
 
Check whether the table uses the compressed compact page format.
482
 
@return compressed page size, or 0 if not compressed */
483
 
UNIV_INLINE
484
 
ulint
485
 
dict_table_zip_size(
486
 
/*================*/
487
 
        const dict_table_t*     table)  /*!< in: table */
488
 
{
489
 
        ut_ad(table);
490
 
 
491
 
        return(dict_table_flags_to_zip_size(table->flags));
492
 
}
493
 
 
494
 
/*********************************************************************//**
495
 
Obtain exclusive locks on all index trees of the table. This is to prevent
496
 
accessing index trees while InnoDB is updating internal metadata for
497
 
operations such as truncate tables. */
498
 
UNIV_INLINE
499
 
void
500
 
dict_table_x_lock_indexes(
501
 
/*======================*/
502
 
        dict_table_t*   table)  /*!< in: table */
503
 
{
504
 
        dict_index_t*   index;
505
 
 
506
 
        ut_a(table);
507
 
        ut_ad(mutex_own(&(dict_sys->mutex)));
508
 
 
509
 
        /* Loop through each index of the table and lock them */
510
 
        for (index = dict_table_get_first_index(table);
511
 
             index != NULL;
512
 
             index = dict_table_get_next_index(index)) {
513
 
                rw_lock_x_lock(dict_index_get_lock(index));
514
 
        }
515
 
}
516
 
 
517
 
/*********************************************************************//**
518
 
Release the exclusive locks on all index tree. */
519
 
UNIV_INLINE
520
 
void
521
 
dict_table_x_unlock_indexes(
522
 
/*========================*/
523
 
        dict_table_t*   table)  /*!< in: table */
524
 
{
525
 
        dict_index_t*   index;
526
 
 
527
 
        ut_a(table);
528
 
        ut_ad(mutex_own(&(dict_sys->mutex)));
529
 
 
530
 
        for (index = dict_table_get_first_index(table);
531
 
             index != NULL;
532
 
             index = dict_table_get_next_index(index)) {
533
 
                rw_lock_x_unlock(dict_index_get_lock(index));
534
 
        }
535
 
}
536
 
/********************************************************************//**
537
 
Gets the number of fields in the internal representation of an index,
538
 
including fields added by the dictionary system.
539
 
@return number of fields */
540
 
UNIV_INLINE
541
 
ulint
542
 
dict_index_get_n_fields(
543
 
/*====================*/
544
 
        const dict_index_t*     index)  /*!< in: an internal
545
 
                                        representation of index (in
546
 
                                        the dictionary cache) */
547
 
{
548
 
        ut_ad(index);
549
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
550
 
 
551
 
        return(index->n_fields);
552
 
}
553
 
 
554
 
/********************************************************************//**
555
 
Gets the number of fields in the internal representation of an index
556
 
that uniquely determine the position of an index entry in the index, if
557
 
we do not take multiversioning into account: in the B-tree use the value
558
 
returned by dict_index_get_n_unique_in_tree.
559
 
@return number of fields */
560
 
UNIV_INLINE
561
 
ulint
562
 
dict_index_get_n_unique(
563
 
/*====================*/
564
 
        const dict_index_t*     index)  /*!< in: an internal representation
565
 
                                        of index (in the dictionary cache) */
566
 
{
567
 
        ut_ad(index);
568
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
569
 
        ut_ad(index->cached);
570
 
 
571
 
        return(index->n_uniq);
572
 
}
573
 
 
574
 
/********************************************************************//**
575
 
Gets the number of fields in the internal representation of an index
576
 
which uniquely determine the position of an index entry in the index, if
577
 
we also take multiversioning into account.
578
 
@return number of fields */
579
 
UNIV_INLINE
580
 
ulint
581
 
dict_index_get_n_unique_in_tree(
582
 
/*============================*/
583
 
        const dict_index_t*     index)  /*!< in: an internal representation
584
 
                                        of index (in the dictionary cache) */
585
 
{
586
 
        ut_ad(index);
587
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
588
 
        ut_ad(index->cached);
589
 
 
590
 
        if (dict_index_is_clust(index)) {
591
 
 
592
 
                return(dict_index_get_n_unique(index));
593
 
        }
594
 
 
595
 
        return(dict_index_get_n_fields(index));
596
 
}
597
 
 
598
 
/********************************************************************//**
599
 
Gets the number of user-defined ordering fields in the index. In the internal
600
 
representation of clustered indexes we add the row id to the ordering fields
601
 
to make a clustered index unique, but this function returns the number of
602
 
fields the user defined in the index as ordering fields.
603
 
@return number of fields */
604
 
UNIV_INLINE
605
 
ulint
606
 
dict_index_get_n_ordering_defined_by_user(
607
 
/*======================================*/
608
 
        const dict_index_t*     index)  /*!< in: an internal representation
609
 
                                        of index (in the dictionary cache) */
610
 
{
611
 
        return(index->n_user_defined_cols);
612
 
}
613
 
 
614
 
#ifdef UNIV_DEBUG
615
 
/********************************************************************//**
616
 
Gets the nth field of an index.
617
 
@return pointer to field object */
618
 
UNIV_INLINE
619
 
dict_field_t*
620
 
dict_index_get_nth_field(
621
 
/*=====================*/
622
 
        const dict_index_t*     index,  /*!< in: index */
623
 
        ulint                   pos)    /*!< in: position of field */
624
 
{
625
 
        ut_ad(index);
626
 
        ut_ad(pos < index->n_def);
627
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
628
 
 
629
 
        return((dict_field_t*) (index->fields) + pos);
630
 
}
631
 
#endif /* UNIV_DEBUG */
632
 
 
633
 
/********************************************************************//**
634
 
Returns the position of a system column in an index.
635
 
@return position, ULINT_UNDEFINED if not contained */
636
 
UNIV_INLINE
637
 
ulint
638
 
dict_index_get_sys_col_pos(
639
 
/*=======================*/
640
 
        const dict_index_t*     index,  /*!< in: index */
641
 
        ulint                   type)   /*!< in: DATA_ROW_ID, ... */
642
 
{
643
 
        ut_ad(index);
644
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
645
 
        ut_ad(!(index->type & DICT_UNIVERSAL));
646
 
 
647
 
        if (dict_index_is_clust(index)) {
648
 
 
649
 
                return(dict_col_get_clust_pos(
650
 
                               dict_table_get_sys_col(index->table, type),
651
 
                               index));
652
 
        }
653
 
 
654
 
        return(dict_index_get_nth_col_pos(
655
 
                       index, dict_table_get_sys_col_no(index->table, type)));
656
 
}
657
 
 
658
 
/*********************************************************************//**
659
 
Gets the field column.
660
 
@return field->col, pointer to the table column */
661
 
UNIV_INLINE
662
 
const dict_col_t*
663
 
dict_field_get_col(
664
 
/*===============*/
665
 
        const dict_field_t*     field)  /*!< in: index field */
666
 
{
667
 
        ut_ad(field);
668
 
 
669
 
        return(field->col);
670
 
}
671
 
 
672
 
/********************************************************************//**
673
 
Gets pointer to the nth column in an index.
674
 
@return column */
675
 
UNIV_INLINE
676
 
const dict_col_t*
677
 
dict_index_get_nth_col(
678
 
/*===================*/
679
 
        const dict_index_t*     index,  /*!< in: index */
680
 
        ulint                   pos)    /*!< in: position of the field */
681
 
{
682
 
        return(dict_field_get_col(dict_index_get_nth_field(index, pos)));
683
 
}
684
 
 
685
 
/********************************************************************//**
686
 
Gets the column number the nth field in an index.
687
 
@return column number */
688
 
UNIV_INLINE
689
 
ulint
690
 
dict_index_get_nth_col_no(
691
 
/*======================*/
692
 
        const dict_index_t*     index,  /*!< in: index */
693
 
        ulint                   pos)    /*!< in: position of the field */
694
 
{
695
 
        return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
696
 
}
697
 
 
698
 
#ifndef UNIV_HOTBACKUP
699
 
/********************************************************************//**
700
 
Returns the minimum data size of an index record.
701
 
@return minimum data size in bytes */
702
 
UNIV_INLINE
703
 
ulint
704
 
dict_index_get_min_size(
705
 
/*====================*/
706
 
        const dict_index_t*     index)  /*!< in: index */
707
 
{
708
 
        ulint   n       = dict_index_get_n_fields(index);
709
 
        ulint   size    = 0;
710
 
 
711
 
        while (n--) {
712
 
                size += dict_col_get_min_size(dict_index_get_nth_col(index,
713
 
                                                                     n));
714
 
        }
715
 
 
716
 
        return(size);
717
 
}
718
 
 
719
 
/*********************************************************************//**
720
 
Gets the space id of the root of the index tree.
721
 
@return space id */
722
 
UNIV_INLINE
723
 
ulint
724
 
dict_index_get_space(
725
 
/*=================*/
726
 
        const dict_index_t*     index)  /*!< in: index */
727
 
{
728
 
        ut_ad(index);
729
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
730
 
 
731
 
        return(index->space);
732
 
}
733
 
 
734
 
/*********************************************************************//**
735
 
Sets the space id of the root of the index tree. */
736
 
UNIV_INLINE
737
 
void
738
 
dict_index_set_space(
739
 
/*=================*/
740
 
        dict_index_t*   index,  /*!< in/out: index */
741
 
        ulint           space)  /*!< in: space id */
742
 
{
743
 
        ut_ad(index);
744
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
745
 
 
746
 
        index->space = space;
747
 
}
748
 
 
749
 
/*********************************************************************//**
750
 
Gets the page number of the root of the index tree.
751
 
@return page number */
752
 
UNIV_INLINE
753
 
ulint
754
 
dict_index_get_page(
755
 
/*================*/
756
 
        const dict_index_t*     index)  /*!< in: index */
757
 
{
758
 
        ut_ad(index);
759
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
760
 
 
761
 
        return(index->page);
762
 
}
763
 
 
764
 
/*********************************************************************//**
765
 
Sets the page number of the root of index tree. */
766
 
UNIV_INLINE
767
 
void
768
 
dict_index_set_page(
769
 
/*================*/
770
 
        dict_index_t*   index,  /*!< in/out: index */
771
 
        ulint           page)   /*!< in: page number */
772
 
{
773
 
        ut_ad(index);
774
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
775
 
 
776
 
        index->page = page;
777
 
}
778
 
 
779
 
/*********************************************************************//**
780
 
Gets the read-write lock of the index tree.
781
 
@return read-write lock */
782
 
UNIV_INLINE
783
 
rw_lock_t*
784
 
dict_index_get_lock(
785
 
/*================*/
786
 
        dict_index_t*   index)  /*!< in: index */
787
 
{
788
 
        ut_ad(index);
789
 
        ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
790
 
 
791
 
        return(&(index->lock));
792
 
}
793
 
 
794
 
/********************************************************************//**
795
 
Returns free space reserved for future updates of records. This is
796
 
relevant only in the case of many consecutive inserts, as updates
797
 
which make the records bigger might fragment the index.
798
 
@return number of free bytes on page, reserved for updates */
799
 
UNIV_INLINE
800
 
ulint
801
 
dict_index_get_space_reserve(void)
802
 
/*==============================*/
803
 
{
804
 
        return(UNIV_PAGE_SIZE / 16);
805
 
}
806
 
 
807
 
/**********************************************************************//**
808
 
Checks if a table is in the dictionary cache.
809
 
@return table, NULL if not found */
810
 
UNIV_INLINE
811
 
dict_table_t*
812
 
dict_table_check_if_in_cache_low(
813
 
/*=============================*/
814
 
        const char*     table_name)     /*!< in: table name */
815
 
{
816
 
        dict_table_t*   table;
817
 
        ulint           table_fold;
818
 
 
819
 
        ut_ad(table_name);
820
 
        ut_ad(mutex_own(&(dict_sys->mutex)));
821
 
 
822
 
        /* Look for the table name in the hash table */
823
 
        table_fold = ut_fold_string(table_name);
824
 
 
825
 
        HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold,
826
 
                    dict_table_t*, table, ut_ad(table->cached),
827
 
                    !strcmp(table->name, table_name));
828
 
        return(table);
829
 
}
830
 
 
831
 
/**********************************************************************//**
832
 
Gets a table; loads it to the dictionary cache if necessary. A low-level
833
 
function.
834
 
@return table, NULL if not found */
835
 
UNIV_INLINE
836
 
dict_table_t*
837
 
dict_table_get_low(
838
 
/*===============*/
839
 
        const char*     table_name)     /*!< in: table name */
840
 
{
841
 
        dict_table_t*   table;
842
 
 
843
 
        ut_ad(table_name);
844
 
        ut_ad(mutex_own(&(dict_sys->mutex)));
845
 
 
846
 
        table = dict_table_check_if_in_cache_low(table_name);
847
 
 
848
 
        if (table == NULL) {
849
 
                table = dict_load_table(table_name, TRUE);
850
 
        }
851
 
 
852
 
        ut_ad(!table || table->cached);
853
 
 
854
 
        return(table);
855
 
}
856
 
 
857
 
/**********************************************************************//**
858
 
Returns a table object based on table id.
859
 
@return table, NULL if does not exist */
860
 
UNIV_INLINE
861
 
dict_table_t*
862
 
dict_table_get_on_id_low(
863
 
/*=====================*/
864
 
        table_id_t      table_id)       /*!< in: table id */
865
 
{
866
 
        dict_table_t*   table;
867
 
        ulint           fold;
868
 
 
869
 
        ut_ad(mutex_own(&(dict_sys->mutex)));
870
 
 
871
 
        /* Look for the table name in the hash table */
872
 
        fold = ut_fold_ull(table_id);
873
 
 
874
 
        HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold,
875
 
                    dict_table_t*, table, ut_ad(table->cached),
876
 
                    table->id == table_id);
877
 
        if (table == NULL) {
878
 
                table = dict_load_table_on_id(table_id);
879
 
        }
880
 
 
881
 
        ut_ad(!table || table->cached);
882
 
 
883
 
        /* TODO: should get the type information from MySQL */
884
 
 
885
 
        return(table);
886
 
}
887
 
#endif /* !UNIV_HOTBACKUP */