MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_innodb.h
1 /*****************************************************************************
2 
3 Copyright (c) 2000, 2012, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /*
20  This file is based on ha_berkeley.h of MySQL distribution
21 
22  This file defines the Innodb handler: the interface between MySQL and
23  Innodb
24 */
25 
26 #include "dict0stats.h"
27 
28 /* Structure defines translation table between mysql index and innodb
29 index structures */
31  ulint index_count;
33  ulint array_size;
37 };
38 
39 
41 typedef struct st_innobase_share {
44  const char* table_name;
45  uint use_count;
54 
55 
57 struct row_prebuilt_t;
58 
60 class ha_innobase: public handler
61 {
62  row_prebuilt_t* prebuilt;
65  THD* user_thd;
68  THR_LOCK_DATA lock;
69  INNOBASE_SHARE* share;
72  uchar* upd_buf;
73  ulint upd_buf_size;
74  uchar srch_key_val1[MAX_KEY_LENGTH + MAX_REF_PARTS*2];
75  uchar srch_key_val2[MAX_KEY_LENGTH + MAX_REF_PARTS*2];
81  Table_flags int_table_flags;
82  uint primary_key;
83  ulong start_of_scan;
86  uint last_match_mode;/* match mode of the latest search:
87  ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
88  or undefined */
89  uint num_write_row;
91  uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
92  const uchar* record);
93  inline void update_thd(THD* thd);
94  void update_thd();
95  int change_active_index(uint keynr);
96  int general_fetch(uchar* buf, uint direction, uint match_mode);
97  dberr_t innobase_lock_autoinc();
98  ulonglong innobase_peek_autoinc();
99  dberr_t innobase_set_max_autoinc(ulonglong auto_inc);
100  dberr_t innobase_reset_autoinc(ulonglong auto_inc);
101  dberr_t innobase_get_autoinc(ulonglong* value);
102  void innobase_initialize_autoinc();
103  dict_index_t* innobase_get_index(uint keynr);
104 
105  /* Init values for the class: */
106  public:
107  ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
108  ~ha_innobase();
109  /*
110  Get the row type from the storage engine. If this method returns
111  ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
112  */
113  enum row_type get_row_type() const;
114 
115  const char* table_type() const;
116  const char* index_type(uint key_number);
117  const char** bas_ext() const;
118  Table_flags table_flags() const;
119  ulong index_flags(uint idx, uint part, bool all_parts) const;
120  uint max_supported_keys() const;
121  uint max_supported_key_length() const;
122  uint max_supported_key_part_length() const;
124 
125  int open(const char *name, int mode, uint test_if_locked);
126  handler* clone(const char *name, MEM_ROOT *mem_root);
127  int close(void);
128  double scan_time();
129  double read_time(uint index, uint ranges, ha_rows rows);
130  longlong get_memory_buffer_size() const;
131 
132  int write_row(uchar * buf);
133  int update_row(const uchar * old_data, uchar * new_data);
134  int delete_row(const uchar * buf);
136  void try_semi_consistent_read(bool yes);
137  void unlock_row();
138 
139  int index_init(uint index, bool sorted);
140  int index_end();
141  int index_read(uchar * buf, const uchar * key,
142  uint key_len, enum ha_rkey_function find_flag);
143  int index_read_idx(uchar * buf, uint index, const uchar * key,
144  uint key_len, enum ha_rkey_function find_flag);
145  int index_read_last(uchar * buf, const uchar * key, uint key_len);
146  int index_next(uchar * buf);
147  int index_next_same(uchar * buf, const uchar *key, uint keylen);
148  int index_prev(uchar * buf);
149  int index_first(uchar * buf);
150  int index_last(uchar * buf);
151 
152  int rnd_init(bool scan);
153  int rnd_end();
154  int rnd_next(uchar *buf);
155  int rnd_pos(uchar * buf, uchar *pos);
156 
157  int ft_init();
158  void ft_end();
159  FT_INFO *ft_init_ext(uint flags, uint inx, String* key);
160  int ft_read(uchar* buf);
161 
162  void position(const uchar *record);
163  int info(uint);
164  int analyze(THD* thd,HA_CHECK_OPT* check_opt);
165  int optimize(THD* thd,HA_CHECK_OPT* check_opt);
166  int discard_or_import_tablespace(my_bool discard);
167  int extra(enum ha_extra_function operation);
168  int reset();
169  int external_lock(THD *thd, int lock_type);
170  int transactional_table_lock(THD *thd, int lock_type);
171  int start_stmt(THD *thd, thr_lock_type lock_type);
172  void position(uchar *record);
173  ha_rows records_in_range(uint inx, key_range *min_key, key_range
174  *max_key);
175  ha_rows estimate_rows_upper_bound();
176 
177  void update_create_info(HA_CREATE_INFO* create_info);
178  int parse_table_name(const char*name,
179  HA_CREATE_INFO* create_info,
180  ulint flags,
181  ulint flags2,
182  char* norm_name,
183  char* temp_path,
184  char* remote_path);
185  int create(const char *name, register TABLE *form,
186  HA_CREATE_INFO *create_info);
187  int truncate();
188  int delete_table(const char *name);
189  int rename_table(const char* from, const char* to);
190  int check(THD* thd, HA_CHECK_OPT* check_opt);
191  char* update_table_comment(const char* comment);
192  char* get_foreign_key_create_info();
193  int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
194  int get_parent_foreign_key_list(THD *thd,
195  List<FOREIGN_KEY_INFO> *f_key_list);
196  bool can_switch_engines();
197  uint referenced_by_foreign_key();
198  void free_foreign_key_create_info(char* str);
199  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
200  enum thr_lock_type lock_type);
202  virtual void get_auto_increment(ulonglong offset, ulonglong increment,
203  ulonglong nb_desired_values,
204  ulonglong *first_value,
205  ulonglong *nb_reserved_values);
206  int reset_auto_increment(ulonglong value);
207 
208  virtual bool get_error_message(int error, String *buf);
209  virtual bool get_foreign_dup_key(char*, uint, char*, uint);
210  uint8 table_cache_type();
211  /*
212  ask handler about permission to cache table during query registration
213  */
214  my_bool register_query_cache_table(THD *thd, char *table_key,
215  uint key_length,
216  qc_engine_callback *call_back,
217  ulonglong *engine_data);
218  static const char *get_mysql_bin_log_name();
219  static ulonglong get_mysql_bin_log_pos();
221  int cmp_ref(const uchar *ref1, const uchar *ref2);
239  enum_alter_inplace_result check_if_supported_inplace_alter(
240  TABLE* altered_table,
241  Alter_inplace_info* ha_alter_info);
255  TABLE* altered_table,
256  Alter_inplace_info* ha_alter_info);
257 
270  bool inplace_alter_table(
271  TABLE* altered_table,
272  Alter_inplace_info* ha_alter_info);
273 
289  TABLE* altered_table,
290  Alter_inplace_info* ha_alter_info,
291  bool commit);
294  uint table_changes);
295 private:
302  void build_template(bool whole_row);
305  inline void reset_template();
306 
307  int info_low(uint, bool);
308 
309 public:
319  void* seq_init_param,
320  uint n_ranges, uint mode,
321  HANDLER_BUFFER* buf);
325  int multi_range_read_next(char** range_info);
337  ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF* seq,
338  void* seq_init_param,
339  uint n_ranges, uint* bufsz,
340  uint* flags, Cost_estimate* cost);
351  ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
352  uint* bufsz, uint* flags,
353  Cost_estimate* cost);
354 
360  class Item* idx_cond_push(uint keyno, class Item* idx_cond);
361 
362 private:
364  DsMrr_impl ds_mrr;
365  /* @} */
366 };
367 
368 /* Some accessor functions which the InnoDB plugin needs, but which
369 can not be added to mysql/plugin.h as part of the public interface;
370 the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */
371 
372 #ifndef INNODB_COMPATIBILITY_HOOKS
373 #error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
374 #endif
375 
376 LEX_STRING* thd_query_string(MYSQL_THD thd);
377 
378 extern "C" {
379 
380 struct charset_info_st *thd_charset(MYSQL_THD thd);
381 
388 int thd_slave_thread(const MYSQL_THD thd);
389 
396 int thd_non_transactional_update(const MYSQL_THD thd);
397 
403 int thd_binlog_format(const MYSQL_THD thd);
404 
410 void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
411 
417 bool thd_binlog_filter_ok(const MYSQL_THD thd);
418 
425 bool thd_sqlcom_can_generate_row_events(const MYSQL_THD thd);
426 
433 enum durability_properties thd_get_durability_property(const MYSQL_THD thd);
434 
439 void thd_get_autoinc(const MYSQL_THD thd, ulong* off, ulong* inc)
440 __attribute__((nonnull));
441 
446 bool thd_is_strict_mode(const MYSQL_THD thd)
447 __attribute__((nonnull));
448 } /* extern "C" */
449 
450 struct trx_t;
451 
452 extern const struct _ft_vft ft_vft_result;
453 
454 /* Structure Returned by ha_innobase::ft_init_ext() */
455 typedef struct new_ft_info
456 {
457  struct _ft_vft *please;
458  struct _ft_vft_ext *could_you;
459  row_prebuilt_t* ft_prebuilt;
460  fts_result_t* ft_result;
461 } NEW_FT_INFO;
462 
463 /*********************************************************************/
466 trx_t*
468 /*==================*/
469  MYSQL_THD thd);
471 /*********************************************************************/
477 UNIV_INTERN
478 bool
479 innobase_index_name_is_reserved(
480 /*============================*/
481  THD* thd,
482  const KEY* key_info,
483  ulint num_of_keys)
485  __attribute__((nonnull, warn_unused_result));
486 
487 /*****************************************************************/
490 UNIV_INTERN
491 bool
492 innobase_table_flags(
493 /*=================*/
494  const TABLE* form,
495  const HA_CREATE_INFO* create_info,
497  THD* thd,
498  bool use_tablespace,
500  ulint* flags,
501  ulint* flags2)
502  __attribute__((nonnull, warn_unused_result));
503 
504 /*****************************************************************/
510 UNIV_INTERN
511 const char*
512 create_options_are_invalid(
513 /*=======================*/
514  THD* thd,
515  TABLE* form,
517  HA_CREATE_INFO* create_info,
518  bool use_tablespace)
519  __attribute__((nonnull, warn_unused_result));
520 
521 /*********************************************************************/
525 UNIV_INTERN
526 float
527 innobase_fts_retrieve_ranking(
528 /*==========================*/
529  FT_INFO* fts_hdl);
531 /*********************************************************************/
535 UNIV_INTERN
536 float
537 innobase_fts_find_ranking(
538 /*======================*/
539  FT_INFO* fts_hdl,
540  uchar* record,
541  uint len);
542 /*********************************************************************/
544 UNIV_INTERN
545 void
546 innobase_fts_close_ranking(
547 /*=======================*/
548  FT_INFO* fts_hdl)
549  __attribute__((nonnull));
550 /*****************************************************************/
553 UNIV_INTERN
554 ibool
555 innobase_fts_load_stopword(
556 /*=======================*/
558  trx_t* trx,
559  THD* thd)
560  __attribute__((nonnull(1,3), warn_unused_result));
561 
563 enum fts_doc_id_index_enum {
564  FTS_INCORRECT_DOC_ID_INDEX,
565  FTS_EXIST_DOC_ID_INDEX,
566  FTS_NOT_EXIST_DOC_ID_INDEX
567 };
568 
569 /*******************************************************************/
573 UNIV_INTERN
574 enum fts_doc_id_index_enum
575 innobase_fts_check_doc_id_index(
576 /*============================*/
577  const dict_table_t* table,
578  const TABLE* altered_table,
580  ulint* fts_doc_col_no)
582  __attribute__((warn_unused_result));
583 
584 /*******************************************************************/
589 UNIV_INTERN
590 enum fts_doc_id_index_enum
591 innobase_fts_check_doc_id_index_in_def(
592 /*===================================*/
593  ulint n_key,
594  const KEY* key_info)
595  __attribute__((nonnull, warn_unused_result));
596 
597 /***********************************************************************
598 @return version of the extended FTS API */
599 uint
600 innobase_fts_get_version();
601 
602 /***********************************************************************
603 @return Which part of the extended FTS API is supported */
604 ulonglong
605 innobase_fts_flags();
606 
607 /***********************************************************************
608 Find and Retrieve the FTS doc_id for the current result row
609 @return the document ID */
610 ulonglong
611 innobase_fts_retrieve_docid(
612 /*============================*/
613  FT_INFO_EXT* fts_hdl);
615 /***********************************************************************
616 Find and retrieve the size of the current result
617 @return number of matching rows */
618 ulonglong
619 innobase_fts_count_matches(
620 /*============================*/
621  FT_INFO_EXT* fts_hdl);
625 extern const char innobase_index_reserve_name[];
626 
627 /*********************************************************************/
632 UNIV_INTERN
633 void
635 /*=====================================*/
636  dict_table_t* innodb_table,
637  const HA_CREATE_INFO* create_info);
639 /*********************************************************************/
644 UNIV_INTERN
645 void
647 /*=====================================*/
648  dict_table_t* innodb_table,
649  const TABLE_SHARE* table_share);