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
292
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
268
293
ut_ad(table->cached);
289
314
#ifdef UNIV_DEBUG
290
/************************************************************************
291
Gets the nth column of a table. */
315
/********************************************************************//**
316
Gets the nth column of a table.
317
@return pointer to column object */
294
320
dict_table_get_nth_col(
295
321
/*===================*/
296
/* out: pointer to column object */
297
const dict_table_t* table, /* in: table */
298
ulint pos) /* in: position of column */
322
const dict_table_t* table, /*!< in: table */
323
ulint pos) /*!< in: position of column */
301
326
ut_ad(pos < table->n_def);
304
329
return((dict_col_t*) (table->cols) + pos);
307
/************************************************************************
308
Gets the given system column of a table. */
332
/********************************************************************//**
333
Gets the given system column of a table.
334
@return pointer to column object */
311
337
dict_table_get_sys_col(
312
338
/*===================*/
313
/* out: pointer to column object */
314
const dict_table_t* table, /* in: table */
315
ulint sys) /* in: DATA_ROW_ID, ... */
339
const dict_table_t* table, /*!< in: table */
340
ulint sys) /*!< in: DATA_ROW_ID, ... */
330
355
#endif /* UNIV_DEBUG */
332
/************************************************************************
333
Gets the given system column number of a table. */
357
/********************************************************************//**
358
Gets the given system column number of a table.
359
@return column number */
336
362
dict_table_get_sys_col_no(
337
363
/*======================*/
338
/* out: column number */
339
const dict_table_t* table, /* in: table */
340
ulint sys) /* in: DATA_ROW_ID, ... */
364
const dict_table_t* table, /*!< in: table */
365
ulint sys) /*!< in: DATA_ROW_ID, ... */
343
368
ut_ad(sys < DATA_N_SYS_COLS);
365
389
return(UNIV_LIKELY(table->flags & DICT_TF_COMPACT));
368
/************************************************************************
369
Determine the file format of a table. */
392
/********************************************************************//**
393
Determine the file format of a table.
394
@return file format version */
372
397
dict_table_get_format(
373
398
/*==================*/
374
/* out: file format version */
375
const dict_table_t* table) /* in: table */
399
const dict_table_t* table) /*!< in: table */
379
403
return((table->flags & DICT_TF_FORMAT_MASK) >> DICT_TF_FORMAT_SHIFT);
382
/************************************************************************
406
/********************************************************************//**
383
407
Determine the file format of a table. */
386
410
dict_table_set_format(
387
411
/*==================*/
388
dict_table_t* table, /* in/out: table */
389
ulint format) /* in: file format version */
412
dict_table_t* table, /*!< in/out: table */
413
ulint format) /*!< in: file format version */
394
418
| (format << DICT_TF_FORMAT_SHIFT);
397
/************************************************************************
398
Extract the compressed page size from table flags. */
421
/********************************************************************//**
422
Extract the compressed page size from table flags.
423
@return compressed page size, or 0 if not compressed */
401
426
dict_table_flags_to_zip_size(
402
427
/*=========================*/
403
/* out: compressed page size,
404
or 0 if not compressed */
405
ulint flags) /* in: flags */
428
ulint flags) /*!< in: flags */
407
430
ulint zip_size = flags & DICT_TF_ZSSIZE_MASK;
416
439
return(zip_size);
419
/************************************************************************
420
Check whether the table uses the compressed compact page format. */
442
/********************************************************************//**
443
Check whether the table uses the compressed compact page format.
444
@return compressed page size, or 0 if not compressed */
423
447
dict_table_zip_size(
424
448
/*================*/
425
/* out: compressed page size,
426
or 0 if not compressed */
427
const dict_table_t* table) /* in: table */
449
const dict_table_t* table) /*!< in: table */
431
453
return(dict_table_flags_to_zip_size(table->flags));
434
/************************************************************************
456
/********************************************************************//**
435
457
Gets the number of fields in the internal representation of an index,
436
including fields added by the dictionary system. */
458
including fields added by the dictionary system.
459
@return number of fields */
439
462
dict_index_get_n_fields(
440
463
/*====================*/
441
/* out: number of fields */
442
const dict_index_t* index) /* in: an internal
464
const dict_index_t* index) /*!< in: an internal
443
465
representation of index (in
444
466
the dictionary cache) */
449
471
return(index->n_fields);
452
/************************************************************************
474
/********************************************************************//**
453
475
Gets the number of fields in the internal representation of an index
454
476
that uniquely determine the position of an index entry in the index, if
455
477
we do not take multiversioning into account: in the B-tree use the value
456
returned by dict_index_get_n_unique_in_tree. */
478
returned by dict_index_get_n_unique_in_tree.
479
@return number of fields */
459
482
dict_index_get_n_unique(
460
483
/*====================*/
461
/* out: number of fields */
462
const dict_index_t* index) /* in: an internal representation
484
const dict_index_t* index) /*!< in: an internal representation
463
485
of index (in the dictionary cache) */
469
491
return(index->n_uniq);
472
/************************************************************************
494
/********************************************************************//**
473
495
Gets the number of fields in the internal representation of an index
474
496
which uniquely determine the position of an index entry in the index, if
475
we also take multiversioning into account. */
497
we also take multiversioning into account.
498
@return number of fields */
478
501
dict_index_get_n_unique_in_tree(
479
502
/*============================*/
480
/* out: number of fields */
481
const dict_index_t* index) /* in: an internal representation
503
const dict_index_t* index) /*!< in: an internal representation
482
504
of index (in the dictionary cache) */
493
515
return(dict_index_get_n_fields(index));
496
/************************************************************************
518
/********************************************************************//**
497
519
Gets the number of user-defined ordering fields in the index. In the internal
498
520
representation of clustered indexes we add the row id to the ordering fields
499
521
to make a clustered index unique, but this function returns the number of
500
fields the user defined in the index as ordering fields. */
522
fields the user defined in the index as ordering fields.
523
@return number of fields */
503
526
dict_index_get_n_ordering_defined_by_user(
504
527
/*======================================*/
505
/* out: number of fields */
506
const dict_index_t* index) /* in: an internal representation
528
const dict_index_t* index) /*!< in: an internal representation
507
529
of index (in the dictionary cache) */
509
531
return(index->n_user_defined_cols);
512
534
#ifdef UNIV_DEBUG
513
/************************************************************************
514
Gets the nth field of an index. */
535
/********************************************************************//**
536
Gets the nth field of an index.
537
@return pointer to field object */
517
540
dict_index_get_nth_field(
518
541
/*=====================*/
519
/* out: pointer to field object */
520
const dict_index_t* index, /* in: index */
521
ulint pos) /* in: position of field */
542
const dict_index_t* index, /*!< in: index */
543
ulint pos) /*!< in: position of field */
524
546
ut_ad(pos < index->n_def);
529
551
#endif /* UNIV_DEBUG */
531
/************************************************************************
532
Returns the position of a system column in an index. */
553
/********************************************************************//**
554
Returns the position of a system column in an index.
555
@return position, ULINT_UNDEFINED if not contained */
535
558
dict_index_get_sys_col_pos(
536
559
/*=======================*/
538
ULINT_UNDEFINED if not contained */
539
const dict_index_t* index, /* in: index */
540
ulint type) /* in: DATA_ROW_ID, ... */
560
const dict_index_t* index, /*!< in: index */
561
ulint type) /*!< in: DATA_ROW_ID, ... */
543
564
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
554
575
index, dict_table_get_sys_col_no(index->table, type)));
557
/*************************************************************************
558
Gets the field column. */
578
/*********************************************************************//**
579
Gets the field column.
580
@return field->col, pointer to the table column */
560
582
const dict_col_t*
561
583
dict_field_get_col(
562
584
/*===============*/
563
const dict_field_t* field)
585
const dict_field_t* field) /*!< in: index field */
567
589
return(field->col);
570
/************************************************************************
571
Gets pointer to the nth column in an index. */
592
/********************************************************************//**
593
Gets pointer to the nth column in an index.
573
596
const dict_col_t*
574
597
dict_index_get_nth_col(
575
598
/*===================*/
577
const dict_index_t* index, /* in: index */
578
ulint pos) /* in: position of the field */
599
const dict_index_t* index, /*!< in: index */
600
ulint pos) /*!< in: position of the field */
580
602
return(dict_field_get_col(dict_index_get_nth_field(index, pos)));
583
/************************************************************************
584
Gets the column number the nth field in an index. */
605
/********************************************************************//**
606
Gets the column number the nth field in an index.
607
@return column number */
587
610
dict_index_get_nth_col_no(
588
611
/*======================*/
589
/* out: column number */
590
const dict_index_t* index, /* in: index */
591
ulint pos) /* in: position of the field */
612
const dict_index_t* index, /*!< in: index */
613
ulint pos) /*!< in: position of the field */
593
615
return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
596
/************************************************************************
597
Returns the minimum data size of an index record. */
618
#ifndef UNIV_HOTBACKUP
619
/********************************************************************//**
620
Returns the minimum data size of an index record.
621
@return minimum data size in bytes */
600
624
dict_index_get_min_size(
601
625
/*====================*/
602
/* out: minimum data size in bytes */
603
const dict_index_t* index) /* in: index */
626
const dict_index_t* index) /*!< in: index */
605
628
ulint n = dict_index_get_n_fields(index);
688
711
return(&(index->lock));
691
/************************************************************************
714
/********************************************************************//**
692
715
Returns free space reserved for future updates of records. This is
693
716
relevant only in the case of many consecutive inserts, as updates
694
which make the records bigger might fragment the index. */
717
which make the records bigger might fragment the index.
718
@return number of free bytes on page, reserved for updates */
697
721
dict_index_get_space_reserve(void)
698
722
/*==============================*/
699
/* out: number of free bytes on page,
700
reserved for updates */
702
724
return(UNIV_PAGE_SIZE / 16);
705
/**************************************************************************
706
Checks if a table is in the dictionary cache. */
727
/**********************************************************************//**
728
Checks if a table is in the dictionary cache.
729
@return table, NULL if not found */
709
732
dict_table_check_if_in_cache_low(
710
733
/*=============================*/
711
/* out: table, NULL if not found */
712
const char* table_name) /* in: table name */
734
const char* table_name) /*!< in: table name */
714
736
dict_table_t* table;
715
737
ulint table_fold;