1
/******************************************************
6
Created 1/8/1996 Heikki Tuuri
7
*******************************************************/
13
#include "dict0types.h"
15
#include "data0type.h"
16
#include "data0data.h"
17
#include "sync0sync.h"
20
#include "rem0types.h"
21
#include "btr0types.h"
24
#include "hash0hash.h"
27
#include "trx0types.h"
29
#ifndef UNIV_HOTBACKUP
30
/**********************************************************************
31
Makes all characters in a NUL-terminated UTF-8 string lower case. */
36
char* a); /* in/out: string to put in lower case */
37
#endif /* !UNIV_HOTBACKUP */
38
/************************************************************************
39
Get the database name length in a table name. */
44
/* out: database name length */
45
const char* name); /* in: table name in the form
46
dbname '/' tablename */
47
/************************************************************************
48
Return the end of table name where we have removed dbname and '/'. */
54
const char* name); /* in: table name in the form
55
dbname '/' tablename */
56
/**************************************************************************
57
Returns a table object based on table id. */
62
/* out: table, NULL if does not exist */
63
dulint table_id, /* in: table id */
64
trx_t* trx); /* in: transaction handle */
65
/************************************************************************
66
Decrements the count of open MySQL handles to a table. */
69
dict_table_decrement_handle_count(
70
/*==============================*/
71
dict_table_t* table, /* in/out: table */
72
ibool dict_locked); /* in: TRUE=data dictionary locked */
73
/**************************************************************************
74
Inits the data dictionary module. */
79
/************************************************************************
80
Gets the space id of every table of the data dictionary and makes a linear
81
list and a hash table of them to the data dictionary cache. This function
82
can be called at database startup if we did not need to do a crash recovery.
83
In crash recovery we must scan the space id's from the .ibd files in MySQL
84
database directories. */
87
dict_load_space_id_list(void);
88
/*=========================*/
89
/*************************************************************************
90
Gets the column data type. */
95
const dict_col_t* col, /* in: column */
96
dtype_t* type); /* out: data type */
98
/*************************************************************************
99
Assert that a column and a data type match. */
102
dict_col_type_assert_equal(
103
/*=======================*/
105
const dict_col_t* col, /* in: column */
106
const dtype_t* type); /* in: data type */
107
#endif /* UNIV_DEBUG */
108
/***************************************************************************
109
Returns the minimum size of the column. */
112
dict_col_get_min_size(
113
/*==================*/
114
/* out: minimum size */
115
const dict_col_t* col); /* in: column */
116
/***************************************************************************
117
Returns the maximum size of the column. */
120
dict_col_get_max_size(
121
/*==================*/
122
/* out: maximum size */
123
const dict_col_t* col); /* in: column */
124
/***************************************************************************
125
Returns the size of a fixed size column, 0 if not a fixed size column. */
128
dict_col_get_fixed_size(
129
/*====================*/
130
/* out: fixed size, or 0 */
131
const dict_col_t* col); /* in: column */
132
/***************************************************************************
133
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
134
For fixed length types it is the fixed length of the type, otherwise 0. */
137
dict_col_get_sql_null_size(
138
/*=======================*/
139
/* out: SQL null storage size
140
in ROW_FORMAT=REDUNDANT */
141
const dict_col_t* col); /* in: column */
143
/*************************************************************************
144
Gets the column number. */
149
const dict_col_t* col);
150
/*************************************************************************
151
Gets the column position in the clustered index. */
154
dict_col_get_clust_pos(
155
/*===================*/
156
const dict_col_t* col, /* in: table column */
157
const dict_index_t* clust_index); /* in: clustered index */
158
/********************************************************************
159
If the given column name is reserved for InnoDB system columns, return
163
dict_col_name_is_reserved(
164
/*======================*/
165
/* out: TRUE if name is reserved */
166
const char* name); /* in: column name */
167
/************************************************************************
168
Acquire the autoinc lock.*/
171
dict_table_autoinc_lock(
172
/*====================*/
173
dict_table_t* table); /* in/out: table */
174
/************************************************************************
175
Unconditionally set the autoinc counter. */
178
dict_table_autoinc_initialize(
179
/*==========================*/
180
dict_table_t* table, /* in/out: table */
181
ib_uint64_t value); /* in: next value to assign to a row */
182
/************************************************************************
183
Reads the next autoinc value (== autoinc counter value), 0 if not yet
187
dict_table_autoinc_read(
188
/*====================*/
189
/* out: value for a new row, or 0 */
190
const dict_table_t* table); /* in: table */
191
/************************************************************************
192
Updates the autoinc counter if the value supplied is greater than the
196
dict_table_autoinc_update_if_greater(
197
/*=================================*/
199
dict_table_t* table, /* in/out: table */
200
ib_uint64_t value); /* in: value which was assigned to a row */
201
/************************************************************************
202
Release the autoinc lock.*/
205
dict_table_autoinc_unlock(
206
/*======================*/
207
dict_table_t* table); /* in/out: table */
208
/**************************************************************************
209
Adds system columns to a table object. */
212
dict_table_add_system_columns(
213
/*==========================*/
214
dict_table_t* table, /* in/out: table */
215
mem_heap_t* heap); /* in: temporary heap */
216
/**************************************************************************
217
Adds a table object to the dictionary cache. */
220
dict_table_add_to_cache(
221
/*====================*/
222
dict_table_t* table, /* in: table */
223
mem_heap_t* heap); /* in: temporary heap */
224
/**************************************************************************
225
Removes a table object from the dictionary cache. */
228
dict_table_remove_from_cache(
229
/*=========================*/
230
dict_table_t* table); /* in, own: table */
231
/**************************************************************************
232
Renames a table object. */
235
dict_table_rename_in_cache(
236
/*=======================*/
237
/* out: TRUE if success */
238
dict_table_t* table, /* in/out: table */
239
const char* new_name, /* in: new name */
240
ibool rename_also_foreigns);/* in: in ALTER TABLE we want
241
to preserve the original table name
242
in constraints which reference it */
243
/**************************************************************************
244
Change the id of a table object in the dictionary cache. This is used in
245
DISCARD TABLESPACE. */
248
dict_table_change_id_in_cache(
249
/*==========================*/
250
dict_table_t* table, /* in/out: table object already in cache */
251
dulint new_id);/* in: new id to set */
252
/**************************************************************************
253
Adds a foreign key constraint object to the dictionary cache. May free
254
the object if there already is an object with the same identifier in.
255
At least one of foreign table or referenced table must already be in
256
the dictionary cache! */
259
dict_foreign_add_to_cache(
260
/*======================*/
261
/* out: DB_SUCCESS or error code */
262
dict_foreign_t* foreign, /* in, own: foreign key constraint */
263
ibool check_charsets);/* in: TRUE=check charset
265
/*************************************************************************
266
Check if the index is referenced by a foreign key, if TRUE return the
267
matching instance NULL otherwise. */
270
dict_table_get_referenced_constraint(
271
/*=================================*/
272
/* out: pointer to foreign key struct if index
273
is defined for foreign key, otherwise NULL */
274
dict_table_t* table, /* in: InnoDB table */
275
dict_index_t* index); /* in: InnoDB index */
276
/*************************************************************************
277
Checks if a table is referenced by foreign keys. */
280
dict_table_is_referenced_by_foreign_key(
281
/*====================================*/
282
/* out: TRUE if table is referenced
284
const dict_table_t* table); /* in: InnoDB table */
285
/**************************************************************************
286
Replace the index in the foreign key list that matches this index's
287
definition with an equivalent index. */
290
dict_table_replace_index_in_foreign_list(
291
/*=====================================*/
292
dict_table_t* table, /* in/out: table */
293
dict_index_t* index); /* in: index to be replaced */
294
/*************************************************************************
295
Checks if a index is defined for a foreign key constraint. Index is a part
296
of a foreign key constraint if the index is referenced by foreign key
297
or index is a foreign key index */
300
dict_table_get_foreign_constraint(
301
/*==============================*/
302
/* out: pointer to foreign key struct if index
303
is defined for foreign key, otherwise NULL */
304
dict_table_t* table, /* in: InnoDB table */
305
dict_index_t* index); /* in: InnoDB index */
306
/*************************************************************************
307
Scans a table create SQL string and adds to the data dictionary
308
the foreign key constraints declared in the string. This function
309
should be called after the indexes for a table have been created.
310
Each foreign key constraint must be accompanied with indexes in
311
bot participating tables. The indexes are allowed to contain more
312
fields than mentioned in the constraint. */
315
dict_create_foreign_constraints(
316
/*============================*/
317
/* out: error code or DB_SUCCESS */
318
trx_t* trx, /* in: transaction */
319
const char* sql_string, /* in: table create statement where
320
foreign keys are declared like:
321
FOREIGN KEY (a, b) REFERENCES
322
table2(c, d), table2 can be written
323
also with the database
324
name before it: test.table2; the
325
default database id the database of
327
const char* name, /* in: table full name in the
329
database_name/table_name */
330
ibool reject_fks); /* in: if TRUE, fail with error
331
code DB_CANNOT_ADD_CONSTRAINT if
332
any foreign keys are found. */
333
/**************************************************************************
334
Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. */
337
dict_foreign_parse_drop_constraints(
338
/*================================*/
339
/* out: DB_SUCCESS or
340
DB_CANNOT_DROP_CONSTRAINT if
341
syntax error or the constraint
343
mem_heap_t* heap, /* in: heap from which we can
345
trx_t* trx, /* in: transaction */
346
dict_table_t* table, /* in: table */
347
ulint* n, /* out: number of constraints
349
const char*** constraints_to_drop); /* out: id's of the
350
constraints to drop */
351
/**************************************************************************
352
Returns a table object and optionally increment its MySQL open handle count.
353
NOTE! This is a high-level function to be used mainly from outside the
354
'dict' directory. Inside this directory dict_table_get_low is usually the
355
appropriate function. */
360
/* out: table, NULL if
362
const char* table_name, /* in: table name */
363
ibool inc_mysql_count);
364
/* in: whether to increment the open
365
handle count on the table */
366
/**************************************************************************
367
Returns a index object, based on table and index id, and memoryfixes it. */
370
dict_index_get_on_id_low(
371
/*=====================*/
372
/* out: index, NULL if does not
374
dict_table_t* table, /* in: table */
375
dulint index_id); /* in: index id */
376
/**************************************************************************
377
Checks if a table is in the dictionary cache. */
381
dict_table_check_if_in_cache_low(
382
/*=============================*/
383
/* out: table, NULL if not found */
384
const char* table_name); /* in: table name */
385
/**************************************************************************
386
Gets a table; loads it to the dictionary cache if necessary. A low-level
392
/* out: table, NULL if not found */
393
const char* table_name); /* in: table name */
394
/**************************************************************************
395
Returns a table object based on table id. */
398
dict_table_get_on_id_low(
399
/*=====================*/
400
/* out: table, NULL if does not exist */
401
dulint table_id); /* in: table id */
402
/**************************************************************************
403
Find an index that is equivalent to the one passed in and is not marked
407
dict_foreign_find_equiv_index(
408
/*==========================*/
409
/* out: index equivalent to
410
foreign->foreign_index, or NULL */
411
dict_foreign_t* foreign);/* in: foreign key */
412
/**************************************************************************
413
Returns an index object by matching on the name and column names and if
414
more than index is found return the index with the higher id.*/
417
dict_table_get_index_by_max_id(
418
/*===========================*/
419
/* out: matching index, NULL if not found */
420
dict_table_t* table, /* in: table */
421
const char* name, /* in: the index name to find */
422
const char** columns,/* in: array of column names */
423
ulint n_cols);/* in: number of columns */
424
/**************************************************************************
425
Returns a column's name. */
428
dict_table_get_col_name(
429
/*====================*/
430
/* out: column name. NOTE: not
431
guaranteed to stay valid if table is
432
modified in any way (columns added,
434
const dict_table_t* table, /* in: table */
435
ulint col_nr);/* in: column number */
437
/**************************************************************************
438
Prints a table definition. */
443
dict_table_t* table); /* in: table */
444
/**************************************************************************
445
Prints a table data. */
448
dict_table_print_low(
449
/*=================*/
450
dict_table_t* table); /* in: table */
451
/**************************************************************************
452
Prints a table data when we know the table name. */
455
dict_table_print_by_name(
456
/*=====================*/
458
/**************************************************************************
459
Outputs info on foreign keys of a table. */
462
dict_print_info_on_foreign_keys(
463
/*============================*/
464
ibool create_table_format, /* in: if TRUE then print in
465
a format suitable to be inserted into
466
a CREATE TABLE, otherwise in the format
467
of SHOW TABLE STATUS */
468
FILE* file, /* in: file where to print */
469
trx_t* trx, /* in: transaction */
470
dict_table_t* table); /* in: table */
471
/**************************************************************************
472
Outputs info on a foreign key of a table in a format suitable for
476
dict_print_info_on_foreign_key_in_create_format(
477
/*============================================*/
478
FILE* file, /* in: file where to print */
479
trx_t* trx, /* in: transaction */
480
dict_foreign_t* foreign, /* in: foreign key constraint */
481
ibool add_newline); /* in: whether to add a newline */
482
/************************************************************************
483
Displays the names of the index and the table. */
486
dict_index_name_print(
487
/*==================*/
488
FILE* file, /* in: output stream */
489
trx_t* trx, /* in: transaction */
490
const dict_index_t* index); /* in: index to print */
492
/************************************************************************
493
Gets the first index on the table (the clustered index). */
496
dict_table_get_first_index(
497
/*=======================*/
498
/* out: index, NULL if none exists */
499
const dict_table_t* table); /* in: table */
500
/************************************************************************
501
Gets the next index on the table. */
504
dict_table_get_next_index(
505
/*======================*/
506
/* out: index, NULL if none left */
507
const dict_index_t* index); /* in: index */
508
#else /* UNIV_DEBUG */
509
# define dict_table_get_first_index(table) UT_LIST_GET_FIRST((table)->indexes)
510
# define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
511
#endif /* UNIV_DEBUG */
512
/************************************************************************
513
Check whether the index is the clustered index. */
518
/* out: nonzero for clustered index,
519
zero for other indexes */
520
const dict_index_t* index) /* in: index */
521
__attribute__((pure));
522
/************************************************************************
523
Check whether the index is unique. */
526
dict_index_is_unique(
527
/*=================*/
528
/* out: nonzero for unique index,
529
zero for other indexes */
530
const dict_index_t* index) /* in: index */
531
__attribute__((pure));
532
/************************************************************************
533
Check whether the index is the insert buffer tree. */
538
/* out: nonzero for insert buffer,
539
zero for other indexes */
540
const dict_index_t* index) /* in: index */
541
__attribute__((pure));
543
/************************************************************************
544
Gets the number of user-defined columns in a table in the dictionary
548
dict_table_get_n_user_cols(
549
/*=======================*/
550
/* out: number of user-defined
552
columns of a table */
553
const dict_table_t* table); /* in: table */
554
/************************************************************************
555
Gets the number of system columns in a table in the dictionary cache. */
558
dict_table_get_n_sys_cols(
559
/*======================*/
560
/* out: number of system (e.g.,
561
ROW_ID) columns of a table */
562
const dict_table_t* table); /* in: table */
563
/************************************************************************
564
Gets the number of all columns (also system) in a table in the dictionary
568
dict_table_get_n_cols(
569
/*==================*/
570
/* out: number of columns of a table */
571
const dict_table_t* table); /* in: table */
573
/************************************************************************
574
Gets the nth column of a table. */
577
dict_table_get_nth_col(
578
/*===================*/
579
/* out: pointer to column object */
580
const dict_table_t* table, /* in: table */
581
ulint pos); /* in: position of column */
582
/************************************************************************
583
Gets the given system column of a table. */
586
dict_table_get_sys_col(
587
/*===================*/
588
/* out: pointer to column object */
589
const dict_table_t* table, /* in: table */
590
ulint sys); /* in: DATA_ROW_ID, ... */
591
#else /* UNIV_DEBUG */
592
#define dict_table_get_nth_col(table, pos) \
593
((table)->cols + (pos))
594
#define dict_table_get_sys_col(table, sys) \
595
((table)->cols + (table)->n_cols + (sys) - DATA_N_SYS_COLS)
596
#endif /* UNIV_DEBUG */
597
/************************************************************************
598
Gets the given system column number of a table. */
601
dict_table_get_sys_col_no(
602
/*======================*/
603
/* out: column number */
604
const dict_table_t* table, /* in: table */
605
ulint sys); /* in: DATA_ROW_ID, ... */
606
/************************************************************************
607
Returns the minimum data size of an index record. */
610
dict_index_get_min_size(
611
/*====================*/
612
/* out: minimum data size in bytes */
613
const dict_index_t* index); /* in: index */
614
/************************************************************************
615
Check whether the table uses the compact page format. */
620
/* out: TRUE if table uses the
621
compact page format */
622
const dict_table_t* table); /* in: table */
623
/************************************************************************
624
Determine the file format of a table. */
627
dict_table_get_format(
628
/*==================*/
629
/* out: file format version */
630
const dict_table_t* table); /* in: table */
631
/************************************************************************
632
Set the file format of a table. */
635
dict_table_set_format(
636
/*==================*/
637
dict_table_t* table, /* in/out: table */
638
ulint format);/* in: file format version */
639
/************************************************************************
640
Extract the compressed page size from table flags. */
643
dict_table_flags_to_zip_size(
644
/*=========================*/
645
/* out: compressed page size,
646
or 0 if not compressed */
647
ulint flags) /* in: flags */
648
__attribute__((__const__));
649
/************************************************************************
650
Check whether the table uses the compressed compact page format. */
655
/* out: compressed page size,
656
or 0 if not compressed */
657
const dict_table_t* table); /* in: table */
658
/************************************************************************
659
Checks if a column is in the ordering columns of the clustered index of a
660
table. Column prefixes are treated like whole columns. */
663
dict_table_col_in_clustered_key(
664
/*============================*/
665
/* out: TRUE if the column, or its
666
prefix, is in the clustered key */
667
const dict_table_t* table, /* in: table */
668
ulint n); /* in: column number */
669
/***********************************************************************
670
Copies types of columns contained in table to tuple and sets all
671
fields of the tuple to the SQL NULL value. This function should
672
be called right after dtuple_create(). */
675
dict_table_copy_types(
676
/*==================*/
677
dtuple_t* tuple, /* in/out: data tuple */
678
const dict_table_t* table); /* in: table */
679
/**************************************************************************
680
Looks for an index with the given id. NOTE that we do not reserve
681
the dictionary mutex: this function is for emergency purposes like
682
printing info of a corrupt database page! */
685
dict_index_find_on_id_low(
686
/*======================*/
687
/* out: index or NULL if not found from cache */
688
dulint id); /* in: index id */
689
/**************************************************************************
690
Adds an index to the dictionary cache. */
693
dict_index_add_to_cache(
694
/*====================*/
695
/* out: DB_SUCCESS or error code */
696
dict_table_t* table, /* in: table on which the index is */
697
dict_index_t* index, /* in, own: index; NOTE! The index memory
698
object is freed in this function! */
699
ulint page_no,/* in: root page number of the index */
700
ibool strict);/* in: TRUE=refuse to create the index
701
if records could be too big to fit in
703
/**************************************************************************
704
Removes an index from the dictionary cache. */
707
dict_index_remove_from_cache(
708
/*=========================*/
709
dict_table_t* table, /* in/out: table */
710
dict_index_t* index); /* in, own: index */
711
/************************************************************************
712
Gets the number of fields in the internal representation of an index,
713
including fields added by the dictionary system. */
716
dict_index_get_n_fields(
717
/*====================*/
718
/* out: number of fields */
719
const dict_index_t* index); /* in: an internal
720
representation of index (in
721
the dictionary cache) */
722
/************************************************************************
723
Gets the number of fields in the internal representation of an index
724
that uniquely determine the position of an index entry in the index, if
725
we do not take multiversioning into account: in the B-tree use the value
726
returned by dict_index_get_n_unique_in_tree. */
729
dict_index_get_n_unique(
730
/*====================*/
731
/* out: number of fields */
732
const dict_index_t* index); /* in: an internal representation
733
of index (in the dictionary cache) */
734
/************************************************************************
735
Gets the number of fields in the internal representation of an index
736
which uniquely determine the position of an index entry in the index, if
737
we also take multiversioning into account. */
740
dict_index_get_n_unique_in_tree(
741
/*============================*/
742
/* out: number of fields */
743
const dict_index_t* index); /* in: an internal representation
744
of index (in the dictionary cache) */
745
/************************************************************************
746
Gets the number of user-defined ordering fields in the index. In the internal
747
representation we add the row id to the ordering fields to make all indexes
748
unique, but this function returns the number of fields the user defined
749
in the index as ordering fields. */
752
dict_index_get_n_ordering_defined_by_user(
753
/*======================================*/
754
/* out: number of fields */
755
const dict_index_t* index); /* in: an internal representation
756
of index (in the dictionary cache) */
758
/************************************************************************
759
Gets the nth field of an index. */
762
dict_index_get_nth_field(
763
/*=====================*/
764
/* out: pointer to field object */
765
const dict_index_t* index, /* in: index */
766
ulint pos); /* in: position of field */
767
#else /* UNIV_DEBUG */
768
# define dict_index_get_nth_field(index, pos) ((index)->fields + (pos))
769
#endif /* UNIV_DEBUG */
770
/************************************************************************
771
Gets pointer to the nth column in an index. */
774
dict_index_get_nth_col(
775
/*===================*/
777
const dict_index_t* index, /* in: index */
778
ulint pos); /* in: position of the field */
779
/************************************************************************
780
Gets the column number of the nth field in an index. */
783
dict_index_get_nth_col_no(
784
/*======================*/
785
/* out: column number */
786
const dict_index_t* index, /* in: index */
787
ulint pos); /* in: position of the field */
788
/************************************************************************
789
Looks for column n in an index. */
792
dict_index_get_nth_col_pos(
793
/*=======================*/
794
/* out: position in internal
795
representation of the index;
796
if not contained, returns
798
const dict_index_t* index, /* in: index */
799
ulint n); /* in: column number */
800
/************************************************************************
801
Returns TRUE if the index contains a column or a prefix of that column. */
804
dict_index_contains_col_or_prefix(
805
/*==============================*/
806
/* out: TRUE if contains the column
808
const dict_index_t* index, /* in: index */
809
ulint n); /* in: column number */
810
/************************************************************************
811
Looks for a matching field in an index. The column has to be the same. The
812
column in index must be complete, or must contain a prefix longer than the
813
column in index2. That is, we must be able to construct the prefix in index2
814
from the prefix in index. */
817
dict_index_get_nth_field_pos(
818
/*=========================*/
819
/* out: position in internal
820
representation of the index;
821
if not contained, returns
823
const dict_index_t* index, /* in: index from which to search */
824
const dict_index_t* index2, /* in: index */
825
ulint n); /* in: field number in index2 */
826
/************************************************************************
827
Looks for column n position in the clustered index. */
830
dict_table_get_nth_col_pos(
831
/*=======================*/
832
/* out: position in internal
834
the clustered index */
835
const dict_table_t* table, /* in: table */
836
ulint n); /* in: column number */
837
/************************************************************************
838
Returns the position of a system column in an index. */
841
dict_index_get_sys_col_pos(
842
/*=======================*/
844
ULINT_UNDEFINED if not contained */
845
const dict_index_t* index, /* in: index */
846
ulint type); /* in: DATA_ROW_ID, ... */
847
/***********************************************************************
848
Adds a column to index. */
853
dict_index_t* index, /* in/out: index */
854
const dict_table_t* table, /* in: table */
855
dict_col_t* col, /* in: column */
856
ulint prefix_len); /* in: column prefix length */
857
/***********************************************************************
858
Copies types of fields contained in index to tuple. */
861
dict_index_copy_types(
862
/*==================*/
863
dtuple_t* tuple, /* in/out: data tuple */
864
const dict_index_t* index, /* in: index */
865
ulint n_fields); /* in: number of
866
field types to copy */
867
/*************************************************************************
868
Gets the field column. */
873
const dict_field_t* field);
875
/**************************************************************************
876
Returns an index object if it is found in the dictionary cache.
877
Assumes that dict_sys->mutex is already being held. */
880
dict_index_get_if_in_cache_low(
881
/*===========================*/
882
/* out: index, NULL if not found */
883
dulint index_id); /* in: index id */
884
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
885
/**************************************************************************
886
Returns an index object if it is found in the dictionary cache. */
889
dict_index_get_if_in_cache(
890
/*=======================*/
891
/* out: index, NULL if not found */
892
dulint index_id); /* in: index id */
893
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
895
/**************************************************************************
896
Checks that a tuple has n_fields_cmp value in a sensible range, so that
897
no comparison can occur with the page number field in a node pointer. */
900
dict_index_check_search_tuple(
901
/*==========================*/
902
/* out: TRUE if ok */
903
const dict_index_t* index, /* in: index tree */
904
const dtuple_t* tuple); /* in: tuple used in a search */
905
/**************************************************************************
906
Check for duplicate index entries in a table [using the index name] */
909
dict_table_check_for_dup_indexes(
910
/*=============================*/
911
const dict_table_t* table); /* in: Check for dup indexes
914
#endif /* UNIV_DEBUG */
915
/**************************************************************************
916
Builds a node pointer out of a physical record and a page number. */
919
dict_index_build_node_ptr(
920
/*======================*/
921
/* out, own: node pointer */
922
const dict_index_t* index, /* in: index */
923
const rec_t* rec, /* in: record for which to build node
925
ulint page_no,/* in: page number to put in node
927
mem_heap_t* heap, /* in: memory heap where pointer
929
ulint level); /* in: level of rec in tree:
930
0 means leaf level */
931
/**************************************************************************
932
Copies an initial segment of a physical record, long enough to specify an
933
index entry uniquely. */
936
dict_index_copy_rec_order_prefix(
937
/*=============================*/
938
/* out: pointer to the prefix record */
939
const dict_index_t* index, /* in: index */
940
const rec_t* rec, /* in: record for which to
942
ulint* n_fields,/* out: number of fields copied */
943
byte** buf, /* in/out: memory buffer for the
944
copied prefix, or NULL */
945
ulint* buf_size);/* in/out: buffer size */
946
/**************************************************************************
947
Builds a typed data tuple out of a physical record. */
950
dict_index_build_data_tuple(
951
/*========================*/
952
/* out, own: data tuple */
953
dict_index_t* index, /* in: index */
954
rec_t* rec, /* in: record for which to build data tuple */
955
ulint n_fields,/* in: number of data fields */
956
mem_heap_t* heap); /* in: memory heap where tuple created */
957
/*************************************************************************
958
Gets the space id of the root of the index tree. */
961
dict_index_get_space(
962
/*=================*/
964
const dict_index_t* index); /* in: index */
965
/*************************************************************************
966
Sets the space id of the root of the index tree. */
969
dict_index_set_space(
970
/*=================*/
971
dict_index_t* index, /* in/out: index */
972
ulint space); /* in: space id */
973
/*************************************************************************
974
Gets the page number of the root of the index tree. */
979
/* out: page number */
980
const dict_index_t* tree); /* in: index */
981
/*************************************************************************
982
Sets the page number of the root of index tree. */
987
dict_index_t* index, /* in/out: index */
988
ulint page); /* in: page number */
989
/*************************************************************************
990
Gets the type of the index tree. */
996
const dict_index_t* index); /* in: index */
997
/*************************************************************************
998
Gets the read-write lock of the index tree. */
1001
dict_index_get_lock(
1002
/*================*/
1003
/* out: read-write lock */
1004
dict_index_t* index); /* in: index */
1005
/************************************************************************
1006
Returns free space reserved for future updates of records. This is
1007
relevant only in the case of many consecutive inserts, as updates
1008
which make the records bigger might fragment the index. */
1011
dict_index_get_space_reserve(void);
1012
/*==============================*/
1013
/* out: number of free bytes on page,
1014
reserved for updates */
1015
/*************************************************************************
1016
Calculates the minimum record length in an index. */
1019
dict_index_calc_min_rec_len(
1020
/*========================*/
1021
const dict_index_t* index); /* in: index */
1022
/*************************************************************************
1023
Calculates new estimates for table and index statistics. The statistics
1024
are used in query optimization. */
1027
dict_update_statistics_low(
1028
/*=======================*/
1029
dict_table_t* table, /* in/out: table */
1030
ibool has_dict_mutex);/* in: TRUE if the caller has the
1032
/*************************************************************************
1033
Calculates new estimates for table and index statistics. The statistics
1034
are used in query optimization. */
1037
dict_update_statistics(
1038
/*===================*/
1039
dict_table_t* table); /* in/out: table */
1040
/************************************************************************
1041
Reserves the dictionary system mutex for MySQL. */
1044
dict_mutex_enter_for_mysql(void);
1045
/*============================*/
1046
/************************************************************************
1047
Releases the dictionary system mutex for MySQL. */
1050
dict_mutex_exit_for_mysql(void);
1051
/*===========================*/
1052
/************************************************************************
1053
Checks if the database name in two table names is the same. */
1056
dict_tables_have_same_db(
1057
/*=====================*/
1058
/* out: TRUE if same db name */
1059
const char* name1, /* in: table name in the form
1060
dbname '/' tablename */
1061
const char* name2); /* in: table name in the form
1062
dbname '/' tablename */
1063
/**************************************************************************
1064
Get index by name */
1067
dict_table_get_index_on_name(
1068
/*=========================*/
1069
/* out: index, NULL if does not exist */
1070
dict_table_t* table, /* in: table */
1071
const char* name); /* in: name of the index to find */
1072
/**************************************************************************
1073
In case there is more than one index with the same name return the index
1074
with the min(id). */
1077
dict_table_get_index_on_name_and_min_id(
1078
/*====================================*/
1079
/* out: index, NULL if does not exist */
1080
dict_table_t* table, /* in: table */
1081
const char* name); /* in: name of the index to find */
1082
/* Buffers for storing detailed information about the latest foreign key
1083
and unique key errors */
1084
extern FILE* dict_foreign_err_file;
1085
extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */
1087
extern dict_sys_t* dict_sys; /* the dictionary system */
1088
extern rw_lock_t dict_operation_lock;
1090
/* Dictionary system struct */
1091
struct dict_sys_struct{
1092
mutex_t mutex; /* mutex protecting the data
1093
dictionary; protects also the
1094
disk-based dictionary system tables;
1095
this mutex serializes CREATE TABLE
1096
and DROP TABLE, as well as reading
1097
the dictionary data for a table from
1099
dulint row_id; /* the next row id to assign;
1100
NOTE that at a checkpoint this
1101
must be written to the dict system
1102
header and flushed to a file; in
1103
recovery this must be derived from
1105
hash_table_t* table_hash; /* hash table of the tables, based
1107
hash_table_t* table_id_hash; /* hash table of the tables, based
1109
UT_LIST_BASE_NODE_T(dict_table_t)
1110
table_LRU; /* LRU list of tables */
1111
ulint size; /* varying space in bytes occupied
1112
by the data dictionary table and
1114
dict_table_t* sys_tables; /* SYS_TABLES table */
1115
dict_table_t* sys_columns; /* SYS_COLUMNS table */
1116
dict_table_t* sys_indexes; /* SYS_INDEXES table */
1117
dict_table_t* sys_fields; /* SYS_FIELDS table */
1121
#include "dict0dict.ic"