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.

197 lines
7.2 KiB

  1. /*****************************************************************************
  2. Copyright (c) 2005, 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/row0merge.h
  15. Index build routines using a merge sort
  16. Created 13/06/2005 Jan Lindstrom
  17. *******************************************************/
  18. #ifndef row0merge_h
  19. #define row0merge_h
  20. #include "univ.i"
  21. #include "data0data.h"
  22. #include "dict0types.h"
  23. #include "trx0types.h"
  24. #include "que0types.h"
  25. #include "mtr0mtr.h"
  26. #include "rem0types.h"
  27. #include "rem0rec.h"
  28. #include "read0types.h"
  29. #include "btr0types.h"
  30. #include "row0mysql.h"
  31. #include "lock0types.h"
  32. /** Index field definition */
  33. struct merge_index_field_struct {
  34. ulint prefix_len; /*!< column prefix length, or 0
  35. if indexing the whole column */
  36. const char* field_name; /*!< field name */
  37. };
  38. /** Index field definition */
  39. typedef struct merge_index_field_struct merge_index_field_t;
  40. /** Definition of an index being created */
  41. struct merge_index_def_struct {
  42. const char* name; /*!< index name */
  43. ulint ind_type; /*!< 0, DICT_UNIQUE,
  44. or DICT_CLUSTERED */
  45. ulint n_fields; /*!< number of fields
  46. in index */
  47. merge_index_field_t* fields; /*!< field definitions */
  48. };
  49. /** Definition of an index being created */
  50. typedef struct merge_index_def_struct merge_index_def_t;
  51. /*********************************************************************//**
  52. Sets an exclusive lock on a table, for the duration of creating indexes.
  53. @return error code or DB_SUCCESS */
  54. UNIV_INTERN
  55. ulint
  56. row_merge_lock_table(
  57. /*=================*/
  58. trx_t* trx, /*!< in/out: transaction */
  59. dict_table_t* table, /*!< in: table to lock */
  60. enum lock_mode mode); /*!< in: LOCK_X or LOCK_S */
  61. /*********************************************************************//**
  62. Drop an index from the InnoDB system tables. The data dictionary must
  63. have been locked exclusively by the caller, because the transaction
  64. will not be committed. */
  65. UNIV_INTERN
  66. void
  67. row_merge_drop_index(
  68. /*=================*/
  69. dict_index_t* index, /*!< in: index to be removed */
  70. dict_table_t* table, /*!< in: table */
  71. trx_t* trx); /*!< in: transaction handle */
  72. /*********************************************************************//**
  73. Drop those indexes which were created before an error occurred when
  74. building an index. The data dictionary must have been locked
  75. exclusively by the caller, because the transaction will not be
  76. committed. */
  77. UNIV_INTERN
  78. void
  79. row_merge_drop_indexes(
  80. /*===================*/
  81. trx_t* trx, /*!< in: transaction */
  82. dict_table_t* table, /*!< in: table containing the indexes */
  83. dict_index_t** index, /*!< in: indexes to drop */
  84. ulint num_created); /*!< in: number of elements in index[] */
  85. /*********************************************************************//**
  86. Drop all partially created indexes during crash recovery. */
  87. UNIV_INTERN
  88. void
  89. row_merge_drop_temp_indexes(void);
  90. /*=============================*/
  91. /*********************************************************************//**
  92. Rename the tables in the data dictionary. The data dictionary must
  93. have been locked exclusively by the caller, because the transaction
  94. will not be committed.
  95. @return error code or DB_SUCCESS */
  96. UNIV_INTERN
  97. ulint
  98. row_merge_rename_tables(
  99. /*====================*/
  100. dict_table_t* old_table, /*!< in/out: old table, renamed to
  101. tmp_name */
  102. dict_table_t* new_table, /*!< in/out: new table, renamed to
  103. old_table->name */
  104. const char* tmp_name, /*!< in: new name for old_table */
  105. trx_t* trx); /*!< in: transaction handle */
  106. /*********************************************************************//**
  107. Create a temporary table for creating a primary key, using the definition
  108. of an existing table.
  109. @return table, or NULL on error */
  110. UNIV_INTERN
  111. dict_table_t*
  112. row_merge_create_temporary_table(
  113. /*=============================*/
  114. const char* table_name, /*!< in: new table name */
  115. const merge_index_def_t*index_def, /*!< in: the index definition
  116. of the primary key */
  117. const dict_table_t* table, /*!< in: old table definition */
  118. trx_t* trx); /*!< in/out: transaction
  119. (sets error_state) */
  120. /*********************************************************************//**
  121. Rename the temporary indexes in the dictionary to permanent ones. The
  122. data dictionary must have been locked exclusively by the caller,
  123. because the transaction will not be committed.
  124. @return DB_SUCCESS if all OK */
  125. UNIV_INTERN
  126. ulint
  127. row_merge_rename_indexes(
  128. /*=====================*/
  129. trx_t* trx, /*!< in/out: transaction */
  130. dict_table_t* table); /*!< in/out: table with new indexes */
  131. /*********************************************************************//**
  132. Create the index and load in to the dictionary.
  133. @return index, or NULL on error */
  134. UNIV_INTERN
  135. dict_index_t*
  136. row_merge_create_index(
  137. /*===================*/
  138. trx_t* trx, /*!< in/out: trx (sets error_state) */
  139. dict_table_t* table, /*!< in: the index is on this table */
  140. const merge_index_def_t*index_def);
  141. /*!< in: the index definition */
  142. /*********************************************************************//**
  143. Check if a transaction can use an index.
  144. @return TRUE if index can be used by the transaction else FALSE */
  145. UNIV_INTERN
  146. ibool
  147. row_merge_is_index_usable(
  148. /*======================*/
  149. const trx_t* trx, /*!< in: transaction */
  150. const dict_index_t* index); /*!< in: index to check */
  151. /*********************************************************************//**
  152. If there are views that refer to the old table name then we "attach" to
  153. the new instance of the table else we drop it immediately.
  154. @return DB_SUCCESS or error code */
  155. UNIV_INTERN
  156. ulint
  157. row_merge_drop_table(
  158. /*=================*/
  159. trx_t* trx, /*!< in: transaction */
  160. dict_table_t* table); /*!< in: table instance to drop */
  161. /*********************************************************************//**
  162. Build indexes on a table by reading a clustered index,
  163. creating a temporary file containing index entries, merge sorting
  164. these index entries and inserting sorted index entries to indexes.
  165. @return DB_SUCCESS or error code */
  166. UNIV_INTERN
  167. ulint
  168. row_merge_build_indexes(
  169. /*====================*/
  170. trx_t* trx, /*!< in: transaction */
  171. dict_table_t* old_table, /*!< in: table where rows are
  172. read from */
  173. dict_table_t* new_table, /*!< in: table where indexes are
  174. created; identical to old_table
  175. unless creating a PRIMARY KEY */
  176. dict_index_t** indexes, /*!< in: indexes to be created */
  177. ulint n_indexes, /*!< in: size of indexes[] */
  178. TABLE* table); /*!< in/out: MySQL table, for
  179. reporting erroneous key value
  180. if applicable */
  181. #endif /* row0merge.h */