1
/*****************************************************************************
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/dict0dict.h
21
Data dictionary system
23
Created 1/8/1996 Heikki Tuuri
24
*******************************************************/
30
#include "dict0types.h"
32
#include "data0type.h"
33
#include "data0data.h"
35
#include "rem0types.h"
38
#include "hash0hash.h"
41
#include "trx0types.h"
43
#ifndef UNIV_HOTBACKUP
44
# include "sync0sync.h"
46
/******************************************************************//**
47
Makes all characters in a NUL-terminated UTF-8 string lower case. */
52
char* a); /*!< in/out: string to put in lower case */
53
/********************************************************************//**
54
Get the database name length in a table name.
55
@return database name length */
60
const char* name); /*!< in: table name in the form
61
dbname '/' tablename */
62
/********************************************************************//**
63
Return the end of table name where we have removed dbname and '/'.
69
const char* name); /*!< in: table name in the form
70
dbname '/' tablename */
71
/**********************************************************************//**
72
Returns a table object based on table id.
73
@return table, NULL if does not exist */
78
dulint table_id, /*!< in: table id */
79
trx_t* trx); /*!< in: transaction handle */
80
/********************************************************************//**
81
Decrements the count of open MySQL handles to a table. */
84
dict_table_decrement_handle_count(
85
/*==============================*/
86
dict_table_t* table, /*!< in/out: table */
87
ibool dict_locked); /*!< in: TRUE=data dictionary locked */
88
/**********************************************************************//**
89
Inits the data dictionary module. */
94
/********************************************************************//**
95
Gets the space id of every table of the data dictionary and makes a linear
96
list and a hash table of them to the data dictionary cache. This function
97
can be called at database startup if we did not need to do a crash recovery.
98
In crash recovery we must scan the space id's from the .ibd files in MySQL
99
database directories. */
102
dict_load_space_id_list(void);
103
/*=========================*/
104
/*********************************************************************//**
105
Gets the column data type. */
110
const dict_col_t* col, /*!< in: column */
111
dtype_t* type); /*!< out: data type */
112
#endif /* !UNIV_HOTBACKUP */
114
/*********************************************************************//**
115
Assert that a column and a data type match.
119
dict_col_type_assert_equal(
120
/*=======================*/
121
const dict_col_t* col, /*!< in: column */
122
const dtype_t* type); /*!< in: data type */
123
#endif /* UNIV_DEBUG */
124
#ifndef UNIV_HOTBACKUP
125
/***********************************************************************//**
126
Returns the minimum size of the column.
127
@return minimum size */
130
dict_col_get_min_size(
131
/*==================*/
132
const dict_col_t* col); /*!< in: column */
133
/***********************************************************************//**
134
Returns the maximum size of the column.
135
@return maximum size */
138
dict_col_get_max_size(
139
/*==================*/
140
const dict_col_t* col); /*!< in: column */
141
/***********************************************************************//**
142
Returns the size of a fixed size column, 0 if not a fixed size column.
143
@return fixed size, or 0 */
146
dict_col_get_fixed_size(
147
/*====================*/
148
const dict_col_t* col, /*!< in: column */
149
ulint comp); /*!< in: nonzero=ROW_FORMAT=COMPACT */
150
/***********************************************************************//**
151
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
152
For fixed length types it is the fixed length of the type, otherwise 0.
153
@return SQL null storage size in ROW_FORMAT=REDUNDANT */
156
dict_col_get_sql_null_size(
157
/*=======================*/
158
const dict_col_t* col, /*!< in: column */
159
ulint comp); /*!< in: nonzero=ROW_FORMAT=COMPACT */
161
/*********************************************************************//**
162
Gets the column number.
163
@return col->ind, table column position (starting from 0) */
168
const dict_col_t* col); /*!< in: column */
169
/*********************************************************************//**
170
Gets the column position in the clustered index. */
173
dict_col_get_clust_pos(
174
/*===================*/
175
const dict_col_t* col, /*!< in: table column */
176
const dict_index_t* clust_index); /*!< in: clustered index */
177
/****************************************************************//**
178
If the given column name is reserved for InnoDB system columns, return
180
@return TRUE if name is reserved */
183
dict_col_name_is_reserved(
184
/*======================*/
185
const char* name); /*!< in: column name */
186
/********************************************************************//**
187
Acquire the autoinc lock. */
190
dict_table_autoinc_lock(
191
/*====================*/
192
dict_table_t* table); /*!< in/out: table */
193
/********************************************************************//**
194
Unconditionally set the autoinc counter. */
197
dict_table_autoinc_initialize(
198
/*==========================*/
199
dict_table_t* table, /*!< in/out: table */
200
ib_uint64_t value); /*!< in: next value to assign to a row */
201
/********************************************************************//**
202
Reads the next autoinc value (== autoinc counter value), 0 if not yet
204
@return value for a new row, or 0 */
207
dict_table_autoinc_read(
208
/*====================*/
209
const dict_table_t* table); /*!< in: table */
210
/********************************************************************//**
211
Updates the autoinc counter if the value supplied is greater than the
215
dict_table_autoinc_update_if_greater(
216
/*=================================*/
218
dict_table_t* table, /*!< in/out: table */
219
ib_uint64_t value); /*!< in: value which was assigned to a row */
220
/********************************************************************//**
221
Release the autoinc lock. */
224
dict_table_autoinc_unlock(
225
/*======================*/
226
dict_table_t* table); /*!< in/out: table */
227
#endif /* !UNIV_HOTBACKUP */
228
/**********************************************************************//**
229
Adds system columns to a table object. */
232
dict_table_add_system_columns(
233
/*==========================*/
234
dict_table_t* table, /*!< in/out: table */
235
mem_heap_t* heap); /*!< in: temporary heap */
236
#ifndef UNIV_HOTBACKUP
237
/**********************************************************************//**
238
Adds a table object to the dictionary cache. */
241
dict_table_add_to_cache(
242
/*====================*/
243
dict_table_t* table, /*!< in: table */
244
mem_heap_t* heap); /*!< in: temporary heap */
245
/**********************************************************************//**
246
Removes a table object from the dictionary cache. */
249
dict_table_remove_from_cache(
250
/*=========================*/
251
dict_table_t* table); /*!< in, own: table */
252
/**********************************************************************//**
253
Renames a table object.
254
@return TRUE if success */
257
dict_table_rename_in_cache(
258
/*=======================*/
259
dict_table_t* table, /*!< in/out: table */
260
const char* new_name, /*!< in: new name */
261
ibool rename_also_foreigns);/*!< in: in ALTER TABLE we want
262
to preserve the original table name
263
in constraints which reference it */
264
/**********************************************************************//**
265
Change the id of a table object in the dictionary cache. This is used in
266
DISCARD TABLESPACE. */
269
dict_table_change_id_in_cache(
270
/*==========================*/
271
dict_table_t* table, /*!< in/out: table object already in cache */
272
dulint new_id);/*!< in: new id to set */
273
/**********************************************************************//**
274
Adds a foreign key constraint object to the dictionary cache. May free
275
the object if there already is an object with the same identifier in.
276
At least one of foreign table or referenced table must already be in
277
the dictionary cache!
278
@return DB_SUCCESS or error code */
281
dict_foreign_add_to_cache(
282
/*======================*/
283
dict_foreign_t* foreign, /*!< in, own: foreign key constraint */
284
ibool check_charsets);/*!< in: TRUE=check charset
286
/*********************************************************************//**
287
Check if the index is referenced by a foreign key, if TRUE return the
288
matching instance NULL otherwise.
289
@return pointer to foreign key struct if index is defined for foreign
290
key, otherwise NULL */
293
dict_table_get_referenced_constraint(
294
/*=================================*/
295
dict_table_t* table, /*!< in: InnoDB table */
296
dict_index_t* index); /*!< in: InnoDB index */
297
/*********************************************************************//**
298
Checks if a table is referenced by foreign keys.
299
@return TRUE if table is referenced by a foreign key */
302
dict_table_is_referenced_by_foreign_key(
303
/*====================================*/
304
const dict_table_t* table); /*!< in: InnoDB table */
305
/**********************************************************************//**
306
Replace the index in the foreign key list that matches this index's
307
definition with an equivalent index. */
310
dict_table_replace_index_in_foreign_list(
311
/*=====================================*/
312
dict_table_t* table, /*!< in/out: table */
313
dict_index_t* index); /*!< in: index to be replaced */
314
/*********************************************************************//**
315
Checks if a index is defined for a foreign key constraint. Index is a part
316
of a foreign key constraint if the index is referenced by foreign key
317
or index is a foreign key index
318
@return pointer to foreign key struct if index is defined for foreign
319
key, otherwise NULL */
322
dict_table_get_foreign_constraint(
323
/*==============================*/
324
dict_table_t* table, /*!< in: InnoDB table */
325
dict_index_t* index); /*!< in: InnoDB index */
326
/*********************************************************************//**
327
Scans a table create SQL string and adds to the data dictionary
328
the foreign key constraints declared in the string. This function
329
should be called after the indexes for a table have been created.
330
Each foreign key constraint must be accompanied with indexes in
331
bot participating tables. The indexes are allowed to contain more
332
fields than mentioned in the constraint.
333
@return error code or DB_SUCCESS */
336
dict_create_foreign_constraints(
337
/*============================*/
338
trx_t* trx, /*!< in: transaction */
339
const char* sql_string, /*!< in: table create statement where
340
foreign keys are declared like:
341
FOREIGN KEY (a, b) REFERENCES
342
table2(c, d), table2 can be written
343
also with the database
344
name before it: test.table2; the
345
default database id the database of
347
const char* name, /*!< in: table full name in the
349
database_name/table_name */
350
ibool reject_fks); /*!< in: if TRUE, fail with error
351
code DB_CANNOT_ADD_CONSTRAINT if
352
any foreign keys are found. */
353
/**********************************************************************//**
354
Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement.
355
@return DB_SUCCESS or DB_CANNOT_DROP_CONSTRAINT if syntax error or the
356
constraint id does not match */
359
dict_foreign_parse_drop_constraints(
360
/*================================*/
361
mem_heap_t* heap, /*!< in: heap from which we can
363
trx_t* trx, /*!< in: transaction */
364
dict_table_t* table, /*!< in: table */
365
ulint* n, /*!< out: number of constraints
367
const char*** constraints_to_drop); /*!< out: id's of the
368
constraints to drop */
369
/**********************************************************************//**
370
Returns a table object and optionally increment its MySQL open handle count.
371
NOTE! This is a high-level function to be used mainly from outside the
372
'dict' directory. Inside this directory dict_table_get_low is usually the
373
appropriate function.
374
@return table, NULL if does not exist */
379
const char* table_name, /*!< in: table name */
380
ibool inc_mysql_count);
381
/*!< in: whether to increment the open
382
handle count on the table */
383
/**********************************************************************//**
384
Returns a index object, based on table and index id, and memoryfixes it.
385
@return index, NULL if does not exist */
388
dict_index_get_on_id_low(
389
/*=====================*/
390
dict_table_t* table, /*!< in: table */
391
dulint index_id); /*!< in: index id */
392
/**********************************************************************//**
393
Checks if a table is in the dictionary cache.
394
@return table, NULL if not found */
398
dict_table_check_if_in_cache_low(
399
/*=============================*/
400
const char* table_name); /*!< in: table name */
401
/**********************************************************************//**
402
Gets a table; loads it to the dictionary cache if necessary. A low-level
404
@return table, NULL if not found */
409
const char* table_name); /*!< in: table name */
410
/**********************************************************************//**
411
Returns a table object based on table id.
412
@return table, NULL if does not exist */
415
dict_table_get_on_id_low(
416
/*=====================*/
417
dulint table_id); /*!< in: table id */
418
/**********************************************************************//**
419
Find an index that is equivalent to the one passed in and is not marked
421
@return index equivalent to foreign->foreign_index, or NULL */
424
dict_foreign_find_equiv_index(
425
/*==========================*/
426
dict_foreign_t* foreign);/*!< in: foreign key */
427
/**********************************************************************//**
428
Returns an index object by matching on the name and column names and
429
if more than one index matches return the index with the max id
430
@return matching index, NULL if not found */
433
dict_table_get_index_by_max_id(
434
/*===========================*/
435
dict_table_t* table, /*!< in: table */
436
const char* name, /*!< in: the index name to find */
437
const char** columns,/*!< in: array of column names */
438
ulint n_cols);/*!< in: number of columns */
439
/**********************************************************************//**
440
Returns a column's name.
441
@return column name. NOTE: not guaranteed to stay valid if table is
442
modified in any way (columns added, etc.). */
445
dict_table_get_col_name(
446
/*====================*/
447
const dict_table_t* table, /*!< in: table */
448
ulint col_nr);/*!< in: column number */
450
/**********************************************************************//**
451
Prints a table definition. */
456
dict_table_t* table); /*!< in: table */
457
/**********************************************************************//**
458
Prints a table data. */
461
dict_table_print_low(
462
/*=================*/
463
dict_table_t* table); /*!< in: table */
464
/**********************************************************************//**
465
Prints a table data when we know the table name. */
468
dict_table_print_by_name(
469
/*=====================*/
470
const char* name); /*!< in: table name */
471
/**********************************************************************//**
472
Outputs info on foreign keys of a table. */
475
dict_print_info_on_foreign_keys(
476
/*============================*/
477
ibool create_table_format, /*!< in: if TRUE then print in
478
a format suitable to be inserted into
479
a CREATE TABLE, otherwise in the format
480
of SHOW TABLE STATUS */
481
FILE* file, /*!< in: file where to print */
482
trx_t* trx, /*!< in: transaction */
483
dict_table_t* table); /*!< in: table */
484
/**********************************************************************//**
485
Outputs info on a foreign key of a table in a format suitable for
489
dict_print_info_on_foreign_key_in_create_format(
490
/*============================================*/
491
FILE* file, /*!< in: file where to print */
492
trx_t* trx, /*!< in: transaction */
493
dict_foreign_t* foreign, /*!< in: foreign key constraint */
494
ibool add_newline); /*!< in: whether to add a newline */
495
/********************************************************************//**
496
Displays the names of the index and the table. */
499
dict_index_name_print(
500
/*==================*/
501
FILE* file, /*!< in: output stream */
502
trx_t* trx, /*!< in: transaction */
503
const dict_index_t* index); /*!< in: index to print */
505
/********************************************************************//**
506
Gets the first index on the table (the clustered index).
507
@return index, NULL if none exists */
510
dict_table_get_first_index(
511
/*=======================*/
512
const dict_table_t* table); /*!< in: table */
513
/********************************************************************//**
514
Gets the next index on the table.
515
@return index, NULL if none left */
518
dict_table_get_next_index(
519
/*======================*/
520
const dict_index_t* index); /*!< in: index */
521
#else /* UNIV_DEBUG */
522
# define dict_table_get_first_index(table) UT_LIST_GET_FIRST((table)->indexes)
523
# define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
524
#endif /* UNIV_DEBUG */
525
#endif /* !UNIV_HOTBACKUP */
526
/********************************************************************//**
527
Check whether the index is the clustered index.
528
@return nonzero for clustered index, zero for other indexes */
533
const dict_index_t* index) /*!< in: index */
534
__attribute__((pure));
535
/********************************************************************//**
536
Check whether the index is unique.
537
@return nonzero for unique index, zero for other indexes */
540
dict_index_is_unique(
541
/*=================*/
542
const dict_index_t* index) /*!< in: index */
543
__attribute__((pure));
544
/********************************************************************//**
545
Check whether the index is the insert buffer tree.
546
@return nonzero for insert buffer, zero for other indexes */
551
const dict_index_t* index) /*!< in: index */
552
__attribute__((pure));
553
/********************************************************************//**
554
Check whether the index is a secondary index or the insert buffer tree.
555
@return nonzero for insert buffer, zero for other indexes */
558
dict_index_is_sec_or_ibuf(
559
/*======================*/
560
const dict_index_t* index) /*!< in: index */
561
__attribute__((pure));
563
/********************************************************************//**
564
Gets the number of user-defined columns in a table in the dictionary
566
@return number of user-defined (e.g., not ROW_ID) columns of a table */
569
dict_table_get_n_user_cols(
570
/*=======================*/
571
const dict_table_t* table); /*!< in: table */
572
/********************************************************************//**
573
Gets the number of system columns in a table in the dictionary cache.
574
@return number of system (e.g., ROW_ID) columns of a table */
577
dict_table_get_n_sys_cols(
578
/*======================*/
579
const dict_table_t* table); /*!< in: table */
580
/********************************************************************//**
581
Gets the number of all columns (also system) in a table in the dictionary
583
@return number of columns of a table */
586
dict_table_get_n_cols(
587
/*==================*/
588
const dict_table_t* table); /*!< in: table */
590
/********************************************************************//**
591
Gets the nth column of a table.
592
@return pointer to column object */
595
dict_table_get_nth_col(
596
/*===================*/
597
const dict_table_t* table, /*!< in: table */
598
ulint pos); /*!< in: position of column */
599
/********************************************************************//**
600
Gets the given system column of a table.
601
@return pointer to column object */
604
dict_table_get_sys_col(
605
/*===================*/
606
const dict_table_t* table, /*!< in: table */
607
ulint sys); /*!< in: DATA_ROW_ID, ... */
608
#else /* UNIV_DEBUG */
609
#define dict_table_get_nth_col(table, pos) \
610
((table)->cols + (pos))
611
#define dict_table_get_sys_col(table, sys) \
612
((table)->cols + (table)->n_cols + (sys) - DATA_N_SYS_COLS)
613
#endif /* UNIV_DEBUG */
614
/********************************************************************//**
615
Gets the given system column number of a table.
616
@return column number */
619
dict_table_get_sys_col_no(
620
/*======================*/
621
const dict_table_t* table, /*!< in: table */
622
ulint sys); /*!< in: DATA_ROW_ID, ... */
623
#ifndef UNIV_HOTBACKUP
624
/********************************************************************//**
625
Returns the minimum data size of an index record.
626
@return minimum data size in bytes */
629
dict_index_get_min_size(
630
/*====================*/
631
const dict_index_t* index); /*!< in: index */
632
#endif /* !UNIV_HOTBACKUP */
633
/********************************************************************//**
634
Check whether the table uses the compact page format.
635
@return TRUE if table uses the compact page format */
640
const dict_table_t* table); /*!< in: table */
641
/********************************************************************//**
642
Determine the file format of a table.
643
@return file format version */
646
dict_table_get_format(
647
/*==================*/
648
const dict_table_t* table); /*!< in: table */
649
/********************************************************************//**
650
Set the file format of a table. */
653
dict_table_set_format(
654
/*==================*/
655
dict_table_t* table, /*!< in/out: table */
656
ulint format);/*!< in: file format version */
657
/********************************************************************//**
658
Extract the compressed page size from table flags.
659
@return compressed page size, or 0 if not compressed */
662
dict_table_flags_to_zip_size(
663
/*=========================*/
664
ulint flags) /*!< in: flags */
665
__attribute__((const));
666
/********************************************************************//**
667
Check whether the table uses the compressed compact page format.
668
@return compressed page size, or 0 if not compressed */
673
const dict_table_t* table); /*!< in: table */
674
/********************************************************************//**
675
Checks if a column is in the ordering columns of the clustered index of a
676
table. Column prefixes are treated like whole columns.
677
@return TRUE if the column, or its prefix, is in the clustered key */
680
dict_table_col_in_clustered_key(
681
/*============================*/
682
const dict_table_t* table, /*!< in: table */
683
ulint n); /*!< in: column number */
684
#ifndef UNIV_HOTBACKUP
685
/*******************************************************************//**
686
Copies types of columns contained in table to tuple and sets all
687
fields of the tuple to the SQL NULL value. This function should
688
be called right after dtuple_create(). */
691
dict_table_copy_types(
692
/*==================*/
693
dtuple_t* tuple, /*!< in/out: data tuple */
694
const dict_table_t* table); /*!< in: table */
695
/**********************************************************************//**
696
Looks for an index with the given id. NOTE that we do not reserve
697
the dictionary mutex: this function is for emergency purposes like
698
printing info of a corrupt database page!
699
@return index or NULL if not found from cache */
702
dict_index_find_on_id_low(
703
/*======================*/
704
dulint id); /*!< in: index id */
705
/**********************************************************************//**
706
Adds an index to the dictionary cache.
707
@return DB_SUCCESS or error code */
710
dict_index_add_to_cache(
711
/*====================*/
712
dict_table_t* table, /*!< in: table on which the index is */
713
dict_index_t* index, /*!< in, own: index; NOTE! The index memory
714
object is freed in this function! */
715
ulint page_no,/*!< in: root page number of the index */
716
ibool strict);/*!< in: TRUE=refuse to create the index
717
if records could be too big to fit in
719
#endif /* !UNIV_HOTBACKUP */
720
/********************************************************************//**
721
Gets the number of fields in the internal representation of an index,
722
including fields added by the dictionary system.
723
@return number of fields */
726
dict_index_get_n_fields(
727
/*====================*/
728
const dict_index_t* index); /*!< in: an internal
729
representation of index (in
730
the dictionary cache) */
731
/********************************************************************//**
732
Gets the number of fields in the internal representation of an index
733
that uniquely determine the position of an index entry in the index, if
734
we do not take multiversioning into account: in the B-tree use the value
735
returned by dict_index_get_n_unique_in_tree.
736
@return number of fields */
739
dict_index_get_n_unique(
740
/*====================*/
741
const dict_index_t* index); /*!< in: an internal representation
742
of index (in the dictionary cache) */
743
/********************************************************************//**
744
Gets the number of fields in the internal representation of an index
745
which uniquely determine the position of an index entry in the index, if
746
we also take multiversioning into account.
747
@return number of fields */
750
dict_index_get_n_unique_in_tree(
751
/*============================*/
752
const dict_index_t* index); /*!< in: an internal representation
753
of index (in the dictionary cache) */
754
/********************************************************************//**
755
Gets the number of user-defined ordering fields in the index. In the internal
756
representation we add the row id to the ordering fields to make all indexes
757
unique, but this function returns the number of fields the user defined
758
in the index as ordering fields.
759
@return number of fields */
762
dict_index_get_n_ordering_defined_by_user(
763
/*======================================*/
764
const dict_index_t* index); /*!< in: an internal representation
765
of index (in the dictionary cache) */
767
/********************************************************************//**
768
Gets the nth field of an index.
769
@return pointer to field object */
772
dict_index_get_nth_field(
773
/*=====================*/
774
const dict_index_t* index, /*!< in: index */
775
ulint pos); /*!< in: position of field */
776
#else /* UNIV_DEBUG */
777
# define dict_index_get_nth_field(index, pos) ((index)->fields + (pos))
778
#endif /* UNIV_DEBUG */
779
/********************************************************************//**
780
Gets pointer to the nth column in an index.
784
dict_index_get_nth_col(
785
/*===================*/
786
const dict_index_t* index, /*!< in: index */
787
ulint pos); /*!< in: position of the field */
788
/********************************************************************//**
789
Gets the column number of the nth field in an index.
790
@return column number */
793
dict_index_get_nth_col_no(
794
/*======================*/
795
const dict_index_t* index, /*!< in: index */
796
ulint pos); /*!< in: position of the field */
797
/********************************************************************//**
798
Looks for column n in an index.
799
@return position in internal representation of the index;
800
ULINT_UNDEFINED if not contained */
803
dict_index_get_nth_col_pos(
804
/*=======================*/
805
const dict_index_t* index, /*!< in: index */
806
ulint n); /*!< in: column number */
807
/********************************************************************//**
808
Returns TRUE if the index contains a column or a prefix of that column.
809
@return TRUE if contains the column or its prefix */
812
dict_index_contains_col_or_prefix(
813
/*==============================*/
814
const dict_index_t* index, /*!< in: index */
815
ulint n); /*!< in: column number */
816
/********************************************************************//**
817
Looks for a matching field in an index. The column has to be the same. The
818
column in index must be complete, or must contain a prefix longer than the
819
column in index2. That is, we must be able to construct the prefix in index2
820
from the prefix in index.
821
@return position in internal representation of the index;
822
ULINT_UNDEFINED if not contained */
825
dict_index_get_nth_field_pos(
826
/*=========================*/
827
const dict_index_t* index, /*!< in: index from which to search */
828
const dict_index_t* index2, /*!< in: index */
829
ulint n); /*!< in: field number in index2 */
830
/********************************************************************//**
831
Looks for column n position in the clustered index.
832
@return position in internal representation of the clustered index */
835
dict_table_get_nth_col_pos(
836
/*=======================*/
837
const dict_table_t* table, /*!< in: table */
838
ulint n); /*!< in: column number */
839
/********************************************************************//**
840
Returns the position of a system column in an index.
841
@return position, ULINT_UNDEFINED if not contained */
844
dict_index_get_sys_col_pos(
845
/*=======================*/
846
const dict_index_t* index, /*!< in: index */
847
ulint type); /*!< in: DATA_ROW_ID, ... */
848
/*******************************************************************//**
849
Adds a column to index. */
854
dict_index_t* index, /*!< in/out: index */
855
const dict_table_t* table, /*!< in: table */
856
dict_col_t* col, /*!< in: column */
857
ulint prefix_len); /*!< in: column prefix length */
858
#ifndef UNIV_HOTBACKUP
859
/*******************************************************************//**
860
Copies types of fields contained in index to tuple. */
863
dict_index_copy_types(
864
/*==================*/
865
dtuple_t* tuple, /*!< in/out: data tuple */
866
const dict_index_t* index, /*!< in: index */
867
ulint n_fields); /*!< in: number of
868
field types to copy */
869
#endif /* !UNIV_HOTBACKUP */
870
/*********************************************************************//**
871
Gets the field column.
872
@return field->col, pointer to the table column */
877
const dict_field_t* field); /*!< in: index field */
878
#ifndef UNIV_HOTBACKUP
879
/**********************************************************************//**
880
Returns an index object if it is found in the dictionary cache.
881
Assumes that dict_sys->mutex is already being held.
882
@return index, NULL if not found */
885
dict_index_get_if_in_cache_low(
886
/*===========================*/
887
dulint index_id); /*!< in: index id */
888
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
889
/**********************************************************************//**
890
Returns an index object if it is found in the dictionary cache.
891
@return index, NULL if not found */
894
dict_index_get_if_in_cache(
895
/*=======================*/
896
dulint index_id); /*!< in: index id */
897
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
899
/**********************************************************************//**
900
Checks that a tuple has n_fields_cmp value in a sensible range, so that
901
no comparison can occur with the page number field in a node pointer.
902
@return TRUE if ok */
905
dict_index_check_search_tuple(
906
/*==========================*/
907
const dict_index_t* index, /*!< in: index tree */
908
const dtuple_t* tuple); /*!< in: tuple used in a search */
909
/**********************************************************************//**
910
Check for duplicate index entries in a table [using the index name] */
913
dict_table_check_for_dup_indexes(
914
/*=============================*/
915
const dict_table_t* table); /*!< in: Check for dup indexes
918
#endif /* UNIV_DEBUG */
919
/**********************************************************************//**
920
Builds a node pointer out of a physical record and a page number.
921
@return own: node pointer */
924
dict_index_build_node_ptr(
925
/*======================*/
926
const dict_index_t* index, /*!< in: index */
927
const rec_t* rec, /*!< in: record for which to build node
929
ulint page_no,/*!< in: page number to put in node
931
mem_heap_t* heap, /*!< in: memory heap where pointer
933
ulint level); /*!< in: level of rec in tree:
934
0 means leaf level */
935
/**********************************************************************//**
936
Copies an initial segment of a physical record, long enough to specify an
937
index entry uniquely.
938
@return pointer to the prefix record */
941
dict_index_copy_rec_order_prefix(
942
/*=============================*/
943
const dict_index_t* index, /*!< in: index */
944
const rec_t* rec, /*!< in: record for which to
946
ulint* n_fields,/*!< out: number of fields copied */
947
byte** buf, /*!< in/out: memory buffer for the
948
copied prefix, or NULL */
949
ulint* buf_size);/*!< in/out: buffer size */
950
/**********************************************************************//**
951
Builds a typed data tuple out of a physical record.
952
@return own: data tuple */
955
dict_index_build_data_tuple(
956
/*========================*/
957
dict_index_t* index, /*!< in: index */
958
rec_t* rec, /*!< in: record for which to build data tuple */
959
ulint n_fields,/*!< in: number of data fields */
960
mem_heap_t* heap); /*!< in: memory heap where tuple created */
961
/*********************************************************************//**
962
Gets the space id of the root of the index tree.
966
dict_index_get_space(
967
/*=================*/
968
const dict_index_t* index); /*!< in: index */
969
/*********************************************************************//**
970
Sets the space id of the root of the index tree. */
973
dict_index_set_space(
974
/*=================*/
975
dict_index_t* index, /*!< in/out: index */
976
ulint space); /*!< in: space id */
977
/*********************************************************************//**
978
Gets the page number of the root of the index tree.
979
@return page number */
984
const dict_index_t* tree); /*!< in: index */
985
/*********************************************************************//**
986
Sets the page number of the root of index tree. */
991
dict_index_t* index, /*!< in/out: index */
992
ulint page); /*!< in: page number */
993
/*********************************************************************//**
994
Gets the read-write lock of the index tree.
995
@return read-write lock */
1000
dict_index_t* index); /*!< in: index */
1001
/********************************************************************//**
1002
Returns free space reserved for future updates of records. This is
1003
relevant only in the case of many consecutive inserts, as updates
1004
which make the records bigger might fragment the index.
1005
@return number of free bytes on page, reserved for updates */
1008
dict_index_get_space_reserve(void);
1009
/*==============================*/
1010
/*********************************************************************//**
1011
Calculates the minimum record length in an index. */
1014
dict_index_calc_min_rec_len(
1015
/*========================*/
1016
const dict_index_t* index); /*!< in: index */
1017
/*********************************************************************//**
1018
Calculates new estimates for table and index statistics. The statistics
1019
are used in query optimization. */
1022
dict_update_statistics_low(
1023
/*=======================*/
1024
dict_table_t* table, /*!< in/out: table */
1025
ibool has_dict_mutex);/*!< in: TRUE if the caller has the
1027
/*********************************************************************//**
1028
Calculates new estimates for table and index statistics. The statistics
1029
are used in query optimization. */
1032
dict_update_statistics(
1033
/*===================*/
1034
dict_table_t* table); /*!< in/out: table */
1035
/********************************************************************//**
1036
Reserves the dictionary system mutex for MySQL. */
1039
dict_mutex_enter_for_mysql(void);
1040
/*============================*/
1041
/********************************************************************//**
1042
Releases the dictionary system mutex for MySQL. */
1045
dict_mutex_exit_for_mysql(void);
1046
/*===========================*/
1047
/********************************************************************//**
1048
Checks if the database name in two table names is the same.
1049
@return TRUE if same db name */
1052
dict_tables_have_same_db(
1053
/*=====================*/
1054
const char* name1, /*!< in: table name in the form
1055
dbname '/' tablename */
1056
const char* name2); /*!< in: table name in the form
1057
dbname '/' tablename */
1058
/*********************************************************************//**
1059
Removes an index from the cache */
1062
dict_index_remove_from_cache(
1063
/*=========================*/
1064
dict_table_t* table, /*!< in/out: table */
1065
dict_index_t* index); /*!< in, own: index */
1066
/**********************************************************************//**
1068
@return index, NULL if does not exist */
1071
dict_table_get_index_on_name(
1072
/*=========================*/
1073
dict_table_t* table, /*!< in: table */
1074
const char* name); /*!< in: name of the index to find */
1075
/**********************************************************************//**
1076
In case there is more than one index with the same name return the index
1078
@return index, NULL if does not exist */
1081
dict_table_get_index_on_name_and_min_id(
1082
/*====================================*/
1083
dict_table_t* table, /*!< in: table */
1084
const char* name); /*!< in: name of the index to find */
1085
/* Buffers for storing detailed information about the latest foreign key
1086
and unique key errors */
1087
extern FILE* dict_foreign_err_file;
1088
extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */
1090
/** the dictionary system */
1091
extern dict_sys_t* dict_sys;
1092
/** the data dictionary rw-latch protecting dict_sys */
1093
extern rw_lock_t dict_operation_lock;
1095
/* Dictionary system struct */
1096
struct dict_sys_struct{
1097
mutex_t mutex; /*!< mutex protecting the data
1098
dictionary; protects also the
1099
disk-based dictionary system tables;
1100
this mutex serializes CREATE TABLE
1101
and DROP TABLE, as well as reading
1102
the dictionary data for a table from
1104
dulint row_id; /*!< the next row id to assign;
1105
NOTE that at a checkpoint this
1106
must be written to the dict system
1107
header and flushed to a file; in
1108
recovery this must be derived from
1110
hash_table_t* table_hash; /*!< hash table of the tables, based
1112
hash_table_t* table_id_hash; /*!< hash table of the tables, based
1114
UT_LIST_BASE_NODE_T(dict_table_t)
1115
table_LRU; /*!< LRU list of tables */
1116
ulint size; /*!< varying space in bytes occupied
1117
by the data dictionary table and
1119
dict_table_t* sys_tables; /*!< SYS_TABLES table */
1120
dict_table_t* sys_columns; /*!< SYS_COLUMNS table */
1121
dict_table_t* sys_indexes; /*!< SYS_INDEXES table */
1122
dict_table_t* sys_fields; /*!< SYS_FIELDS table */
1124
#endif /* !UNIV_HOTBACKUP */
1126
/** dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records */
1127
extern dict_index_t* dict_ind_redundant;
1128
/** dummy index for ROW_FORMAT=COMPACT supremum and infimum records */
1129
extern dict_index_t* dict_ind_compact;
1131
/**********************************************************************//**
1132
Inits dict_ind_redundant and dict_ind_compact. */
1135
dict_ind_init(void);
1139
#include "dict0dict.ic"