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.

508 lines
18 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Implement the configuration parameter and settable global variable innodb_file_format. Implement file format version stamping of *.ibd files and SYS_TABLES.TYPE. This change breaks introduces an incompatible change for for compressed tables. We can do this, as we have not released yet. innodb-zip.test: Add tests for stricter KEY_BLOCK_SIZE and ROW_FORMAT checks. DICT_TF_COMPRESSED_MASK, DICT_TF_COMPRESSED_SHIFT: Replace with DICT_TF_ZSSIZE_MASK, DICT_TF_ZSSIZE_SHIFT. DICT_TF_FORMAT_MASK, DICT_TF_FORMAT_SHIFT, DICT_TF_FORMAT_51, DICT_TF_FORMAT_ZIP: File format version, stored in table->flags, in the .ibd file header, and in SYS_TABLES.TYPE. dict_create_sys_tables_tuple(): Write the table flags to SYS_TABLES.TYPE if the format is at least DICT_TF_FORMAT_ZIP. For old formats (DICT_TF_FORMAT_51), write DICT_TABLE_ORDINARY as the table type. DB_TABLE_ZIP_NO_IBD: Remove the error code. The error handling is done in ha_innodb.cc; as a failsafe measure, dict_build_table_def_step() will silently clear the compression and format flags instead of returning this error. dict_mem_table_create(): Assert that no extra bits are set in the flags. dict_sys_tables_get_zip_size(): Rename to dict_sys_tables_get_flags(). Check all flag bits, and return ULINT_UNDEFINED if the combination is unsupported. dict_boot(): Document the SYS_TABLES columns N_COLS and TYPE. dict_table_get_format(), dict_table_set_format(), dict_table_flags_to_zip_size(): New accessors to table->flags. dtuple_convert_big_rec(): Introduce the auxiliary variables local_len, local_prefix_len. Store a 768-byte prefix locally if the file format is less than DICT_TF_FORMAT_ZIP. dtuple_convert_back_big_rec(): Restore the columns. srv_file_format: New variable: innodb_file_format. fil_create_new_single_table_tablespace(): Replace the parameter zip_size with table->flags. fil_open_single_table_tablespace(): Replace the parameter zip_size_in_k with table->flags. Check the flags. fil_space_struct, fil_space_create(), fil_op_write_log(): Replace zip_size with flags. fil_node_open_file(): Note a TODO item for InnoDB Hot Backup. Check that the tablespace flags match. fil_space_get_zip_size(): Rename to fil_space_get_flags(). Add a wrapper for fil_space_get_zip_size(). fsp_header_get_flags(): New function. fsp_header_init_fields(): Replace zip_size with flags. FSP_SPACE_FLAGS: New name for the tablespace flags. This field used to be called FSP_PAGE_ZIP_SIZE, or FSP_LOWEST_NO_WRITE. It has always been written as 0 in MySQL/InnoDB versions 4.1 to 5.1. MLOG_ZIP_FILE_CREATE: Rename to MLOG_FILE_CREATE2. Add a 32-bit parameter for the tablespace flags. ha_innobase::create(): Check the table attributes ROW_FORMAT and KEY_BLOCK_SIZE. Issue errors if they are inappropriate, or warnings if the inherited attributes (in ALTER TABLE) will be ignored. PAGE_ZIP_MIN_SIZE_SHIFT: New constant: the 2-logarithm of PAGE_ZIP_MIN_SIZE.
18 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
branches/zip: Merge revisions 2702:2722 from branches/5.1: ------------------------------------------------------------------------ r2702 | sunny | 2008-09-30 11:41:56 +0300 (Tue, 30 Sep 2008) | 13 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Since handler::get_auto_increment() doesn't allow us to return the cause of failure we have to inform MySQL using the sql_print_warning() function to return the cause for autoinc failure. Previously we simply printed the error code, this patch prints the text string representing the following two error codes: DB_LOCK_WAIT_TIMEOUT DB_DEADLOCK. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Approved by Marko. ------------------------------------------------------------------------ r2709 | vasil | 2008-10-01 10:13:13 +0300 (Wed, 01 Oct 2008) | 10 lines Changed paths: M /branches/5.1/include/lock0lock.h M /branches/5.1/lock/lock0lock.c A /branches/5.1/mysql-test/innodb_bug38231.result A /branches/5.1/mysql-test/innodb_bug38231.test M /branches/5.1/row/row0mysql.c branches/5.1: Fix Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK In TRUNCATE TABLE and discard tablespace: do not remove table-level S and X locks and do not assert on such locks not being wait locks. Leave such locks alone. Approved by: Heikki (rb://14) ------------------------------------------------------------------------ r2710 | vasil | 2008-10-01 14:13:58 +0300 (Wed, 01 Oct 2008) | 6 lines Changed paths: M /branches/5.1/include/sync0sync.ic branches/5.1: Silence a compilation warning in UNIV_DEBUG. Approved by: Marko (via IM) ------------------------------------------------------------------------ r2719 | vasil | 2008-10-03 18:17:28 +0300 (Fri, 03 Oct 2008) | 49 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug39438-master.opt A /branches/5.1/mysql-test/innodb_bug39438.result A /branches/5.1/mysql-test/innodb_bug39438.test branches/5.1: Fix Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch In ha_innobase::info() - do not try to get the free space for a tablespace which has been discarded with ALTER TABLE ... DISCARD TABLESPACE or if the .ibd file is missing for some other reason. ibd_file_missing and tablespace_discarded are manipulated only in row_discard_tablespace_for_mysql() and in row_import_tablespace_for_mysql() and the manipulation is protected/surrounded by row_mysql_lock_data_dictionary()/row_mysql_unlock_data_dictionary() thus we do the same in ha_innobase::info() when checking the values of those members to avoid race conditions. I have tested the code-path with UNIV_DEBUG and UNIV_SYNC_DEBUG. Looks like it is not possible to avoid mysqld printing warnings in the mysql-test case and thus this test innodb_bug39438 must be added to the list of exceptional test cases that are allowed to print warnings. For this, the following patch must be applied to the mysql source tree: --- cut --- === modified file 'mysql-test/lib/mtr_report.pl' --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000 +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000 @@ -412,7 +412,10 @@ # When trying to set lower_case_table_names = 2 # on a case sensitive file system. Bug#37402. - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or + + # this test is expected to print warnings + ($testname eq 'main.innodb_bug39438') ) { next; # Skip these lines --- cut --- The mysql-test is currently somewhat disabled (see inside innodb_bug39438.test), after the above patch has been applied to the mysql source tree, the test can be enabled. rb://20 Reviewed by: Inaam, Calvin Approved by: Heikki ------------------------------------------------------------------------ r2720 | vasil | 2008-10-03 19:52:39 +0300 (Fri, 03 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Print a warning if an attempt is made to get the free space for a table whose .ibd file is missing or the tablespace has been discarded. This is a followup to r2719. Suggested by: Inaam ------------------------------------------------------------------------ r2721 | sunny | 2008-10-04 02:08:23 +0300 (Sat, 04 Oct 2008) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: We need to send the messages to the client because handler::get_auto_increment() doesn't allow a way to return the specific error for why it failed. rb://18 ------------------------------------------------------------------------ r2722 | sunny | 2008-10-04 02:48:04 +0300 (Sat, 04 Oct 2008) | 18 lines Changed paths: M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/dict0mem.h M /branches/5.1/include/row0mysql.h M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0mysql.c branches/5.1: This bug has always existed but was masked by other errors. The fix for bug# 38839 triggered this bug. When the offset and increment are > 1 we need to calculate the next value taking into consideration the two variables. Previously we simply assumed they were 1 particularly offset was never used. MySQL does its own calculation and that's probably why it seemed to work in the past. We would return what we thought was the correct next value and then MySQL would recalculate the actual value from that and return it to the caller (e.g., handler::write_row()). Several new tests have been added that try and catch some edge cases. The tests exposed a wrap around error in MySQL next value calculation which was filed as bug#39828. The tests will need to be updated once MySQL fix that bug. One good side effect of this fix is that dict_table_t size has been reduced by 8 bytes because we have moved the autoinc_increment field to the row_prebuilt_t structure. See review-board for a detailed discussion. rb://3 ------------------------------------------------------------------------
17 years ago
20 years ago
20 years ago
20 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1996, 2009, Innobase Oy. 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., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/dict0mem.h
  15. Data dictionary memory object creation
  16. Created 1/8/1996 Heikki Tuuri
  17. *******************************************************/
  18. #ifndef dict0mem_h
  19. #define dict0mem_h
  20. #include "univ.i"
  21. #include "dict0types.h"
  22. #include "data0type.h"
  23. #include "mem0mem.h"
  24. #include "rem0types.h"
  25. #include "btr0types.h"
  26. #ifndef UNIV_HOTBACKUP
  27. # include "lock0types.h"
  28. # include "que0types.h"
  29. # include "sync0rw.h"
  30. #endif /* !UNIV_HOTBACKUP */
  31. #include "ut0mem.h"
  32. #include "ut0lst.h"
  33. #include "ut0rnd.h"
  34. #include "ut0byte.h"
  35. #include "hash0hash.h"
  36. #include "trx0types.h"
  37. /* Type flags of an index: OR'ing of the flags is allowed to define a
  38. combination of types */
  39. #define DICT_CLUSTERED 1 /* clustered index */
  40. #define DICT_UNIQUE 2 /* unique index */
  41. #define DICT_UNIVERSAL 4 /* index which can contain records from any
  42. other index */
  43. #define DICT_IBUF 8 /* insert buffer tree */
  44. /* Types for a table object */
  45. #define DICT_TABLE_ORDINARY 1
  46. #if 0 /* not implemented */
  47. #define DICT_TABLE_CLUSTER_MEMBER 2
  48. #define DICT_TABLE_CLUSTER 3 /* this means that the table is
  49. really a cluster definition */
  50. #endif
  51. /* Table flags. All unused bits must be 0. */
  52. #define DICT_TF_COMPACT 1 /* Compact page format.
  53. This must be set for
  54. new file formats
  55. (later than
  56. DICT_TF_FORMAT_51). */
  57. /* compressed page size (0=uncompressed, up to 15 compressed sizes) */
  58. #define DICT_TF_ZSSIZE_SHIFT 1
  59. #define DICT_TF_ZSSIZE_MASK (15 << DICT_TF_ZSSIZE_SHIFT)
  60. #define DICT_TF_ZSSIZE_MAX (UNIV_PAGE_SIZE_SHIFT - PAGE_ZIP_MIN_SIZE_SHIFT + 1)
  61. #define DICT_TF_FORMAT_SHIFT 5 /* file format */
  62. #define DICT_TF_FORMAT_MASK (127 << DICT_TF_FORMAT_SHIFT)
  63. #define DICT_TF_FORMAT_51 0 /* InnoDB/MySQL up to 5.1 */
  64. #define DICT_TF_FORMAT_ZIP 1 /* InnoDB plugin for 5.1:
  65. compressed tables,
  66. new BLOB treatment */
  67. #define DICT_TF_FORMAT_MAX DICT_TF_FORMAT_ZIP
  68. #define DICT_TF_BITS 6 /* number of flag bits */
  69. #if (1 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT)) <= DICT_TF_FORMAT_MAX
  70. # error "DICT_TF_BITS is insufficient for DICT_TF_FORMAT_MAX"
  71. #endif
  72. /**********************************************************************//**
  73. Creates a table memory object.
  74. @return own: table object */
  75. UNIV_INTERN
  76. dict_table_t*
  77. dict_mem_table_create(
  78. /*==================*/
  79. const char* name, /*!< in: table name */
  80. ulint space, /*!< in: space where the clustered index
  81. of the table is placed; this parameter
  82. is ignored if the table is made
  83. a member of a cluster */
  84. ulint n_cols, /*!< in: number of columns */
  85. ulint flags); /*!< in: table flags */
  86. /****************************************************************//**
  87. Free a table memory object. */
  88. UNIV_INTERN
  89. void
  90. dict_mem_table_free(
  91. /*================*/
  92. dict_table_t* table); /*!< in: table */
  93. /**********************************************************************//**
  94. Adds a column definition to a table. */
  95. UNIV_INTERN
  96. void
  97. dict_mem_table_add_col(
  98. /*===================*/
  99. dict_table_t* table, /*!< in: table */
  100. mem_heap_t* heap, /*!< in: temporary memory heap, or NULL */
  101. const char* name, /*!< in: column name, or NULL */
  102. ulint mtype, /*!< in: main datatype */
  103. ulint prtype, /*!< in: precise type */
  104. ulint len); /*!< in: precision */
  105. /**********************************************************************//**
  106. Creates an index memory object.
  107. @return own: index object */
  108. UNIV_INTERN
  109. dict_index_t*
  110. dict_mem_index_create(
  111. /*==================*/
  112. const char* table_name, /*!< in: table name */
  113. const char* index_name, /*!< in: index name */
  114. ulint space, /*!< in: space where the index tree is
  115. placed, ignored if the index is of
  116. the clustered type */
  117. ulint type, /*!< in: DICT_UNIQUE,
  118. DICT_CLUSTERED, ... ORed */
  119. ulint n_fields); /*!< in: number of fields */
  120. /**********************************************************************//**
  121. Adds a field definition to an index. NOTE: does not take a copy
  122. of the column name if the field is a column. The memory occupied
  123. by the column name may be released only after publishing the index. */
  124. UNIV_INTERN
  125. void
  126. dict_mem_index_add_field(
  127. /*=====================*/
  128. dict_index_t* index, /*!< in: index */
  129. const char* name, /*!< in: column name */
  130. ulint prefix_len); /*!< in: 0 or the column prefix length
  131. in a MySQL index like
  132. INDEX (textcol(25)) */
  133. /**********************************************************************//**
  134. Frees an index memory object. */
  135. UNIV_INTERN
  136. void
  137. dict_mem_index_free(
  138. /*================*/
  139. dict_index_t* index); /*!< in: index */
  140. /**********************************************************************//**
  141. Creates and initializes a foreign constraint memory object.
  142. @return own: foreign constraint struct */
  143. UNIV_INTERN
  144. dict_foreign_t*
  145. dict_mem_foreign_create(void);
  146. /*=========================*/
  147. /* Data structure for a column in a table */
  148. struct dict_col_struct{
  149. /*----------------------*/
  150. /* The following are copied from dtype_t,
  151. so that all bit-fields can be packed tightly. */
  152. unsigned mtype:8; /* main data type */
  153. unsigned prtype:24; /* precise type; MySQL data
  154. type, charset code, flags to
  155. indicate nullability,
  156. signedness, whether this is a
  157. binary string, whether this is
  158. a true VARCHAR where MySQL
  159. uses 2 bytes to store the length */
  160. /* the remaining fields do not affect alphabetical ordering: */
  161. unsigned len:16; /* length; for MySQL data this
  162. is field->pack_length(),
  163. except that for a >= 5.0.3
  164. type true VARCHAR this is the
  165. maximum byte length of the
  166. string data (in addition to
  167. the string, MySQL uses 1 or 2
  168. bytes to store the string length) */
  169. unsigned mbminlen:2; /* minimum length of a
  170. character, in bytes */
  171. unsigned mbmaxlen:3; /* maximum length of a
  172. character, in bytes */
  173. /*----------------------*/
  174. /* End of definitions copied from dtype_t */
  175. unsigned ind:10; /* table column position
  176. (starting from 0) */
  177. unsigned ord_part:1; /* nonzero if this column
  178. appears in the ordering fields
  179. of an index */
  180. };
  181. /* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the maximum
  182. indexed column length (or indexed prefix length). It is set to 3*256,
  183. so that one can create a column prefix index on 256 characters of a
  184. TEXT or VARCHAR column also in the UTF-8 charset. In that charset,
  185. a character may take at most 3 bytes.
  186. This constant MUST NOT BE CHANGED, or the compatibility of InnoDB data
  187. files would be at risk! */
  188. #define DICT_MAX_INDEX_COL_LEN REC_MAX_INDEX_COL_LEN
  189. /* Data structure for a field in an index */
  190. struct dict_field_struct{
  191. dict_col_t* col; /* pointer to the table column */
  192. const char* name; /* name of the column */
  193. unsigned prefix_len:10; /* 0 or the length of the column
  194. prefix in bytes in a MySQL index of
  195. type, e.g., INDEX (textcol(25));
  196. must be smaller than
  197. DICT_MAX_INDEX_COL_LEN; NOTE that
  198. in the UTF-8 charset, MySQL sets this
  199. to 3 * the prefix len in UTF-8 chars */
  200. unsigned fixed_len:10; /* 0 or the fixed length of the
  201. column if smaller than
  202. DICT_MAX_INDEX_COL_LEN */
  203. };
  204. /* Data structure for an index. Most fields will be
  205. initialized to 0, NULL or FALSE in dict_mem_index_create(). */
  206. struct dict_index_struct{
  207. dulint id; /* id of the index */
  208. mem_heap_t* heap; /* memory heap */
  209. const char* name; /* index name */
  210. const char* table_name; /* table name */
  211. dict_table_t* table; /* back pointer to table */
  212. #ifndef UNIV_HOTBACKUP
  213. unsigned space:32;
  214. /* space where the index tree is placed */
  215. unsigned page:32;/* index tree root page number */
  216. #endif /* !UNIV_HOTBACKUP */
  217. unsigned type:4; /* index type (DICT_CLUSTERED, DICT_UNIQUE,
  218. DICT_UNIVERSAL, DICT_IBUF) */
  219. unsigned trx_id_offset:10;/* position of the trx id column
  220. in a clustered index record, if the fields
  221. before it are known to be of a fixed size,
  222. 0 otherwise */
  223. unsigned n_user_defined_cols:10;
  224. /* number of columns the user defined to
  225. be in the index: in the internal
  226. representation we add more columns */
  227. unsigned n_uniq:10;/* number of fields from the beginning
  228. which are enough to determine an index
  229. entry uniquely */
  230. unsigned n_def:10;/* number of fields defined so far */
  231. unsigned n_fields:10;/* number of fields in the index */
  232. unsigned n_nullable:10;/* number of nullable fields */
  233. unsigned cached:1;/* TRUE if the index object is in the
  234. dictionary cache */
  235. unsigned to_be_dropped:1;
  236. /* TRUE if this index is marked to be
  237. dropped in ha_innobase::prepare_drop_index(),
  238. otherwise FALSE */
  239. dict_field_t* fields; /* array of field descriptions */
  240. #ifndef UNIV_HOTBACKUP
  241. UT_LIST_NODE_T(dict_index_t)
  242. indexes;/* list of indexes of the table */
  243. btr_search_t* search_info; /* info used in optimistic searches */
  244. /*----------------------*/
  245. ib_int64_t* stat_n_diff_key_vals;
  246. /* approximate number of different key values
  247. for this index, for each n-column prefix
  248. where n <= dict_get_n_unique(index); we
  249. periodically calculate new estimates */
  250. ulint stat_index_size;
  251. /* approximate index size in database pages */
  252. ulint stat_n_leaf_pages;
  253. /* approximate number of leaf pages in the
  254. index tree */
  255. rw_lock_t lock; /* read-write lock protecting the upper levels
  256. of the index tree */
  257. ib_uint64_t trx_id; /* id of the transaction that created this
  258. index, or 0 if the index existed
  259. when InnoDB was started up */
  260. #endif /* !UNIV_HOTBACKUP */
  261. #ifdef UNIV_DEBUG
  262. ulint magic_n;/* magic number */
  263. # define DICT_INDEX_MAGIC_N 76789786
  264. #endif
  265. };
  266. /* Data structure for a foreign key constraint; an example:
  267. FOREIGN KEY (A, B) REFERENCES TABLE2 (C, D). Most fields will be
  268. initialized to 0, NULL or FALSE in dict_mem_foreign_create(). */
  269. struct dict_foreign_struct{
  270. mem_heap_t* heap; /* this object is allocated from
  271. this memory heap */
  272. char* id; /* id of the constraint as a
  273. null-terminated string */
  274. unsigned n_fields:10; /* number of indexes' first fields
  275. for which the the foreign key
  276. constraint is defined: we allow the
  277. indexes to contain more fields than
  278. mentioned in the constraint, as long
  279. as the first fields are as mentioned */
  280. unsigned type:6; /* 0 or DICT_FOREIGN_ON_DELETE_CASCADE
  281. or DICT_FOREIGN_ON_DELETE_SET_NULL */
  282. char* foreign_table_name;/* foreign table name */
  283. dict_table_t* foreign_table; /* table where the foreign key is */
  284. const char** foreign_col_names;/* names of the columns in the
  285. foreign key */
  286. char* referenced_table_name;/* referenced table name */
  287. dict_table_t* referenced_table;/* table where the referenced key
  288. is */
  289. const char** referenced_col_names;/* names of the referenced
  290. columns in the referenced table */
  291. dict_index_t* foreign_index; /* foreign index; we require that
  292. both tables contain explicitly defined
  293. indexes for the constraint: InnoDB
  294. does not generate new indexes
  295. implicitly */
  296. dict_index_t* referenced_index;/* referenced index */
  297. UT_LIST_NODE_T(dict_foreign_t)
  298. foreign_list; /* list node for foreign keys of the
  299. table */
  300. UT_LIST_NODE_T(dict_foreign_t)
  301. referenced_list;/* list node for referenced keys of the
  302. table */
  303. };
  304. /* The flags for ON_UPDATE and ON_DELETE can be ORed; the default is that
  305. a foreign key constraint is enforced, therefore RESTRICT just means no flag */
  306. #define DICT_FOREIGN_ON_DELETE_CASCADE 1
  307. #define DICT_FOREIGN_ON_DELETE_SET_NULL 2
  308. #define DICT_FOREIGN_ON_UPDATE_CASCADE 4
  309. #define DICT_FOREIGN_ON_UPDATE_SET_NULL 8
  310. #define DICT_FOREIGN_ON_DELETE_NO_ACTION 16
  311. #define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32
  312. /* Data structure for a database table. Most fields will be
  313. initialized to 0, NULL or FALSE in dict_mem_table_create(). */
  314. struct dict_table_struct{
  315. dulint id; /* id of the table */
  316. mem_heap_t* heap; /* memory heap */
  317. const char* name; /* table name */
  318. const char* dir_path_of_temp_table;/* NULL or the directory path
  319. where a TEMPORARY table that was explicitly
  320. created by a user should be placed if
  321. innodb_file_per_table is defined in my.cnf;
  322. in Unix this is usually /tmp/..., in Windows
  323. \temp\... */
  324. unsigned space:32;
  325. /* space where the clustered index of the
  326. table is placed */
  327. unsigned flags:DICT_TF_BITS;/* DICT_TF_COMPACT, ... */
  328. unsigned ibd_file_missing:1;
  329. /* TRUE if this is in a single-table
  330. tablespace and the .ibd file is missing; then
  331. we must return in ha_innodb.cc an error if the
  332. user tries to query such an orphaned table */
  333. unsigned tablespace_discarded:1;
  334. /* this flag is set TRUE when the user
  335. calls DISCARD TABLESPACE on this
  336. table, and reset to FALSE in IMPORT
  337. TABLESPACE */
  338. unsigned cached:1;/* TRUE if the table object has been added
  339. to the dictionary cache */
  340. unsigned n_def:10;/* number of columns defined so far */
  341. unsigned n_cols:10;/* number of columns */
  342. dict_col_t* cols; /* array of column descriptions */
  343. const char* col_names;
  344. /* Column names packed in a character string
  345. "name1\0name2\0...nameN\0". Until
  346. the string contains n_cols, it will be
  347. allocated from a temporary heap. The final
  348. string will be allocated from table->heap. */
  349. #ifndef UNIV_HOTBACKUP
  350. hash_node_t name_hash; /* hash chain node */
  351. hash_node_t id_hash; /* hash chain node */
  352. UT_LIST_BASE_NODE_T(dict_index_t)
  353. indexes; /* list of indexes of the table */
  354. UT_LIST_BASE_NODE_T(dict_foreign_t)
  355. foreign_list;/* list of foreign key constraints
  356. in the table; these refer to columns
  357. in other tables */
  358. UT_LIST_BASE_NODE_T(dict_foreign_t)
  359. referenced_list;/* list of foreign key constraints
  360. which refer to this table */
  361. UT_LIST_NODE_T(dict_table_t)
  362. table_LRU; /* node of the LRU list of tables */
  363. ulint n_mysql_handles_opened;
  364. /* count of how many handles MySQL has opened
  365. to this table; dropping of the table is
  366. NOT allowed until this count gets to zero;
  367. MySQL does NOT itself check the number of
  368. open handles at drop */
  369. ulint n_foreign_key_checks_running;
  370. /* count of how many foreign key check
  371. operations are currently being performed
  372. on the table: we cannot drop the table while
  373. there are foreign key checks running on
  374. it! */
  375. trx_id_t query_cache_inv_trx_id;
  376. /* transactions whose trx id < than this
  377. number are not allowed to store to the MySQL
  378. query cache or retrieve from it; when a trx
  379. with undo logs commits, it sets this to the
  380. value of the trx id counter for the tables it
  381. had an IX lock on */
  382. UT_LIST_BASE_NODE_T(lock_t)
  383. locks; /* list of locks on the table */
  384. #ifdef UNIV_DEBUG
  385. /*----------------------*/
  386. ibool does_not_fit_in_memory;
  387. /* this field is used to specify in simulations
  388. tables which are so big that disk should be
  389. accessed: disk access is simulated by
  390. putting the thread to sleep for a while;
  391. NOTE that this flag is not stored to the data
  392. dictionary on disk, and the database will
  393. forget about value TRUE if it has to reload
  394. the table definition from disk */
  395. #endif /* UNIV_DEBUG */
  396. /*----------------------*/
  397. unsigned big_rows:1;
  398. /* flag: TRUE if the maximum length of
  399. a single row exceeds BIG_ROW_SIZE;
  400. initialized in dict_table_add_to_cache() */
  401. unsigned stat_initialized:1; /* TRUE if statistics have
  402. been calculated the first time
  403. after database startup or table creation */
  404. ib_int64_t stat_n_rows;
  405. /* approximate number of rows in the table;
  406. we periodically calculate new estimates */
  407. ulint stat_clustered_index_size;
  408. /* approximate clustered index size in
  409. database pages */
  410. ulint stat_sum_of_other_index_sizes;
  411. /* other indexes in database pages */
  412. ulint stat_modified_counter;
  413. /* when a row is inserted, updated, or deleted,
  414. we add 1 to this number; we calculate new
  415. estimates for the stat_... values for the
  416. table and the indexes at an interval of 2 GB
  417. or when about 1 / 16 of table has been
  418. modified; also when the estimate operation is
  419. called for MySQL SHOW TABLE STATUS; the
  420. counter is reset to zero at statistics
  421. calculation; this counter is not protected by
  422. any latch, because this is only used for
  423. heuristics */
  424. /*----------------------*/
  425. /* The following fields are used by the
  426. AUTOINC code. The actual collection of
  427. tables locked during AUTOINC read/write is
  428. kept in trx_t. In order to quickly determine
  429. whether a transaction has locked the AUTOINC
  430. lock we keep a pointer to the transaction
  431. here in the autoinc_trx variable. This is to
  432. avoid acquiring the kernel mutex and scanning
  433. the vector in trx_t.
  434. When an AUTOINC lock has to wait, the
  435. corresponding lock instance is created on
  436. the trx lock heap rather than use the
  437. pre-allocated instance in autoinc_lock below.*/
  438. lock_t* autoinc_lock;
  439. /* a buffer for an AUTOINC lock
  440. for this table: we allocate the memory here
  441. so that individual transactions can get it
  442. and release it without a need to allocate
  443. space from the lock heap of the trx:
  444. otherwise the lock heap would grow rapidly
  445. if we do a large insert from a select */
  446. mutex_t autoinc_mutex;
  447. /* mutex protecting the autoincrement
  448. counter */
  449. ib_uint64_t autoinc;/* autoinc counter value to give to the
  450. next inserted row */
  451. ulong n_waiting_or_granted_auto_inc_locks;
  452. /* This counter is used to track the number
  453. of granted and pending autoinc locks on this
  454. table. This value is set after acquiring the
  455. kernel mutex but we peek the contents to
  456. determine whether other transactions have
  457. acquired the AUTOINC lock or not. Of course
  458. only one transaction can be granted the
  459. lock but there can be multiple waiters. */
  460. const trx_t* autoinc_trx;
  461. /* The transaction that currently holds the
  462. the AUTOINC lock on this table. */
  463. /*----------------------*/
  464. #endif /* !UNIV_HOTBACKUP */
  465. #ifdef UNIV_DEBUG
  466. ulint magic_n;/* magic number */
  467. # define DICT_TABLE_MAGIC_N 76333786
  468. #endif /* UNIV_DEBUG */
  469. };
  470. #ifndef UNIV_NONINL
  471. #include "dict0mem.ic"
  472. #endif
  473. #endif