00001 /****************************************************** 00002 Data dictionary system 00003 00004 (c) 1996 Innobase Oy 00005 00006 Created 1/8/1996 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef dict0dict_h 00010 #define dict0dict_h 00011 00012 #include "univ.i" 00013 #include "dict0types.h" 00014 #include "dict0mem.h" 00015 #include "data0type.h" 00016 #include "data0data.h" 00017 #include "sync0sync.h" 00018 #include "sync0rw.h" 00019 #include "mem0mem.h" 00020 #include "rem0types.h" 00021 #include "btr0types.h" 00022 #include "ut0mem.h" 00023 #include "ut0lst.h" 00024 #include "hash0hash.h" 00025 #include "ut0rnd.h" 00026 #include "ut0byte.h" 00027 #include "trx0types.h" 00028 00029 #ifndef UNIV_HOTBACKUP 00030 /********************************************************************** 00031 Makes all characters in a NUL-terminated UTF-8 string lower case. */ 00032 00033 void 00034 dict_casedn_str( 00035 /*============*/ 00036 char* a); /* in/out: string to put in lower case */ 00037 #endif /* !UNIV_HOTBACKUP */ 00038 /************************************************************************ 00039 Get the database name length in a table name. */ 00040 00041 ulint 00042 dict_get_db_name_len( 00043 /*=================*/ 00044 /* out: database name length */ 00045 const char* name); /* in: table name in the form 00046 dbname '/' tablename */ 00047 /************************************************************************ 00048 Return the end of table name where we have removed dbname and '/'. */ 00049 00050 const char* 00051 dict_remove_db_name( 00052 /*================*/ 00053 /* out: table name */ 00054 const char* name); /* in: table name in the form 00055 dbname '/' tablename */ 00056 /************************************************************************ 00057 Decrements the count of open MySQL handles to a table. */ 00058 00059 void 00060 dict_table_decrement_handle_count( 00061 /*==============================*/ 00062 dict_table_t* table); /* in: table */ 00063 /************************************************************************** 00064 Inits the data dictionary module. */ 00065 00066 void 00067 dict_init(void); 00068 /*===========*/ 00069 /************************************************************************ 00070 Gets the space id of every table of the data dictionary and makes a linear 00071 list and a hash table of them to the data dictionary cache. This function 00072 can be called at database startup if we did not need to do a crash recovery. 00073 In crash recovery we must scan the space id's from the .ibd files in MySQL 00074 database directories. */ 00075 00076 void 00077 dict_load_space_id_list(void); 00078 /*=========================*/ 00079 /************************************************************************* 00080 Gets the column data type. */ 00081 UNIV_INLINE 00082 dtype_t* 00083 dict_col_get_type( 00084 /*==============*/ 00085 dict_col_t* col); 00086 /************************************************************************* 00087 Gets the column number. */ 00088 UNIV_INLINE 00089 ulint 00090 dict_col_get_no( 00091 /*============*/ 00092 dict_col_t* col); 00093 /************************************************************************* 00094 Gets the column position in the clustered index. */ 00095 UNIV_INLINE 00096 ulint 00097 dict_col_get_clust_pos( 00098 /*===================*/ 00099 dict_col_t* col); 00100 /******************************************************************** 00101 If the given column name is reserved for InnoDB system columns, return 00102 TRUE. */ 00103 00104 ibool 00105 dict_col_name_is_reserved( 00106 /*======================*/ 00107 /* out: TRUE if name is reserved */ 00108 const char* name); /* in: column name */ 00109 /************************************************************************ 00110 Initializes the autoinc counter. It is not an error to initialize an already 00111 initialized counter. */ 00112 00113 void 00114 dict_table_autoinc_initialize( 00115 /*==========================*/ 00116 dict_table_t* table, /* in: table */ 00117 ib_longlong value); /* in: next value to assign to a row */ 00118 /************************************************************************ 00119 Gets the next autoinc value (== autoinc counter value), 0 if not yet 00120 initialized. If initialized, increments the counter by 1. */ 00121 00122 ib_longlong 00123 dict_table_autoinc_get( 00124 /*===================*/ 00125 /* out: value for a new row, or 0 */ 00126 dict_table_t* table); /* in: table */ 00127 /************************************************************************ 00128 Decrements the autoinc counter value by 1. */ 00129 00130 void 00131 dict_table_autoinc_decrement( 00132 /*=========================*/ 00133 dict_table_t* table); /* in: table */ 00134 /************************************************************************ 00135 Reads the next autoinc value (== autoinc counter value), 0 if not yet 00136 initialized. */ 00137 00138 ib_longlong 00139 dict_table_autoinc_read( 00140 /*====================*/ 00141 /* out: value for a new row, or 0 */ 00142 dict_table_t* table); /* in: table */ 00143 /************************************************************************ 00144 Peeks the autoinc counter value, 0 if not yet initialized. Does not 00145 increment the counter. The read not protected by any mutex! */ 00146 00147 ib_longlong 00148 dict_table_autoinc_peek( 00149 /*====================*/ 00150 /* out: value of the counter */ 00151 dict_table_t* table); /* in: table */ 00152 /************************************************************************ 00153 Updates the autoinc counter if the value supplied is equal or bigger than the 00154 current value. If not inited, does nothing. */ 00155 00156 void 00157 dict_table_autoinc_update( 00158 /*======================*/ 00159 00160 dict_table_t* table, /* in: table */ 00161 ib_longlong value); /* in: value which was assigned to a row */ 00162 /************************************************************************** 00163 Adds a table object to the dictionary cache. */ 00164 00165 void 00166 dict_table_add_to_cache( 00167 /*====================*/ 00168 dict_table_t* table); /* in: table */ 00169 /************************************************************************** 00170 Removes a table object from the dictionary cache. */ 00171 00172 void 00173 dict_table_remove_from_cache( 00174 /*=========================*/ 00175 dict_table_t* table); /* in, own: table */ 00176 /************************************************************************** 00177 Renames a table object. */ 00178 00179 ibool 00180 dict_table_rename_in_cache( 00181 /*=======================*/ 00182 /* out: TRUE if success */ 00183 dict_table_t* table, /* in: table */ 00184 const char* new_name, /* in: new name */ 00185 ibool rename_also_foreigns);/* in: in ALTER TABLE we want 00186 to preserve the original table name 00187 in constraints which reference it */ 00188 /************************************************************************** 00189 Change the id of a table object in the dictionary cache. This is used in 00190 DISCARD TABLESPACE. */ 00191 00192 void 00193 dict_table_change_id_in_cache( 00194 /*==========================*/ 00195 dict_table_t* table, /* in: table object already in cache */ 00196 dulint new_id);/* in: new id to set */ 00197 /************************************************************************** 00198 Adds a foreign key constraint object to the dictionary cache. May free 00199 the object if there already is an object with the same identifier in. 00200 At least one of foreign table or referenced table must already be in 00201 the dictionary cache! */ 00202 00203 ulint 00204 dict_foreign_add_to_cache( 00205 /*======================*/ 00206 /* out: DB_SUCCESS or error code */ 00207 dict_foreign_t* foreign, /* in, own: foreign key constraint */ 00208 ibool check_charsets);/* in: TRUE=check charset 00209 compatibility */ 00210 /************************************************************************* 00211 Checks if a table is referenced by foreign keys. */ 00212 00213 ibool 00214 dict_table_referenced_by_foreign_key( 00215 /*=================================*/ 00216 /* out: TRUE if table is referenced by a 00217 foreign key */ 00218 dict_table_t* table); /* in: InnoDB table */ 00219 /************************************************************************** 00220 Determines whether a string starts with the specified keyword. */ 00221 00222 ibool 00223 dict_str_starts_with_keyword( 00224 /*=========================*/ 00225 /* out: TRUE if str starts 00226 with keyword */ 00227 void* mysql_thd, /* in: MySQL thread handle */ 00228 const char* str, /* in: string to scan for keyword */ 00229 const char* keyword); /* in: keyword to look for */ 00230 /************************************************************************* 00231 Scans a table create SQL string and adds to the data dictionary 00232 the foreign key constraints declared in the string. This function 00233 should be called after the indexes for a table have been created. 00234 Each foreign key constraint must be accompanied with indexes in 00235 bot participating tables. The indexes are allowed to contain more 00236 fields than mentioned in the constraint. */ 00237 00238 ulint 00239 dict_create_foreign_constraints( 00240 /*============================*/ 00241 /* out: error code or DB_SUCCESS */ 00242 trx_t* trx, /* in: transaction */ 00243 const char* sql_string, /* in: table create statement where 00244 foreign keys are declared like: 00245 FOREIGN KEY (a, b) REFERENCES 00246 table2(c, d), table2 can be written 00247 also with the database 00248 name before it: test.table2; the 00249 default database id the database of 00250 parameter name */ 00251 const char* name, /* in: table full name in the 00252 normalized form 00253 database_name/table_name */ 00254 ibool reject_fks); /* in: if TRUE, fail with error 00255 code DB_CANNOT_ADD_CONSTRAINT if 00256 any foreign keys are found. */ 00257 /************************************************************************** 00258 Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. */ 00259 00260 ulint 00261 dict_foreign_parse_drop_constraints( 00262 /*================================*/ 00263 /* out: DB_SUCCESS or 00264 DB_CANNOT_DROP_CONSTRAINT if 00265 syntax error or the constraint 00266 id does not match */ 00267 mem_heap_t* heap, /* in: heap from which we can 00268 allocate memory */ 00269 trx_t* trx, /* in: transaction */ 00270 dict_table_t* table, /* in: table */ 00271 ulint* n, /* out: number of constraints 00272 to drop */ 00273 const char*** constraints_to_drop); /* out: id's of the 00274 constraints to drop */ 00275 /************************************************************************** 00276 Returns a table object. NOTE! This is a high-level function to be used 00277 mainly from outside the 'dict' directory. Inside this directory 00278 dict_table_get_low is usually the appropriate function. */ 00279 00280 dict_table_t* 00281 dict_table_get( 00282 /*===========*/ 00283 /* out: table, NULL if 00284 does not exist */ 00285 const char* table_name); /* in: table name */ 00286 /************************************************************************** 00287 Returns a table object and increments MySQL open handle count on the table. 00288 */ 00289 00290 dict_table_t* 00291 dict_table_get_and_increment_handle_count( 00292 /*======================================*/ 00293 /* out: table, NULL if 00294 does not exist */ 00295 const char* table_name); /* in: table name */ 00296 /************************************************************************** 00297 Returns a table object based on table id. */ 00298 00299 dict_table_t* 00300 dict_table_get_on_id( 00301 /*=================*/ 00302 /* out: table, NULL if does not exist */ 00303 dulint table_id, /* in: table id */ 00304 trx_t* trx); /* in: transaction handle */ 00305 /************************************************************************** 00306 Returns a table object based on table id. */ 00307 UNIV_INLINE 00308 dict_table_t* 00309 dict_table_get_on_id_low( 00310 /*=====================*/ 00311 /* out: table, NULL if does not exist */ 00312 dulint table_id); /* in: table id */ 00313 /************************************************************************** 00314 Checks if a table is in the dictionary cache. */ 00315 UNIV_INLINE 00316 dict_table_t* 00317 dict_table_check_if_in_cache_low( 00318 /*=============================*/ 00319 /* out: table, NULL if not found */ 00320 const char* table_name); /* in: table name */ 00321 /************************************************************************** 00322 Gets a table; loads it to the dictionary cache if necessary. A low-level 00323 function. */ 00324 UNIV_INLINE 00325 dict_table_t* 00326 dict_table_get_low( 00327 /*===============*/ 00328 /* out: table, NULL if not found */ 00329 const char* table_name); /* in: table name */ 00330 /************************************************************************** 00331 A noninlined version of dict_table_get_low. */ 00332 00333 dict_table_t* 00334 dict_table_get_low_noninlined( 00335 /*==========================*/ 00336 /* out: table, NULL if not found */ 00337 const char* table_name); /* in: table name */ 00338 /************************************************************************** 00339 Returns an index object. */ 00340 UNIV_INLINE 00341 dict_index_t* 00342 dict_table_get_index( 00343 /*=================*/ 00344 /* out: index, NULL if does not exist */ 00345 dict_table_t* table, /* in: table */ 00346 const char* name); /* in: index name */ 00347 /************************************************************************** 00348 Returns an index object. */ 00349 00350 dict_index_t* 00351 dict_table_get_index_noninline( 00352 /*===========================*/ 00353 /* out: index, NULL if does not exist */ 00354 dict_table_t* table, /* in: table */ 00355 const char* name); /* in: index name */ 00356 /************************************************************************** 00357 Prints a table definition. */ 00358 00359 void 00360 dict_table_print( 00361 /*=============*/ 00362 dict_table_t* table); /* in: table */ 00363 /************************************************************************** 00364 Prints a table data. */ 00365 00366 void 00367 dict_table_print_low( 00368 /*=================*/ 00369 dict_table_t* table); /* in: table */ 00370 /************************************************************************** 00371 Prints a table data when we know the table name. */ 00372 00373 void 00374 dict_table_print_by_name( 00375 /*=====================*/ 00376 const char* name); 00377 /************************************************************************** 00378 Outputs info on foreign keys of a table. */ 00379 00380 void 00381 dict_print_info_on_foreign_keys( 00382 /*============================*/ 00383 ibool create_table_format, /* in: if TRUE then print in 00384 a format suitable to be inserted into 00385 a CREATE TABLE, otherwise in the format 00386 of SHOW TABLE STATUS */ 00387 FILE* file, /* in: file where to print */ 00388 trx_t* trx, /* in: transaction */ 00389 dict_table_t* table); /* in: table */ 00390 /************************************************************************** 00391 Outputs info on a foreign key of a table in a format suitable for 00392 CREATE TABLE. */ 00393 void 00394 dict_print_info_on_foreign_key_in_create_format( 00395 /*============================================*/ 00396 FILE* file, /* in: file where to print */ 00397 trx_t* trx, /* in: transaction */ 00398 dict_foreign_t* foreign, /* in: foreign key constraint */ 00399 ibool add_newline); /* in: whether to add a newline */ 00400 /************************************************************************ 00401 Displays the names of the index and the table. */ 00402 void 00403 dict_index_name_print( 00404 /*==================*/ 00405 FILE* file, /* in: output stream */ 00406 trx_t* trx, /* in: transaction */ 00407 const dict_index_t* index); /* in: index to print */ 00408 /************************************************************************ 00409 Gets the first index on the table (the clustered index). */ 00410 UNIV_INLINE 00411 dict_index_t* 00412 dict_table_get_first_index( 00413 /*=======================*/ 00414 /* out: index, NULL if none exists */ 00415 dict_table_t* table); /* in: table */ 00416 /************************************************************************ 00417 Gets the first index on the table (the clustered index). */ 00418 00419 dict_index_t* 00420 dict_table_get_first_index_noninline( 00421 /*=================================*/ 00422 /* out: index, NULL if none exists */ 00423 dict_table_t* table); /* in: table */ 00424 /************************************************************************ 00425 Gets the next index on the table. */ 00426 UNIV_INLINE 00427 dict_index_t* 00428 dict_table_get_next_index( 00429 /*======================*/ 00430 /* out: index, NULL if none left */ 00431 dict_index_t* index); /* in: index */ 00432 /************************************************************************ 00433 Gets the next index on the table. */ 00434 00435 dict_index_t* 00436 dict_table_get_next_index_noninline( 00437 /*================================*/ 00438 /* out: index, NULL if none left */ 00439 dict_index_t* index); /* in: index */ 00440 /************************************************************************ 00441 Gets the number of user-defined columns in a table in the dictionary 00442 cache. */ 00443 UNIV_INLINE 00444 ulint 00445 dict_table_get_n_user_cols( 00446 /*=======================*/ 00447 /* out: number of user-defined (e.g., not 00448 ROW_ID) columns of a table */ 00449 dict_table_t* table); /* in: table */ 00450 /************************************************************************ 00451 Gets the number of system columns in a table in the dictionary cache. */ 00452 UNIV_INLINE 00453 ulint 00454 dict_table_get_n_sys_cols( 00455 /*======================*/ 00456 /* out: number of system (e.g., 00457 ROW_ID) columns of a table */ 00458 dict_table_t* table); /* in: table */ 00459 /************************************************************************ 00460 Gets the number of all columns (also system) in a table in the dictionary 00461 cache. */ 00462 UNIV_INLINE 00463 ulint 00464 dict_table_get_n_cols( 00465 /*==================*/ 00466 /* out: number of columns of a table */ 00467 dict_table_t* table); /* in: table */ 00468 /************************************************************************ 00469 Gets the nth column of a table. */ 00470 UNIV_INLINE 00471 dict_col_t* 00472 dict_table_get_nth_col( 00473 /*===================*/ 00474 /* out: pointer to column object */ 00475 dict_table_t* table, /* in: table */ 00476 ulint pos); /* in: position of column */ 00477 /************************************************************************ 00478 Gets the nth column of a table. */ 00479 00480 dict_col_t* 00481 dict_table_get_nth_col_noninline( 00482 /*=============================*/ 00483 /* out: pointer to column object */ 00484 dict_table_t* table, /* in: table */ 00485 ulint pos); /* in: position of column */ 00486 /************************************************************************ 00487 Gets the given system column of a table. */ 00488 UNIV_INLINE 00489 dict_col_t* 00490 dict_table_get_sys_col( 00491 /*===================*/ 00492 /* out: pointer to column object */ 00493 dict_table_t* table, /* in: table */ 00494 ulint sys); /* in: DATA_ROW_ID, ... */ 00495 /************************************************************************ 00496 Gets the given system column number of a table. */ 00497 UNIV_INLINE 00498 ulint 00499 dict_table_get_sys_col_no( 00500 /*======================*/ 00501 /* out: column number */ 00502 dict_table_t* table, /* in: table */ 00503 ulint sys); /* in: DATA_ROW_ID, ... */ 00504 /************************************************************************ 00505 Check whether the table uses the compact page format. */ 00506 UNIV_INLINE 00507 ibool 00508 dict_table_is_comp( 00509 /*===============*/ 00510 /* out: TRUE if table uses the 00511 compact page format */ 00512 const dict_table_t* table); /* in: table */ 00513 /************************************************************************ 00514 Check whether the table uses the compact page format. */ 00515 00516 ibool 00517 dict_table_is_comp_noninline( 00518 /*=========================*/ 00519 /* out: TRUE if table uses the 00520 compact page format */ 00521 const dict_table_t* table); /* in: table */ 00522 /************************************************************************ 00523 Checks if a column is in the ordering columns of the clustered index of a 00524 table. Column prefixes are treated like whole columns. */ 00525 00526 ibool 00527 dict_table_col_in_clustered_key( 00528 /*============================*/ 00529 /* out: TRUE if the column, or its prefix, is 00530 in the clustered key */ 00531 dict_table_t* table, /* in: table */ 00532 ulint n); /* in: column number */ 00533 /*********************************************************************** 00534 Copies types of columns contained in table to tuple. */ 00535 00536 void 00537 dict_table_copy_types( 00538 /*==================*/ 00539 dtuple_t* tuple, /* in: data tuple */ 00540 dict_table_t* table); /* in: index */ 00541 /************************************************************************** 00542 Looks for an index with the given id. NOTE that we do not reserve 00543 the dictionary mutex: this function is for emergency purposes like 00544 printing info of a corrupt database page! */ 00545 00546 dict_index_t* 00547 dict_index_find_on_id_low( 00548 /*======================*/ 00549 /* out: index or NULL if not found from cache */ 00550 dulint id); /* in: index id */ 00551 /************************************************************************** 00552 Adds an index to dictionary cache. */ 00553 00554 ibool 00555 dict_index_add_to_cache( 00556 /*====================*/ 00557 /* out: TRUE if success */ 00558 dict_table_t* table, /* in: table on which the index is */ 00559 dict_index_t* index, /* in, own: index; NOTE! The index memory 00560 object is freed in this function! */ 00561 ulint page_no);/* in: root page number of the index */ 00562 /************************************************************************ 00563 Gets the number of fields in the internal representation of an index, 00564 including fields added by the dictionary system. */ 00565 UNIV_INLINE 00566 ulint 00567 dict_index_get_n_fields( 00568 /*====================*/ 00569 /* out: number of fields */ 00570 dict_index_t* index); /* in: an internal representation of index 00571 (in the dictionary cache) */ 00572 /************************************************************************ 00573 Gets the number of fields in the internal representation of an index 00574 that uniquely determine the position of an index entry in the index, if 00575 we do not take multiversioning into account: in the B-tree use the value 00576 returned by dict_index_get_n_unique_in_tree. */ 00577 UNIV_INLINE 00578 ulint 00579 dict_index_get_n_unique( 00580 /*====================*/ 00581 /* out: number of fields */ 00582 dict_index_t* index); /* in: an internal representation of index 00583 (in the dictionary cache) */ 00584 /************************************************************************ 00585 Gets the number of fields in the internal representation of an index 00586 which uniquely determine the position of an index entry in the index, if 00587 we also take multiversioning into account. */ 00588 UNIV_INLINE 00589 ulint 00590 dict_index_get_n_unique_in_tree( 00591 /*============================*/ 00592 /* out: number of fields */ 00593 dict_index_t* index); /* in: an internal representation of index 00594 (in the dictionary cache) */ 00595 /************************************************************************ 00596 Gets the number of user-defined ordering fields in the index. In the internal 00597 representation we add the row id to the ordering fields to make all indexes 00598 unique, but this function returns the number of fields the user defined 00599 in the index as ordering fields. */ 00600 UNIV_INLINE 00601 ulint 00602 dict_index_get_n_ordering_defined_by_user( 00603 /*======================================*/ 00604 /* out: number of fields */ 00605 dict_index_t* index); /* in: an internal representation of index 00606 (in the dictionary cache) */ 00607 /************************************************************************ 00608 Gets the nth field of an index. */ 00609 UNIV_INLINE 00610 dict_field_t* 00611 dict_index_get_nth_field( 00612 /*=====================*/ 00613 /* out: pointer to field object */ 00614 dict_index_t* index, /* in: index */ 00615 ulint pos); /* in: position of field */ 00616 /************************************************************************ 00617 Gets pointer to the nth field data type in an index. */ 00618 UNIV_INLINE 00619 dtype_t* 00620 dict_index_get_nth_type( 00621 /*====================*/ 00622 /* out: data type */ 00623 dict_index_t* index, /* in: index */ 00624 ulint pos); /* in: position of the field */ 00625 /************************************************************************ 00626 Gets the column number of the nth field in an index. */ 00627 UNIV_INLINE 00628 ulint 00629 dict_index_get_nth_col_no( 00630 /*======================*/ 00631 /* out: column number */ 00632 dict_index_t* index, /* in: index */ 00633 ulint pos); /* in: position of the field */ 00634 /************************************************************************ 00635 Looks for column n in an index. */ 00636 00637 ulint 00638 dict_index_get_nth_col_pos( 00639 /*=======================*/ 00640 /* out: position in internal representation 00641 of the index; if not contained, returns 00642 ULINT_UNDEFINED */ 00643 dict_index_t* index, /* in: index */ 00644 ulint n); /* in: column number */ 00645 /************************************************************************ 00646 Returns TRUE if the index contains a column or a prefix of that column. */ 00647 00648 ibool 00649 dict_index_contains_col_or_prefix( 00650 /*==============================*/ 00651 /* out: TRUE if contains the column or its 00652 prefix */ 00653 dict_index_t* index, /* in: index */ 00654 ulint n); /* in: column number */ 00655 /************************************************************************ 00656 Looks for a matching field in an index. The column has to be the same. The 00657 column in index must be complete, or must contain a prefix longer than the 00658 column in index2. That is, we must be able to construct the prefix in index2 00659 from the prefix in index. */ 00660 00661 ulint 00662 dict_index_get_nth_field_pos( 00663 /*=========================*/ 00664 /* out: position in internal representation 00665 of the index; if not contained, returns 00666 ULINT_UNDEFINED */ 00667 dict_index_t* index, /* in: index from which to search */ 00668 dict_index_t* index2, /* in: index */ 00669 ulint n); /* in: field number in index2 */ 00670 /************************************************************************ 00671 Looks for column n position in the clustered index. */ 00672 00673 ulint 00674 dict_table_get_nth_col_pos( 00675 /*=======================*/ 00676 /* out: position in internal representation 00677 of the clustered index */ 00678 dict_table_t* table, /* in: table */ 00679 ulint n); /* in: column number */ 00680 /************************************************************************ 00681 Returns the position of a system column in an index. */ 00682 UNIV_INLINE 00683 ulint 00684 dict_index_get_sys_col_pos( 00685 /*=======================*/ 00686 /* out: position, ULINT_UNDEFINED if not 00687 contained */ 00688 dict_index_t* index, /* in: index */ 00689 ulint type); /* in: DATA_ROW_ID, ... */ 00690 /*********************************************************************** 00691 Adds a column to index. */ 00692 00693 void 00694 dict_index_add_col( 00695 /*===============*/ 00696 dict_index_t* index, /* in: index */ 00697 dict_col_t* col, /* in: column */ 00698 ulint prefix_len); /* in: column prefix length */ 00699 /*********************************************************************** 00700 Copies types of fields contained in index to tuple. */ 00701 00702 void 00703 dict_index_copy_types( 00704 /*==================*/ 00705 dtuple_t* tuple, /* in: data tuple */ 00706 dict_index_t* index, /* in: index */ 00707 ulint n_fields); /* in: number of field types to copy */ 00708 /************************************************************************* 00709 Gets the index tree where the index is stored. */ 00710 UNIV_INLINE 00711 dict_tree_t* 00712 dict_index_get_tree( 00713 /*================*/ 00714 /* out: index tree */ 00715 dict_index_t* index); /* in: index */ 00716 /************************************************************************* 00717 Gets the field column. */ 00718 UNIV_INLINE 00719 dict_col_t* 00720 dict_field_get_col( 00721 /*===============*/ 00722 dict_field_t* field); 00723 /************************************************************************** 00724 Creates an index tree struct. */ 00725 00726 dict_tree_t* 00727 dict_tree_create( 00728 /*=============*/ 00729 /* out, own: created tree */ 00730 dict_index_t* index, /* in: the index for which to create: in the 00731 case of a mixed tree, this should be the 00732 index of the cluster object */ 00733 ulint page_no);/* in: root page number of the index */ 00734 /************************************************************************** 00735 Frees an index tree struct. */ 00736 00737 void 00738 dict_tree_free( 00739 /*===========*/ 00740 dict_tree_t* tree); /* in, own: index tree */ 00741 /************************************************************************** 00742 In an index tree, finds the index corresponding to a record in the tree. */ 00743 00744 /************************************************************************** 00745 Returns an index object if it is found in the dictionary cache. */ 00746 00747 dict_index_t* 00748 dict_index_get_if_in_cache( 00749 /*=======================*/ 00750 /* out: index, NULL if not found */ 00751 dulint index_id); /* in: index id */ 00752 #ifdef UNIV_DEBUG 00753 /************************************************************************** 00754 Checks that a tuple has n_fields_cmp value in a sensible range, so that 00755 no comparison can occur with the page number field in a node pointer. */ 00756 00757 ibool 00758 dict_tree_check_search_tuple( 00759 /*=========================*/ 00760 /* out: TRUE if ok */ 00761 dict_tree_t* tree, /* in: index tree */ 00762 dtuple_t* tuple); /* in: tuple used in a search */ 00763 #endif /* UNIV_DEBUG */ 00764 /************************************************************************** 00765 Builds a node pointer out of a physical record and a page number. */ 00766 00767 dtuple_t* 00768 dict_tree_build_node_ptr( 00769 /*=====================*/ 00770 /* out, own: node pointer */ 00771 dict_tree_t* tree, /* in: index tree */ 00772 rec_t* rec, /* in: record for which to build node 00773 pointer */ 00774 ulint page_no,/* in: page number to put in node pointer */ 00775 mem_heap_t* heap, /* in: memory heap where pointer created */ 00776 ulint level); /* in: level of rec in tree: 0 means leaf 00777 level */ 00778 /************************************************************************** 00779 Copies an initial segment of a physical record, long enough to specify an 00780 index entry uniquely. */ 00781 00782 rec_t* 00783 dict_tree_copy_rec_order_prefix( 00784 /*============================*/ 00785 /* out: pointer to the prefix record */ 00786 dict_tree_t* tree, /* in: index tree */ 00787 rec_t* rec, /* in: record for which to copy prefix */ 00788 ulint* n_fields,/* out: number of fields copied */ 00789 byte** buf, /* in/out: memory buffer for the copied prefix, 00790 or NULL */ 00791 ulint* buf_size);/* in/out: buffer size */ 00792 /************************************************************************** 00793 Builds a typed data tuple out of a physical record. */ 00794 00795 dtuple_t* 00796 dict_tree_build_data_tuple( 00797 /*=======================*/ 00798 /* out, own: data tuple */ 00799 dict_tree_t* tree, /* in: index tree */ 00800 rec_t* rec, /* in: record for which to build data tuple */ 00801 ulint n_fields,/* in: number of data fields */ 00802 mem_heap_t* heap); /* in: memory heap where tuple created */ 00803 /************************************************************************* 00804 Gets the space id of the root of the index tree. */ 00805 UNIV_INLINE 00806 ulint 00807 dict_tree_get_space( 00808 /*================*/ 00809 /* out: space id */ 00810 dict_tree_t* tree); /* in: tree */ 00811 /************************************************************************* 00812 Sets the space id of the root of the index tree. */ 00813 UNIV_INLINE 00814 void 00815 dict_tree_set_space( 00816 /*================*/ 00817 dict_tree_t* tree, /* in: tree */ 00818 ulint space); /* in: space id */ 00819 /************************************************************************* 00820 Gets the page number of the root of the index tree. */ 00821 UNIV_INLINE 00822 ulint 00823 dict_tree_get_page( 00824 /*===============*/ 00825 /* out: page number */ 00826 dict_tree_t* tree); /* in: tree */ 00827 /************************************************************************* 00828 Sets the page number of the root of index tree. */ 00829 UNIV_INLINE 00830 void 00831 dict_tree_set_page( 00832 /*===============*/ 00833 dict_tree_t* tree, /* in: tree */ 00834 ulint page); /* in: page number */ 00835 /************************************************************************* 00836 Gets the type of the index tree. */ 00837 UNIV_INLINE 00838 ulint 00839 dict_tree_get_type( 00840 /*===============*/ 00841 /* out: type */ 00842 dict_tree_t* tree); /* in: tree */ 00843 /************************************************************************* 00844 Gets the read-write lock of the index tree. */ 00845 UNIV_INLINE 00846 rw_lock_t* 00847 dict_tree_get_lock( 00848 /*===============*/ 00849 /* out: read-write lock */ 00850 dict_tree_t* tree); /* in: tree */ 00851 /************************************************************************ 00852 Returns free space reserved for future updates of records. This is 00853 relevant only in the case of many consecutive inserts, as updates 00854 which make the records bigger might fragment the index. */ 00855 UNIV_INLINE 00856 ulint 00857 dict_tree_get_space_reserve( 00858 /*========================*/ 00859 /* out: number of free bytes on page, 00860 reserved for updates */ 00861 dict_tree_t* tree); /* in: a tree */ 00862 /************************************************************************* 00863 Calculates the minimum record length in an index. */ 00864 00865 ulint 00866 dict_index_calc_min_rec_len( 00867 /*========================*/ 00868 dict_index_t* index); /* in: index */ 00869 /************************************************************************* 00870 Calculates new estimates for table and index statistics. The statistics 00871 are used in query optimization. */ 00872 00873 void 00874 dict_update_statistics_low( 00875 /*=======================*/ 00876 dict_table_t* table, /* in: table */ 00877 ibool has_dict_mutex);/* in: TRUE if the caller has the 00878 dictionary mutex */ 00879 /************************************************************************* 00880 Calculates new estimates for table and index statistics. The statistics 00881 are used in query optimization. */ 00882 00883 void 00884 dict_update_statistics( 00885 /*===================*/ 00886 dict_table_t* table); /* in: table */ 00887 /************************************************************************ 00888 Reserves the dictionary system mutex for MySQL. */ 00889 00890 void 00891 dict_mutex_enter_for_mysql(void); 00892 /*============================*/ 00893 /************************************************************************ 00894 Releases the dictionary system mutex for MySQL. */ 00895 00896 void 00897 dict_mutex_exit_for_mysql(void); 00898 /*===========================*/ 00899 /************************************************************************ 00900 Checks if the database name in two table names is the same. */ 00901 00902 ibool 00903 dict_tables_have_same_db( 00904 /*=====================*/ 00905 /* out: TRUE if same db name */ 00906 const char* name1, /* in: table name in the form 00907 dbname '/' tablename */ 00908 const char* name2); /* in: table name in the form 00909 dbname '/' tablename */ 00910 /************************************************************************* 00911 Scans from pointer onwards. Stops if is at the start of a copy of 00912 'string' where characters are compared without case sensitivity. Stops 00913 also at '\0'. */ 00914 00915 const char* 00916 dict_scan_to( 00917 /*=========*/ 00918 /* out: scanned up to this */ 00919 const char* ptr, /* in: scan from */ 00920 const char* string);/* in: look for this */ 00921 /* Buffers for storing detailed information about the latest foreign key 00922 and unique key errors */ 00923 extern FILE* dict_foreign_err_file; 00924 extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */ 00925 00926 extern dict_sys_t* dict_sys; /* the dictionary system */ 00927 extern rw_lock_t dict_operation_lock; 00928 00929 /* Dictionary system struct */ 00930 struct dict_sys_struct{ 00931 mutex_t mutex; /* mutex protecting the data 00932 dictionary; protects also the 00933 disk-based dictionary system tables; 00934 this mutex serializes CREATE TABLE 00935 and DROP TABLE, as well as reading 00936 the dictionary data for a table from 00937 system tables */ 00938 dulint row_id; /* the next row id to assign; 00939 NOTE that at a checkpoint this 00940 must be written to the dict system 00941 header and flushed to a file; in 00942 recovery this must be derived from 00943 the log records */ 00944 hash_table_t* table_hash; /* hash table of the tables, based 00945 on name */ 00946 hash_table_t* table_id_hash; /* hash table of the tables, based 00947 on id */ 00948 hash_table_t* col_hash; /* hash table of the columns */ 00949 UT_LIST_BASE_NODE_T(dict_table_t) 00950 table_LRU; /* LRU list of tables */ 00951 ulint size; /* varying space in bytes occupied 00952 by the data dictionary table and 00953 index objects */ 00954 dict_table_t* sys_tables; /* SYS_TABLES table */ 00955 dict_table_t* sys_columns; /* SYS_COLUMNS table */ 00956 dict_table_t* sys_indexes; /* SYS_INDEXES table */ 00957 dict_table_t* sys_fields; /* SYS_FIELDS table */ 00958 }; 00959 00960 #ifndef UNIV_NONINL 00961 #include "dict0dict.ic" 00962 #endif 00963 00964 #endif
1.4.7

