MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_myisam.h
1 /*
2  Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16 
17 
18 /* class for the the myisam handler */
19 
20 #include <myisam.h>
21 #include <ft_global.h>
22 #include "handler.h" /* handler */
23 #include "table.h" /* TABLE_SHARE */
24 
25 struct TABLE_SHARE;
27 
28 #define HA_RECOVER_DEFAULT 1 /* Automatic recover active */
29 #define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */
30 #define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */
31 #define HA_RECOVER_QUICK 8 /* Don't check rows in data file */
32 #define HA_RECOVER_OFF 16 /* No automatic recover */
33 
34 extern TYPELIB myisam_recover_typelib;
35 extern const char *myisam_recover_names[];
36 extern ulonglong myisam_recover_options;
37 
38 C_MODE_START
39 ICP_RESULT index_cond_func_myisam(void *arg);
40 C_MODE_END
41 
42 class ha_myisam: public handler
43 {
44  MI_INFO *file;
45  ulonglong int_table_flags;
46  char *data_file_name, *index_file_name;
47  bool can_enable_indexes;
48  int repair(THD *thd, MI_CHECK &param, bool optimize);
49 
50  public:
51  ha_myisam(handlerton *hton, TABLE_SHARE *table_arg);
52  ~ha_myisam() {}
53  handler *clone(const char *name, MEM_ROOT *mem_root);
54  const char *table_type() const { return "MyISAM"; }
55  const char *index_type(uint key_number);
56  const char **bas_ext() const;
57  ulonglong table_flags() const { return int_table_flags; }
58  int index_init(uint idx, bool sorted);
59  int index_end();
60  int rnd_end();
61 
62  ulong index_flags(uint inx, uint part, bool all_parts) const
63  {
64  if (table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT)
65  return 0;
66 
67  ulong flags= HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE |
68  HA_READ_ORDER | HA_KEYREAD_ONLY | HA_DO_INDEX_COND_PUSHDOWN;
69 
70  // @todo: Check if spatial indexes really have all these properties
71  if (table_share->key_info[inx].flags & HA_SPATIAL)
72  flags|= HA_KEY_SCAN_NOT_ROR;
73 
74  return flags;
75  }
76  uint max_supported_keys() const { return MI_MAX_KEY; }
77  uint max_supported_key_length() const { return MI_MAX_KEY_LENGTH; }
78  uint max_supported_key_part_length() const { return MI_MAX_KEY_LENGTH; }
79  uint checksum() const;
80 
81  int open(const char *name, int mode, uint test_if_locked);
82  int close(void);
83  int write_row(uchar * buf);
84  int update_row(const uchar * old_data, uchar * new_data);
85  int delete_row(const uchar * buf);
86  int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
87  enum ha_rkey_function find_flag);
88  int index_read_idx_map(uchar *buf, uint index, const uchar *key,
89  key_part_map keypart_map,
90  enum ha_rkey_function find_flag);
91  int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map);
92  int index_next(uchar * buf);
93  int index_prev(uchar * buf);
94  int index_first(uchar * buf);
95  int index_last(uchar * buf);
96  int index_next_same(uchar *buf, const uchar *key, uint keylen);
97  int ft_init()
98  {
99  if (!ft_handler)
100  return 1;
101  ft_handler->please->reinit_search(ft_handler);
102  return 0;
103  }
104  FT_INFO *ft_init_ext(uint flags, uint inx,String *key)
105  {
106  return ft_init_search(flags,file,inx,
107  (uchar *)key->ptr(), key->length(), key->charset(),
108  table->record[0]);
109  }
110  int ft_read(uchar *buf);
111  int rnd_init(bool scan);
112  int rnd_next(uchar *buf);
113  int rnd_pos(uchar * buf, uchar *pos);
114  int restart_rnd_next(uchar *buf, uchar *pos);
115  void position(const uchar *record);
116  int info(uint);
117  int extra(enum ha_extra_function operation);
118  int extra_opt(enum ha_extra_function operation, ulong cache_size);
119  int reset(void);
120  int external_lock(THD *thd, int lock_type);
121  int delete_all_rows(void);
122  int truncate();
123  int reset_auto_increment(ulonglong value);
124  int disable_indexes(uint mode);
125  int enable_indexes(uint mode);
126  int indexes_are_disabled(void);
127  void start_bulk_insert(ha_rows rows);
128  int end_bulk_insert();
129  ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
130  void update_create_info(HA_CREATE_INFO *create_info);
131  int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
133  enum thr_lock_type lock_type);
134  virtual void get_auto_increment(ulonglong offset, ulonglong increment,
135  ulonglong nb_desired_values,
136  ulonglong *first_value,
137  ulonglong *nb_reserved_values);
138  int rename_table(const char * from, const char * to);
139  int delete_table(const char *name);
140  int check(THD* thd, HA_CHECK_OPT* check_opt);
141  int analyze(THD* thd,HA_CHECK_OPT* check_opt);
142  int repair(THD* thd, HA_CHECK_OPT* check_opt);
143  bool check_and_repair(THD *thd);
144  bool is_crashed() const;
145  bool auto_repair() const { return myisam_recover_options != HA_RECOVER_OFF; }
146  int optimize(THD* thd, HA_CHECK_OPT* check_opt);
147  int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt);
148  int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);
149  bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes);
150 #ifdef HAVE_QUERY_CACHE
151  my_bool register_query_cache_table(THD *thd, char *table_key,
152  uint key_length,
153  qc_engine_callback
154  *engine_callback,
155  ulonglong *engine_data);
156 #endif
157  MI_INFO *file_ptr(void)
158  {
159  return file;
160  }
161 public:
165  int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
166  uint n_ranges, uint mode, HANDLER_BUFFER *buf);
167  int multi_range_read_next(char **range_info);
168  ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
169  void *seq_init_param,
170  uint n_ranges, uint *bufsz,
171  uint *flags, Cost_estimate *cost);
172  ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
173  uint *bufsz, uint *flags, Cost_estimate *cost);
174 
175  /* Index condition pushdown implementation */
176  Item *idx_cond_push(uint keyno, Item* idx_cond);
177 private:
178  DsMrr_impl ds_mrr;
179  friend ICP_RESULT index_cond_func_myisam(void *arg);
180 };
181