1
/**********************************************************************
6
Created 1/8/1996 Heikki Tuuri
7
***********************************************************************/
12
#include "rem0types.h"
13
#include "data0type.h"
15
/*************************************************************************
16
Gets the column data type. */
21
const dict_col_t* col, /* in: column */
22
dtype_t* type) /* out: data type */
26
type->mtype = col->mtype;
27
type->prtype = col->prtype;
29
type->mbminlen = col->mbminlen;
30
type->mbmaxlen = col->mbmaxlen;
34
/*************************************************************************
35
Assert that a column and a data type match. */
38
dict_col_type_assert_equal(
39
/*=======================*/
41
const dict_col_t* col, /* in: column */
42
const dtype_t* type) /* in: data type */
47
ut_ad(col->mtype == type->mtype);
48
ut_ad(col->prtype == type->prtype);
49
ut_ad(col->len == type->len);
50
ut_ad(col->mbminlen == type->mbminlen);
51
ut_ad(col->mbmaxlen == type->mbmaxlen);
55
#endif /* UNIV_DEBUG */
57
/***************************************************************************
58
Returns the minimum size of the column. */
61
dict_col_get_min_size(
62
/*==================*/
63
/* out: minimum size */
64
const dict_col_t* col) /* in: column */
66
return(dtype_get_min_size_low(col->mtype, col->prtype, col->len,
67
col->mbminlen, col->mbmaxlen));
69
/***************************************************************************
70
Returns the maximum size of the column. */
73
dict_col_get_max_size(
74
/*==================*/
75
/* out: maximum size */
76
const dict_col_t* col) /* in: column */
78
return(dtype_get_max_size_low(col->mtype, col->len));
80
/***************************************************************************
81
Returns the size of a fixed size column, 0 if not a fixed size column. */
84
dict_col_get_fixed_size(
85
/*====================*/
86
/* out: fixed size, or 0 */
87
const dict_col_t* col) /* in: column */
89
return(dtype_get_fixed_size_low(col->mtype, col->prtype, col->len,
90
col->mbminlen, col->mbmaxlen));
92
/***************************************************************************
93
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
94
For fixed length types it is the fixed length of the type, otherwise 0. */
97
dict_col_get_sql_null_size(
98
/*=======================*/
99
/* out: SQL null storage size
100
in ROW_FORMAT=REDUNDANT */
101
const dict_col_t* col) /* in: column */
103
return(dict_col_get_fixed_size(col));
106
/*************************************************************************
107
Gets the column number. */
112
const dict_col_t* col)
119
/*************************************************************************
120
Gets the column position in the clustered index. */
123
dict_col_get_clust_pos(
124
/*===================*/
125
const dict_col_t* col, /* in: table column */
126
const dict_index_t* clust_index) /* in: clustered index */
131
ut_ad(clust_index && clust_index->type & DICT_CLUSTERED);
133
for (i = 0; i < clust_index->n_def; i++) {
134
const dict_field_t* field = &clust_index->fields[i];
136
if (!field->prefix_len && field->col == col) {
141
return(ULINT_UNDEFINED);
144
/************************************************************************
145
Gets the first index on the table (the clustered index). */
148
dict_table_get_first_index(
149
/*=======================*/
150
/* out: index, NULL if none exists */
151
dict_table_t* table) /* in: table */
154
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
156
return(UT_LIST_GET_FIRST(table->indexes));
159
/************************************************************************
160
Gets the next index on the table. */
163
dict_table_get_next_index(
164
/*======================*/
165
/* out: index, NULL if none left */
166
dict_index_t* index) /* in: index */
169
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
171
return(UT_LIST_GET_NEXT(indexes, index));
174
/************************************************************************
175
Gets the number of user-defined columns in a table in the dictionary
179
dict_table_get_n_user_cols(
180
/*=======================*/
181
/* out: number of user-defined (e.g., not
182
ROW_ID) columns of a table */
183
dict_table_t* table) /* in: table */
186
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
188
return(table->n_cols - DATA_N_SYS_COLS);
191
/************************************************************************
192
Gets the number of system columns in a table in the dictionary cache. */
195
dict_table_get_n_sys_cols(
196
/*======================*/
197
/* out: number of system (e.g.,
198
ROW_ID) columns of a table */
199
dict_table_t* table __attribute__((unused))) /* in: table */
202
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
203
ut_ad(table->cached);
205
return(DATA_N_SYS_COLS);
208
/************************************************************************
209
Gets the number of all columns (also system) in a table in the dictionary
213
dict_table_get_n_cols(
214
/*==================*/
215
/* out: number of columns of a table */
216
dict_table_t* table) /* in: table */
219
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
221
return(table->n_cols);
224
/************************************************************************
225
Gets the nth column of a table. */
228
dict_table_get_nth_col(
229
/*===================*/
230
/* out: pointer to column object */
231
const dict_table_t* table, /* in: table */
232
ulint pos) /* in: position of column */
235
ut_ad(pos < table->n_def);
236
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
238
return((table->cols) + pos);
241
/************************************************************************
242
Gets the given system column of a table. */
245
dict_table_get_sys_col(
246
/*===================*/
247
/* out: pointer to column object */
248
const dict_table_t* table, /* in: table */
249
ulint sys) /* in: DATA_ROW_ID, ... */
251
const dict_col_t* col;
254
ut_ad(sys < DATA_N_SYS_COLS);
255
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
257
col = dict_table_get_nth_col(table, table->n_cols
258
- DATA_N_SYS_COLS + sys);
259
ut_ad(col->mtype == DATA_SYS);
260
ut_ad(col->prtype == (sys | DATA_NOT_NULL));
265
/************************************************************************
266
Gets the given system column number of a table. */
269
dict_table_get_sys_col_no(
270
/*======================*/
271
/* out: column number */
272
dict_table_t* table, /* in: table */
273
ulint sys) /* in: DATA_ROW_ID, ... */
276
ut_ad(sys < DATA_N_SYS_COLS);
277
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
279
return(table->n_cols - DATA_N_SYS_COLS + sys);
282
/************************************************************************
283
Check whether the table uses the compact page format. */
288
/* out: TRUE if table uses the
289
compact page format */
290
const dict_table_t* table) /* in: table */
294
#if DICT_TF_COMPACT != TRUE
298
return(UNIV_LIKELY(table->flags & DICT_TF_COMPACT));
301
/************************************************************************
302
Gets the number of fields in the internal representation of an index,
303
including fields added by the dictionary system. */
306
dict_index_get_n_fields(
307
/*====================*/
308
/* out: number of fields */
309
dict_index_t* index) /* in: an internal representation of index
310
(in the dictionary cache) */
313
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
315
return(index->n_fields);
318
/************************************************************************
319
Gets the number of fields in the internal representation of an index
320
that uniquely determine the position of an index entry in the index, if
321
we do not take multiversioning into account: in the B-tree use the value
322
returned by dict_index_get_n_unique_in_tree. */
325
dict_index_get_n_unique(
326
/*====================*/
327
/* out: number of fields */
328
dict_index_t* index) /* in: an internal representation of index
329
(in the dictionary cache) */
332
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
333
ut_ad(index->cached);
335
return(index->n_uniq);
338
/************************************************************************
339
Gets the number of fields in the internal representation of an index
340
which uniquely determine the position of an index entry in the index, if
341
we also take multiversioning into account. */
344
dict_index_get_n_unique_in_tree(
345
/*============================*/
346
/* out: number of fields */
347
dict_index_t* index) /* in: an internal representation of index
348
(in the dictionary cache) */
351
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
352
ut_ad(index->cached);
354
if (index->type & DICT_CLUSTERED) {
356
return(dict_index_get_n_unique(index));
359
return(dict_index_get_n_fields(index));
362
/************************************************************************
363
Gets the number of user-defined ordering fields in the index. In the internal
364
representation of clustered indexes we add the row id to the ordering fields
365
to make a clustered index unique, but this function returns the number of
366
fields the user defined in the index as ordering fields. */
369
dict_index_get_n_ordering_defined_by_user(
370
/*======================================*/
371
/* out: number of fields */
372
dict_index_t* index) /* in: an internal representation of index
373
(in the dictionary cache) */
375
return(index->n_user_defined_cols);
378
/************************************************************************
379
Gets the nth field of an index. */
382
dict_index_get_nth_field(
383
/*=====================*/
384
/* out: pointer to field object */
385
dict_index_t* index, /* in: index */
386
ulint pos) /* in: position of field */
389
ut_ad(pos < index->n_def);
390
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
392
return((index->fields) + pos);
395
/************************************************************************
396
Returns the position of a system column in an index. */
399
dict_index_get_sys_col_pos(
400
/*=======================*/
401
/* out: position, ULINT_UNDEFINED if not
403
dict_index_t* index, /* in: index */
404
ulint type) /* in: DATA_ROW_ID, ... */
407
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
408
ut_ad(!(index->type & DICT_UNIVERSAL));
410
if (index->type & DICT_CLUSTERED) {
412
return(dict_col_get_clust_pos(
413
dict_table_get_sys_col(index->table, type),
417
return(dict_index_get_nth_col_pos(
418
index, dict_table_get_sys_col_no(index->table, type)));
421
/*************************************************************************
422
Gets the field column. */
427
const dict_field_t* field)
434
/************************************************************************
435
Gets pointer to the nth column in an index. */
438
dict_index_get_nth_col(
439
/*===================*/
441
const dict_index_t* index, /* in: index */
442
ulint pos) /* in: position of the field */
444
return(dict_field_get_col(dict_index_get_nth_field((dict_index_t*)
448
/************************************************************************
449
Gets the column number the nth field in an index. */
452
dict_index_get_nth_col_no(
453
/*======================*/
454
/* out: column number */
455
const dict_index_t* index, /* in: index */
456
ulint pos) /* in: position of the field */
458
return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
461
/*************************************************************************
462
Gets the space id of the root of the index tree. */
465
dict_index_get_space(
466
/*=================*/
468
dict_index_t* index) /* in: index */
471
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
473
return(index->space);
476
/*************************************************************************
477
Sets the space id of the root of the index tree. */
480
dict_index_set_space(
481
/*=================*/
482
dict_index_t* index, /* in: index */
483
ulint space) /* in: space id */
486
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
488
index->space = space;
491
/*************************************************************************
492
Gets the page number of the root of the index tree. */
497
/* out: page number */
498
dict_index_t* index) /* in: index */
501
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
506
/*************************************************************************
507
Sets the page number of the root of index tree. */
512
dict_index_t* index, /* in: index */
513
ulint page) /* in: page number */
516
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
521
/*************************************************************************
522
Gets the type of the index tree. */
528
dict_index_t* index) /* in: index */
531
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
536
/*************************************************************************
537
Gets the read-write lock of the index tree. */
542
/* out: read-write lock */
543
dict_index_t* index) /* in: index */
546
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
548
return(&(index->lock));
551
/************************************************************************
552
Returns free space reserved for future updates of records. This is
553
relevant only in the case of many consecutive inserts, as updates
554
which make the records bigger might fragment the index. */
557
dict_index_get_space_reserve(void)
558
/*==============================*/
559
/* out: number of free bytes on page,
560
reserved for updates */
562
return(UNIV_PAGE_SIZE / 16);
565
/**************************************************************************
566
Checks if a table is in the dictionary cache. */
569
dict_table_check_if_in_cache_low(
570
/*=============================*/
571
/* out: table, NULL if not found */
572
const char* table_name) /* in: table name */
578
ut_ad(mutex_own(&(dict_sys->mutex)));
580
/* Look for the table name in the hash table */
581
table_fold = ut_fold_string(table_name);
583
HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold, table,
584
ut_strcmp(table->name, table_name) == 0);
588
/**************************************************************************
589
Gets a table; loads it to the dictionary cache if necessary. A low-level
595
/* out: table, NULL if not found */
596
const char* table_name) /* in: table name */
601
ut_ad(mutex_own(&(dict_sys->mutex)));
603
table = dict_table_check_if_in_cache_low(table_name);
606
table = dict_load_table(table_name);
612
/**************************************************************************
613
Returns a table object based on table id. */
616
dict_table_get_on_id_low(
617
/*=====================*/
618
/* out: table, NULL if does not exist */
619
dulint table_id) /* in: table id */
624
ut_ad(mutex_own(&(dict_sys->mutex)));
626
/* Look for the table name in the hash table */
627
fold = ut_fold_dulint(table_id);
629
HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold, table,
630
ut_dulint_cmp(table->id, table_id) == 0);
632
table = dict_load_table_on_id(table_id);
635
/* TODO: should get the type information from MySQL */
640
/**************************************************************************
641
Returns an index object. */
644
dict_table_get_index(
645
/*=================*/
646
/* out: index, NULL if does not exist */
647
dict_table_t* table, /* in: table */
648
const char* name) /* in: index name */
650
dict_index_t* index = NULL;
652
index = dict_table_get_first_index(table);
654
while (index != NULL) {
655
if (ut_strcmp(name, index->name) == 0) {
660
index = dict_table_get_next_index(index);