InnoDB Plugin  1.0
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 {
42  THR_LOCK lock;
44  const char* table_name;
45  uint use_count;
54 
55 
57 struct row_prebuilt_t;
58 
60 class ha_innobase: public handler
61 {
65  THD* user_thd;
68  THR_LOCK_DATA lock;
72  uchar* upd_buf;
73  ulint upd_buf_size;
74  Table_flags int_table_flags;
75  uint primary_key;
76  ulong start_of_scan;
79  uint last_match_mode;/* match mode of the latest search:
80  ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
81  or undefined */
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  dberr_t innobase_lock_autoinc();
91  ulonglong innobase_peek_autoinc();
92  dberr_t innobase_set_max_autoinc(ulonglong auto_inc);
93  dberr_t innobase_reset_autoinc(ulonglong auto_inc);
94  dberr_t innobase_get_autoinc(ulonglong* value);
95  void innobase_initialize_autoinc();
96  dict_index_t* innobase_get_index(uint keynr);
97 
98  /* Init values for the class: */
99  public:
100  ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
101  ~ha_innobase();
102  /*
103  Get the row type from the storage engine. If this method returns
104  ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
105  */
106  enum row_type get_row_type() const;
107 
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 
118  int open(const char *name, int mode, uint test_if_locked);
119  handler* clone(const char *name, MEM_ROOT *mem_root);
120  int close(void);
121  double scan_time();
122  double read_time(uint index, uint ranges, ha_rows rows);
123  longlong get_memory_buffer_size() const;
124 
125  int write_row(uchar * buf);
126  int update_row(const uchar * old_data, uchar * new_data);
127  int delete_row(const uchar * buf);
128  bool was_semi_consistent_read();
129  void try_semi_consistent_read(bool yes);
130  void unlock_row();
131 
132  int index_init(uint index, bool sorted);
133  int index_end();
134  int index_read(uchar * buf, const uchar * key,
135  uint key_len, enum ha_rkey_function find_flag);
136  int index_read_idx(uchar * buf, uint index, const uchar * key,
137  uint key_len, enum ha_rkey_function find_flag);
138  int index_read_last(uchar * buf, const uchar * key, uint key_len);
139  int index_next(uchar * buf);
140  int index_next_same(uchar * buf, const uchar *key, uint keylen);
141  int index_prev(uchar * buf);
142  int index_first(uchar * buf);
143  int index_last(uchar * buf);
144 
145  int rnd_init(bool scan);
146  int rnd_end();
147  int rnd_next(uchar *buf);
148  int rnd_pos(uchar * buf, uchar *pos);
149 
150  int ft_init();
151  void ft_end();
152  FT_INFO *ft_init_ext(uint flags, uint inx, String* key);
153  int ft_read(uchar* buf);
154 
155  void position(const uchar *record);
156  int info(uint);
157  int analyze(THD* thd,HA_CHECK_OPT* check_opt);
158  int optimize(THD* thd,HA_CHECK_OPT* check_opt);
159  int discard_or_import_tablespace(my_bool discard);
160  int extra(enum ha_extra_function operation);
161  int reset();
162  int external_lock(THD *thd, int lock_type);
163  int transactional_table_lock(THD *thd, int lock_type);
164  int start_stmt(THD *thd, thr_lock_type lock_type);
165  void position(uchar *record);
166  ha_rows records_in_range(uint inx, key_range *min_key, key_range
167  *max_key);
168  ha_rows estimate_rows_upper_bound();
169 
170  void update_create_info(HA_CREATE_INFO* create_info);
171  int parse_table_name(const char*name,
172  HA_CREATE_INFO* create_info,
173  ulint flags,
174  ulint flags2,
175  char* norm_name,
176  char* temp_path,
177  char* remote_path);
178  int create(const char *name, register TABLE *form,
179  HA_CREATE_INFO *create_info);
180  int truncate();
181  int delete_table(const char *name);
182  int rename_table(const char* from, const char* to);
183  int check(THD* thd, HA_CHECK_OPT* check_opt);
184  char* update_table_comment(const char* comment);
185  char* get_foreign_key_create_info();
186  int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
187  int get_parent_foreign_key_list(THD *thd,
188  List<FOREIGN_KEY_INFO> *f_key_list);
189  bool can_switch_engines();
190  uint referenced_by_foreign_key();
191  void free_foreign_key_create_info(char* str);
192  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
193  enum thr_lock_type lock_type);
194  void init_table_handle_for_HANDLER();
195  virtual void get_auto_increment(ulonglong offset, ulonglong increment,
196  ulonglong nb_desired_values,
197  ulonglong *first_value,
198  ulonglong *nb_reserved_values);
199  int reset_auto_increment(ulonglong value);
200 
201  virtual bool get_error_message(int error, String *buf);
202  virtual bool get_foreign_dup_key(char*, uint, char*, uint);
203  uint8 table_cache_type();
204  /*
205  ask handler about permission to cache table during query registration
206  */
207  my_bool register_query_cache_table(THD *thd, char *table_key,
208  uint key_length,
209  qc_engine_callback *call_back,
210  ulonglong *engine_data);
211  static const char *get_mysql_bin_log_name();
212  static ulonglong get_mysql_bin_log_pos();
213  bool primary_key_is_clustered();
214  int cmp_ref(const uchar *ref1, const uchar *ref2);
232  enum_alter_inplace_result check_if_supported_inplace_alter(
233  TABLE* altered_table,
234  Alter_inplace_info* ha_alter_info);
248  TABLE* altered_table,
249  Alter_inplace_info* ha_alter_info);
250 
263  bool inplace_alter_table(
264  TABLE* altered_table,
265  Alter_inplace_info* ha_alter_info);
266 
282  TABLE* altered_table,
283  Alter_inplace_info* ha_alter_info,
284  bool commit);
286  bool check_if_incompatible_data(HA_CREATE_INFO *info,
287  uint table_changes);
288 private:
295  void build_template(bool whole_row);
298  inline void reset_template();
299 
300  int info_low(uint, bool);
301 
302 public:
311  int multi_range_read_init(RANGE_SEQ_IF* seq,
312  void* seq_init_param,
313  uint n_ranges, uint mode,
314  HANDLER_BUFFER* buf);
318  int multi_range_read_next(char** range_info);
330  ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF* seq,
331  void* seq_init_param,
332  uint n_ranges, uint* bufsz,
333  uint* flags, Cost_estimate* cost);
344  ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
345  uint* bufsz, uint* flags,
346  Cost_estimate* cost);
347 
353  class Item* idx_cond_push(uint keyno, class Item* idx_cond);
354 
355 private:
357  DsMrr_impl ds_mrr;
358  /* @} */
359 };
360 
361 /* Some accessor functions which the InnoDB plugin needs, but which
362 can not be added to mysql/plugin.h as part of the public interface;
363 the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */
364 
365 #ifndef INNODB_COMPATIBILITY_HOOKS
366 #error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
367 #endif
368 
369 LEX_STRING* thd_query_string(MYSQL_THD thd);
370 
371 extern "C" {
372 
373 struct charset_info_st *thd_charset(MYSQL_THD thd);
374 
381 int thd_slave_thread(const MYSQL_THD thd);
382 
389 int thd_non_transactional_update(const MYSQL_THD thd);
390 
396 int thd_binlog_format(const MYSQL_THD thd);
397 
403 void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
404 
410 bool thd_binlog_filter_ok(const MYSQL_THD thd);
411 
418 bool thd_sqlcom_can_generate_row_events(const MYSQL_THD thd);
419 
426 enum durability_properties thd_get_durability_property(const MYSQL_THD thd);
427 
432 void thd_get_autoinc(const MYSQL_THD thd, ulong* off, ulong* inc)
433 __attribute__((nonnull));
434 
439 bool thd_is_strict_mode(const MYSQL_THD thd)
440 __attribute__((nonnull));
441 } /* extern "C" */
442 
443 struct trx_t;
444 
445 extern const struct _ft_vft ft_vft_result;
446 
447 /* Structure Returned by ha_innobase::ft_init_ext() */
448 typedef struct new_ft_info
449 {
450  struct _ft_vft *please;
451  struct _ft_vft_ext *could_you;
452  row_prebuilt_t* ft_prebuilt;
453  fts_result_t* ft_result;
454 } NEW_FT_INFO;
455 
456 /*********************************************************************/
459 trx_t*
460 innobase_trx_allocate(
461 /*==================*/
462  MYSQL_THD thd);
464 /*********************************************************************/
470 UNIV_INTERN
471 bool
472 innobase_index_name_is_reserved(
473 /*============================*/
474  THD* thd,
475  const KEY* key_info,
476  ulint num_of_keys)
478  __attribute__((nonnull, warn_unused_result));
479 
480 /*****************************************************************/
483 UNIV_INTERN
484 bool
485 innobase_table_flags(
486 /*=================*/
487  const TABLE* form,
488  const HA_CREATE_INFO* create_info,
490  THD* thd,
491  bool use_tablespace,
493  ulint* flags,
494  ulint* flags2)
495  __attribute__((nonnull, warn_unused_result));
496 
497 /*****************************************************************/
503 UNIV_INTERN
504 const char*
505 create_options_are_invalid(
506 /*=======================*/
507  THD* thd,
508  TABLE* form,
510  HA_CREATE_INFO* create_info,
511  bool use_tablespace)
512  __attribute__((nonnull, warn_unused_result));
513 
514 /*********************************************************************/
518 UNIV_INTERN
519 float
520 innobase_fts_retrieve_ranking(
521 /*==========================*/
522  FT_INFO* fts_hdl);
524 /*********************************************************************/
528 UNIV_INTERN
529 float
530 innobase_fts_find_ranking(
531 /*======================*/
532  FT_INFO* fts_hdl,
533  uchar* record,
534  uint len);
535 /*********************************************************************/
537 UNIV_INTERN
538 void
539 innobase_fts_close_ranking(
540 /*=======================*/
541  FT_INFO* fts_hdl)
542  __attribute__((nonnull));
543 /*****************************************************************/
546 UNIV_INTERN
547 ibool
548 innobase_fts_load_stopword(
549 /*=======================*/
550  dict_table_t* table,
551  trx_t* trx,
552  THD* thd)
553  __attribute__((nonnull(1,3), warn_unused_result));
554 
556 enum fts_doc_id_index_enum {
557  FTS_INCORRECT_DOC_ID_INDEX,
558  FTS_EXIST_DOC_ID_INDEX,
559  FTS_NOT_EXIST_DOC_ID_INDEX
560 };
561 
562 /*******************************************************************/
566 UNIV_INTERN
567 enum fts_doc_id_index_enum
568 innobase_fts_check_doc_id_index(
569 /*============================*/
570  const dict_table_t* table,
571  const TABLE* altered_table,
573  ulint* fts_doc_col_no)
575  __attribute__((warn_unused_result));
576 
577 /*******************************************************************/
582 UNIV_INTERN
583 enum fts_doc_id_index_enum
584 innobase_fts_check_doc_id_index_in_def(
585 /*===================================*/
586  ulint n_key,
587  const KEY* key_info)
588  __attribute__((nonnull, warn_unused_result));
589 
590 /***********************************************************************
591 @return version of the extended FTS API */
592 uint
593 innobase_fts_get_version();
594 
595 /***********************************************************************
596 @return Which part of the extended FTS API is supported */
597 ulonglong
598 innobase_fts_flags();
599 
600 /***********************************************************************
601 Find and Retrieve the FTS doc_id for the current result row
602 @return the document ID */
603 ulonglong
604 innobase_fts_retrieve_docid(
605 /*============================*/
606  FT_INFO_EXT* fts_hdl);
608 /***********************************************************************
609 Find and retrieve the size of the current result
610 @return number of matching rows */
611 ulonglong
612 innobase_fts_count_matches(
613 /*============================*/
614  FT_INFO_EXT* fts_hdl);
618 extern const char innobase_index_reserve_name[];
619 
620 /*********************************************************************/
625 UNIV_INTERN
626 void
627 innobase_copy_frm_flags_from_create_info(
628 /*=====================================*/
629  dict_table_t* innodb_table,
630  const HA_CREATE_INFO* create_info);
632 /*********************************************************************/
637 UNIV_INTERN
638 void
639 innobase_copy_frm_flags_from_table_share(
640 /*=====================================*/
641  dict_table_t* innodb_table,
642  const TABLE_SHARE* table_share);