MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dict0mem.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2012, Facebook Inc.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17 
18 *****************************************************************************/
19 
20 /**************************************************/
27 #ifndef dict0mem_h
28 #define dict0mem_h
29 
30 #include "univ.i"
31 #include "dict0types.h"
32 #include "data0type.h"
33 #include "mem0mem.h"
34 #include "row0types.h"
35 #include "rem0types.h"
36 #include "btr0types.h"
37 #ifndef UNIV_HOTBACKUP
38 # include "lock0types.h"
39 # include "que0types.h"
40 # include "sync0rw.h"
41 #endif /* !UNIV_HOTBACKUP */
42 #include "ut0mem.h"
43 #include "ut0lst.h"
44 #include "ut0rnd.h"
45 #include "ut0byte.h"
46 #include "hash0hash.h"
47 #include "trx0types.h"
48 #include "fts0fts.h"
49 
50 /* Forward declaration. */
51 struct ib_rbt_t;
52 
55 /* @{ */
56 #define DICT_CLUSTERED 1
57 #define DICT_UNIQUE 2
58 #define DICT_UNIVERSAL 4
60 #define DICT_IBUF 8
61 #define DICT_CORRUPT 16
63 #define DICT_FTS 32 /* FTS index; can't be combined with the
64  other flags */
65 
66 #define DICT_IT_BITS 6
68 /* @} */
69 
70 #if 0 /* not implemented, retained for history */
71 
72 #define DICT_TABLE_ORDINARY 1
73 #define DICT_TABLE_CLUSTER_MEMBER 2
74 #define DICT_TABLE_CLUSTER 3 /* this means that the table is
75  really a cluster definition */
76 #endif
77 
78 /* Table and tablespace flags are generally not used for the Antelope file
79 format except for the low order bit, which is used differently depending on
80 where the flags are stored.
81 
82 ==================== Low order flags bit =========================
83  | REDUNDANT | COMPACT | COMPRESSED and DYNAMIC
84 SYS_TABLES.TYPE | 1 | 1 | 1
85 dict_table_t::flags | 0 | 1 | 1
86 FSP_SPACE_FLAGS | 0 | 0 | 1
87 fil_space_t::flags | 0 | 0 | 1
88 
89 Before the 5.1 plugin, SYS_TABLES.TYPE was always DICT_TABLE_ORDINARY (1)
90 and the tablespace flags field was always 0. In the 5.1 plugin, these fields
91 were repurposed to identify compressed and dynamic row formats.
92 
93 The following types and constants describe the flags found in dict_table_t
94 and SYS_TABLES.TYPE. Similar flags found in fil_space_t and FSP_SPACE_FLAGS
95 are described in fsp0fsp.h. */
96 
97 /* @{ */
99 #define DICT_TF_REDUNDANT 0
101 #define DICT_TF_COMPACT 1
105 #define DICT_N_COLS_COMPACT 0x80000000UL
106 
108 #define DICT_TF_WIDTH_COMPACT 1
110 #define DICT_TF_WIDTH_ZIP_SSIZE 4
111 
116 #define DICT_TF_WIDTH_ATOMIC_BLOBS 1
117 
121 #define DICT_TF_WIDTH_DATA_DIR 1
122 
124 #define DICT_TF_BITS (DICT_TF_WIDTH_COMPACT \
125  + DICT_TF_WIDTH_ZIP_SSIZE \
126  + DICT_TF_WIDTH_ATOMIC_BLOBS \
127  + DICT_TF_WIDTH_DATA_DIR)
128 
130 #define DICT_TF_BIT_MASK (~(~0 << DICT_TF_BITS))
131 
133 #define DICT_TF_POS_COMPACT 0
135 #define DICT_TF_POS_ZIP_SSIZE (DICT_TF_POS_COMPACT \
136  + DICT_TF_WIDTH_COMPACT)
138 #define DICT_TF_POS_ATOMIC_BLOBS (DICT_TF_POS_ZIP_SSIZE \
139  + DICT_TF_WIDTH_ZIP_SSIZE)
141 #define DICT_TF_POS_DATA_DIR (DICT_TF_POS_ATOMIC_BLOBS \
142  + DICT_TF_WIDTH_ATOMIC_BLOBS)
144 #define DICT_TF_POS_UNUSED (DICT_TF_POS_DATA_DIR \
145  + DICT_TF_WIDTH_DATA_DIR)
146 
148 #define DICT_TF_MASK_COMPACT \
149  ((~(~0 << DICT_TF_WIDTH_COMPACT)) \
150  << DICT_TF_POS_COMPACT)
152 #define DICT_TF_MASK_ZIP_SSIZE \
153  ((~(~0 << DICT_TF_WIDTH_ZIP_SSIZE)) \
154  << DICT_TF_POS_ZIP_SSIZE)
156 #define DICT_TF_MASK_ATOMIC_BLOBS \
157  ((~(~0 << DICT_TF_WIDTH_ATOMIC_BLOBS)) \
158  << DICT_TF_POS_ATOMIC_BLOBS)
160 #define DICT_TF_MASK_DATA_DIR \
161  ((~(~0 << DICT_TF_WIDTH_DATA_DIR)) \
162  << DICT_TF_POS_DATA_DIR)
163 
165 #define DICT_TF_GET_COMPACT(flags) \
166  ((flags & DICT_TF_MASK_COMPACT) \
167  >> DICT_TF_POS_COMPACT)
169 #define DICT_TF_GET_ZIP_SSIZE(flags) \
170  ((flags & DICT_TF_MASK_ZIP_SSIZE) \
171  >> DICT_TF_POS_ZIP_SSIZE)
173 #define DICT_TF_HAS_ATOMIC_BLOBS(flags) \
174  ((flags & DICT_TF_MASK_ATOMIC_BLOBS) \
175  >> DICT_TF_POS_ATOMIC_BLOBS)
177 #define DICT_TF_HAS_DATA_DIR(flags) \
178  ((flags & DICT_TF_MASK_DATA_DIR) \
179  >> DICT_TF_POS_DATA_DIR)
181 #define DICT_TF_GET_UNUSED(flags) \
182  (flags >> DICT_TF_POS_UNUSED)
183 /* @} */
184 
192 /* @{ */
194 #define DICT_TF2_BITS 6
195 #define DICT_TF2_BIT_MASK ~(~0 << DICT_TF2_BITS)
196 
198 #define DICT_TF2_TEMPORARY 1
200 #define DICT_TF2_FTS_HAS_DOC_ID 2
202 #define DICT_TF2_FTS 4
203 
205 #define DICT_TF2_FTS_ADD_DOC_ID 8
206 
208 #define DICT_TF2_USE_TABLESPACE 16
209 
211 #define DICT_TF2_DISCARDED 32
212 /* @} */
213 
214 #define DICT_TF2_FLAG_SET(table, flag) \
215  (table->flags2 |= (flag))
216 
217 #define DICT_TF2_FLAG_IS_SET(table, flag) \
218  (table->flags2 & (flag))
219 
220 #define DICT_TF2_FLAG_UNSET(table, flag) \
221  (table->flags2 &= ~(flag))
222 
229 #define DICT_FK_MAX_RECURSIVE_LOAD 20
230 
237 #define FK_MAX_CASCADE_DEL 255
238 
239 /**********************************************************************/
242 UNIV_INTERN
245 /*==================*/
246  const char* name,
247  ulint space,
249  ulint n_cols,
250  ulint flags,
251  ulint flags2);
252 /****************************************************************/
254 UNIV_INTERN
255 void
257 /*================*/
258  dict_table_t* table);
259 /**********************************************************************/
261 UNIV_INTERN
262 void
264 /*===================*/
266  mem_heap_t* heap,
267  const char* name,
268  ulint mtype,
269  ulint prtype,
270  ulint len)
271  __attribute__((nonnull(1)));
272 /**********************************************************************/
274 UNIV_INTERN
275 void
277 /*======================*/
279  unsigned nth_col,
280  const char* from,
281  const char* to)
282  __attribute__((nonnull));
283 /**********************************************************************/
286 UNIV_INTERN
287 void
289 /*========================*/
290  dict_col_t* column,
292  ulint col_pos,
293  ulint mtype,
294  ulint prtype,
295  ulint col_len);
296 /**********************************************************************/
299 UNIV_INLINE
300 void
302 /*=======================*/
304  mem_heap_t* heap,
305  const char* table_name,
306  const char* index_name,
307  ulint space,
310  ulint type,
312  ulint n_fields);
313 /**********************************************************************/
316 UNIV_INTERN
319 /*==================*/
320  const char* table_name,
321  const char* index_name,
322  ulint space,
325  ulint type,
327  ulint n_fields);
328 /**********************************************************************/
332 UNIV_INTERN
333 void
335 /*=====================*/
337  const char* name,
338  ulint prefix_len);
341 /**********************************************************************/
343 UNIV_INTERN
344 void
346 /*================*/
347  dict_index_t* index);
348 /**********************************************************************/
351 UNIV_INTERN
354 /*=========================*/
355 
356 /**********************************************************************/
361 UNIV_INTERN
362 void
364 /*===================================*/
365  dict_foreign_t* foreign,
366  ibool do_alloc);
368 /**********************************************************************/
373 UNIV_INTERN
374 void
376 /*======================================*/
377  dict_foreign_t* foreign,
378  ibool do_alloc);
380 /*******************************************************************/
383 UNIV_INTERN __attribute__((nonnull, warn_unused_result))
384 char*
385 dict_mem_create_temporary_tablename(
386 /*================================*/
388  const char* dbtab,
389  table_id_t id);
392 struct dict_col_t{
393  /*----------------------*/
396  /* @{ */
397  unsigned prtype:32;
404  unsigned mtype:8;
406  /* the remaining fields do not affect alphabetical ordering: */
408  unsigned len:16;
417  unsigned mbminmaxlen:5;
422  /*----------------------*/
423  /* End of definitions copied from dtype_t */
424  /* @} */
426  unsigned ind:10;
428  unsigned ord_part:1;
431  unsigned max_prefix:12;
434 };
435 
447 #define DICT_ANTELOPE_MAX_INDEX_COL_LEN REC_ANTELOPE_MAX_INDEX_COL_LEN
448 
454 #define DICT_MAX_FIELD_LEN_BY_FORMAT(table) \
455  ((dict_table_get_format(table) < UNIV_FORMAT_B) \
456  ? (REC_ANTELOPE_MAX_INDEX_COL_LEN - 1) \
457  : REC_VERSION_56_MAX_INDEX_COL_LEN)
458 
459 #define DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(flags) \
460  ((DICT_TF_HAS_ATOMIC_BLOBS(flags) < UNIV_FORMAT_B) \
461  ? (REC_ANTELOPE_MAX_INDEX_COL_LEN - 1) \
462  : REC_VERSION_56_MAX_INDEX_COL_LEN)
463 
465 #define DICT_MAX_FIXED_COL_LEN DICT_ANTELOPE_MAX_INDEX_COL_LEN
466 
470  const char* name;
471  unsigned prefix_len:12;
479  unsigned fixed_len:10;
482 };
483 
484 /**********************************************************************/
506 #define ZIP_PAD_ROUND_LEN (128)
507 
509 #define ZIP_PAD_SUCCESSFUL_ROUND_LIMIT (5)
510 
512 #define ZIP_PAD_INCR (128)
513 
516 extern ulong zip_failure_threshold_pct;
517 
520 extern ulong zip_pad_max;
521 
527  ulint pad;
528  ulint success;
530  ulint failure;
532  ulint n_rounds;
534 };
535 
539  index_id_t id;
541  const char* name;
542  const char* table_name;
544 #ifndef UNIV_HOTBACKUP
545  unsigned space:32;
547  unsigned page:32;
548 #endif /* !UNIV_HOTBACKUP */
549  unsigned type:DICT_IT_BITS;
552 #define MAX_KEY_LENGTH_BITS 12
553  unsigned trx_id_offset:MAX_KEY_LENGTH_BITS;
558 #if (1<<MAX_KEY_LENGTH_BITS) < MAX_KEY_LENGTH
559 # error (1<<MAX_KEY_LENGTH_BITS) < MAX_KEY_LENGTH
560 #endif
561  unsigned n_user_defined_cols:10;
565  unsigned n_uniq:10;
568  unsigned n_def:10;
569  unsigned n_fields:10;
570  unsigned n_nullable:10;
571  unsigned cached:1;
573  unsigned to_be_dropped:1;
576  unsigned online_status:2;
584 #ifndef UNIV_HOTBACKUP
586  indexes;
594  /*----------------------*/
596  /* @{ */
597  ib_uint64_t* stat_n_diff_key_vals;
605  ib_uint64_t* stat_n_sample_sizes;
610  ib_uint64_t* stat_n_non_null_key_vals;
611  /* approximate number of non-null key values
612  for this index, for each column where
613  1 <= n <= dict_get_n_unique(index) (the array
614  is indexed from 0 to n_uniq-1); This
615  is used when innodb_stats_method is
616  "nulls_ignored". */
623  /* @} */
624  rw_lock_t lock;
626  trx_id_t trx_id;
631 #endif /* !UNIV_HOTBACKUP */
632 #ifdef UNIV_BLOB_DEBUG
633  ib_mutex_t blobs_mutex;
635  ib_rbt_t* blobs;
638 #endif /* UNIV_BLOB_DEBUG */
639 #ifdef UNIV_DEBUG
640  ulint magic_n;
642 # define DICT_INDEX_MAGIC_N 76789786
643 #endif
644 };
645 
647 enum online_index_status {
664 };
665 
670  mem_heap_t* heap;
672  char* id;
674  unsigned n_fields:10;
680  unsigned type:6;
682  char* foreign_table_name;
686  const char** foreign_col_names;
688  char* referenced_table_name;
693  const char** referenced_col_names;
702  foreign_list;
707 };
708 
711 /* @{ */
712 #define DICT_FOREIGN_ON_DELETE_CASCADE 1
713 #define DICT_FOREIGN_ON_DELETE_SET_NULL 2
714 #define DICT_FOREIGN_ON_UPDATE_CASCADE 4
715 #define DICT_FOREIGN_ON_UPDATE_SET_NULL 8
716 #define DICT_FOREIGN_ON_DELETE_NO_ACTION 16
717 #define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32
718 /* @} */
719 
723  table_id_t id;
725  char* name;
726  const char* dir_path_of_temp_table;
732  char* data_dir_path;
734  unsigned space:32;
737  unsigned flags:DICT_TF_BITS;
738  unsigned flags2:DICT_TF2_BITS;
739  unsigned ibd_file_missing:1;
744  unsigned cached:1;
746  unsigned to_be_dropped:1;
754  unsigned n_def:10;
755  unsigned n_cols:10;
756  unsigned can_be_evicted:1;
759  unsigned corrupted:1;
761  unsigned drop_aborted:1;
765  dict_col_t* cols;
766  const char* col_names;
772 #ifndef UNIV_HOTBACKUP
773  hash_node_t name_hash;
774  hash_node_t id_hash;
775  UT_LIST_BASE_NODE_T(dict_index_t)
776  indexes;
777  UT_LIST_BASE_NODE_T(dict_foreign_t)
778  foreign_list;
781  UT_LIST_BASE_NODE_T(dict_foreign_t)
782  referenced_list;
785  table_LRU;
786  unsigned fk_max_recusive_level:8;
792  ulint n_foreign_key_checks_running;
798  trx_id_t def_trx_id;
804  trx_id_t query_cache_inv_trx_id;
812 #ifdef UNIV_DEBUG
813  /*----------------------*/
814  ibool does_not_fit_in_memory;
825 #endif /* UNIV_DEBUG */
826  /*----------------------*/
827  unsigned big_rows:1;
832  /* @{ */
833  unsigned stat_initialized:1;
838  ib_uint32_t stat_persistent;
855 #define DICT_STATS_PERSISTENT_ON (1 << 1)
856 #define DICT_STATS_PERSISTENT_OFF (1 << 2)
857  ib_uint32_t stats_auto_recalc;
876 #define DICT_STATS_AUTO_RECALC_ON (1 << 1)
877 #define DICT_STATS_AUTO_RECALC_OFF (1 << 2)
878  ulint stats_sample_pages;
884  ib_uint64_t stat_n_rows;
887  ulint stat_clustered_index_size;
892  ib_uint64_t stat_modified_counter;
905 #define BG_STAT_NONE 0
906 #define BG_STAT_IN_PROGRESS (1 << 0)
907 
912 #define BG_STAT_SHOULD_QUIT (1 << 1)
913 
918  byte stats_bg_flag;
922  /* @} */
923  /*----------------------*/
938  /* @{ */
939  lock_t* autoinc_lock;
947  ib_mutex_t autoinc_mutex;
950  ib_uint64_t autoinc;
952  ulong n_waiting_or_granted_auto_inc_locks;
961  const trx_t* autoinc_trx;
965  fts_t* fts; /* FTS specific state variables */
966  /* @} */
967  /*----------------------*/
969  ib_quiesce_t quiesce;
975  /*----------------------*/
976  ulint n_rec_locks;
981  ulint n_ref_count;
987  UT_LIST_BASE_NODE_T(lock_t)
988  locks;
990 #endif /* !UNIV_HOTBACKUP */
991 
992 #ifdef UNIV_DEBUG
993  ulint magic_n;
995 # define DICT_TABLE_MAGIC_N 76333786
996 #endif /* UNIV_DEBUG */
997 };
998 
999 #ifndef UNIV_NONINL
1000 #include "dict0mem.ic"
1001 #endif
1002 
1003 #endif