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
Initializes the autoinc counter. It is not an error to initialize an already
176
initialized counter. */
179
dict_table_autoinc_initialize(
180
/*==========================*/
181
dict_table_t* table, /* in/out: table */
182
ib_uint64_t value); /* in: next value to assign to a row */
183
/************************************************************************
184
Reads the next autoinc value (== autoinc counter value), 0 if not yet
188
dict_table_autoinc_read(
189
/*====================*/
190
/* out: value for a new row, or 0 */
191
const dict_table_t* table); /* in: table */
192
/************************************************************************
193
Updates the autoinc counter if the value supplied is equal or bigger than the
194
current value. If not inited, does nothing. */
197
dict_table_autoinc_update(
198
/*======================*/
200
dict_table_t* table, /* in/out: table */
201
ib_uint64_t value); /* in: value which was assigned to a row */
202
/************************************************************************
203
Release the autoinc lock.*/
206
dict_table_autoinc_unlock(
207
/*======================*/
208
dict_table_t* table); /* in/out: table */
209
/**************************************************************************
210
Adds system columns to a table object. */
213
dict_table_add_system_columns(
214
/*==========================*/
215
dict_table_t* table, /* in/out: table */
216
mem_heap_t* heap); /* in: temporary heap */
217
/**************************************************************************
218
Adds a table object to the dictionary cache. */
221
dict_table_add_to_cache(
222
/*====================*/
223
dict_table_t* table, /* in: table */
224
mem_heap_t* heap); /* in: temporary heap */
225
/**************************************************************************
226
Removes a table object from the dictionary cache. */
229
dict_table_remove_from_cache(
230
/*=========================*/
231
dict_table_t* table); /* in, own: table */
232
/**************************************************************************
233
Renames a table object. */
236
dict_table_rename_in_cache(
237
/*=======================*/
238
/* out: TRUE if success */
239
dict_table_t* table, /* in/out: table */
240
const char* new_name, /* in: new name */
241
ibool rename_also_foreigns);/* in: in ALTER TABLE we want
242
to preserve the original table name
243
in constraints which reference it */
244
/**************************************************************************
245
Change the id of a table object in the dictionary cache. This is used in
246
DISCARD TABLESPACE. */
249
dict_table_change_id_in_cache(
250
/*==========================*/
251
dict_table_t* table, /* in/out: table object already in cache */
252
dulint new_id);/* in: new id to set */
253
/**************************************************************************
254
Adds a foreign key constraint object to the dictionary cache. May free
255
the object if there already is an object with the same identifier in.
256
At least one of foreign table or referenced table must already be in
257
the dictionary cache! */
260
dict_foreign_add_to_cache(
261
/*======================*/
262
/* out: DB_SUCCESS or error code */
263
dict_foreign_t* foreign, /* in, own: foreign key constraint */
264
ibool check_charsets);/* in: TRUE=check charset
266
/*************************************************************************
267
Check if the index is referenced by a foreign key, if TRUE return the
268
matching instance NULL otherwise. */
271
dict_table_get_referenced_constraint(
272
/*=================================*/
273
/* out: pointer to foreign key struct if index
274
is defined for foreign key, otherwise NULL */
275
dict_table_t* table, /* in: InnoDB table */
276
dict_index_t* index); /* in: InnoDB index */
277
/*************************************************************************
278
Checks if a table is referenced by foreign keys. */
281
dict_table_is_referenced_by_foreign_key(
282
/*====================================*/
283
/* out: TRUE if table is referenced
285
const dict_table_t* table); /* in: InnoDB table */
286
/**************************************************************************
287
Replace the index in the foreign key list that matches this index's
288
definition with an equivalent index. */
291
dict_table_replace_index_in_foreign_list(
292
/*=====================================*/
293
dict_table_t* table, /* in/out: table */
294
dict_index_t* index); /* in: index to be replaced */
295
/**************************************************************************
296
Determines whether a string starts with the specified keyword. */
299
dict_str_starts_with_keyword(
300
/*=========================*/
301
/* out: TRUE if str starts
303
void* mysql_thd, /* in: MySQL thread handle */
304
const char* str, /* in: string to scan for keyword */
305
const char* keyword); /* in: keyword to look for */
306
/*************************************************************************
307
Checks if a index is defined for a foreign key constraint. Index is a part
308
of a foreign key constraint if the index is referenced by foreign key
309
or index is a foreign key index */
312
dict_table_get_foreign_constraint(
313
/*==============================*/
314
/* out: pointer to foreign key struct if index
315
is defined for foreign key, otherwise NULL */
316
dict_table_t* table, /* in: InnoDB table */
317
dict_index_t* index); /* in: InnoDB index */
318
/*************************************************************************
319
Scans a table create SQL string and adds to the data dictionary
320
the foreign key constraints declared in the string. This function
321
should be called after the indexes for a table have been created.
322
Each foreign key constraint must be accompanied with indexes in
323
bot participating tables. The indexes are allowed to contain more
324
fields than mentioned in the constraint. */
327
dict_create_foreign_constraints(
328
/*============================*/
329
/* out: error code or DB_SUCCESS */
330
trx_t* trx, /* in: transaction */
331
const char* sql_string, /* in: table create statement where
332
foreign keys are declared like:
333
FOREIGN KEY (a, b) REFERENCES
334
table2(c, d), table2 can be written
335
also with the database
336
name before it: test.table2; the
337
default database id the database of
339
const char* name, /* in: table full name in the
341
database_name/table_name */
342
ibool reject_fks); /* in: if TRUE, fail with error
343
code DB_CANNOT_ADD_CONSTRAINT if
344
any foreign keys are found. */
345
/**************************************************************************
346
Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. */
349
dict_foreign_parse_drop_constraints(
350
/*================================*/
351
/* out: DB_SUCCESS or
352
DB_CANNOT_DROP_CONSTRAINT if
353
syntax error or the constraint
355
mem_heap_t* heap, /* in: heap from which we can
357
trx_t* trx, /* in: transaction */
358
dict_table_t* table, /* in: table */
359
ulint* n, /* out: number of constraints
361
const char*** constraints_to_drop); /* out: id's of the
362
constraints to drop */
363
/**************************************************************************
364
Returns a table object and optionally increment its MySQL open handle count.
365
NOTE! This is a high-level function to be used mainly from outside the
366
'dict' directory. Inside this directory dict_table_get_low is usually the
367
appropriate function. */
372
/* out: table, NULL if
374
const char* table_name, /* in: table name */
375
ibool inc_mysql_count);
376
/* in: whether to increment the open
377
handle count on the table */
378
/**************************************************************************
379
Returns a index object, based on table and index id, and memoryfixes it. */
382
dict_index_get_on_id_low(
383
/*=====================*/
384
/* out: index, NULL if does not
386
dict_table_t* table, /* in: table */
387
dulint index_id); /* in: index id */
388
/**************************************************************************
389
Checks if a table is in the dictionary cache. */
393
dict_table_check_if_in_cache_low(
394
/*=============================*/
395
/* out: table, NULL if not found */
396
const char* table_name); /* in: table name */
397
/**************************************************************************
398
Gets a table; loads it to the dictionary cache if necessary. A low-level
404
/* out: table, NULL if not found */
405
const char* table_name); /* in: table name */
406
/**************************************************************************
407
Returns a table object based on table id. */
410
dict_table_get_on_id_low(
411
/*=====================*/
412
/* out: table, NULL if does not exist */
413
dulint table_id); /* in: table id */
414
/**************************************************************************
415
Returns an index object by matching on the name and column names and if
416
more than index is found return the index with the higher id.*/
419
dict_table_get_index_by_max_id(
420
/*===========================*/
421
/* out: matching index, NULL if not found */
422
dict_table_t* table, /* in: table */
423
const char* name, /* in: the index name to find */
424
const char** columns,/* in: array of column names */
425
ulint n_cols);/* in: number of columns */
426
/**************************************************************************
427
Returns a column's name. */
430
dict_table_get_col_name(
431
/*====================*/
432
/* out: column name. NOTE: not
433
guaranteed to stay valid if table is
434
modified in any way (columns added,
436
const dict_table_t* table, /* in: table */
437
ulint col_nr);/* in: column number */
439
/**************************************************************************
440
Prints a table definition. */
445
dict_table_t* table); /* in: table */
446
/**************************************************************************
447
Prints a table data. */
450
dict_table_print_low(
451
/*=================*/
452
dict_table_t* table); /* in: table */
453
/**************************************************************************
454
Prints a table data when we know the table name. */
457
dict_table_print_by_name(
458
/*=====================*/
460
/**************************************************************************
461
Outputs info on foreign keys of a table. */
464
dict_print_info_on_foreign_keys(
465
/*============================*/
466
ibool create_table_format, /* in: if TRUE then print in
467
a format suitable to be inserted into
468
a CREATE TABLE, otherwise in the format
469
of SHOW TABLE STATUS */
470
FILE* file, /* in: file where to print */
471
trx_t* trx, /* in: transaction */
472
dict_table_t* table); /* in: table */
473
/**************************************************************************
474
Outputs info on a foreign key of a table in a format suitable for
478
dict_print_info_on_foreign_key_in_create_format(
479
/*============================================*/
480
FILE* file, /* in: file where to print */
481
trx_t* trx, /* in: transaction */
482
dict_foreign_t* foreign, /* in: foreign key constraint */
483
ibool add_newline); /* in: whether to add a newline */
484
/************************************************************************
485
Displays the names of the index and the table. */
488
dict_index_name_print(
489
/*==================*/
490
FILE* file, /* in: output stream */
491
trx_t* trx, /* in: transaction */
492
const dict_index_t* index); /* in: index to print */
494
/************************************************************************
495
Gets the first index on the table (the clustered index). */
498
dict_table_get_first_index(
499
/*=======================*/
500
/* out: index, NULL if none exists */
501
const dict_table_t* table); /* in: table */
502
/************************************************************************
503
Gets the next index on the table. */
506
dict_table_get_next_index(
507
/*======================*/
508
/* out: index, NULL if none left */
509
const dict_index_t* index); /* in: index */
510
#else /* UNIV_DEBUG */
511
# define dict_table_get_first_index(table) UT_LIST_GET_FIRST((table)->indexes)
512
# define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
513
#endif /* UNIV_DEBUG */
514
/************************************************************************
515
Check whether the index is the clustered index. */
520
/* out: nonzero for clustered index,
521
zero for other indexes */
522
const dict_index_t* index) /* in: index */
523
__attribute__((pure));
524
/************************************************************************
525
Check whether the index is unique. */
528
dict_index_is_unique(
529
/*=================*/
530
/* out: nonzero for unique index,
531
zero for other indexes */
532
const dict_index_t* index) /* in: index */
533
__attribute__((pure));
534
/************************************************************************
535
Check whether the index is the insert buffer tree. */
540
/* out: nonzero for insert buffer,
541
zero for other indexes */
542
const dict_index_t* index) /* in: index */
543
__attribute__((pure));
545
/************************************************************************
546
Gets the number of user-defined columns in a table in the dictionary
550
dict_table_get_n_user_cols(
551
/*=======================*/
552
/* out: number of user-defined
554
columns of a table */
555
const dict_table_t* table); /* in: table */
556
/************************************************************************
557
Gets the number of system columns in a table in the dictionary cache. */
560
dict_table_get_n_sys_cols(
561
/*======================*/
562
/* out: number of system (e.g.,
563
ROW_ID) columns of a table */
564
const dict_table_t* table); /* in: table */
565
/************************************************************************
566
Gets the number of all columns (also system) in a table in the dictionary
570
dict_table_get_n_cols(
571
/*==================*/
572
/* out: number of columns of a table */
573
const dict_table_t* table); /* in: table */
575
/************************************************************************
576
Gets the nth column of a table. */
579
dict_table_get_nth_col(
580
/*===================*/
581
/* out: pointer to column object */
582
const dict_table_t* table, /* in: table */
583
ulint pos); /* in: position of column */
584
/************************************************************************
585
Gets the given system column of a table. */
588
dict_table_get_sys_col(
589
/*===================*/
590
/* out: pointer to column object */
591
const dict_table_t* table, /* in: table */
592
ulint sys); /* in: DATA_ROW_ID, ... */
593
#else /* UNIV_DEBUG */
594
#define dict_table_get_nth_col(table, pos) \
595
((table)->cols + (pos))
596
#define dict_table_get_sys_col(table, sys) \
597
((table)->cols + (table)->n_cols + (sys) - DATA_N_SYS_COLS)
598
#endif /* UNIV_DEBUG */
599
/************************************************************************
600
Gets the given system column number of a table. */
603
dict_table_get_sys_col_no(
604
/*======================*/
605
/* out: column number */
606
const dict_table_t* table, /* in: table */
607
ulint sys); /* in: DATA_ROW_ID, ... */
608
/************************************************************************
609
Returns the minimum data size of an index record. */
612
dict_index_get_min_size(
613
/*====================*/
614
/* out: minimum data size in bytes */
615
const dict_index_t* index); /* in: index */
616
/************************************************************************
617
Check whether the table uses the compact page format. */
622
/* out: TRUE if table uses the
623
compact page format */
624
const dict_table_t* table); /* in: table */
625
/************************************************************************
626
Determine the file format of a table. */
629
dict_table_get_format(
630
/*==================*/
631
/* out: file format version */
632
const dict_table_t* table); /* in: table */
633
/************************************************************************
634
Set the file format of a table. */
637
dict_table_set_format(
638
/*==================*/
639
dict_table_t* table, /* in/out: table */
640
ulint format);/* in: file format version */
641
/************************************************************************
642
Extract the compressed page size from table flags. */
645
dict_table_flags_to_zip_size(
646
/*=========================*/
647
/* out: compressed page size,
648
or 0 if not compressed */
649
ulint flags) /* in: flags */
650
__attribute__((__const__));
651
/************************************************************************
652
Check whether the table uses the compressed compact page format. */
657
/* out: compressed page size,
658
or 0 if not compressed */
659
const dict_table_t* table); /* in: table */
660
/************************************************************************
661
Checks if a column is in the ordering columns of the clustered index of a
662
table. Column prefixes are treated like whole columns. */
665
dict_table_col_in_clustered_key(
666
/*============================*/
667
/* out: TRUE if the column, or its
668
prefix, is in the clustered key */
669
const dict_table_t* table, /* in: table */
670
ulint n); /* in: column number */
671
/***********************************************************************
672
Copies types of columns contained in table to tuple and sets all
673
fields of the tuple to the SQL NULL value. This function should
674
be called right after dtuple_create(). */
677
dict_table_copy_types(
678
/*==================*/
679
dtuple_t* tuple, /* in/out: data tuple */
680
const dict_table_t* table); /* in: table */
681
/**************************************************************************
682
Looks for an index with the given id. NOTE that we do not reserve
683
the dictionary mutex: this function is for emergency purposes like
684
printing info of a corrupt database page! */
687
dict_index_find_on_id_low(
688
/*======================*/
689
/* out: index or NULL if not found from cache */
690
dulint id); /* in: index id */
691
/**************************************************************************
692
Adds an index to the dictionary cache. */
695
dict_index_add_to_cache(
696
/*====================*/
697
/* out: DB_SUCCESS or error code */
698
dict_table_t* table, /* in: table on which the index is */
699
dict_index_t* index, /* in, own: index; NOTE! The index memory
700
object is freed in this function! */
701
ulint page_no);/* in: root page number of the index */
702
/**************************************************************************
703
Removes an index from the dictionary cache. */
706
dict_index_remove_from_cache(
707
/*=========================*/
708
dict_table_t* table, /* in/out: table */
709
dict_index_t* index); /* in, own: index */
710
/************************************************************************
711
Gets the number of fields in the internal representation of an index,
712
including fields added by the dictionary system. */
715
dict_index_get_n_fields(
716
/*====================*/
717
/* out: number of fields */
718
const dict_index_t* index); /* in: an internal
719
representation of index (in
720
the dictionary cache) */
721
/************************************************************************
722
Gets the number of fields in the internal representation of an index
723
that uniquely determine the position of an index entry in the index, if
724
we do not take multiversioning into account: in the B-tree use the value
725
returned by dict_index_get_n_unique_in_tree. */
728
dict_index_get_n_unique(
729
/*====================*/
730
/* out: number of fields */
731
const dict_index_t* index); /* in: an internal representation
732
of index (in the dictionary cache) */
733
/************************************************************************
734
Gets the number of fields in the internal representation of an index
735
which uniquely determine the position of an index entry in the index, if
736
we also take multiversioning into account. */
739
dict_index_get_n_unique_in_tree(
740
/*============================*/
741
/* out: number of fields */
742
const dict_index_t* index); /* in: an internal representation
743
of index (in the dictionary cache) */
744
/************************************************************************
745
Gets the number of user-defined ordering fields in the index. In the internal
746
representation we add the row id to the ordering fields to make all indexes
747
unique, but this function returns the number of fields the user defined
748
in the index as ordering fields. */
751
dict_index_get_n_ordering_defined_by_user(
752
/*======================================*/
753
/* out: number of fields */
754
const dict_index_t* index); /* in: an internal representation
755
of index (in the dictionary cache) */
757
/************************************************************************
758
Gets the nth field of an index. */
761
dict_index_get_nth_field(
762
/*=====================*/
763
/* out: pointer to field object */
764
const dict_index_t* index, /* in: index */
765
ulint pos); /* in: position of field */
766
#else /* UNIV_DEBUG */
767
# define dict_index_get_nth_field(index, pos) ((index)->fields + (pos))
768
#endif /* UNIV_DEBUG */
769
/************************************************************************
770
Gets pointer to the nth column in an index. */
773
dict_index_get_nth_col(
774
/*===================*/
776
const dict_index_t* index, /* in: index */
777
ulint pos); /* in: position of the field */
778
/************************************************************************
779
Gets the column number of the nth field in an index. */
782
dict_index_get_nth_col_no(
783
/*======================*/
784
/* out: column number */
785
const dict_index_t* index, /* in: index */
786
ulint pos); /* in: position of the field */
787
/************************************************************************
788
Looks for column n in an index. */
791
dict_index_get_nth_col_pos(
792
/*=======================*/
793
/* out: position in internal
794
representation of the index;
795
if not contained, returns
797
const dict_index_t* index, /* in: index */
798
ulint n); /* in: column number */
799
/************************************************************************
800
Returns TRUE if the index contains a column or a prefix of that column. */
803
dict_index_contains_col_or_prefix(
804
/*==============================*/
805
/* out: TRUE if contains the column
807
const dict_index_t* index, /* in: index */
808
ulint n); /* in: column number */
809
/************************************************************************
810
Looks for a matching field in an index. The column has to be the same. The
811
column in index must be complete, or must contain a prefix longer than the
812
column in index2. That is, we must be able to construct the prefix in index2
813
from the prefix in index. */
816
dict_index_get_nth_field_pos(
817
/*=========================*/
818
/* out: position in internal
819
representation of the index;
820
if not contained, returns
822
const dict_index_t* index, /* in: index from which to search */
823
const dict_index_t* index2, /* in: index */
824
ulint n); /* in: field number in index2 */
825
/************************************************************************
826
Looks for column n position in the clustered index. */
829
dict_table_get_nth_col_pos(
830
/*=======================*/
831
/* out: position in internal
833
the clustered index */
834
const dict_table_t* table, /* in: table */
835
ulint n); /* in: column number */
836
/************************************************************************
837
Returns the position of a system column in an index. */
840
dict_index_get_sys_col_pos(
841
/*=======================*/
843
ULINT_UNDEFINED if not contained */
844
const dict_index_t* index, /* in: index */
845
ulint type); /* in: DATA_ROW_ID, ... */
846
/***********************************************************************
847
Adds a column to index. */
852
dict_index_t* index, /* in/out: index */
853
const dict_table_t* table, /* in: table */
854
dict_col_t* col, /* in: column */
855
ulint prefix_len); /* in: column prefix length */
856
/***********************************************************************
857
Copies types of fields contained in index to tuple. */
860
dict_index_copy_types(
861
/*==================*/
862
dtuple_t* tuple, /* in/out: data tuple */
863
const dict_index_t* index, /* in: index */
864
ulint n_fields); /* in: number of
865
field types to copy */
866
/*************************************************************************
867
Gets the field column. */
872
const dict_field_t* field);
874
/**************************************************************************
875
Returns an index object if it is found in the dictionary cache.
876
Assumes that dict_sys->mutex is already being held. */
879
dict_index_get_if_in_cache_low(
880
/*===========================*/
881
/* out: index, NULL if not found */
882
dulint index_id); /* in: index id */
883
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
884
/**************************************************************************
885
Returns an index object if it is found in the dictionary cache. */
888
dict_index_get_if_in_cache(
889
/*=======================*/
890
/* out: index, NULL if not found */
891
dulint index_id); /* in: index id */
892
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
894
/**************************************************************************
895
Checks that a tuple has n_fields_cmp value in a sensible range, so that
896
no comparison can occur with the page number field in a node pointer. */
899
dict_index_check_search_tuple(
900
/*==========================*/
901
/* out: TRUE if ok */
902
const dict_index_t* index, /* in: index tree */
903
const dtuple_t* tuple); /* in: tuple used in a search */
904
/**************************************************************************
905
Check for duplicate index entries in a table [using the index name] */
908
dict_table_check_for_dup_indexes(
909
/*=============================*/
910
const dict_table_t* table); /* in: Check for dup indexes
913
#endif /* UNIV_DEBUG */
914
/**************************************************************************
915
Builds a node pointer out of a physical record and a page number. */
918
dict_index_build_node_ptr(
919
/*======================*/
920
/* out, own: node pointer */
921
const dict_index_t* index, /* in: index */
922
const rec_t* rec, /* in: record for which to build node
924
ulint page_no,/* in: page number to put in node
926
mem_heap_t* heap, /* in: memory heap where pointer
928
ulint level); /* in: level of rec in tree:
929
0 means leaf level */
930
/**************************************************************************
931
Copies an initial segment of a physical record, long enough to specify an
932
index entry uniquely. */
935
dict_index_copy_rec_order_prefix(
936
/*=============================*/
937
/* out: pointer to the prefix record */
938
const dict_index_t* index, /* in: index */
939
const rec_t* rec, /* in: record for which to
941
ulint* n_fields,/* out: number of fields copied */
942
byte** buf, /* in/out: memory buffer for the
943
copied prefix, or NULL */
944
ulint* buf_size);/* in/out: buffer size */
945
/**************************************************************************
946
Builds a typed data tuple out of a physical record. */
949
dict_index_build_data_tuple(
950
/*========================*/
951
/* out, own: data tuple */
952
dict_index_t* index, /* in: index */
953
rec_t* rec, /* in: record for which to build data tuple */
954
ulint n_fields,/* in: number of data fields */
955
mem_heap_t* heap); /* in: memory heap where tuple created */
956
/*************************************************************************
957
Gets the space id of the root of the index tree. */
960
dict_index_get_space(
961
/*=================*/
963
const dict_index_t* index); /* in: index */
964
/*************************************************************************
965
Sets the space id of the root of the index tree. */
968
dict_index_set_space(
969
/*=================*/
970
dict_index_t* index, /* in/out: index */
971
ulint space); /* in: space id */
972
/*************************************************************************
973
Gets the page number of the root of the index tree. */
978
/* out: page number */
979
const dict_index_t* tree); /* in: index */
980
/*************************************************************************
981
Sets the page number of the root of index tree. */
986
dict_index_t* index, /* in/out: index */
987
ulint page); /* in: page number */
988
/*************************************************************************
989
Gets the type of the index tree. */
995
const dict_index_t* index); /* in: index */
996
/*************************************************************************
997
Gets the read-write lock of the index tree. */
1000
dict_index_get_lock(
1001
/*================*/
1002
/* out: read-write lock */
1003
dict_index_t* index); /* in: index */
1004
/************************************************************************
1005
Returns free space reserved for future updates of records. This is
1006
relevant only in the case of many consecutive inserts, as updates
1007
which make the records bigger might fragment the index. */
1010
dict_index_get_space_reserve(void);
1011
/*==============================*/
1012
/* out: number of free bytes on page,
1013
reserved for updates */
1014
/*************************************************************************
1015
Calculates the minimum record length in an index. */
1018
dict_index_calc_min_rec_len(
1019
/*========================*/
1020
const dict_index_t* index); /* in: index */
1021
/*************************************************************************
1022
Calculates new estimates for table and index statistics. The statistics
1023
are used in query optimization. */
1026
dict_update_statistics_low(
1027
/*=======================*/
1028
dict_table_t* table, /* in/out: table */
1029
ibool has_dict_mutex);/* in: TRUE if the caller has the
1031
/*************************************************************************
1032
Calculates new estimates for table and index statistics. The statistics
1033
are used in query optimization. */
1036
dict_update_statistics(
1037
/*===================*/
1038
dict_table_t* table); /* in/out: table */
1039
/************************************************************************
1040
Reserves the dictionary system mutex for MySQL. */
1043
dict_mutex_enter_for_mysql(void);
1044
/*============================*/
1045
/************************************************************************
1046
Releases the dictionary system mutex for MySQL. */
1049
dict_mutex_exit_for_mysql(void);
1050
/*===========================*/
1051
/************************************************************************
1052
Checks if the database name in two table names is the same. */
1055
dict_tables_have_same_db(
1056
/*=====================*/
1057
/* out: TRUE if same db name */
1058
const char* name1, /* in: table name in the form
1059
dbname '/' tablename */
1060
const char* name2); /* in: table name in the form
1061
dbname '/' tablename */
1062
/*************************************************************************
1063
Scans from pointer onwards. Stops if is at the start of a copy of
1064
'string' where characters are compared without case sensitivity. Stops
1070
/* out: scanned up to this */
1071
const char* ptr, /* in: scan from */
1072
const char* string);/* in: look for this */
1073
/*************************************************************************
1074
Get index by name */
1077
dict_table_get_index_on_name(
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
/**************************************************************************
1083
Find and index that is equivalent to the one passed in and is not marked
1087
dict_table_find_equivalent_index(
1088
/*=============================*/
1089
dict_table_t* table, /* in/out: table */
1090
dict_index_t* index); /* in: index to match */
1091
/**************************************************************************
1092
In case there is more than one index with the same name return the index
1093
with the min(id). */
1096
dict_table_get_index_on_name_and_min_id(
1097
/*====================================*/
1098
/* out: index, NULL if does not exist */
1099
dict_table_t* table, /* in: table */
1100
const char* name); /* in: name of the index to find */
1101
/* Buffers for storing detailed information about the latest foreign key
1102
and unique key errors */
1103
extern FILE* dict_foreign_err_file;
1104
extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */
1106
extern dict_sys_t* dict_sys; /* the dictionary system */
1107
extern rw_lock_t dict_operation_lock;
1109
/* Dictionary system struct */
1110
struct dict_sys_struct{
1111
mutex_t mutex; /* mutex protecting the data
1112
dictionary; protects also the
1113
disk-based dictionary system tables;
1114
this mutex serializes CREATE TABLE
1115
and DROP TABLE, as well as reading
1116
the dictionary data for a table from
1118
dulint row_id; /* the next row id to assign;
1119
NOTE that at a checkpoint this
1120
must be written to the dict system
1121
header and flushed to a file; in
1122
recovery this must be derived from
1124
hash_table_t* table_hash; /* hash table of the tables, based
1126
hash_table_t* table_id_hash; /* hash table of the tables, based
1128
UT_LIST_BASE_NODE_T(dict_table_t)
1129
table_LRU; /* LRU list of tables */
1130
ulint size; /* varying space in bytes occupied
1131
by the data dictionary table and
1133
dict_table_t* sys_tables; /* SYS_TABLES table */
1134
dict_table_t* sys_columns; /* SYS_COLUMNS table */
1135
dict_table_t* sys_indexes; /* SYS_INDEXES table */
1136
dict_table_t* sys_fields; /* SYS_FIELDS table */
1140
#include "dict0dict.ic"