Drizzled Public API Documentation

dict0dict.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
4 
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.
8 
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.
12 
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., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #pragma once
27 #ifndef dict0dict_h
28 #define dict0dict_h
29 
30 #include "univ.i"
31 #include "dict0types.h"
32 #include "dict0mem.h"
33 #include "data0type.h"
34 #include "data0data.h"
35 #include "mem0mem.h"
36 #include "rem0types.h"
37 #include "ut0mem.h"
38 #include "ut0lst.h"
39 #include "hash0hash.h"
40 #include "ut0rnd.h"
41 #include "ut0byte.h"
42 #include "trx0types.h"
43 
44 #ifndef UNIV_HOTBACKUP
45 # include "sync0sync.h"
46 # include "sync0rw.h"
47 /******************************************************************/
49 UNIV_INTERN
50 void
51 dict_casedn_str(
52 /*============*/
53  char* a);
54 /********************************************************************/
57 UNIV_INTERN
58 ulint
59 dict_get_db_name_len(
60 /*=================*/
61  const char* name);
63 /********************************************************************/
67 const char*
68 dict_remove_db_name(
69 /*================*/
70  const char* name);
72 /**********************************************************************/
75 UNIV_INTERN
77 dict_table_get_on_id(
78 /*=================*/
79  table_id_t table_id,
80  trx_t* trx);
81 /********************************************************************/
83 UNIV_INTERN
84 void
85 dict_table_decrement_handle_count(
86 /*==============================*/
87  dict_table_t* table,
88  ibool dict_locked);
89 /**********************************************************************/
91 UNIV_INTERN
92 void
93 dict_init(void);
94 /*===========*/
95 /********************************************************************/
101 UNIV_INTERN
102 void
104 /*=========================*/
105 /*********************************************************************/
108 UNIV_INLINE
109 ulint
111 /*==================*/
112  const dict_col_t* col);
113 /*********************************************************************/
116 UNIV_INLINE
117 ulint
119 /*==================*/
120  const dict_col_t* col);
121 /*********************************************************************/
123 UNIV_INLINE
124 void
126 /*=====================*/
127  dict_col_t* col,
128  ulint mbminlen,
130  ulint mbmaxlen);
132 /*********************************************************************/
134 UNIV_INLINE
135 void
137 /*===============*/
138  const dict_col_t* col,
139  dtype_t* type);
140 #endif /* !UNIV_HOTBACKUP */
141 #ifdef UNIV_DEBUG
142 /*********************************************************************/
145 UNIV_INLINE
146 ibool
147 dict_col_type_assert_equal(
148 /*=======================*/
149  const dict_col_t* col,
150  const dtype_t* type);
151 #endif /* UNIV_DEBUG */
152 #ifndef UNIV_HOTBACKUP
153 /***********************************************************************/
156 UNIV_INLINE
157 ulint
159 /*==================*/
160  const dict_col_t* col);
161 /***********************************************************************/
164 UNIV_INLINE
165 ulint
167 /*==================*/
168  const dict_col_t* col);
169 /***********************************************************************/
172 UNIV_INLINE
173 ulint
175 /*====================*/
176  const dict_col_t* col,
177  ulint comp);
178 /***********************************************************************/
182 UNIV_INLINE
183 ulint
185 /*=======================*/
186  const dict_col_t* col,
187  ulint comp);
189 /*********************************************************************/
192 UNIV_INLINE
193 ulint
195 /*============*/
196  const dict_col_t* col);
197 /*********************************************************************/
199 UNIV_INLINE
200 ulint
202 /*===================*/
203  const dict_col_t* col,
204  const dict_index_t* clust_index);
205 /****************************************************************/
209 UNIV_INTERN
210 ibool
211 dict_col_name_is_reserved(
212 /*======================*/
213  const char* name);
214 /********************************************************************/
216 UNIV_INTERN
217 void
218 dict_table_autoinc_lock(
219 /*====================*/
220  dict_table_t* table);
221 /********************************************************************/
223 UNIV_INTERN
224 void
225 dict_table_autoinc_initialize(
226 /*==========================*/
227  dict_table_t* table,
228  ib_uint64_t value);
229 /********************************************************************/
233 UNIV_INTERN
234 ib_uint64_t
235 dict_table_autoinc_read(
236 /*====================*/
237  const dict_table_t* table);
238 /********************************************************************/
241 UNIV_INTERN
242 void
243 dict_table_autoinc_update_if_greater(
244 /*=================================*/
245 
246  dict_table_t* table,
247  ib_uint64_t value);
248 /********************************************************************/
250 UNIV_INTERN
251 void
252 dict_table_autoinc_unlock(
253 /*======================*/
254  dict_table_t* table);
255 #endif /* !UNIV_HOTBACKUP */
256 /**********************************************************************/
258 UNIV_INTERN
259 void
260 dict_table_add_system_columns(
261 /*==========================*/
262  dict_table_t* table,
263  mem_heap_t* heap);
264 #ifndef UNIV_HOTBACKUP
265 /**********************************************************************/
267 UNIV_INTERN
268 void
269 dict_table_add_to_cache(
270 /*====================*/
271  dict_table_t* table,
272  mem_heap_t* heap);
273 /**********************************************************************/
275 UNIV_INTERN
276 void
277 dict_table_remove_from_cache(
278 /*=========================*/
279  dict_table_t* table);
280 /**********************************************************************/
283 UNIV_INTERN
284 ibool
285 dict_table_rename_in_cache(
286 /*=======================*/
287  dict_table_t* table,
288  const char* new_name,
289  ibool rename_also_foreigns);
292 /**********************************************************************/
295 UNIV_INTERN
296 void
297 dict_table_change_id_in_cache(
298 /*==========================*/
299  dict_table_t* table,
300  table_id_t new_id);
301 /**********************************************************************/
307 UNIV_INTERN
308 ulint
309 dict_foreign_add_to_cache(
310 /*======================*/
311  dict_foreign_t* foreign,
312  ibool check_charsets);
314 /*********************************************************************/
319 UNIV_INTERN
321 dict_table_get_referenced_constraint(
322 /*=================================*/
323  dict_table_t* table,
324  dict_index_t* index);
325 /*********************************************************************/
328 UNIV_INTERN
329 ibool
330 dict_table_is_referenced_by_foreign_key(
331 /*====================================*/
332  const dict_table_t* table);
333 /**********************************************************************/
336 UNIV_INTERN
337 void
338 dict_table_replace_index_in_foreign_list(
339 /*=====================================*/
340  dict_table_t* table,
341  dict_index_t* index,
342  const trx_t* trx);
343 /*********************************************************************/
349 UNIV_INTERN
351 dict_table_get_foreign_constraint(
352 /*==============================*/
353  dict_table_t* table,
354  dict_index_t* index);
355 /*********************************************************************/
363 UNIV_INTERN
364 ulint
365 dict_create_foreign_constraints(
366 /*============================*/
367  trx_t* trx,
368  const char* sql_string,
376  size_t sql_length,
377  const char* name,
380  ibool reject_fks);
383 /**********************************************************************/
387 UNIV_INTERN
388 ulint
389 dict_foreign_parse_drop_constraints(
390 /*================================*/
391  mem_heap_t* heap,
393  trx_t* trx,
394  dict_table_t* table,
395  ulint* n,
397  const char*** constraints_to_drop);
399 /**********************************************************************/
405 UNIV_INTERN
407 dict_table_get(
408 /*===========*/
409  const char* table_name,
410  ibool inc_mysql_count);
413 /**********************************************************************/
416 UNIV_INTERN
418 dict_index_get_on_id_low(
419 /*=====================*/
420  dict_table_t* table,
421  index_id_t index_id);
422 /**********************************************************************/
426 UNIV_INLINE
429 /*=============================*/
430  const char* table_name);
431 /**********************************************************************/
435 UNIV_INLINE
438 /*===============*/
439  const char* table_name);
440 /**********************************************************************/
443 UNIV_INLINE
446 /*=====================*/
447  table_id_t table_id);
448 /**********************************************************************/
452 UNIV_INTERN
454 dict_foreign_find_equiv_index(
455 /*==========================*/
456  dict_foreign_t* foreign);
457 /**********************************************************************/
461 UNIV_INTERN
463 dict_table_get_index_by_max_id(
464 /*===========================*/
465  dict_table_t* table,
466  const char* name,
467  const char** columns,
468  ulint n_cols);
469 /**********************************************************************/
473 UNIV_INTERN
474 const char*
475 dict_table_get_col_name(
476 /*====================*/
477  const dict_table_t* table,
478  ulint col_nr);
480 /**********************************************************************/
482 UNIV_INTERN
483 void
484 dict_table_print(
485 /*=============*/
486  dict_table_t* table);
487 /**********************************************************************/
489 UNIV_INTERN
490 void
491 dict_table_print_low(
492 /*=================*/
493  dict_table_t* table);
494 /**********************************************************************/
496 UNIV_INTERN
497 void
498 dict_table_print_by_name(
499 /*=====================*/
500  const char* name);
501 /**********************************************************************/
503 UNIV_INTERN
504 void
505 dict_print_info_on_foreign_keys(
506 /*============================*/
507  ibool create_table_format,
511  FILE* file,
512  trx_t* trx,
513  dict_table_t* table);
514 /**********************************************************************/
517 UNIV_INTERN
518 void
519 dict_print_info_on_foreign_key_in_create_format(
520 /*============================================*/
521  FILE* file,
522  trx_t* trx,
523  dict_foreign_t* foreign,
524  ibool add_newline);
525 /********************************************************************/
527 UNIV_INTERN
528 void
529 dict_index_name_print(
530 /*==================*/
531  FILE* file,
532  trx_t* trx,
533  const dict_index_t* index);
534 #ifdef UNIV_DEBUG
535 /********************************************************************/
538 UNIV_INLINE
540 dict_table_get_first_index(
541 /*=======================*/
542  const dict_table_t* table);
543 /********************************************************************/
546 UNIV_INLINE
548 dict_table_get_next_index(
549 /*======================*/
550  const dict_index_t* index);
551 #else /* UNIV_DEBUG */
552 # define dict_table_get_first_index(table) UT_LIST_GET_FIRST((table)->indexes)
553 # define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
554 #endif /* UNIV_DEBUG */
555 #endif /* !UNIV_HOTBACKUP */
556 /********************************************************************/
559 UNIV_INLINE
560 ulint
562 /*================*/
563  const dict_index_t* index)
564  __attribute__((pure));
565 /********************************************************************/
568 UNIV_INLINE
569 ulint
571 /*=================*/
572  const dict_index_t* index)
573  __attribute__((pure));
574 /********************************************************************/
577 UNIV_INLINE
578 ulint
580 /*===============*/
581  const dict_index_t* index)
582  __attribute__((pure));
583 /********************************************************************/
586 UNIV_INLINE
587 ulint
589 /*======================*/
590  const dict_index_t* index)
591  __attribute__((pure));
592 
593 /********************************************************************/
597 UNIV_INLINE
598 ulint
600 /*=======================*/
601  const dict_table_t* table);
602 /********************************************************************/
605 UNIV_INLINE
606 ulint
608 /*======================*/
609  const dict_table_t* table);
610 /********************************************************************/
614 UNIV_INLINE
615 ulint
617 /*==================*/
618  const dict_table_t* table);
619 #ifdef UNIV_DEBUG
620 /********************************************************************/
623 UNIV_INLINE
624 dict_col_t*
625 dict_table_get_nth_col(
626 /*===================*/
627  const dict_table_t* table,
628  ulint pos);
629 /********************************************************************/
632 UNIV_INLINE
633 dict_col_t*
634 dict_table_get_sys_col(
635 /*===================*/
636  const dict_table_t* table,
637  ulint sys);
638 #else /* UNIV_DEBUG */
639 #define dict_table_get_nth_col(table, pos) \
640 ((table)->cols + (pos))
641 #define dict_table_get_sys_col(table, sys) \
642 ((table)->cols + (table)->n_cols + (sys) - DATA_N_SYS_COLS)
643 #endif /* UNIV_DEBUG */
644 /********************************************************************/
647 UNIV_INLINE
648 ulint
650 /*======================*/
651  const dict_table_t* table,
652  ulint sys);
653 #ifndef UNIV_HOTBACKUP
654 /********************************************************************/
657 UNIV_INLINE
658 ulint
660 /*====================*/
661  const dict_index_t* index);
662 #endif /* !UNIV_HOTBACKUP */
663 /********************************************************************/
666 UNIV_INLINE
667 ibool
669 /*===============*/
670  const dict_table_t* table);
671 /********************************************************************/
674 UNIV_INLINE
675 ulint
677 /*==================*/
678  const dict_table_t* table);
679 /********************************************************************/
681 UNIV_INLINE
682 void
684 /*==================*/
685  dict_table_t* table,
686  ulint format);
687 /********************************************************************/
690 UNIV_INLINE
691 ulint
693 /*=========================*/
694  ulint flags)
695  __attribute__((const));
696 /********************************************************************/
699 UNIV_INLINE
700 ulint
702 /*================*/
703  const dict_table_t* table);
704 /*********************************************************************/
708 UNIV_INLINE
709 void
711 /*======================*/
712  dict_table_t* table);
713 /*********************************************************************/
715 UNIV_INLINE
716 void
718 /*========================*/
719  dict_table_t* table);
720 /********************************************************************/
724 UNIV_INTERN
725 ibool
726 dict_table_col_in_clustered_key(
727 /*============================*/
728  const dict_table_t* table,
729  ulint n);
730 #ifndef UNIV_HOTBACKUP
731 /*******************************************************************/
735 UNIV_INTERN
736 void
737 dict_table_copy_types(
738 /*==================*/
739  dtuple_t* tuple,
740  const dict_table_t* table);
741 /**********************************************************************/
746 UNIV_INTERN
748 dict_index_find_on_id_low(
749 /*======================*/
750  index_id_t id);
751 /**********************************************************************/
754 UNIV_INTERN
755 ulint
756 dict_index_add_to_cache(
757 /*====================*/
758  dict_table_t* table,
759  dict_index_t* index,
761  ulint page_no,
762  ibool strict);
765 #endif /* !UNIV_HOTBACKUP */
766 /********************************************************************/
770 UNIV_INLINE
771 ulint
773 /*====================*/
774  const dict_index_t* index);
777 /********************************************************************/
783 UNIV_INLINE
784 ulint
786 /*====================*/
787  const dict_index_t* index);
789 /********************************************************************/
794 UNIV_INLINE
795 ulint
797 /*============================*/
798  const dict_index_t* index);
800 /********************************************************************/
806 UNIV_INLINE
807 ulint
809 /*======================================*/
810  const dict_index_t* index);
812 #ifdef UNIV_DEBUG
813 /********************************************************************/
816 UNIV_INLINE
818 dict_index_get_nth_field(
819 /*=====================*/
820  const dict_index_t* index,
821  ulint pos);
822 #else /* UNIV_DEBUG */
823 # define dict_index_get_nth_field(index, pos) ((index)->fields + (pos))
824 #endif /* UNIV_DEBUG */
825 /********************************************************************/
828 UNIV_INLINE
829 const dict_col_t*
831 /*===================*/
832  const dict_index_t* index,
833  ulint pos);
834 /********************************************************************/
837 UNIV_INLINE
838 ulint
840 /*======================*/
841  const dict_index_t* index,
842  ulint pos);
843 /********************************************************************/
847 UNIV_INTERN
848 ulint
849 dict_index_get_nth_col_pos(
850 /*=======================*/
851  const dict_index_t* index,
852  ulint n);
853 /********************************************************************/
856 UNIV_INTERN
857 ibool
858 dict_index_contains_col_or_prefix(
859 /*==============================*/
860  const dict_index_t* index,
861  ulint n);
862 /********************************************************************/
869 UNIV_INTERN
870 ulint
871 dict_index_get_nth_field_pos(
872 /*=========================*/
873  const dict_index_t* index,
874  const dict_index_t* index2,
875  ulint n);
876 /********************************************************************/
879 UNIV_INTERN
880 ulint
881 dict_table_get_nth_col_pos(
882 /*=======================*/
883  const dict_table_t* table,
884  ulint n);
885 /********************************************************************/
888 UNIV_INLINE
889 ulint
891 /*=======================*/
892  const dict_index_t* index,
893  ulint type);
894 /*******************************************************************/
896 UNIV_INTERN
897 void
898 dict_index_add_col(
899 /*===============*/
900  dict_index_t* index,
901  const dict_table_t* table,
902  dict_col_t* col,
903  ulint prefix_len);
904 #ifndef UNIV_HOTBACKUP
905 /*******************************************************************/
907 UNIV_INTERN
908 void
909 dict_index_copy_types(
910 /*==================*/
911  dtuple_t* tuple,
912  const dict_index_t* index,
913  ulint n_fields);
915 #endif /* !UNIV_HOTBACKUP */
916 /*********************************************************************/
919 UNIV_INLINE
920 const dict_col_t*
922 /*===============*/
923  const dict_field_t* field);
924 #ifndef UNIV_HOTBACKUP
925 /**********************************************************************/
929 UNIV_INTERN
931 dict_index_get_if_in_cache_low(
932 /*===========================*/
933  index_id_t index_id);
934 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
935 /**********************************************************************/
938 UNIV_INTERN
940 dict_index_get_if_in_cache(
941 /*=======================*/
942  index_id_t index_id);
943 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
944 #ifdef UNIV_DEBUG
945 /**********************************************************************/
949 UNIV_INTERN
950 ibool
951 dict_index_check_search_tuple(
952 /*==========================*/
953  const dict_index_t* index,
954  const dtuple_t* tuple);
955 /**********************************************************************/
957 UNIV_INTERN
958 void
959 dict_table_check_for_dup_indexes(
960 /*=============================*/
961  const dict_table_t* table,
963  ibool tmp_ok);
965 #endif /* UNIV_DEBUG */
966 /**********************************************************************/
969 UNIV_INTERN
970 dtuple_t*
971 dict_index_build_node_ptr(
972 /*======================*/
973  const dict_index_t* index,
974  const rec_t* rec,
976  ulint page_no,
978  mem_heap_t* heap,
980  ulint level);
982 /**********************************************************************/
986 UNIV_INTERN
987 rec_t*
988 dict_index_copy_rec_order_prefix(
989 /*=============================*/
990  const dict_index_t* index,
991  const rec_t* rec,
993  ulint* n_fields,
994  byte** buf,
996  ulint* buf_size);
997 /**********************************************************************/
1000 UNIV_INTERN
1001 dtuple_t*
1002 dict_index_build_data_tuple(
1003 /*========================*/
1004  dict_index_t* index,
1005  rec_t* rec,
1006  ulint n_fields,
1007  mem_heap_t* heap);
1008 /*********************************************************************/
1011 UNIV_INLINE
1012 ulint
1014 /*=================*/
1015  const dict_index_t* index);
1016 /*********************************************************************/
1018 UNIV_INLINE
1019 void
1021 /*=================*/
1022  dict_index_t* index,
1023  ulint space);
1024 /*********************************************************************/
1027 UNIV_INLINE
1028 ulint
1030 /*================*/
1031  const dict_index_t* tree);
1032 /*********************************************************************/
1034 UNIV_INLINE
1035 void
1037 /*================*/
1038  dict_index_t* index,
1039  ulint page);
1040 /*********************************************************************/
1043 UNIV_INLINE
1044 rw_lock_t*
1046 /*================*/
1047  dict_index_t* index);
1048 /********************************************************************/
1053 UNIV_INLINE
1054 ulint
1056 /*==============================*/
1057 /*********************************************************************/
1059 UNIV_INTERN
1060 ulint
1061 dict_index_calc_min_rec_len(
1062 /*========================*/
1063  const dict_index_t* index);
1064 /*********************************************************************/
1067 UNIV_INTERN
1068 void
1069 dict_update_statistics(
1070 /*===================*/
1071  dict_table_t* table,
1072  ibool only_calc_if_missing_stats);
1076 /********************************************************************/
1078 UNIV_INTERN
1079 void
1080 dict_mutex_enter_for_mysql(void);
1081 /*============================*/
1082 /********************************************************************/
1084 UNIV_INTERN
1085 void
1086 dict_mutex_exit_for_mysql(void);
1087 /*===========================*/
1088 /**********************************************************************/
1092 UNIV_INTERN
1093 void
1094 dict_table_stats_lock(
1095 /*==================*/
1096  const dict_table_t* table,
1097  ulint latch_mode);
1099 /**********************************************************************/
1101 UNIV_INTERN
1102 void
1103 dict_table_stats_unlock(
1104 /*====================*/
1105  const dict_table_t* table,
1106  ulint latch_mode);
1108 /********************************************************************/
1111 UNIV_INTERN
1112 ibool
1113 dict_tables_have_same_db(
1114 /*=====================*/
1115  const char* name1,
1117  const char* name2);
1119 /*********************************************************************/
1121 UNIV_INTERN
1122 void
1123 dict_index_remove_from_cache(
1124 /*=========================*/
1125  dict_table_t* table,
1126  dict_index_t* index);
1127 /**********************************************************************/
1130 UNIV_INTERN
1131 dict_index_t*
1132 dict_table_get_index_on_name(
1133 /*=========================*/
1134  dict_table_t* table,
1135  const char* name);
1136 /**********************************************************************/
1140 UNIV_INTERN
1141 dict_index_t*
1142 dict_table_get_index_on_name_and_min_id(
1143 /*====================================*/
1144  dict_table_t* table,
1145  const char* name);
1146 /* Buffers for storing detailed information about the latest foreign key
1147 and unique key errors */
1148 extern FILE* dict_foreign_err_file;
1149 extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */
1150 
1152 extern dict_sys_t* dict_sys;
1154 extern rw_lock_t dict_operation_lock;
1155 
1156 /* Dictionary system struct */
1177  ulint size;
1184 };
1185 #endif /* !UNIV_HOTBACKUP */
1186 
1188 extern dict_index_t* dict_ind_redundant;
1190 extern dict_index_t* dict_ind_compact;
1191 
1192 /**********************************************************************/
1194 UNIV_INTERN
1195 void
1196 dict_ind_init(void);
1197 /*===============*/
1198 
1199 /**********************************************************************/
1201 UNIV_INTERN
1202 void
1203 dict_close(void);
1204 /*============*/
1205 
1206 #ifndef UNIV_NONINL
1207 #include "dict0dict.ic"
1208 #endif
1209 
1210 #endif