You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1407 lines
50 KiB

17 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/dict0dict.h
  15. Data dictionary system
  16. Created 1/8/1996 Heikki Tuuri
  17. *******************************************************/
  18. #ifndef dict0dict_h
  19. #define dict0dict_h
  20. #include "univ.i"
  21. #include "dict0types.h"
  22. #include "dict0mem.h"
  23. #include "data0type.h"
  24. #include "data0data.h"
  25. #include "mem0mem.h"
  26. #include "rem0types.h"
  27. #include "ut0mem.h"
  28. #include "ut0lst.h"
  29. #include "hash0hash.h"
  30. #include "ut0rnd.h"
  31. #include "ut0byte.h"
  32. #include "trx0types.h"
  33. #include "ut0rbt.h"
  34. #ifndef UNIV_HOTBACKUP
  35. # include "sync0sync.h"
  36. # include "sync0rw.h"
  37. /******************************************************************//**
  38. Makes all characters in a NUL-terminated UTF-8 string lower case. */
  39. UNIV_INTERN
  40. void
  41. dict_casedn_str(
  42. /*============*/
  43. char* a); /*!< in/out: string to put in lower case */
  44. /********************************************************************//**
  45. Get the database name length in a table name.
  46. @return database name length */
  47. UNIV_INTERN
  48. ulint
  49. dict_get_db_name_len(
  50. /*=================*/
  51. const char* name); /*!< in: table name in the form
  52. dbname '/' tablename */
  53. /********************************************************************//**
  54. Return the end of table name where we have removed dbname and '/'.
  55. @return table name */
  56. const char*
  57. dict_remove_db_name(
  58. /*================*/
  59. const char* name); /*!< in: table name in the form
  60. dbname '/' tablename */
  61. /**********************************************************************//**
  62. Returns a table object based on table id.
  63. @return table, NULL if does not exist */
  64. UNIV_INTERN
  65. dict_table_t*
  66. dict_table_get_on_id(
  67. /*=================*/
  68. table_id_t table_id, /*!< in: table id */
  69. trx_t* trx); /*!< in: transaction handle */
  70. /********************************************************************//**
  71. Decrements the count of open MySQL handles to a table. */
  72. UNIV_INTERN
  73. void
  74. dict_table_decrement_handle_count(
  75. /*==============================*/
  76. dict_table_t* table, /*!< in/out: table */
  77. ibool dict_locked); /*!< in: TRUE=data dictionary locked */
  78. /**********************************************************************//**
  79. Inits the data dictionary module. */
  80. UNIV_INTERN
  81. void
  82. dict_init(void);
  83. /*===========*/
  84. /********************************************************************//**
  85. Gets the space id of every table of the data dictionary and makes a linear
  86. list and a hash table of them to the data dictionary cache. This function
  87. can be called at database startup if we did not need to do a crash recovery.
  88. In crash recovery we must scan the space id's from the .ibd files in MySQL
  89. database directories. */
  90. UNIV_INTERN
  91. void
  92. dict_load_space_id_list(void);
  93. /*=========================*/
  94. /*********************************************************************//**
  95. Gets the minimum number of bytes per character.
  96. @return minimum multi-byte char size, in bytes */
  97. UNIV_INLINE
  98. ulint
  99. dict_col_get_mbminlen(
  100. /*==================*/
  101. const dict_col_t* col); /*!< in: column */
  102. /*********************************************************************//**
  103. Gets the maximum number of bytes per character.
  104. @return maximum multi-byte char size, in bytes */
  105. UNIV_INLINE
  106. ulint
  107. dict_col_get_mbmaxlen(
  108. /*==================*/
  109. const dict_col_t* col); /*!< in: column */
  110. /*********************************************************************//**
  111. Sets the minimum and maximum number of bytes per character. */
  112. UNIV_INLINE
  113. void
  114. dict_col_set_mbminmaxlen(
  115. /*=====================*/
  116. dict_col_t* col, /*!< in/out: column */
  117. ulint mbminlen, /*!< in: minimum multi-byte
  118. character size, in bytes */
  119. ulint mbmaxlen); /*!< in: minimum multi-byte
  120. character size, in bytes */
  121. /*********************************************************************//**
  122. Gets the column data type. */
  123. UNIV_INLINE
  124. void
  125. dict_col_copy_type(
  126. /*===============*/
  127. const dict_col_t* col, /*!< in: column */
  128. dtype_t* type); /*!< out: data type */
  129. /**********************************************************************//**
  130. Determine bytes of column prefix to be stored in the undo log. Please
  131. note if the table format is UNIV_FORMAT_A (< DICT_TF_FORMAT_ZIP), no prefix
  132. needs to be stored in the undo log.
  133. @return bytes of column prefix to be stored in the undo log */
  134. UNIV_INLINE
  135. ulint
  136. dict_max_field_len_store_undo(
  137. /*==========================*/
  138. dict_table_t* table, /*!< in: table */
  139. const dict_col_t* col); /*!< in: column which index prefix
  140. is based on */
  141. #endif /* !UNIV_HOTBACKUP */
  142. #ifdef UNIV_DEBUG
  143. /*********************************************************************//**
  144. Assert that a column and a data type match.
  145. @return TRUE */
  146. UNIV_INLINE
  147. ibool
  148. dict_col_type_assert_equal(
  149. /*=======================*/
  150. const dict_col_t* col, /*!< in: column */
  151. const dtype_t* type); /*!< in: data type */
  152. #endif /* UNIV_DEBUG */
  153. #ifndef UNIV_HOTBACKUP
  154. /***********************************************************************//**
  155. Returns the minimum size of the column.
  156. @return minimum size */
  157. UNIV_INLINE
  158. ulint
  159. dict_col_get_min_size(
  160. /*==================*/
  161. const dict_col_t* col); /*!< in: column */
  162. /***********************************************************************//**
  163. Returns the maximum size of the column.
  164. @return maximum size */
  165. UNIV_INLINE
  166. ulint
  167. dict_col_get_max_size(
  168. /*==================*/
  169. const dict_col_t* col); /*!< in: column */
  170. /***********************************************************************//**
  171. Returns the size of a fixed size column, 0 if not a fixed size column.
  172. @return fixed size, or 0 */
  173. UNIV_INLINE
  174. ulint
  175. dict_col_get_fixed_size(
  176. /*====================*/
  177. const dict_col_t* col, /*!< in: column */
  178. ulint comp); /*!< in: nonzero=ROW_FORMAT=COMPACT */
  179. /***********************************************************************//**
  180. Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
  181. For fixed length types it is the fixed length of the type, otherwise 0.
  182. @return SQL null storage size in ROW_FORMAT=REDUNDANT */
  183. UNIV_INLINE
  184. ulint
  185. dict_col_get_sql_null_size(
  186. /*=======================*/
  187. const dict_col_t* col, /*!< in: column */
  188. ulint comp); /*!< in: nonzero=ROW_FORMAT=COMPACT */
  189. /*********************************************************************//**
  190. Gets the column number.
  191. @return col->ind, table column position (starting from 0) */
  192. UNIV_INLINE
  193. ulint
  194. dict_col_get_no(
  195. /*============*/
  196. const dict_col_t* col); /*!< in: column */
  197. /*********************************************************************//**
  198. Gets the column position in the clustered index. */
  199. UNIV_INLINE
  200. ulint
  201. dict_col_get_clust_pos(
  202. /*===================*/
  203. const dict_col_t* col, /*!< in: table column */
  204. const dict_index_t* clust_index); /*!< in: clustered index */
  205. /****************************************************************//**
  206. If the given column name is reserved for InnoDB system columns, return
  207. TRUE.
  208. @return TRUE if name is reserved */
  209. UNIV_INTERN
  210. ibool
  211. dict_col_name_is_reserved(
  212. /*======================*/
  213. const char* name); /*!< in: column name */
  214. /********************************************************************//**
  215. Acquire the autoinc lock. */
  216. UNIV_INTERN
  217. void
  218. dict_table_autoinc_lock(
  219. /*====================*/
  220. dict_table_t* table); /*!< in/out: table */
  221. /********************************************************************//**
  222. Unconditionally set the autoinc counter. */
  223. UNIV_INTERN
  224. void
  225. dict_table_autoinc_initialize(
  226. /*==========================*/
  227. dict_table_t* table, /*!< in/out: table */
  228. ib_uint64_t value); /*!< in: next value to assign to a row */
  229. /********************************************************************//**
  230. Reads the next autoinc value (== autoinc counter value), 0 if not yet
  231. initialized.
  232. @return value for a new row, or 0 */
  233. UNIV_INTERN
  234. ib_uint64_t
  235. dict_table_autoinc_read(
  236. /*====================*/
  237. const dict_table_t* table); /*!< in: table */
  238. /********************************************************************//**
  239. Updates the autoinc counter if the value supplied is greater than the
  240. current value. */
  241. UNIV_INTERN
  242. void
  243. dict_table_autoinc_update_if_greater(
  244. /*=================================*/
  245. dict_table_t* table, /*!< in/out: table */
  246. ib_uint64_t value); /*!< in: value which was assigned to a row */
  247. /********************************************************************//**
  248. Release the autoinc lock. */
  249. UNIV_INTERN
  250. void
  251. dict_table_autoinc_unlock(
  252. /*======================*/
  253. dict_table_t* table); /*!< in/out: table */
  254. #endif /* !UNIV_HOTBACKUP */
  255. /**********************************************************************//**
  256. Adds system columns to a table object. */
  257. UNIV_INTERN
  258. void
  259. dict_table_add_system_columns(
  260. /*==========================*/
  261. dict_table_t* table, /*!< in/out: table */
  262. mem_heap_t* heap); /*!< in: temporary heap */
  263. #ifndef UNIV_HOTBACKUP
  264. /**********************************************************************//**
  265. Adds a table object to the dictionary cache. */
  266. UNIV_INTERN
  267. void
  268. dict_table_add_to_cache(
  269. /*====================*/
  270. dict_table_t* table, /*!< in: table */
  271. mem_heap_t* heap); /*!< in: temporary heap */
  272. /**********************************************************************//**
  273. Removes a table object from the dictionary cache. */
  274. UNIV_INTERN
  275. void
  276. dict_table_remove_from_cache(
  277. /*=========================*/
  278. dict_table_t* table); /*!< in, own: table */
  279. /**********************************************************************//**
  280. Renames a table object.
  281. @return TRUE if success */
  282. UNIV_INTERN
  283. ibool
  284. dict_table_rename_in_cache(
  285. /*=======================*/
  286. dict_table_t* table, /*!< in/out: table */
  287. const char* new_name, /*!< in: new name */
  288. ibool rename_also_foreigns);/*!< in: in ALTER TABLE we want
  289. to preserve the original table name
  290. in constraints which reference it */
  291. /**********************************************************************//**
  292. Removes an index from the dictionary cache. */
  293. UNIV_INTERN
  294. void
  295. dict_index_remove_from_cache(
  296. /*=========================*/
  297. dict_table_t* table, /*!< in/out: table */
  298. dict_index_t* index); /*!< in, own: index */
  299. /**********************************************************************//**
  300. Change the id of a table object in the dictionary cache. This is used in
  301. DISCARD TABLESPACE. */
  302. UNIV_INTERN
  303. void
  304. dict_table_change_id_in_cache(
  305. /*==========================*/
  306. dict_table_t* table, /*!< in/out: table object already in cache */
  307. table_id_t new_id);/*!< in: new id to set */
  308. /**********************************************************************//**
  309. Adds a foreign key constraint object to the dictionary cache. May free
  310. the object if there already is an object with the same identifier in.
  311. At least one of foreign table or referenced table must already be in
  312. the dictionary cache!
  313. @return DB_SUCCESS or error code */
  314. UNIV_INTERN
  315. ulint
  316. dict_foreign_add_to_cache(
  317. /*======================*/
  318. dict_foreign_t* foreign, /*!< in, own: foreign key
  319. constraint */
  320. ibool check_charsets, /*!< in: TRUE=check charset
  321. compatibility */
  322. dict_err_ignore_t ignore_err); /*!< in: error to be ignored */
  323. /*********************************************************************//**
  324. Check if the index is referenced by a foreign key, if TRUE return the
  325. matching instance NULL otherwise.
  326. @return pointer to foreign key struct if index is defined for foreign
  327. key, otherwise NULL */
  328. UNIV_INTERN
  329. dict_foreign_t*
  330. dict_table_get_referenced_constraint(
  331. /*=================================*/
  332. dict_table_t* table, /*!< in: InnoDB table */
  333. dict_index_t* index); /*!< in: InnoDB index */
  334. /*********************************************************************//**
  335. Checks if a table is referenced by foreign keys.
  336. @return TRUE if table is referenced by a foreign key */
  337. UNIV_INTERN
  338. ibool
  339. dict_table_is_referenced_by_foreign_key(
  340. /*====================================*/
  341. const dict_table_t* table); /*!< in: InnoDB table */
  342. /**********************************************************************//**
  343. Replace the index in the foreign key list that matches this index's
  344. definition with an equivalent index. */
  345. UNIV_INTERN
  346. void
  347. dict_table_replace_index_in_foreign_list(
  348. /*=====================================*/
  349. dict_table_t* table, /*!< in/out: table */
  350. dict_index_t* index, /*!< in: index to be replaced */
  351. const trx_t* trx); /*!< in: transaction handle */
  352. /*********************************************************************//**
  353. Checks if a index is defined for a foreign key constraint. Index is a part
  354. of a foreign key constraint if the index is referenced by foreign key
  355. or index is a foreign key index
  356. @return pointer to foreign key struct if index is defined for foreign
  357. key, otherwise NULL */
  358. UNIV_INTERN
  359. dict_foreign_t*
  360. dict_table_get_foreign_constraint(
  361. /*==============================*/
  362. dict_table_t* table, /*!< in: InnoDB table */
  363. dict_index_t* index); /*!< in: InnoDB index */
  364. /*********************************************************************//**
  365. Scans a table create SQL string and adds to the data dictionary
  366. the foreign key constraints declared in the string. This function
  367. should be called after the indexes for a table have been created.
  368. Each foreign key constraint must be accompanied with indexes in
  369. bot participating tables. The indexes are allowed to contain more
  370. fields than mentioned in the constraint.
  371. @return error code or DB_SUCCESS */
  372. UNIV_INTERN
  373. ulint
  374. dict_create_foreign_constraints(
  375. /*============================*/
  376. trx_t* trx, /*!< in: transaction */
  377. const char* sql_string, /*!< in: table create statement where
  378. foreign keys are declared like:
  379. FOREIGN KEY (a, b) REFERENCES
  380. table2(c, d), table2 can be written
  381. also with the database
  382. name before it: test.table2; the
  383. default database id the database of
  384. parameter name */
  385. size_t sql_length, /*!< in: length of sql_string */
  386. const char* name, /*!< in: table full name in the
  387. normalized form
  388. database_name/table_name */
  389. ibool reject_fks); /*!< in: if TRUE, fail with error
  390. code DB_CANNOT_ADD_CONSTRAINT if
  391. any foreign keys are found. */
  392. /**********************************************************************//**
  393. Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement.
  394. @return DB_SUCCESS or DB_CANNOT_DROP_CONSTRAINT if syntax error or the
  395. constraint id does not match */
  396. UNIV_INTERN
  397. ulint
  398. dict_foreign_parse_drop_constraints(
  399. /*================================*/
  400. mem_heap_t* heap, /*!< in: heap from which we can
  401. allocate memory */
  402. trx_t* trx, /*!< in: transaction */
  403. dict_table_t* table, /*!< in: table */
  404. ulint* n, /*!< out: number of constraints
  405. to drop */
  406. const char*** constraints_to_drop); /*!< out: id's of the
  407. constraints to drop */
  408. /**********************************************************************//**
  409. Returns a table object and optionally increment its MySQL open handle count.
  410. NOTE! This is a high-level function to be used mainly from outside the
  411. 'dict' directory. Inside this directory dict_table_get_low is usually the
  412. appropriate function.
  413. @return table, NULL if does not exist */
  414. UNIV_INTERN
  415. dict_table_t*
  416. dict_table_get(
  417. /*===========*/
  418. const char* table_name,
  419. /*!< in: table name */
  420. ibool inc_mysql_count,
  421. /*!< in: whether to increment the open
  422. handle count on the table */
  423. dict_err_ignore_t ignore_err);
  424. /*!< in: errors to ignore when loading
  425. the table */
  426. /**********************************************************************//**
  427. Returns a index object, based on table and index id, and memoryfixes it.
  428. @return index, NULL if does not exist */
  429. UNIV_INTERN
  430. dict_index_t*
  431. dict_index_get_on_id_low(
  432. /*=====================*/
  433. dict_table_t* table, /*!< in: table */
  434. index_id_t index_id); /*!< in: index id */
  435. /**********************************************************************//**
  436. Checks if a table is in the dictionary cache.
  437. @return table, NULL if not found */
  438. UNIV_INLINE
  439. dict_table_t*
  440. dict_table_check_if_in_cache_low(
  441. /*=============================*/
  442. const char* table_name); /*!< in: table name */
  443. /**********************************************************************//**
  444. Gets a table; loads it to the dictionary cache if necessary. A low-level
  445. function.
  446. @return table, NULL if not found */
  447. UNIV_INLINE
  448. dict_table_t*
  449. dict_table_get_low(
  450. /*===============*/
  451. const char* table_name, /*!< in: table name */
  452. dict_err_ignore_t
  453. ignore_err); /*!< in: error to be ignored when
  454. loading a table definition */
  455. /**********************************************************************//**
  456. Returns a table object based on table id.
  457. @return table, NULL if does not exist */
  458. UNIV_INLINE
  459. dict_table_t*
  460. dict_table_get_on_id_low(
  461. /*=====================*/
  462. table_id_t table_id); /*!< in: table id */
  463. /**********************************************************************//**
  464. Find an index that is equivalent to the one passed in and is not marked
  465. for deletion.
  466. @return index equivalent to foreign->foreign_index, or NULL */
  467. UNIV_INTERN
  468. dict_index_t*
  469. dict_foreign_find_equiv_index(
  470. /*==========================*/
  471. dict_foreign_t* foreign);/*!< in: foreign key */
  472. /**********************************************************************//**
  473. Returns an index object by matching on the name and column names and
  474. if more than one index matches return the index with the max id
  475. @return matching index, NULL if not found */
  476. UNIV_INTERN
  477. dict_index_t*
  478. dict_table_get_index_by_max_id(
  479. /*===========================*/
  480. dict_table_t* table, /*!< in: table */
  481. const char* name, /*!< in: the index name to find */
  482. const char** columns,/*!< in: array of column names */
  483. ulint n_cols);/*!< in: number of columns */
  484. /**********************************************************************//**
  485. Returns a column's name.
  486. @return column name. NOTE: not guaranteed to stay valid if table is
  487. modified in any way (columns added, etc.). */
  488. UNIV_INTERN
  489. const char*
  490. dict_table_get_col_name(
  491. /*====================*/
  492. const dict_table_t* table, /*!< in: table */
  493. ulint col_nr);/*!< in: column number */
  494. /**********************************************************************//**
  495. Prints a table definition. */
  496. UNIV_INTERN
  497. void
  498. dict_table_print(
  499. /*=============*/
  500. dict_table_t* table); /*!< in: table */
  501. /**********************************************************************//**
  502. Prints a table data. */
  503. UNIV_INTERN
  504. void
  505. dict_table_print_low(
  506. /*=================*/
  507. dict_table_t* table); /*!< in: table */
  508. /**********************************************************************//**
  509. Prints a table data when we know the table name. */
  510. UNIV_INTERN
  511. void
  512. dict_table_print_by_name(
  513. /*=====================*/
  514. const char* name); /*!< in: table name */
  515. /**********************************************************************//**
  516. Outputs info on foreign keys of a table. */
  517. UNIV_INTERN
  518. void
  519. dict_print_info_on_foreign_keys(
  520. /*============================*/
  521. ibool create_table_format, /*!< in: if TRUE then print in
  522. a format suitable to be inserted into
  523. a CREATE TABLE, otherwise in the format
  524. of SHOW TABLE STATUS */
  525. FILE* file, /*!< in: file where to print */
  526. trx_t* trx, /*!< in: transaction */
  527. dict_table_t* table); /*!< in: table */
  528. /**********************************************************************//**
  529. Outputs info on a foreign key of a table in a format suitable for
  530. CREATE TABLE. */
  531. UNIV_INTERN
  532. void
  533. dict_print_info_on_foreign_key_in_create_format(
  534. /*============================================*/
  535. FILE* file, /*!< in: file where to print */
  536. trx_t* trx, /*!< in: transaction */
  537. dict_foreign_t* foreign, /*!< in: foreign key constraint */
  538. ibool add_newline); /*!< in: whether to add a newline */
  539. /********************************************************************//**
  540. Displays the names of the index and the table. */
  541. UNIV_INTERN
  542. void
  543. dict_index_name_print(
  544. /*==================*/
  545. FILE* file, /*!< in: output stream */
  546. trx_t* trx, /*!< in: transaction */
  547. const dict_index_t* index); /*!< in: index to print */
  548. #ifdef UNIV_DEBUG
  549. /********************************************************************//**
  550. Gets the first index on the table (the clustered index).
  551. @return index, NULL if none exists */
  552. UNIV_INLINE
  553. dict_index_t*
  554. dict_table_get_first_index(
  555. /*=======================*/
  556. const dict_table_t* table); /*!< in: table */
  557. /********************************************************************//**
  558. Gets the next index on the table.
  559. @return index, NULL if none left */
  560. UNIV_INLINE
  561. dict_index_t*
  562. dict_table_get_next_index(
  563. /*======================*/
  564. const dict_index_t* index); /*!< in: index */
  565. #else /* UNIV_DEBUG */
  566. # define dict_table_get_first_index(table) UT_LIST_GET_FIRST((table)->indexes)
  567. # define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
  568. #endif /* UNIV_DEBUG */
  569. #endif /* !UNIV_HOTBACKUP */
  570. /* Skip corrupted index */
  571. #define dict_table_skip_corrupt_index(index) \
  572. while (index && dict_index_is_corrupted(index)) { \
  573. index = dict_table_get_next_index(index); \
  574. }
  575. /* Get the next non-corrupt index */
  576. #define dict_table_next_uncorrupted_index(index) \
  577. do { \
  578. index = dict_table_get_next_index(index); \
  579. dict_table_skip_corrupt_index(index); \
  580. } while (0)
  581. /********************************************************************//**
  582. Check whether the index is the clustered index.
  583. @return nonzero for clustered index, zero for other indexes */
  584. UNIV_INLINE
  585. ulint
  586. dict_index_is_clust(
  587. /*================*/
  588. const dict_index_t* index) /*!< in: index */
  589. __attribute__((nonnull, pure, warn_unused_result));
  590. /********************************************************************//**
  591. Check whether the index is unique.
  592. @return nonzero for unique index, zero for other indexes */
  593. UNIV_INLINE
  594. ulint
  595. dict_index_is_unique(
  596. /*=================*/
  597. const dict_index_t* index) /*!< in: index */
  598. __attribute__((nonnull, pure, warn_unused_result));
  599. /********************************************************************//**
  600. Check whether the index is the insert buffer tree.
  601. @return nonzero for insert buffer, zero for other indexes */
  602. UNIV_INLINE
  603. ulint
  604. dict_index_is_ibuf(
  605. /*===============*/
  606. const dict_index_t* index) /*!< in: index */
  607. __attribute__((nonnull, pure, warn_unused_result));
  608. /********************************************************************//**
  609. Check whether the index is a secondary index or the insert buffer tree.
  610. @return nonzero for insert buffer, zero for other indexes */
  611. UNIV_INLINE
  612. ulint
  613. dict_index_is_sec_or_ibuf(
  614. /*======================*/
  615. const dict_index_t* index) /*!< in: index */
  616. __attribute__((nonnull, pure, warn_unused_result));
  617. /********************************************************************//**
  618. Gets the number of user-defined columns in a table in the dictionary
  619. cache.
  620. @return number of user-defined (e.g., not ROW_ID) columns of a table */
  621. UNIV_INLINE
  622. ulint
  623. dict_table_get_n_user_cols(
  624. /*=======================*/
  625. const dict_table_t* table) /*!< in: table */
  626. __attribute__((nonnull, pure, warn_unused_result));
  627. /********************************************************************//**
  628. Gets the number of system columns in a table in the dictionary cache.
  629. @return number of system (e.g., ROW_ID) columns of a table */
  630. UNIV_INLINE
  631. ulint
  632. dict_table_get_n_sys_cols(
  633. /*======================*/
  634. const dict_table_t* table) /*!< in: table */
  635. __attribute__((nonnull, pure, warn_unused_result));
  636. /********************************************************************//**
  637. Gets the number of all columns (also system) in a table in the dictionary
  638. cache.
  639. @return number of columns of a table */
  640. UNIV_INLINE
  641. ulint
  642. dict_table_get_n_cols(
  643. /*==================*/
  644. const dict_table_t* table) /*!< in: table */
  645. __attribute__((nonnull, pure, warn_unused_result));
  646. #ifdef UNIV_DEBUG
  647. /********************************************************************//**
  648. Gets the nth column of a table.
  649. @return pointer to column object */
  650. UNIV_INLINE
  651. dict_col_t*
  652. dict_table_get_nth_col(
  653. /*===================*/
  654. const dict_table_t* table, /*!< in: table */
  655. ulint pos); /*!< in: position of column */
  656. /********************************************************************//**
  657. Gets the given system column of a table.
  658. @return pointer to column object */
  659. UNIV_INLINE
  660. dict_col_t*
  661. dict_table_get_sys_col(
  662. /*===================*/
  663. const dict_table_t* table, /*!< in: table */
  664. ulint sys); /*!< in: DATA_ROW_ID, ... */
  665. #else /* UNIV_DEBUG */
  666. #define dict_table_get_nth_col(table, pos) \
  667. ((table)->cols + (pos))
  668. #define dict_table_get_sys_col(table, sys) \
  669. ((table)->cols + (table)->n_cols + (sys) - DATA_N_SYS_COLS)
  670. #endif /* UNIV_DEBUG */
  671. /********************************************************************//**
  672. Gets the given system column number of a table.
  673. @return column number */
  674. UNIV_INLINE
  675. ulint
  676. dict_table_get_sys_col_no(
  677. /*======================*/
  678. const dict_table_t* table, /*!< in: table */
  679. ulint sys); /*!< in: DATA_ROW_ID, ... */
  680. #ifndef UNIV_HOTBACKUP
  681. /********************************************************************//**
  682. Returns the minimum data size of an index record.
  683. @return minimum data size in bytes */
  684. UNIV_INLINE
  685. ulint
  686. dict_index_get_min_size(
  687. /*====================*/
  688. const dict_index_t* index); /*!< in: index */
  689. #endif /* !UNIV_HOTBACKUP */
  690. /********************************************************************//**
  691. Check whether the table uses the compact page format.
  692. @return TRUE if table uses the compact page format */
  693. UNIV_INLINE
  694. ibool
  695. dict_table_is_comp(
  696. /*===============*/
  697. const dict_table_t* table); /*!< in: table */
  698. /********************************************************************//**
  699. Determine the file format of a table.
  700. @return file format version */
  701. UNIV_INLINE
  702. ulint
  703. dict_table_get_format(
  704. /*==================*/
  705. const dict_table_t* table); /*!< in: table */
  706. /********************************************************************//**
  707. Set the file format of a table. */
  708. UNIV_INLINE
  709. void
  710. dict_table_set_format(
  711. /*==================*/
  712. dict_table_t* table, /*!< in/out: table */
  713. ulint format);/*!< in: file format version */
  714. /********************************************************************//**
  715. Extract the compressed page size from table flags.
  716. @return compressed page size, or 0 if not compressed */
  717. UNIV_INLINE
  718. ulint
  719. dict_table_flags_to_zip_size(
  720. /*=========================*/
  721. ulint flags) /*!< in: flags */
  722. __attribute__((const));
  723. /********************************************************************//**
  724. Check whether the table uses the compressed compact page format.
  725. @return compressed page size, or 0 if not compressed */
  726. UNIV_INLINE
  727. ulint
  728. dict_table_zip_size(
  729. /*================*/
  730. const dict_table_t* table); /*!< in: table */
  731. #ifndef UNIV_HOTBACKUP
  732. /*********************************************************************//**
  733. Obtain exclusive locks on all index trees of the table. This is to prevent
  734. accessing index trees while InnoDB is updating internal metadata for
  735. operations such as truncate tables. */
  736. UNIV_INLINE
  737. void
  738. dict_table_x_lock_indexes(
  739. /*======================*/
  740. dict_table_t* table); /*!< in: table */
  741. /*********************************************************************//**
  742. Release the exclusive locks on all index tree. */
  743. UNIV_INLINE
  744. void
  745. dict_table_x_unlock_indexes(
  746. /*========================*/
  747. dict_table_t* table); /*!< in: table */
  748. #endif /* !UNIV_HOTBACKUP */
  749. /********************************************************************//**
  750. Checks if a column is in the ordering columns of the clustered index of a
  751. table. Column prefixes are treated like whole columns.
  752. @return TRUE if the column, or its prefix, is in the clustered key */
  753. UNIV_INTERN
  754. ibool
  755. dict_table_col_in_clustered_key(
  756. /*============================*/
  757. const dict_table_t* table, /*!< in: table */
  758. ulint n); /*!< in: column number */
  759. #ifndef UNIV_HOTBACKUP
  760. /*******************************************************************//**
  761. Copies types of columns contained in table to tuple and sets all
  762. fields of the tuple to the SQL NULL value. This function should
  763. be called right after dtuple_create(). */
  764. UNIV_INTERN
  765. void
  766. dict_table_copy_types(
  767. /*==================*/
  768. dtuple_t* tuple, /*!< in/out: data tuple */
  769. const dict_table_t* table); /*!< in: table */
  770. /**********************************************************************//**
  771. Looks for an index with the given id. NOTE that we do not reserve
  772. the dictionary mutex: this function is for emergency purposes like
  773. printing info of a corrupt database page!
  774. @return index or NULL if not found from cache */
  775. UNIV_INTERN
  776. dict_index_t*
  777. dict_index_find_on_id_low(
  778. /*======================*/
  779. index_id_t id); /*!< in: index id */
  780. /**********************************************************************//**
  781. Adds an index to the dictionary cache.
  782. @return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */
  783. UNIV_INTERN
  784. ulint
  785. dict_index_add_to_cache(
  786. /*====================*/
  787. dict_table_t* table, /*!< in: table on which the index is */
  788. dict_index_t* index, /*!< in, own: index; NOTE! The index memory
  789. object is freed in this function! */
  790. ulint page_no,/*!< in: root page number of the index */
  791. ibool strict);/*!< in: TRUE=refuse to create the index
  792. if records could be too big to fit in
  793. an B-tree page */
  794. /**********************************************************************//**
  795. Removes an index from the dictionary cache. */
  796. UNIV_INTERN
  797. void
  798. dict_index_remove_from_cache(
  799. /*=========================*/
  800. dict_table_t* table, /*!< in/out: table */
  801. dict_index_t* index); /*!< in, own: index */
  802. #endif /* !UNIV_HOTBACKUP */
  803. /********************************************************************//**
  804. Gets the number of fields in the internal representation of an index,
  805. including fields added by the dictionary system.
  806. @return number of fields */
  807. UNIV_INLINE
  808. ulint
  809. dict_index_get_n_fields(
  810. /*====================*/
  811. const dict_index_t* index); /*!< in: an internal
  812. representation of index (in
  813. the dictionary cache) */
  814. /********************************************************************//**
  815. Gets the number of fields in the internal representation of an index
  816. that uniquely determine the position of an index entry in the index, if
  817. we do not take multiversioning into account: in the B-tree use the value
  818. returned by dict_index_get_n_unique_in_tree.
  819. @return number of fields */
  820. UNIV_INLINE
  821. ulint
  822. dict_index_get_n_unique(
  823. /*====================*/
  824. const dict_index_t* index); /*!< in: an internal representation
  825. of index (in the dictionary cache) */
  826. /********************************************************************//**
  827. Gets the number of fields in the internal representation of an index
  828. which uniquely determine the position of an index entry in the index, if
  829. we also take multiversioning into account.
  830. @return number of fields */
  831. UNIV_INLINE
  832. ulint
  833. dict_index_get_n_unique_in_tree(
  834. /*============================*/
  835. const dict_index_t* index); /*!< in: an internal representation
  836. of index (in the dictionary cache) */
  837. /********************************************************************//**
  838. Gets the number of user-defined ordering fields in the index. In the internal
  839. representation we add the row id to the ordering fields to make all indexes
  840. unique, but this function returns the number of fields the user defined
  841. in the index as ordering fields.
  842. @return number of fields */
  843. UNIV_INLINE
  844. ulint
  845. dict_index_get_n_ordering_defined_by_user(
  846. /*======================================*/
  847. const dict_index_t* index); /*!< in: an internal representation
  848. of index (in the dictionary cache) */
  849. #ifdef UNIV_DEBUG
  850. /********************************************************************//**
  851. Gets the nth field of an index.
  852. @return pointer to field object */
  853. UNIV_INLINE
  854. dict_field_t*
  855. dict_index_get_nth_field(
  856. /*=====================*/
  857. const dict_index_t* index, /*!< in: index */
  858. ulint pos); /*!< in: position of field */
  859. #else /* UNIV_DEBUG */
  860. # define dict_index_get_nth_field(index, pos) ((index)->fields + (pos))
  861. #endif /* UNIV_DEBUG */
  862. /********************************************************************//**
  863. Gets pointer to the nth column in an index.
  864. @return column */
  865. UNIV_INLINE
  866. const dict_col_t*
  867. dict_index_get_nth_col(
  868. /*===================*/
  869. const dict_index_t* index, /*!< in: index */
  870. ulint pos); /*!< in: position of the field */
  871. /********************************************************************//**
  872. Gets the column number of the nth field in an index.
  873. @return column number */
  874. UNIV_INLINE
  875. ulint
  876. dict_index_get_nth_col_no(
  877. /*======================*/
  878. const dict_index_t* index, /*!< in: index */
  879. ulint pos); /*!< in: position of the field */
  880. /********************************************************************//**
  881. Looks for column n in an index.
  882. @return position in internal representation of the index;
  883. ULINT_UNDEFINED if not contained */
  884. UNIV_INTERN
  885. ulint
  886. dict_index_get_nth_col_pos(
  887. /*=======================*/
  888. const dict_index_t* index, /*!< in: index */
  889. ulint n); /*!< in: column number */
  890. /********************************************************************//**
  891. Looks for column n in an index.
  892. @return position in internal representation of the index;
  893. ULINT_UNDEFINED if not contained */
  894. UNIV_INTERN
  895. ulint
  896. dict_index_get_nth_col_or_prefix_pos(
  897. /*=================================*/
  898. const dict_index_t* index, /*!< in: index */
  899. ulint n, /*!< in: column number */
  900. ibool inc_prefix); /*!< in: TRUE=consider
  901. column prefixes too */
  902. /********************************************************************//**
  903. Returns TRUE if the index contains a column or a prefix of that column.
  904. @return TRUE if contains the column or its prefix */
  905. UNIV_INTERN
  906. ibool
  907. dict_index_contains_col_or_prefix(
  908. /*==============================*/
  909. const dict_index_t* index, /*!< in: index */
  910. ulint n); /*!< in: column number */
  911. /********************************************************************//**
  912. Looks for a matching field in an index. The column has to be the same. The
  913. column in index must be complete, or must contain a prefix longer than the
  914. column in index2. That is, we must be able to construct the prefix in index2
  915. from the prefix in index.
  916. @return position in internal representation of the index;
  917. ULINT_UNDEFINED if not contained */
  918. UNIV_INTERN
  919. ulint
  920. dict_index_get_nth_field_pos(
  921. /*=========================*/
  922. const dict_index_t* index, /*!< in: index from which to search */
  923. const dict_index_t* index2, /*!< in: index */
  924. ulint n); /*!< in: field number in index2 */
  925. /********************************************************************//**
  926. Looks for column n position in the clustered index.
  927. @return position in internal representation of the clustered index */
  928. UNIV_INTERN
  929. ulint
  930. dict_table_get_nth_col_pos(
  931. /*=======================*/
  932. const dict_table_t* table, /*!< in: table */
  933. ulint n); /*!< in: column number */
  934. /********************************************************************//**
  935. Returns the position of a system column in an index.
  936. @return position, ULINT_UNDEFINED if not contained */
  937. UNIV_INLINE
  938. ulint
  939. dict_index_get_sys_col_pos(
  940. /*=======================*/
  941. const dict_index_t* index, /*!< in: index */
  942. ulint type); /*!< in: DATA_ROW_ID, ... */
  943. /*******************************************************************//**
  944. Adds a column to index. */
  945. UNIV_INTERN
  946. void
  947. dict_index_add_col(
  948. /*===============*/
  949. dict_index_t* index, /*!< in/out: index */
  950. const dict_table_t* table, /*!< in: table */
  951. dict_col_t* col, /*!< in: column */
  952. ulint prefix_len); /*!< in: column prefix length */
  953. #ifndef UNIV_HOTBACKUP
  954. /*******************************************************************//**
  955. Copies types of fields contained in index to tuple. */
  956. UNIV_INTERN
  957. void
  958. dict_index_copy_types(
  959. /*==================*/
  960. dtuple_t* tuple, /*!< in/out: data tuple */
  961. const dict_index_t* index, /*!< in: index */
  962. ulint n_fields); /*!< in: number of
  963. field types to copy */
  964. #endif /* !UNIV_HOTBACKUP */
  965. /*********************************************************************//**
  966. Gets the field column.
  967. @return field->col, pointer to the table column */
  968. UNIV_INLINE
  969. const dict_col_t*
  970. dict_field_get_col(
  971. /*===============*/
  972. const dict_field_t* field); /*!< in: index field */
  973. #ifndef UNIV_HOTBACKUP
  974. /**********************************************************************//**
  975. Returns an index object if it is found in the dictionary cache.
  976. Assumes that dict_sys->mutex is already being held.
  977. @return index, NULL if not found */
  978. UNIV_INTERN
  979. dict_index_t*
  980. dict_index_get_if_in_cache_low(
  981. /*===========================*/
  982. index_id_t index_id); /*!< in: index id */
  983. #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
  984. /**********************************************************************//**
  985. Returns an index object if it is found in the dictionary cache.
  986. @return index, NULL if not found */
  987. UNIV_INTERN
  988. dict_index_t*
  989. dict_index_get_if_in_cache(
  990. /*=======================*/
  991. index_id_t index_id); /*!< in: index id */
  992. #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
  993. #ifdef UNIV_DEBUG
  994. /**********************************************************************//**
  995. Checks that a tuple has n_fields_cmp value in a sensible range, so that
  996. no comparison can occur with the page number field in a node pointer.
  997. @return TRUE if ok */
  998. UNIV_INTERN
  999. ibool
  1000. dict_index_check_search_tuple(
  1001. /*==========================*/
  1002. const dict_index_t* index, /*!< in: index tree */
  1003. const dtuple_t* tuple); /*!< in: tuple used in a search */
  1004. /**********************************************************************//**
  1005. Check for duplicate index entries in a table [using the index name] */
  1006. UNIV_INTERN
  1007. void
  1008. dict_table_check_for_dup_indexes(
  1009. /*=============================*/
  1010. const dict_table_t* table, /*!< in: Check for dup indexes
  1011. in this table */
  1012. ibool tmp_ok);/*!< in: TRUE=allow temporary
  1013. index names */
  1014. #endif /* UNIV_DEBUG */
  1015. /**********************************************************************//**
  1016. Builds a node pointer out of a physical record and a page number.
  1017. @return own: node pointer */
  1018. UNIV_INTERN
  1019. dtuple_t*
  1020. dict_index_build_node_ptr(
  1021. /*======================*/
  1022. const dict_index_t* index, /*!< in: index */
  1023. const rec_t* rec, /*!< in: record for which to build node
  1024. pointer */
  1025. ulint page_no,/*!< in: page number to put in node
  1026. pointer */
  1027. mem_heap_t* heap, /*!< in: memory heap where pointer
  1028. created */
  1029. ulint level); /*!< in: level of rec in tree:
  1030. 0 means leaf level */
  1031. /**********************************************************************//**
  1032. Copies an initial segment of a physical record, long enough to specify an
  1033. index entry uniquely.
  1034. @return pointer to the prefix record */
  1035. UNIV_INTERN
  1036. rec_t*
  1037. dict_index_copy_rec_order_prefix(
  1038. /*=============================*/
  1039. const dict_index_t* index, /*!< in: index */
  1040. const rec_t* rec, /*!< in: record for which to
  1041. copy prefix */
  1042. ulint* n_fields,/*!< out: number of fields copied */
  1043. byte** buf, /*!< in/out: memory buffer for the
  1044. copied prefix, or NULL */
  1045. ulint* buf_size);/*!< in/out: buffer size */
  1046. /**********************************************************************//**
  1047. Builds a typed data tuple out of a physical record.
  1048. @return own: data tuple */
  1049. UNIV_INTERN
  1050. dtuple_t*
  1051. dict_index_build_data_tuple(
  1052. /*========================*/
  1053. dict_index_t* index, /*!< in: index */
  1054. rec_t* rec, /*!< in: record for which to build data tuple */
  1055. ulint n_fields,/*!< in: number of data fields */
  1056. mem_heap_t* heap); /*!< in: memory heap where tuple created */
  1057. /*********************************************************************//**
  1058. Gets the space id of the root of the index tree.
  1059. @return space id */
  1060. UNIV_INLINE
  1061. ulint
  1062. dict_index_get_space(
  1063. /*=================*/
  1064. const dict_index_t* index); /*!< in: index */
  1065. /*********************************************************************//**
  1066. Sets the space id of the root of the index tree. */
  1067. UNIV_INLINE
  1068. void
  1069. dict_index_set_space(
  1070. /*=================*/
  1071. dict_index_t* index, /*!< in/out: index */
  1072. ulint space); /*!< in: space id */
  1073. /*********************************************************************//**
  1074. Gets the page number of the root of the index tree.
  1075. @return page number */
  1076. UNIV_INLINE
  1077. ulint
  1078. dict_index_get_page(
  1079. /*================*/
  1080. const dict_index_t* tree); /*!< in: index */
  1081. /*********************************************************************//**
  1082. Gets the read-write lock of the index tree.
  1083. @return read-write lock */
  1084. UNIV_INLINE
  1085. rw_lock_t*
  1086. dict_index_get_lock(
  1087. /*================*/
  1088. dict_index_t* index); /*!< in: index */
  1089. /********************************************************************//**
  1090. Returns free space reserved for future updates of records. This is
  1091. relevant only in the case of many consecutive inserts, as updates
  1092. which make the records bigger might fragment the index.
  1093. @return number of free bytes on page, reserved for updates */
  1094. UNIV_INLINE
  1095. ulint
  1096. dict_index_get_space_reserve(void);
  1097. /*==============================*/
  1098. /*********************************************************************//**
  1099. Calculates the minimum record length in an index. */
  1100. UNIV_INTERN
  1101. ulint
  1102. dict_index_calc_min_rec_len(
  1103. /*========================*/
  1104. const dict_index_t* index); /*!< in: index */
  1105. /** Calculate new statistics if 1 / 16 of table has been modified
  1106. since the last time a statistics batch was run.
  1107. We calculate statistics at most every 16th round, since we may have
  1108. a counter table which is very small and updated very often.
  1109. @param t table
  1110. @return true if the table has changed too much and stats need to be
  1111. recalculated
  1112. */
  1113. #define DICT_TABLE_CHANGED_TOO_MUCH(t) \
  1114. ((ib_int64_t) (t)->stat_modified_counter > 16 + (t)->stat_n_rows / 16)
  1115. /*********************************************************************//**
  1116. Calculates new estimates for table and index statistics. The statistics
  1117. are used in query optimization. */
  1118. UNIV_INTERN
  1119. void
  1120. dict_update_statistics(
  1121. /*===================*/
  1122. dict_table_t* table, /*!< in/out: table */
  1123. ibool only_calc_if_missing_stats,/*!< in: only
  1124. update/recalc the stats if they have
  1125. not been initialized yet, otherwise
  1126. do nothing */
  1127. ibool sync,
  1128. ibool only_calc_if_changed_too_much);/*!< in: only
  1129. update/recalc the stats if the table
  1130. has been changed too much since the
  1131. last stats update/recalc */
  1132. /*********************************************************************//**
  1133. */
  1134. UNIV_INTERN
  1135. ibool
  1136. dict_is_older_statistics(
  1137. /*=====================*/
  1138. dict_index_t* index);
  1139. /********************************************************************//**
  1140. Reserves the dictionary system mutex for MySQL. */
  1141. UNIV_INTERN
  1142. void
  1143. dict_mutex_enter_for_mysql(void);
  1144. /*============================*/
  1145. /********************************************************************//**
  1146. Releases the dictionary system mutex for MySQL. */
  1147. UNIV_INTERN
  1148. void
  1149. dict_mutex_exit_for_mysql(void);
  1150. /*===========================*/
  1151. /**********************************************************************//**
  1152. Lock the appropriate latch to protect a given table's statistics.
  1153. table->id is used to pick the corresponding latch from a global array of
  1154. latches. */
  1155. UNIV_INTERN
  1156. void
  1157. dict_table_stats_lock(
  1158. /*==================*/
  1159. const dict_table_t* table, /*!< in: table */
  1160. ulint latch_mode); /*!< in: RW_S_LATCH or
  1161. RW_X_LATCH */
  1162. /**********************************************************************//**
  1163. Unlock the latch that has been locked by dict_table_stats_lock() */
  1164. UNIV_INTERN
  1165. void
  1166. dict_table_stats_unlock(
  1167. /*====================*/
  1168. const dict_table_t* table, /*!< in: table */
  1169. ulint latch_mode); /*!< in: RW_S_LATCH or
  1170. RW_X_LATCH */
  1171. /********************************************************************//**
  1172. Checks if the database name in two table names is the same.
  1173. @return TRUE if same db name */
  1174. UNIV_INTERN
  1175. ibool
  1176. dict_tables_have_same_db(
  1177. /*=====================*/
  1178. const char* name1, /*!< in: table name in the form
  1179. dbname '/' tablename */
  1180. const char* name2); /*!< in: table name in the form
  1181. dbname '/' tablename */
  1182. /*********************************************************************//**
  1183. Removes an index from the cache */
  1184. UNIV_INTERN
  1185. void
  1186. dict_index_remove_from_cache(
  1187. /*=========================*/
  1188. dict_table_t* table, /*!< in/out: table */
  1189. dict_index_t* index); /*!< in, own: index */
  1190. /**********************************************************************//**
  1191. Get index by name
  1192. @return index, NULL if does not exist */
  1193. UNIV_INTERN
  1194. dict_index_t*
  1195. dict_table_get_index_on_name(
  1196. /*=========================*/
  1197. dict_table_t* table, /*!< in: table */
  1198. const char* name); /*!< in: name of the index to find */
  1199. /**********************************************************************//**
  1200. In case there is more than one index with the same name return the index
  1201. with the min(id).
  1202. @return index, NULL if does not exist */
  1203. UNIV_INTERN
  1204. dict_index_t*
  1205. dict_table_get_index_on_name_and_min_id(
  1206. /*====================================*/
  1207. dict_table_t* table, /*!< in: table */
  1208. const char* name); /*!< in: name of the index to find */
  1209. UNIV_INTERN
  1210. void
  1211. dict_table_LRU_trim(
  1212. /*================*/
  1213. dict_table_t* self);
  1214. /* Buffers for storing detailed information about the latest foreign key
  1215. and unique key errors */
  1216. extern FILE* dict_foreign_err_file;
  1217. extern mutex_t dict_foreign_err_mutex; /* mutex protecting the buffers */
  1218. /** the dictionary system */
  1219. extern dict_sys_t* dict_sys;
  1220. /** the data dictionary rw-latch protecting dict_sys */
  1221. extern rw_lock_t dict_operation_lock;
  1222. /* Dictionary system struct */
  1223. struct dict_sys_struct{
  1224. mutex_t mutex; /*!< mutex protecting the data
  1225. dictionary; protects also the
  1226. disk-based dictionary system tables;
  1227. this mutex serializes CREATE TABLE
  1228. and DROP TABLE, as well as reading
  1229. the dictionary data for a table from
  1230. system tables */
  1231. row_id_t row_id; /*!< the next row id to assign;
  1232. NOTE that at a checkpoint this
  1233. must be written to the dict system
  1234. header and flushed to a file; in
  1235. recovery this must be derived from
  1236. the log records */
  1237. hash_table_t* table_hash; /*!< hash table of the tables, based
  1238. on name */
  1239. hash_table_t* table_id_hash; /*!< hash table of the tables, based
  1240. on id */
  1241. UT_LIST_BASE_NODE_T(dict_table_t)
  1242. table_LRU; /*!< LRU list of tables */
  1243. ulint size; /*!< varying space in bytes occupied
  1244. by the data dictionary table and
  1245. index objects */
  1246. dict_table_t* sys_tables; /*!< SYS_TABLES table */
  1247. dict_table_t* sys_columns; /*!< SYS_COLUMNS table */
  1248. dict_table_t* sys_indexes; /*!< SYS_INDEXES table */
  1249. dict_table_t* sys_fields; /*!< SYS_FIELDS table */
  1250. dict_table_t* sys_stats; /*!< SYS_STATS table */
  1251. };
  1252. #endif /* !UNIV_HOTBACKUP */
  1253. /** dummy index for ROW_FORMAT=REDUNDANT supremum and infimum records */
  1254. extern dict_index_t* dict_ind_redundant;
  1255. /** dummy index for ROW_FORMAT=COMPACT supremum and infimum records */
  1256. extern dict_index_t* dict_ind_compact;
  1257. /**********************************************************************//**
  1258. Inits dict_ind_redundant and dict_ind_compact. */
  1259. UNIV_INTERN
  1260. void
  1261. dict_ind_init(void);
  1262. /*===============*/
  1263. /**********************************************************************//**
  1264. Closes the data dictionary module. */
  1265. UNIV_INTERN
  1266. void
  1267. dict_close(void);
  1268. /*============*/
  1269. #ifndef UNIV_HOTBACKUP
  1270. /**********************************************************************//**
  1271. Check whether the table is corrupted.
  1272. @return nonzero for corrupted table, zero for valid tables */
  1273. UNIV_INLINE
  1274. ulint
  1275. dict_table_is_corrupted(
  1276. /*====================*/
  1277. const dict_table_t* table) /*!< in: table */
  1278. __attribute__((nonnull, pure, warn_unused_result));
  1279. /**********************************************************************//**
  1280. Check whether the index is corrupted.
  1281. @return nonzero for corrupted index, zero for valid indexes */
  1282. UNIV_INLINE
  1283. ulint
  1284. dict_index_is_corrupted(
  1285. /*====================*/
  1286. const dict_index_t* index) /*!< in: index */
  1287. __attribute__((nonnull, pure, warn_unused_result));
  1288. #endif /* !UNIV_HOTBACKUP */
  1289. /**********************************************************************//**
  1290. Flags an index and table corrupted both in the data dictionary cache
  1291. and in the system table SYS_INDEXES. */
  1292. UNIV_INTERN
  1293. void
  1294. dict_set_corrupted(
  1295. /*===============*/
  1296. dict_index_t* index) /*!< in/out: index */
  1297. UNIV_COLD __attribute__((nonnull));
  1298. /**********************************************************************//**
  1299. Flags an index corrupted in the data dictionary cache only. This
  1300. is used mostly to mark a corrupted index when index's own dictionary
  1301. is corrupted, and we force to load such index for repair purpose */
  1302. UNIV_INTERN
  1303. void
  1304. dict_set_corrupted_index_cache_only(
  1305. /*================================*/
  1306. dict_index_t* index, /*!< in/out: index */
  1307. dict_table_t* table); /*!< in/out: table */
  1308. /**********************************************************************//**
  1309. Flags a table with specified space_id corrupted in the table dictionary
  1310. cache.
  1311. @return TRUE if successful */
  1312. UNIV_INTERN
  1313. ibool
  1314. dict_set_corrupted_by_space(
  1315. /*========================*/
  1316. ulint space_id); /*!< in: space ID */
  1317. /*************************************************************************
  1318. set is_corrupt flag by space_id*/
  1319. void
  1320. dict_table_set_corrupt_by_space(
  1321. /*============================*/
  1322. ulint space_id,
  1323. ibool need_mutex);
  1324. /**********************************************************************//**
  1325. Compares the given foreign key identifier (the key in rb-tree) and the
  1326. foreign key identifier in the given fk object (value in rb-tree).
  1327. @return negative, 0, or positive if foreign_id is smaller, equal,
  1328. or greater than foreign_obj->id, respectively. */
  1329. UNIV_INLINE
  1330. int
  1331. dict_foreign_rbt_cmp(
  1332. /*=================*/
  1333. const void* foreign_id, /*!< in: the foreign key identifier
  1334. which is used as a key in rb-tree. */
  1335. const void* foreign_obj); /*!< in: the foreign object itself
  1336. which is used as value in rb-tree. */
  1337. /**********************************************************************//**
  1338. Allocate the table->foreign_rbt, which stores all the foreign objects
  1339. that is available in table->foreign_list.
  1340. @return the allocated rbt object */
  1341. UNIV_INLINE
  1342. ib_rbt_t*
  1343. dict_table_init_foreign_rbt(
  1344. /*========================*/
  1345. dict_table_t* table); /*!< in: the table object whose
  1346. table->foreign_rbt will be initialized */
  1347. /**********************************************************************//**
  1348. Allocate the table->referened_rbt, which stores all the foreign objects
  1349. that is available in table->referenced_list.
  1350. @return the allocated rbt object */
  1351. UNIV_INLINE
  1352. ib_rbt_t*
  1353. dict_table_init_referenced_rbt(
  1354. /*===========================*/
  1355. dict_table_t* table); /*!< in: the table object whose
  1356. table->referenced_rbt will be initialized */
  1357. /********************************************************************//**
  1358. Check if it is a temporary table.
  1359. @return true if temporary table flag is set. */
  1360. UNIV_INLINE
  1361. ibool
  1362. dict_table_is_temporary(
  1363. /*====================*/
  1364. const dict_table_t* table); /*!< in: table to check */
  1365. #ifndef UNIV_NONINL
  1366. #include "dict0dict.ic"
  1367. #endif
  1368. #endif