140
141
return(ULINT_UNDEFINED);
144
144
/************************************************************************
145
145
Gets the first index on the table (the clustered index). */
148
148
dict_table_get_first_index(
149
149
/*=======================*/
150
/* out: index, NULL if none exists */
151
const dict_table_t* table) /* in: table */
150
/* out: index, NULL if none exists */
151
dict_table_t* table) /* in: table */
154
154
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
156
return(UT_LIST_GET_FIRST(((dict_table_t*) table)->indexes));
156
return(UT_LIST_GET_FIRST(table->indexes));
159
159
/************************************************************************
163
163
dict_table_get_next_index(
164
164
/*======================*/
165
/* out: index, NULL if none left */
166
const dict_index_t* index) /* in: index */
169
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
171
return(UT_LIST_GET_NEXT(indexes, (dict_index_t*) index));
173
#endif /* UNIV_DEBUG */
175
/************************************************************************
176
Check whether the index is the clustered index. */
181
/* out: nonzero for clustered index,
182
zero for other indexes */
183
const dict_index_t* index) /* in: index */
186
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
188
return(UNIV_UNLIKELY(index->type & DICT_CLUSTERED));
190
/************************************************************************
191
Check whether the index is unique. */
194
dict_index_is_unique(
195
/*=================*/
196
/* out: nonzero for unique index,
197
zero for other indexes */
198
const dict_index_t* index) /* in: index */
201
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
203
return(UNIV_UNLIKELY(index->type & DICT_UNIQUE));
206
/************************************************************************
207
Check whether the index is the insert buffer tree. */
212
/* out: nonzero for insert buffer,
213
zero for other indexes */
214
const dict_index_t* index) /* in: index */
217
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
219
return(UNIV_UNLIKELY(index->type & DICT_IBUF));
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));
222
174
/************************************************************************
227
179
dict_table_get_n_user_cols(
228
180
/*=======================*/
229
/* out: number of user-defined
231
columns of a table */
232
const dict_table_t* table) /* in: table */
181
/* out: number of user-defined (e.g., not
182
ROW_ID) columns of a table */
183
dict_table_t* table) /* in: table */
235
186
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
244
195
dict_table_get_n_sys_cols(
245
196
/*======================*/
246
/* out: number of system (e.g.,
247
ROW_ID) columns of a table */
248
const dict_table_t* table __attribute__((unused))) /* in: table */
197
/* out: number of system (e.g.,
198
ROW_ID) columns of a table */
199
dict_table_t* table __attribute__((unused))) /* in: table */
251
202
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
262
213
dict_table_get_n_cols(
263
214
/*==================*/
264
/* out: number of columns of a table */
265
const dict_table_t* table) /* in: table */
215
/* out: number of columns of a table */
216
dict_table_t* table) /* in: table */
268
219
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
285
235
ut_ad(pos < table->n_def);
286
236
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
288
return((dict_col_t*) (table->cols) + pos);
238
return((table->cols) + pos);
291
241
/************************************************************************
292
242
Gets the given system column of a table. */
295
245
dict_table_get_sys_col(
296
246
/*===================*/
297
247
/* out: pointer to column object */
298
248
const dict_table_t* table, /* in: table */
299
249
ulint sys) /* in: DATA_ROW_ID, ... */
251
const dict_col_t* col;
304
254
ut_ad(sys < DATA_N_SYS_COLS);
320
269
dict_table_get_sys_col_no(
321
270
/*======================*/
322
/* out: column number */
323
const dict_table_t* table, /* in: table */
324
ulint sys) /* in: DATA_ROW_ID, ... */
271
/* out: column number */
272
dict_table_t* table, /* in: table */
273
ulint sys) /* in: DATA_ROW_ID, ... */
327
276
ut_ad(sys < DATA_N_SYS_COLS);
352
301
/************************************************************************
353
Determine the file format of a table. */
356
dict_table_get_format(
357
/*==================*/
358
/* out: file format version */
359
const dict_table_t* table) /* in: table */
363
return((table->flags & DICT_TF_FORMAT_MASK) >> DICT_TF_FORMAT_SHIFT);
366
/************************************************************************
367
Determine the file format of a table. */
370
dict_table_set_format(
371
/*==================*/
372
dict_table_t* table, /* in/out: table */
373
ulint format) /* in: file format version */
377
table->flags = (table->flags & ~DICT_TF_FORMAT_MASK)
378
| (format << DICT_TF_FORMAT_SHIFT);
381
/************************************************************************
382
Extract the compressed page size from table flags. */
385
dict_table_flags_to_zip_size(
386
/*=========================*/
387
/* out: compressed page size,
388
or 0 if not compressed */
389
ulint flags) /* in: flags */
391
ulint zip_size = flags & DICT_TF_ZSSIZE_MASK;
393
if (UNIV_UNLIKELY(zip_size)) {
394
zip_size = ((PAGE_ZIP_MIN_SIZE >> 1)
395
<< (zip_size >> DICT_TF_ZSSIZE_SHIFT));
397
ut_ad(zip_size <= UNIV_PAGE_SIZE);
403
/************************************************************************
404
Check whether the table uses the compressed compact page format. */
409
/* out: compressed page size,
410
or 0 if not compressed */
411
const dict_table_t* table) /* in: table */
415
return(dict_table_flags_to_zip_size(table->flags));
418
/************************************************************************
419
302
Gets the number of fields in the internal representation of an index,
420
303
including fields added by the dictionary system. */
423
306
dict_index_get_n_fields(
424
307
/*====================*/
425
/* out: number of fields */
426
const dict_index_t* index) /* in: an internal
427
representation of index (in
428
the dictionary cache) */
308
/* out: number of fields */
309
dict_index_t* index) /* in: an internal representation of index
310
(in the dictionary cache) */
431
313
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
443
325
dict_index_get_n_unique(
444
326
/*====================*/
445
/* out: number of fields */
446
const dict_index_t* index) /* in: an internal representation
447
of index (in the dictionary cache) */
327
/* out: number of fields */
328
dict_index_t* index) /* in: an internal representation of index
329
(in the dictionary cache) */
450
332
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
462
344
dict_index_get_n_unique_in_tree(
463
345
/*============================*/
464
/* out: number of fields */
465
const dict_index_t* index) /* in: an internal representation
466
of index (in the dictionary cache) */
346
/* out: number of fields */
347
dict_index_t* index) /* in: an internal representation of index
348
(in the dictionary cache) */
469
351
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
470
352
ut_ad(index->cached);
472
if (dict_index_is_clust(index)) {
354
if (index->type & DICT_CLUSTERED) {
474
356
return(dict_index_get_n_unique(index));
487
369
dict_index_get_n_ordering_defined_by_user(
488
370
/*======================================*/
489
/* out: number of fields */
490
const dict_index_t* index) /* in: an internal representation
491
of index (in the dictionary cache) */
371
/* out: number of fields */
372
dict_index_t* index) /* in: an internal representation of index
373
(in the dictionary cache) */
493
375
return(index->n_user_defined_cols);
497
378
/************************************************************************
498
379
Gets the nth field of an index. */
502
383
/*=====================*/
503
384
/* out: pointer to field object */
504
385
const dict_index_t* index, /* in: index */
505
ulint pos) /* in: position of field */
386
ulint pos) /* in: position of field */
508
389
ut_ad(pos < index->n_def);
509
390
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
511
return((dict_field_t*) (index->fields) + pos);
392
return((index->fields) + pos);
513
#endif /* UNIV_DEBUG */
515
395
/************************************************************************
516
396
Returns the position of a system column in an index. */
519
399
dict_index_get_sys_col_pos(
520
400
/*=======================*/
522
ULINT_UNDEFINED if not contained */
523
const dict_index_t* index, /* in: index */
524
ulint type) /* in: DATA_ROW_ID, ... */
401
/* out: position, ULINT_UNDEFINED if not
403
dict_index_t* index, /* in: index */
404
ulint type) /* in: DATA_ROW_ID, ... */
527
407
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
528
408
ut_ad(!(index->type & DICT_UNIVERSAL));
530
if (dict_index_is_clust(index)) {
410
if (index->type & DICT_CLUSTERED) {
532
412
return(dict_col_get_clust_pos(
533
413
dict_table_get_sys_col(index->table, type),
577
457
return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
580
/************************************************************************
581
Returns the minimum data size of an index record. */
584
dict_index_get_min_size(
585
/*====================*/
586
/* out: minimum data size in bytes */
587
const dict_index_t* index) /* in: index */
589
ulint n = dict_index_get_n_fields(index);
593
size += dict_col_get_min_size(dict_index_get_nth_col(index,
600
460
/*************************************************************************
601
461
Gets the space id of the root of the index tree. */
604
464
dict_index_get_space(
605
465
/*=================*/
607
const dict_index_t* index) /* in: index */
467
dict_index_t* index) /* in: index */
610
470
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
719
579
/* Look for the table name in the hash table */
720
580
table_fold = ut_fold_string(table_name);
722
HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold,
723
dict_table_t*, table, !strcmp(table->name, table_name));
582
HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold, table,
583
ut_strcmp(table->name, table_name) == 0);
765
625
/* Look for the table name in the hash table */
766
626
fold = ut_fold_dulint(table_id);
768
HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold,
769
dict_table_t*, table, !ut_dulint_cmp(table->id, table_id));
628
HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold, table,
629
ut_dulint_cmp(table->id, table_id) == 0);
770
630
if (table == NULL) {
771
631
table = dict_load_table_on_id(table_id);
639
/**************************************************************************
640
Returns an index object. */
643
dict_table_get_index(
644
/*=================*/
645
/* out: index, NULL if does not exist */
646
dict_table_t* table, /* in: table */
647
const char* name) /* in: index name */
649
dict_index_t* index = NULL;
651
index = dict_table_get_first_index(table);
653
while (index != NULL) {
654
if (ut_strcmp(name, index->name) == 0) {
659
index = dict_table_get_next_index(index);