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.

349 lines
12 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
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
15 years ago
15 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
15 years ago
15 years ago
  1. /*****************************************************************************
  2. Copyright (c) 2000, 2010, MySQL AB & 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. This file is based on ha_berkeley.h of MySQL distribution
  15. This file defines the Innodb handler: the interface between MySQL and
  16. Innodb
  17. */
  18. #ifdef USE_PRAGMA_INTERFACE
  19. #pragma interface /* gcc class implementation */
  20. #endif
  21. /* Structure defines translation table between mysql index and innodb
  22. index structures */
  23. typedef struct innodb_idx_translate_struct {
  24. ulint index_count; /*!< number of valid index entries
  25. in the index_mapping array */
  26. ulint array_size; /*!< array size of index_mapping */
  27. dict_index_t** index_mapping; /*!< index pointer array directly
  28. maps to index in Innodb from MySQL
  29. array index */
  30. } innodb_idx_translate_t;
  31. /** InnoDB table share */
  32. typedef struct st_innobase_share {
  33. THR_LOCK lock; /*!< MySQL lock protecting
  34. this structure */
  35. const char* table_name; /*!< InnoDB table name */
  36. uint use_count; /*!< reference count,
  37. incremented in get_share()
  38. and decremented in
  39. free_share() */
  40. void* table_name_hash;/*!< hash table chain node */
  41. innodb_idx_translate_t idx_trans_tbl; /*!< index translation
  42. table between MySQL and
  43. Innodb */
  44. dict_table_t* ib_table;
  45. } INNOBASE_SHARE;
  46. /** InnoDB B-tree index */
  47. struct dict_index_struct;
  48. /** Prebuilt structures in an Innobase table handle used within MySQL */
  49. struct row_prebuilt_struct;
  50. /** InnoDB B-tree index */
  51. typedef struct dict_index_struct dict_index_t;
  52. /** Prebuilt structures in an Innobase table handle used within MySQL */
  53. typedef struct row_prebuilt_struct row_prebuilt_t;
  54. /** The class defining a handle to an Innodb table */
  55. class ha_innobase: public handler
  56. {
  57. row_prebuilt_t* prebuilt; /*!< prebuilt struct in InnoDB, used
  58. to save CPU time with prebuilt data
  59. structures*/
  60. THD* user_thd; /*!< the thread handle of the user
  61. currently using the handle; this is
  62. set in external_lock function */
  63. THR_LOCK_DATA lock;
  64. INNOBASE_SHARE* share; /*!< information for MySQL
  65. table locking */
  66. uchar* upd_buf; /*!< buffer used in updates */
  67. ulint upd_buf_size; /*!< the size of upd_buf in bytes */
  68. uchar srch_key_val1[MAX_KEY_LENGTH + MAX_REF_PARTS*2];
  69. uchar srch_key_val2[MAX_KEY_LENGTH + MAX_REF_PARTS*2];
  70. /*!< buffers used in converting
  71. search key values from MySQL format
  72. to InnoDB format. For each column
  73. 2 bytes are used to store length,
  74. hence MAX_REF_PARTS*2. */
  75. Table_flags int_table_flags;
  76. uint primary_key;
  77. ulong start_of_scan; /*!< this is set to 1 when we are
  78. starting a table scan but have not
  79. yet fetched any row, else 0 */
  80. uint last_match_mode;/* match mode of the latest search:
  81. ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
  82. or undefined */
  83. uint num_write_row; /*!< number of write_row() calls */
  84. uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
  85. const uchar* record);
  86. inline void update_thd(THD* thd);
  87. void update_thd();
  88. int change_active_index(uint keynr);
  89. int general_fetch(uchar* buf, uint direction, uint match_mode);
  90. ulint innobase_lock_autoinc();
  91. ulonglong innobase_peek_autoinc();
  92. ulint innobase_set_max_autoinc(ulonglong auto_inc);
  93. ulint innobase_reset_autoinc(ulonglong auto_inc);
  94. ulint innobase_get_autoinc(ulonglong* value);
  95. ulint innobase_update_autoinc(ulonglong auto_inc);
  96. void innobase_initialize_autoinc();
  97. dict_index_t* innobase_get_index(uint keynr);
  98. int info_low(uint flag, bool called_from_analyze);
  99. /* Init values for the class: */
  100. public:
  101. ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
  102. ~ha_innobase();
  103. /*
  104. Get the row type from the storage engine. If this method returns
  105. ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
  106. */
  107. enum row_type get_row_type() const;
  108. const char* table_type() const;
  109. const char* index_type(uint key_number);
  110. const char** bas_ext() const;
  111. Table_flags table_flags() const;
  112. ulong index_flags(uint idx, uint part, bool all_parts) const;
  113. uint max_supported_keys() const;
  114. uint max_supported_key_length() const;
  115. uint max_supported_key_part_length() const;
  116. const key_map* keys_to_use_for_scanning();
  117. int open(const char *name, int mode, uint test_if_locked);
  118. handler* clone(const char *name, MEM_ROOT *mem_root);
  119. int close(void);
  120. double scan_time();
  121. double read_time(uint index, uint ranges, ha_rows rows);
  122. my_bool is_fake_change_enabled(THD *thd);
  123. bool is_corrupt() const;
  124. int write_row(uchar * buf);
  125. int update_row(const uchar * old_data, uchar * new_data);
  126. int delete_row(const uchar * buf);
  127. bool was_semi_consistent_read();
  128. void try_semi_consistent_read(bool yes);
  129. void unlock_row();
  130. int index_init(uint index, bool sorted);
  131. int index_end();
  132. int index_read(uchar * buf, const uchar * key,
  133. uint key_len, enum ha_rkey_function find_flag);
  134. int index_read_idx(uchar * buf, uint index, const uchar * key,
  135. uint key_len, enum ha_rkey_function find_flag);
  136. int index_read_last(uchar * buf, const uchar * key, uint key_len);
  137. int index_next(uchar * buf);
  138. int index_next_same(uchar * buf, const uchar *key, uint keylen);
  139. int index_prev(uchar * buf);
  140. int index_first(uchar * buf);
  141. int index_last(uchar * buf);
  142. int rnd_init(bool scan);
  143. int rnd_end();
  144. int rnd_next(uchar *buf);
  145. int rnd_pos(uchar * buf, uchar *pos);
  146. void position(const uchar *record);
  147. int info(uint);
  148. int analyze(THD* thd,HA_CHECK_OPT* check_opt);
  149. int optimize(THD* thd,HA_CHECK_OPT* check_opt);
  150. int discard_or_import_tablespace(my_bool discard);
  151. int extra(enum ha_extra_function operation);
  152. int reset();
  153. int external_lock(THD *thd, int lock_type);
  154. int transactional_table_lock(THD *thd, int lock_type);
  155. int start_stmt(THD *thd, thr_lock_type lock_type);
  156. void position(uchar *record);
  157. ha_rows records_in_range(uint inx, key_range *min_key, key_range
  158. *max_key);
  159. ha_rows estimate_rows_upper_bound();
  160. void update_create_info(HA_CREATE_INFO* create_info);
  161. int create(const char *name, register TABLE *form,
  162. HA_CREATE_INFO *create_info);
  163. int truncate();
  164. int delete_table(const char *name);
  165. int rename_table(const char* from, const char* to);
  166. int check(THD* thd, HA_CHECK_OPT* check_opt);
  167. char* update_table_comment(const char* comment);
  168. char* get_foreign_key_create_info();
  169. int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
  170. int get_parent_foreign_key_list(THD *thd,
  171. List<FOREIGN_KEY_INFO> *f_key_list);
  172. bool can_switch_engines();
  173. uint referenced_by_foreign_key();
  174. void free_foreign_key_create_info(char* str);
  175. THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
  176. enum thr_lock_type lock_type);
  177. void init_table_handle_for_HANDLER();
  178. virtual void get_auto_increment(ulonglong offset, ulonglong increment,
  179. ulonglong nb_desired_values,
  180. ulonglong *first_value,
  181. ulonglong *nb_reserved_values);
  182. int reset_auto_increment(ulonglong value);
  183. virtual bool get_error_message(int error, String *buf);
  184. uint8 table_cache_type();
  185. /*
  186. ask handler about permission to cache table during query registration
  187. */
  188. my_bool register_query_cache_table(THD *thd, char *table_key,
  189. uint key_length,
  190. qc_engine_callback *call_back,
  191. ulonglong *engine_data);
  192. static char *get_mysql_bin_log_name();
  193. static ulonglong get_mysql_bin_log_pos();
  194. bool primary_key_is_clustered();
  195. int cmp_ref(const uchar *ref1, const uchar *ref2);
  196. /** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
  197. int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys,
  198. handler_add_index **add);
  199. int final_add_index(handler_add_index *add, bool commit);
  200. int prepare_drop_index(TABLE *table_arg, uint *key_num,
  201. uint num_of_keys);
  202. int final_drop_index(TABLE *table_arg);
  203. /** @} */
  204. bool check_if_incompatible_data(HA_CREATE_INFO *info,
  205. uint table_changes);
  206. };
  207. /* Some accessor functions which the InnoDB plugin needs, but which
  208. can not be added to mysql/plugin.h as part of the public interface;
  209. the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */
  210. #ifndef INNODB_COMPATIBILITY_HOOKS
  211. #error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
  212. #endif
  213. extern "C" {
  214. struct charset_info_st *thd_charset(MYSQL_THD thd);
  215. LEX_STRING *thd_query_string(MYSQL_THD thd);
  216. #ifdef EXTENDED_FOR_COMMIT_ORDERED
  217. /** Get the file name and position of the MySQL binlog corresponding to the
  218. * current commit.
  219. */
  220. void mysql_bin_log_commit_pos(THD *thd, ulonglong *out_pos, const char **out_file);
  221. #else
  222. /** Get the file name of the MySQL binlog.
  223. * @return the name of the binlog file
  224. */
  225. const char* mysql_bin_log_file_name(void);
  226. /** Get the current position of the MySQL binlog.
  227. * @return byte offset from the beginning of the binlog
  228. */
  229. ulonglong mysql_bin_log_file_pos(void);
  230. #endif
  231. /**
  232. Check if a user thread is a replication slave thread
  233. @param thd user thread
  234. @retval 0 the user thread is not a replication slave thread
  235. @retval 1 the user thread is a replication slave thread
  236. */
  237. int thd_slave_thread(const MYSQL_THD thd);
  238. /**
  239. Check if a user thread is running a non-transactional update
  240. @param thd user thread
  241. @retval 0 the user thread is not running a non-transactional update
  242. @retval 1 the user thread is running a non-transactional update
  243. */
  244. int thd_non_transactional_update(const MYSQL_THD thd);
  245. /**
  246. Get the user thread's binary logging format
  247. @param thd user thread
  248. @return Value to be used as index into the binlog_format_names array
  249. */
  250. int thd_binlog_format(const MYSQL_THD thd);
  251. /**
  252. Mark transaction to rollback and mark error as fatal to a sub-statement.
  253. @param thd Thread handle
  254. @param all TRUE <=> rollback main transaction.
  255. */
  256. void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
  257. /**
  258. Check if binary logging is filtered for thread's current db.
  259. @param thd Thread handle
  260. @retval 1 the query is not filtered, 0 otherwise.
  261. */
  262. bool thd_binlog_filter_ok(const MYSQL_THD thd);
  263. /**
  264. Check if the query may generate row changes which
  265. may end up in the binary.
  266. @param thd Thread handle
  267. @return 1 the query may generate row changes, 0 otherwise.
  268. */
  269. bool thd_sqlcom_can_generate_row_events(const MYSQL_THD thd);
  270. }
  271. typedef struct trx_struct trx_t;
  272. /********************************************************************//**
  273. @file handler/ha_innodb.h
  274. Converts an InnoDB error code to a MySQL error code and also tells to MySQL
  275. about a possible transaction rollback inside InnoDB caused by a lock wait
  276. timeout or a deadlock.
  277. @return MySQL error code */
  278. extern "C"
  279. int
  280. convert_error_code_to_mysql(
  281. /*========================*/
  282. int error, /*!< in: InnoDB error code */
  283. ulint flags, /*!< in: InnoDB table flags, or 0 */
  284. MYSQL_THD thd); /*!< in: user thread handle or NULL */
  285. /*********************************************************************//**
  286. Allocates an InnoDB transaction for a MySQL handler object.
  287. @return InnoDB transaction handle */
  288. extern "C"
  289. trx_t*
  290. innobase_trx_allocate(
  291. /*==================*/
  292. MYSQL_THD thd); /*!< in: user thread handle */
  293. /*********************************************************************//**
  294. This function checks each index name for a table against reserved
  295. system default primary index name 'GEN_CLUST_INDEX'. If a name
  296. matches, this function pushes an warning message to the client,
  297. and returns true.
  298. @return true if the index name matches the reserved name */
  299. extern "C"
  300. bool
  301. innobase_index_name_is_reserved(
  302. /*============================*/
  303. THD* thd, /*!< in/out: MySQL connection */
  304. const KEY* key_info, /*!< in: Indexes to be created */
  305. ulint num_of_keys); /*!< in: Number of indexes to
  306. be created. */