00001 /****************************************************** 00002 Data dictionary memory object creation 00003 00004 (c) 1996 Innobase Oy 00005 00006 Created 1/8/1996 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef dict0mem_h 00010 #define dict0mem_h 00011 00012 #include "univ.i" 00013 #include "dict0types.h" 00014 #include "data0type.h" 00015 #include "data0data.h" 00016 #include "mem0mem.h" 00017 #include "rem0types.h" 00018 #include "btr0types.h" 00019 #include "ut0mem.h" 00020 #include "ut0lst.h" 00021 #include "ut0rnd.h" 00022 #include "ut0byte.h" 00023 #include "sync0rw.h" 00024 #include "lock0types.h" 00025 #include "hash0hash.h" 00026 #include "que0types.h" 00027 00028 /* Type flags of an index: OR'ing of the flags is allowed to define a 00029 combination of types */ 00030 #define DICT_CLUSTERED 1 /* clustered index */ 00031 #define DICT_UNIQUE 2 /* unique index */ 00032 #define DICT_UNIVERSAL 4 /* index which can contain records from any 00033 other index */ 00034 #define DICT_IBUF 8 /* insert buffer tree */ 00035 00036 /* Types for a table object */ 00037 #define DICT_TABLE_ORDINARY 1 00038 #if 0 /* not implemented */ 00039 #define DICT_TABLE_CLUSTER_MEMBER 2 00040 #define DICT_TABLE_CLUSTER 3 /* this means that the table is 00041 really a cluster definition */ 00042 #endif 00043 00044 /* Table flags */ 00045 #define DICT_TF_COMPACT 1 /* compact page format */ 00046 00047 /************************************************************************** 00048 Creates a table memory object. */ 00049 00050 dict_table_t* 00051 dict_mem_table_create( 00052 /*==================*/ 00053 /* out, own: table object */ 00054 const char* name, /* in: table name */ 00055 ulint space, /* in: space where the clustered index 00056 of the table is placed; this parameter 00057 is ignored if the table is made 00058 a member of a cluster */ 00059 ulint n_cols, /* in: number of columns */ 00060 ulint flags); /* in: table flags */ 00061 /******************************************************************** 00062 Free a table memory object. */ 00063 00064 void 00065 dict_mem_table_free( 00066 /*================*/ 00067 dict_table_t* table); /* in: table */ 00068 /************************************************************************** 00069 Adds a column definition to a table. */ 00070 00071 void 00072 dict_mem_table_add_col( 00073 /*===================*/ 00074 dict_table_t* table, /* in: table */ 00075 const char* name, /* in: column name */ 00076 ulint mtype, /* in: main datatype */ 00077 ulint prtype, /* in: precise type */ 00078 ulint len, /* in: length */ 00079 ulint prec); /* in: precision */ 00080 /************************************************************************** 00081 Creates an index memory object. */ 00082 00083 dict_index_t* 00084 dict_mem_index_create( 00085 /*==================*/ 00086 /* out, own: index object */ 00087 const char* table_name, /* in: table name */ 00088 const char* index_name, /* in: index name */ 00089 ulint space, /* in: space where the index tree is 00090 placed, ignored if the index is of 00091 the clustered type */ 00092 ulint type, /* in: DICT_UNIQUE, 00093 DICT_CLUSTERED, ... ORed */ 00094 ulint n_fields); /* in: number of fields */ 00095 /************************************************************************** 00096 Adds a field definition to an index. NOTE: does not take a copy 00097 of the column name if the field is a column. The memory occupied 00098 by the column name may be released only after publishing the index. */ 00099 00100 void 00101 dict_mem_index_add_field( 00102 /*=====================*/ 00103 dict_index_t* index, /* in: index */ 00104 const char* name, /* in: column name */ 00105 ulint prefix_len); /* in: 0 or the column prefix length 00106 in a MySQL index like 00107 INDEX (textcol(25)) */ 00108 /************************************************************************** 00109 Frees an index memory object. */ 00110 00111 void 00112 dict_mem_index_free( 00113 /*================*/ 00114 dict_index_t* index); /* in: index */ 00115 /************************************************************************** 00116 Creates and initializes a foreign constraint memory object. */ 00117 00118 dict_foreign_t* 00119 dict_mem_foreign_create(void); 00120 /*=========================*/ 00121 /* out, own: foreign constraint struct */ 00122 00123 /* Data structure for a column in a table */ 00124 struct dict_col_struct{ 00125 hash_node_t hash; /* hash chain node */ 00126 ulint ind; /* table column position (they are numbered 00127 starting from 0) */ 00128 ulint clust_pos;/* position of the column in the 00129 clustered index */ 00130 ulint ord_part;/* count of how many times this column 00131 appears in ordering fields of an index */ 00132 const char* name; /* name */ 00133 dtype_t type; /* data type */ 00134 dict_table_t* table; /* back pointer to table of this column */ 00135 ulint aux; /* this is used as an auxiliary variable 00136 in some of the functions below */ 00137 }; 00138 00139 /* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column 00140 length + 1. Starting from 4.1.6, we set it to < 3 * 256, so that one can 00141 create a column prefix index on 255 characters of a TEXT field also in the 00142 UTF-8 charset. In that charset, a character may take at most 3 bytes. */ 00143 00144 #define DICT_MAX_INDEX_COL_LEN 768 00145 00146 /* Data structure for a field in an index */ 00147 struct dict_field_struct{ 00148 dict_col_t* col; /* pointer to the table column */ 00149 const char* name; /* name of the column */ 00150 ulint prefix_len; /* 0 or the length of the column 00151 prefix in bytes in a MySQL index of 00152 type, e.g., INDEX (textcol(25)); 00153 must be smaller than 00154 DICT_MAX_INDEX_COL_LEN; NOTE that 00155 in the UTF-8 charset, MySQL sets this 00156 to 3 * the prefix len in UTF-8 chars */ 00157 ulint fixed_len; /* 0 or the fixed length of the 00158 column if smaller than 00159 DICT_MAX_INDEX_COL_LEN */ 00160 }; 00161 00162 /* Data structure for an index tree */ 00163 struct dict_tree_struct{ 00164 ulint type; /* tree type */ 00165 dulint id; /* id of the index stored in the tree */ 00166 ulint space; /* space of index tree */ 00167 ulint page; /* index tree root page number */ 00168 byte pad[64];/* Padding to prevent other memory hotspots on 00169 the same memory cache line */ 00170 rw_lock_t lock; /* read-write lock protecting the upper levels 00171 of the index tree */ 00172 dict_index_t* tree_index; /* the index stored in the 00173 index tree */ 00174 ulint magic_n;/* magic number */ 00175 }; 00176 00177 #define DICT_TREE_MAGIC_N 7545676 00178 00179 /* Data structure for an index */ 00180 struct dict_index_struct{ 00181 dulint id; /* id of the index */ 00182 mem_heap_t* heap; /* memory heap */ 00183 ulint type; /* index type */ 00184 const char* name; /* index name */ 00185 const char* table_name; /* table name */ 00186 dict_table_t* table; /* back pointer to table */ 00187 ulint space; /* space where the index tree is placed */ 00188 ulint trx_id_offset;/* position of the the trx id column 00189 in a clustered index record, if the fields 00190 before it are known to be of a fixed size, 00191 0 otherwise */ 00192 ulint n_user_defined_cols; 00193 /* number of columns the user defined to 00194 be in the index: in the internal 00195 representation we add more columns */ 00196 ulint n_uniq; /* number of fields from the beginning 00197 which are enough to determine an index 00198 entry uniquely */ 00199 ulint n_def; /* number of fields defined so far */ 00200 ulint n_fields;/* number of fields in the index */ 00201 dict_field_t* fields; /* array of field descriptions */ 00202 ulint n_nullable;/* number of nullable fields */ 00203 UT_LIST_NODE_T(dict_index_t) 00204 indexes;/* list of indexes of the table */ 00205 dict_tree_t* tree; /* index tree struct */ 00206 UT_LIST_NODE_T(dict_index_t) 00207 tree_indexes; /* list of indexes of the same index 00208 tree */ 00209 ibool cached; /* TRUE if the index object is in the 00210 dictionary cache */ 00211 btr_search_t* search_info; /* info used in optimistic searches */ 00212 /*----------------------*/ 00213 ib_longlong* stat_n_diff_key_vals; 00214 /* approximate number of different key values 00215 for this index, for each n-column prefix 00216 where n <= dict_get_n_unique(index); we 00217 periodically calculate new estimates */ 00218 ulint stat_index_size; 00219 /* approximate index size in database pages */ 00220 ulint stat_n_leaf_pages; 00221 /* approximate number of leaf pages in the 00222 index tree */ 00223 ulint magic_n;/* magic number */ 00224 }; 00225 00226 /* Data structure for a foreign key constraint; an example: 00227 FOREIGN KEY (A, B) REFERENCES TABLE2 (C, D) */ 00228 00229 struct dict_foreign_struct{ 00230 mem_heap_t* heap; /* this object is allocated from 00231 this memory heap */ 00232 char* id; /* id of the constraint as a 00233 null-terminated string */ 00234 ulint type; /* 0 or DICT_FOREIGN_ON_DELETE_CASCADE 00235 or DICT_FOREIGN_ON_DELETE_SET_NULL */ 00236 char* foreign_table_name;/* foreign table name */ 00237 dict_table_t* foreign_table; /* table where the foreign key is */ 00238 const char** foreign_col_names;/* names of the columns in the 00239 foreign key */ 00240 char* referenced_table_name;/* referenced table name */ 00241 dict_table_t* referenced_table;/* table where the referenced key 00242 is */ 00243 const char** referenced_col_names;/* names of the referenced 00244 columns in the referenced table */ 00245 ulint n_fields; /* number of indexes' first fields 00246 for which the the foreign key 00247 constraint is defined: we allow the 00248 indexes to contain more fields than 00249 mentioned in the constraint, as long 00250 as the first fields are as mentioned */ 00251 dict_index_t* foreign_index; /* foreign index; we require that 00252 both tables contain explicitly defined 00253 indexes for the constraint: InnoDB 00254 does not generate new indexes 00255 implicitly */ 00256 dict_index_t* referenced_index;/* referenced index */ 00257 UT_LIST_NODE_T(dict_foreign_t) 00258 foreign_list; /* list node for foreign keys of the 00259 table */ 00260 UT_LIST_NODE_T(dict_foreign_t) 00261 referenced_list;/* list node for referenced keys of the 00262 table */ 00263 }; 00264 00265 /* The flags for ON_UPDATE and ON_DELETE can be ORed; the default is that 00266 a foreign key constraint is enforced, therefore RESTRICT just means no flag */ 00267 #define DICT_FOREIGN_ON_DELETE_CASCADE 1 00268 #define DICT_FOREIGN_ON_DELETE_SET_NULL 2 00269 #define DICT_FOREIGN_ON_UPDATE_CASCADE 4 00270 #define DICT_FOREIGN_ON_UPDATE_SET_NULL 8 00271 #define DICT_FOREIGN_ON_DELETE_NO_ACTION 16 00272 #define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32 00273 00274 00275 #define DICT_INDEX_MAGIC_N 76789786 00276 00277 /* Data structure for a database table */ 00278 struct dict_table_struct{ 00279 dulint id; /* id of the table */ 00280 ulint flags; /* DICT_TF_COMPACT, ... */ 00281 mem_heap_t* heap; /* memory heap */ 00282 const char* name; /* table name */ 00283 const char* dir_path_of_temp_table;/* NULL or the directory path 00284 where a TEMPORARY table that was explicitly 00285 created by a user should be placed if 00286 innodb_file_per_table is defined in my.cnf; 00287 in Unix this is usually /tmp/..., in Windows 00288 \temp\... */ 00289 ulint space; /* space where the clustered index of the 00290 table is placed */ 00291 ibool ibd_file_missing;/* TRUE if this is in a single-table 00292 tablespace and the .ibd file is missing; then 00293 we must return in ha_innodb.cc an error if the 00294 user tries to query such an orphaned table */ 00295 ibool tablespace_discarded;/* this flag is set TRUE when the 00296 user calls DISCARD TABLESPACE on this table, 00297 and reset to FALSE in IMPORT TABLESPACE */ 00298 hash_node_t name_hash; /* hash chain node */ 00299 hash_node_t id_hash; /* hash chain node */ 00300 ulint n_def; /* number of columns defined so far */ 00301 ulint n_cols; /* number of columns */ 00302 dict_col_t* cols; /* array of column descriptions */ 00303 UT_LIST_BASE_NODE_T(dict_index_t) 00304 indexes; /* list of indexes of the table */ 00305 UT_LIST_BASE_NODE_T(dict_foreign_t) 00306 foreign_list;/* list of foreign key constraints 00307 in the table; these refer to columns 00308 in other tables */ 00309 UT_LIST_BASE_NODE_T(dict_foreign_t) 00310 referenced_list;/* list of foreign key constraints 00311 which refer to this table */ 00312 UT_LIST_NODE_T(dict_table_t) 00313 table_LRU; /* node of the LRU list of tables */ 00314 ulint n_mysql_handles_opened; 00315 /* count of how many handles MySQL has opened 00316 to this table; dropping of the table is 00317 NOT allowed until this count gets to zero; 00318 MySQL does NOT itself check the number of 00319 open handles at drop */ 00320 ulint n_foreign_key_checks_running; 00321 /* count of how many foreign key check 00322 operations are currently being performed 00323 on the table: we cannot drop the table while 00324 there are foreign key checks running on 00325 it! */ 00326 ibool cached; /* TRUE if the table object has been added 00327 to the dictionary cache */ 00328 lock_t* auto_inc_lock;/* a buffer for an auto-inc lock 00329 for this table: we allocate the memory here 00330 so that individual transactions can get it 00331 and release it without a need to allocate 00332 space from the lock heap of the trx: 00333 otherwise the lock heap would grow rapidly 00334 if we do a large insert from a select */ 00335 dulint query_cache_inv_trx_id; 00336 /* transactions whose trx id < than this 00337 number are not allowed to store to the MySQL 00338 query cache or retrieve from it; when a trx 00339 with undo logs commits, it sets this to the 00340 value of the trx id counter for the tables it 00341 had an IX lock on */ 00342 UT_LIST_BASE_NODE_T(lock_t) 00343 locks; /* list of locks on the table */ 00344 ulint max_row_size; 00345 /* maximum size of a single row in the 00346 table, not guaranteed to be especially 00347 accurate. it's ULINT_MAX if there are 00348 unbounded variable-width fields. initialized 00349 in dict_table_add_to_cache. */ 00350 /*----------------------*/ 00351 ibool does_not_fit_in_memory; 00352 /* this field is used to specify in simulations 00353 tables which are so big that disk should be 00354 accessed: disk access is simulated by 00355 putting the thread to sleep for a while; 00356 NOTE that this flag is not stored to the data 00357 dictionary on disk, and the database will 00358 forget about value TRUE if it has to reload 00359 the table definition from disk */ 00360 /*----------------------*/ 00361 ib_longlong stat_n_rows; 00362 /* approximate number of rows in the table; 00363 we periodically calculate new estimates */ 00364 ulint stat_clustered_index_size; 00365 /* approximate clustered index size in 00366 database pages */ 00367 ulint stat_sum_of_other_index_sizes; 00368 /* other indexes in database pages */ 00369 ibool stat_initialized; /* TRUE if statistics have 00370 been calculated the first time 00371 after database startup or table creation */ 00372 ulint stat_modified_counter; 00373 /* when a row is inserted, updated, or deleted, 00374 we add 1 to this number; we calculate new 00375 estimates for the stat_... values for the 00376 table and the indexes at an interval of 2 GB 00377 or when about 1 / 16 of table has been 00378 modified; also when the estimate operation is 00379 called for MySQL SHOW TABLE STATUS; the 00380 counter is reset to zero at statistics 00381 calculation; this counter is not protected by 00382 any latch, because this is only used for 00383 heuristics */ 00384 /*----------------------*/ 00385 mutex_t autoinc_mutex; 00386 /* mutex protecting the autoincrement 00387 counter */ 00388 ibool autoinc_inited; 00389 /* TRUE if the autoinc counter has been 00390 inited; MySQL gets the init value by executing 00391 SELECT MAX(auto inc column) */ 00392 ib_longlong autoinc;/* autoinc counter value to give to the 00393 next inserted row */ 00394 ulint magic_n;/* magic number */ 00395 }; 00396 #define DICT_TABLE_MAGIC_N 76333786 00397 00398 #ifndef UNIV_NONINL 00399 #include "dict0mem.ic" 00400 #endif 00401 00402 #endif
1.4.7

