1/*
2 Copyright (c) 2000, 2012, Oracle and/or its affiliates.
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#ifdef USE_PRAGMA_INTERFACE
19#pragma interface /* gcc class implementation */
20#endif
21
22/* class for the the myisam handler */
23
24#include <myisam.h>
25#include <ft_global.h>
26#include "handler.h" /* handler */
27#include "table.h" /* TABLE_SHARE */
28
29#define HA_RECOVER_DEFAULT 1 /* Automatic recover active */
30#define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */
31#define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */
32#define HA_RECOVER_QUICK 8 /* Don't check rows in data file */
33#define HA_RECOVER_FULL_BACKUP 16 /* Make a copy of index file too */
34#define HA_RECOVER_OFF 32 /* No automatic recover */
35
36extern TYPELIB myisam_recover_typelib;
37extern const char *myisam_recover_names[];
38extern ulonglong myisam_recover_options;
39
40C_MODE_START
41ICP_RESULT index_cond_func_myisam(void *arg);
42C_MODE_END
43
44class ha_myisam: public handler
45{
46 MI_INFO *file;
47 ulonglong int_table_flags;
48 char *data_file_name, *index_file_name;
49 bool can_enable_indexes;
50 int repair(THD *thd, HA_CHECK &param, bool optimize);
51 void setup_vcols_for_repair(HA_CHECK *param);
52 void restore_vcos_after_repair();
53
54 public:
55 ha_myisam(handlerton *hton, TABLE_SHARE *table_arg);
56 ~ha_myisam() {}
57 handler *clone(const char *name, MEM_ROOT *mem_root);
58 const char *index_type(uint key_number);
59 ulonglong table_flags() const { return int_table_flags; }
60 int index_init(uint idx, bool sorted);
61 int index_end();
62 int rnd_end();
63
64 ulong index_flags(uint inx, uint part, bool all_parts) const;
65 uint max_supported_keys() const { return MI_MAX_KEY; }
66 uint max_supported_key_parts() const { return HA_MAX_KEY_SEG; }
67 uint max_supported_key_length() const { return HA_MAX_KEY_LENGTH; }
68 uint max_supported_key_part_length() const { return HA_MAX_KEY_LENGTH; }
69 uint checksum() const;
70 void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
71 int open(const char *name, int mode, uint test_if_locked);
72 int close(void);
73 int write_row(uchar * buf);
74 int update_row(const uchar * old_data, const uchar * new_data);
75 int delete_row(const uchar * buf);
76 int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
77 enum ha_rkey_function find_flag);
78 int index_read_idx_map(uchar *buf, uint index, const uchar *key,
79 key_part_map keypart_map,
80 enum ha_rkey_function find_flag);
81 int index_next(uchar * buf);
82 int index_prev(uchar * buf);
83 int index_first(uchar * buf);
84 int index_last(uchar * buf);
85 int index_next_same(uchar *buf, const uchar *key, uint keylen);
86 int ft_init()
87 {
88 if (!ft_handler)
89 return 1;
90 ft_handler->please->reinit_search(ft_handler);
91 return 0;
92 }
93 FT_INFO *ft_init_ext(uint flags, uint inx,String *key)
94 {
95 return ft_init_search(flags,file,inx,
96 (uchar *)key->ptr(), key->length(), key->charset(),
97 table->record[0]);
98 }
99 int ft_read(uchar *buf);
100 int rnd_init(bool scan);
101 int rnd_next(uchar *buf);
102 int rnd_pos(uchar * buf, uchar *pos);
103 int remember_rnd_pos();
104 int restart_rnd_next(uchar *buf);
105 void position(const uchar *record);
106 int info(uint);
107 int extra(enum ha_extra_function operation);
108 int extra_opt(enum ha_extra_function operation, ulong cache_size);
109 int reset(void);
110 int external_lock(THD *thd, int lock_type);
111 int delete_all_rows(void);
112 int reset_auto_increment(ulonglong value);
113 int disable_indexes(uint mode);
114 int enable_indexes(uint mode);
115 int indexes_are_disabled(void);
116 void start_bulk_insert(ha_rows rows, uint flags);
117 int end_bulk_insert();
118 ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
119 void update_create_info(HA_CREATE_INFO *create_info);
120 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
121 THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
122 enum thr_lock_type lock_type);
123 virtual void get_auto_increment(ulonglong offset, ulonglong increment,
124 ulonglong nb_desired_values,
125 ulonglong *first_value,
126 ulonglong *nb_reserved_values);
127 int rename_table(const char * from, const char * to);
128 int delete_table(const char *name);
129 int check_for_upgrade(HA_CHECK_OPT *check_opt);
130 int check(THD* thd, HA_CHECK_OPT* check_opt);
131 int analyze(THD* thd,HA_CHECK_OPT* check_opt);
132 int repair(THD* thd, HA_CHECK_OPT* check_opt);
133 bool check_and_repair(THD *thd);
134 bool is_crashed() const;
135 bool auto_repair(int error) const
136 {
137 return (myisam_recover_options != HA_RECOVER_OFF &&
138 error == HA_ERR_CRASHED_ON_USAGE);
139 }
140 int optimize(THD* thd, HA_CHECK_OPT* check_opt);
141 int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt);
142 int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);
143 enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *new_table,
144 Alter_inplace_info *alter_info);
145 bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes);
146#ifdef HAVE_QUERY_CACHE
147 my_bool register_query_cache_table(THD *thd, const char *table_key,
148 uint key_length,
149 qc_engine_callback
150 *engine_callback,
151 ulonglong *engine_data);
152#endif
153 MI_INFO *file_ptr(void)
154 {
155 return file;
156 }
157public:
158 /**
159 * Multi Range Read interface
160 */
161 int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
162 uint n_ranges, uint mode, HANDLER_BUFFER *buf);
163 int multi_range_read_next(range_id_t *range_info);
164 ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
165 void *seq_init_param,
166 uint n_ranges, uint *bufsz,
167 uint *flags, Cost_estimate *cost);
168 ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
169 uint key_parts, uint *bufsz,
170 uint *flags, Cost_estimate *cost);
171 int multi_range_read_explain_info(uint mrr_mode, char *str, size_t size);
172
173 /* Index condition pushdown implementation */
174 Item *idx_cond_push(uint keyno, Item* idx_cond);
175private:
176 DsMrr_impl ds_mrr;
177 friend ICP_RESULT index_cond_func_myisam(void *arg);
178};
179