17
17
*****************************************************************************/
19
/**********************************************************************
19
/******************************************************************//**
20
@file include/dict0dict.ic
20
21
Data dictionary system
22
23
Created 1/8/1996 Heikki Tuuri
23
24
***********************************************************************/
26
#include "data0type.h"
27
#ifndef UNIV_HOTBACKUP
25
28
#include "dict0load.h"
26
29
#include "rem0types.h"
27
#include "data0type.h"
29
/*************************************************************************
31
/*********************************************************************//**
30
32
Gets the column data type. */
33
35
dict_col_copy_type(
34
36
/*===============*/
35
const dict_col_t* col, /* in: column */
36
dtype_t* type) /* out: data type */
37
const dict_col_t* col, /*!< in: column */
38
dtype_t* type) /*!< out: data type */
38
40
ut_ad(col && type);
43
45
type->mbminlen = col->mbminlen;
44
46
type->mbmaxlen = col->mbmaxlen;
48
#endif /* !UNIV_HOTBACKUP */
48
/*************************************************************************
49
Assert that a column and a data type match. */
51
/*********************************************************************//**
52
Assert that a column and a data type match.
52
56
dict_col_type_assert_equal(
53
57
/*=======================*/
55
const dict_col_t* col, /* in: column */
56
const dtype_t* type) /* in: data type */
58
const dict_col_t* col, /*!< in: column */
59
const dtype_t* type) /*!< in: data type */
61
64
ut_ad(col->mtype == type->mtype);
62
65
ut_ad(col->prtype == type->prtype);
63
66
ut_ad(col->len == type->len);
67
# ifndef UNIV_HOTBACKUP
64
68
ut_ad(col->mbminlen == type->mbminlen);
65
69
ut_ad(col->mbmaxlen == type->mbmaxlen);
70
# endif /* !UNIV_HOTBACKUP */
69
74
#endif /* UNIV_DEBUG */
71
/***************************************************************************
72
Returns the minimum size of the column. */
76
#ifndef UNIV_HOTBACKUP
77
/***********************************************************************//**
78
Returns the minimum size of the column.
79
@return minimum size */
75
82
dict_col_get_min_size(
76
83
/*==================*/
77
/* out: minimum size */
78
const dict_col_t* col) /* in: column */
84
const dict_col_t* col) /*!< in: column */
80
86
return(dtype_get_min_size_low(col->mtype, col->prtype, col->len,
81
87
col->mbminlen, col->mbmaxlen));
83
/***************************************************************************
84
Returns the maximum size of the column. */
89
/***********************************************************************//**
90
Returns the maximum size of the column.
91
@return maximum size */
87
94
dict_col_get_max_size(
88
95
/*==================*/
89
/* out: maximum size */
90
const dict_col_t* col) /* in: column */
96
const dict_col_t* col) /*!< in: column */
92
98
return(dtype_get_max_size_low(col->mtype, col->len));
94
/***************************************************************************
95
Returns the size of a fixed size column, 0 if not a fixed size column. */
100
#endif /* !UNIV_HOTBACKUP */
101
/***********************************************************************//**
102
Returns the size of a fixed size column, 0 if not a fixed size column.
103
@return fixed size, or 0 */
98
106
dict_col_get_fixed_size(
99
107
/*====================*/
100
/* out: fixed size, or 0 */
101
const dict_col_t* col) /* in: column */
108
const dict_col_t* col, /*!< in: column */
109
ulint comp) /*!< in: nonzero=ROW_FORMAT=COMPACT */
103
111
return(dtype_get_fixed_size_low(col->mtype, col->prtype, col->len,
104
col->mbminlen, col->mbmaxlen));
112
col->mbminlen, col->mbmaxlen, comp));
106
/***************************************************************************
114
/***********************************************************************//**
107
115
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
108
For fixed length types it is the fixed length of the type, otherwise 0. */
116
For fixed length types it is the fixed length of the type, otherwise 0.
117
@return SQL null storage size in ROW_FORMAT=REDUNDANT */
111
120
dict_col_get_sql_null_size(
112
121
/*=======================*/
113
/* out: SQL null storage size
114
in ROW_FORMAT=REDUNDANT */
115
const dict_col_t* col) /* in: column */
122
const dict_col_t* col, /*!< in: column */
123
ulint comp) /*!< in: nonzero=ROW_FORMAT=COMPACT */
117
return(dict_col_get_fixed_size(col));
125
return(dict_col_get_fixed_size(col, comp));
120
/*************************************************************************
121
Gets the column number. */
128
/*********************************************************************//**
129
Gets the column number.
130
@return col->ind, table column position (starting from 0) */
126
const dict_col_t* col)
135
const dict_col_t* col) /*!< in: column */
130
139
return(col->ind);
133
/*************************************************************************
142
/*********************************************************************//**
134
143
Gets the column position in the clustered index. */
137
146
dict_col_get_clust_pos(
138
147
/*===================*/
139
const dict_col_t* col, /* in: table column */
140
const dict_index_t* clust_index) /* in: clustered index */
148
const dict_col_t* col, /*!< in: table column */
149
const dict_index_t* clust_index) /*!< in: clustered index */
156
165
return(ULINT_UNDEFINED);
168
#ifndef UNIV_HOTBACKUP
159
169
#ifdef UNIV_DEBUG
160
/************************************************************************
161
Gets the first index on the table (the clustered index). */
170
/********************************************************************//**
171
Gets the first index on the table (the clustered index).
172
@return index, NULL if none exists */
164
175
dict_table_get_first_index(
165
176
/*=======================*/
166
/* out: index, NULL if none exists */
167
const dict_table_t* table) /* in: table */
177
const dict_table_t* table) /*!< in: table */
170
180
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
172
182
return(UT_LIST_GET_FIRST(((dict_table_t*) table)->indexes));
175
/************************************************************************
176
Gets the next index on the table. */
185
/********************************************************************//**
186
Gets the next index on the table.
187
@return index, NULL if none left */
179
190
dict_table_get_next_index(
180
191
/*======================*/
181
/* out: index, NULL if none left */
182
const dict_index_t* index) /* in: index */
192
const dict_index_t* index) /*!< in: index */
185
195
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
187
197
return(UT_LIST_GET_NEXT(indexes, (dict_index_t*) index));
189
199
#endif /* UNIV_DEBUG */
200
#endif /* !UNIV_HOTBACKUP */
191
/************************************************************************
192
Check whether the index is the clustered index. */
202
/********************************************************************//**
203
Check whether the index is the clustered index.
204
@return nonzero for clustered index, zero for other indexes */
195
207
dict_index_is_clust(
196
208
/*================*/
197
/* out: nonzero for clustered index,
198
zero for other indexes */
199
const dict_index_t* index) /* in: index */
209
const dict_index_t* index) /*!< in: index */
202
212
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
204
214
return(UNIV_UNLIKELY(index->type & DICT_CLUSTERED));
206
/************************************************************************
207
Check whether the index is unique. */
216
/********************************************************************//**
217
Check whether the index is unique.
218
@return nonzero for unique index, zero for other indexes */
210
221
dict_index_is_unique(
211
222
/*=================*/
212
/* out: nonzero for unique index,
213
zero for other indexes */
214
const dict_index_t* index) /* in: index */
223
const dict_index_t* index) /*!< in: index */
217
226
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
219
228
return(UNIV_UNLIKELY(index->type & DICT_UNIQUE));
222
/************************************************************************
223
Check whether the index is the insert buffer tree. */
231
/********************************************************************//**
232
Check whether the index is the insert buffer tree.
233
@return nonzero for insert buffer, zero for other indexes */
226
236
dict_index_is_ibuf(
227
237
/*===============*/
228
/* out: nonzero for insert buffer,
229
zero for other indexes */
230
const dict_index_t* index) /* in: index */
238
const dict_index_t* index) /*!< in: index */
233
241
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
235
243
return(UNIV_UNLIKELY(index->type & DICT_IBUF));
238
/************************************************************************
246
/********************************************************************//**
247
Check whether the index is a secondary index or the insert buffer tree.
248
@return nonzero for insert buffer, zero for other indexes */
251
dict_index_is_sec_or_ibuf(
252
/*======================*/
253
const dict_index_t* index) /*!< in: index */
258
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
262
return(UNIV_LIKELY(!(type & DICT_CLUSTERED) || (type & DICT_IBUF)));
265
/********************************************************************//**
239
266
Gets the number of user-defined columns in a table in the dictionary
268
@return number of user-defined (e.g., not ROW_ID) columns of a table */
243
271
dict_table_get_n_user_cols(
244
272
/*=======================*/
245
/* out: number of user-defined
247
columns of a table */
248
const dict_table_t* table) /* in: table */
273
const dict_table_t* table) /*!< in: table */
251
276
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
253
278
return(table->n_cols - DATA_N_SYS_COLS);
256
/************************************************************************
257
Gets the number of system columns in a table in the dictionary cache. */
281
/********************************************************************//**
282
Gets the number of system columns in a table in the dictionary cache.
283
@return number of system (e.g., ROW_ID) columns of a table */
260
286
dict_table_get_n_sys_cols(
261
287
/*======================*/
262
/* out: number of system (e.g.,
263
ROW_ID) columns of a table */
264
const dict_table_t* table __attribute__((unused))) /* in: table */
288
const dict_table_t* table __attribute__((unused))) /*!< in: table */
267
291
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
289
313
#ifdef UNIV_DEBUG
290
/************************************************************************
291
Gets the nth column of a table. */
314
/********************************************************************//**
315
Gets the nth column of a table.
316
@return pointer to column object */
294
319
dict_table_get_nth_col(
295
320
/*===================*/
296
/* out: pointer to column object */
297
const dict_table_t* table, /* in: table */
298
ulint pos) /* in: position of column */
321
const dict_table_t* table, /*!< in: table */
322
ulint pos) /*!< in: position of column */
301
325
ut_ad(pos < table->n_def);
304
328
return((dict_col_t*) (table->cols) + pos);
307
/************************************************************************
308
Gets the given system column of a table. */
331
/********************************************************************//**
332
Gets the given system column of a table.
333
@return pointer to column object */
311
336
dict_table_get_sys_col(
312
337
/*===================*/
313
/* out: pointer to column object */
314
const dict_table_t* table, /* in: table */
315
ulint sys) /* in: DATA_ROW_ID, ... */
338
const dict_table_t* table, /*!< in: table */
339
ulint sys) /*!< in: DATA_ROW_ID, ... */
330
354
#endif /* UNIV_DEBUG */
332
/************************************************************************
333
Gets the given system column number of a table. */
356
/********************************************************************//**
357
Gets the given system column number of a table.
358
@return column number */
336
361
dict_table_get_sys_col_no(
337
362
/*======================*/
338
/* out: column number */
339
const dict_table_t* table, /* in: table */
340
ulint sys) /* in: DATA_ROW_ID, ... */
363
const dict_table_t* table, /*!< in: table */
364
ulint sys) /*!< in: DATA_ROW_ID, ... */
343
367
ut_ad(sys < DATA_N_SYS_COLS);
365
388
return(UNIV_LIKELY(table->flags & DICT_TF_COMPACT));
368
/************************************************************************
369
Determine the file format of a table. */
391
/********************************************************************//**
392
Determine the file format of a table.
393
@return file format version */
372
396
dict_table_get_format(
373
397
/*==================*/
374
/* out: file format version */
375
const dict_table_t* table) /* in: table */
398
const dict_table_t* table) /*!< in: table */
379
402
return((table->flags & DICT_TF_FORMAT_MASK) >> DICT_TF_FORMAT_SHIFT);
382
/************************************************************************
405
/********************************************************************//**
383
406
Determine the file format of a table. */
386
409
dict_table_set_format(
387
410
/*==================*/
388
dict_table_t* table, /* in/out: table */
389
ulint format) /* in: file format version */
411
dict_table_t* table, /*!< in/out: table */
412
ulint format) /*!< in: file format version */
394
417
| (format << DICT_TF_FORMAT_SHIFT);
397
/************************************************************************
398
Extract the compressed page size from table flags. */
420
/********************************************************************//**
421
Extract the compressed page size from table flags.
422
@return compressed page size, or 0 if not compressed */
401
425
dict_table_flags_to_zip_size(
402
426
/*=========================*/
403
/* out: compressed page size,
404
or 0 if not compressed */
405
ulint flags) /* in: flags */
427
ulint flags) /*!< in: flags */
407
429
ulint zip_size = flags & DICT_TF_ZSSIZE_MASK;
416
438
return(zip_size);
419
/************************************************************************
420
Check whether the table uses the compressed compact page format. */
441
/********************************************************************//**
442
Check whether the table uses the compressed compact page format.
443
@return compressed page size, or 0 if not compressed */
423
446
dict_table_zip_size(
424
447
/*================*/
425
/* out: compressed page size,
426
or 0 if not compressed */
427
const dict_table_t* table) /* in: table */
448
const dict_table_t* table) /*!< in: table */
431
452
return(dict_table_flags_to_zip_size(table->flags));
434
/************************************************************************
455
/********************************************************************//**
435
456
Gets the number of fields in the internal representation of an index,
436
including fields added by the dictionary system. */
457
including fields added by the dictionary system.
458
@return number of fields */
439
461
dict_index_get_n_fields(
440
462
/*====================*/
441
/* out: number of fields */
442
const dict_index_t* index) /* in: an internal
463
const dict_index_t* index) /*!< in: an internal
443
464
representation of index (in
444
465
the dictionary cache) */
449
470
return(index->n_fields);
452
/************************************************************************
473
/********************************************************************//**
453
474
Gets the number of fields in the internal representation of an index
454
475
that uniquely determine the position of an index entry in the index, if
455
476
we do not take multiversioning into account: in the B-tree use the value
456
returned by dict_index_get_n_unique_in_tree. */
477
returned by dict_index_get_n_unique_in_tree.
478
@return number of fields */
459
481
dict_index_get_n_unique(
460
482
/*====================*/
461
/* out: number of fields */
462
const dict_index_t* index) /* in: an internal representation
483
const dict_index_t* index) /*!< in: an internal representation
463
484
of index (in the dictionary cache) */
469
490
return(index->n_uniq);
472
/************************************************************************
493
/********************************************************************//**
473
494
Gets the number of fields in the internal representation of an index
474
495
which uniquely determine the position of an index entry in the index, if
475
we also take multiversioning into account. */
496
we also take multiversioning into account.
497
@return number of fields */
478
500
dict_index_get_n_unique_in_tree(
479
501
/*============================*/
480
/* out: number of fields */
481
const dict_index_t* index) /* in: an internal representation
502
const dict_index_t* index) /*!< in: an internal representation
482
503
of index (in the dictionary cache) */
493
514
return(dict_index_get_n_fields(index));
496
/************************************************************************
517
/********************************************************************//**
497
518
Gets the number of user-defined ordering fields in the index. In the internal
498
519
representation of clustered indexes we add the row id to the ordering fields
499
520
to make a clustered index unique, but this function returns the number of
500
fields the user defined in the index as ordering fields. */
521
fields the user defined in the index as ordering fields.
522
@return number of fields */
503
525
dict_index_get_n_ordering_defined_by_user(
504
526
/*======================================*/
505
/* out: number of fields */
506
const dict_index_t* index) /* in: an internal representation
527
const dict_index_t* index) /*!< in: an internal representation
507
528
of index (in the dictionary cache) */
509
530
return(index->n_user_defined_cols);
512
533
#ifdef UNIV_DEBUG
513
/************************************************************************
514
Gets the nth field of an index. */
534
/********************************************************************//**
535
Gets the nth field of an index.
536
@return pointer to field object */
517
539
dict_index_get_nth_field(
518
540
/*=====================*/
519
/* out: pointer to field object */
520
const dict_index_t* index, /* in: index */
521
ulint pos) /* in: position of field */
541
const dict_index_t* index, /*!< in: index */
542
ulint pos) /*!< in: position of field */
524
545
ut_ad(pos < index->n_def);
529
550
#endif /* UNIV_DEBUG */
531
/************************************************************************
532
Returns the position of a system column in an index. */
552
/********************************************************************//**
553
Returns the position of a system column in an index.
554
@return position, ULINT_UNDEFINED if not contained */
535
557
dict_index_get_sys_col_pos(
536
558
/*=======================*/
538
ULINT_UNDEFINED if not contained */
539
const dict_index_t* index, /* in: index */
540
ulint type) /* in: DATA_ROW_ID, ... */
559
const dict_index_t* index, /*!< in: index */
560
ulint type) /*!< in: DATA_ROW_ID, ... */
543
563
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
554
574
index, dict_table_get_sys_col_no(index->table, type)));
557
/*************************************************************************
558
Gets the field column. */
577
/*********************************************************************//**
578
Gets the field column.
579
@return field->col, pointer to the table column */
560
581
const dict_col_t*
561
582
dict_field_get_col(
562
583
/*===============*/
563
const dict_field_t* field)
584
const dict_field_t* field) /*!< in: index field */
567
588
return(field->col);
570
/************************************************************************
571
Gets pointer to the nth column in an index. */
591
/********************************************************************//**
592
Gets pointer to the nth column in an index.
573
595
const dict_col_t*
574
596
dict_index_get_nth_col(
575
597
/*===================*/
577
const dict_index_t* index, /* in: index */
578
ulint pos) /* in: position of the field */
598
const dict_index_t* index, /*!< in: index */
599
ulint pos) /*!< in: position of the field */
580
601
return(dict_field_get_col(dict_index_get_nth_field(index, pos)));
583
/************************************************************************
584
Gets the column number the nth field in an index. */
604
/********************************************************************//**
605
Gets the column number the nth field in an index.
606
@return column number */
587
609
dict_index_get_nth_col_no(
588
610
/*======================*/
589
/* out: column number */
590
const dict_index_t* index, /* in: index */
591
ulint pos) /* in: position of the field */
611
const dict_index_t* index, /*!< in: index */
612
ulint pos) /*!< in: position of the field */
593
614
return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
596
/************************************************************************
597
Returns the minimum data size of an index record. */
617
#ifndef UNIV_HOTBACKUP
618
/********************************************************************//**
619
Returns the minimum data size of an index record.
620
@return minimum data size in bytes */
600
623
dict_index_get_min_size(
601
624
/*====================*/
602
/* out: minimum data size in bytes */
603
const dict_index_t* index) /* in: index */
625
const dict_index_t* index) /*!< in: index */
605
627
ulint n = dict_index_get_n_fields(index);
688
710
return(&(index->lock));
691
/************************************************************************
713
/********************************************************************//**
692
714
Returns free space reserved for future updates of records. This is
693
715
relevant only in the case of many consecutive inserts, as updates
694
which make the records bigger might fragment the index. */
716
which make the records bigger might fragment the index.
717
@return number of free bytes on page, reserved for updates */
697
720
dict_index_get_space_reserve(void)
698
721
/*==============================*/
699
/* out: number of free bytes on page,
700
reserved for updates */
702
723
return(UNIV_PAGE_SIZE / 16);
705
/**************************************************************************
706
Checks if a table is in the dictionary cache. */
726
/**********************************************************************//**
727
Checks if a table is in the dictionary cache.
728
@return table, NULL if not found */
709
731
dict_table_check_if_in_cache_low(
710
732
/*=============================*/
711
/* out: table, NULL if not found */
712
const char* table_name) /* in: table name */
733
const char* table_name) /*!< in: table name */
714
735
dict_table_t* table;
715
736
ulint table_fold;