1#ifndef HA_MARIA_INCLUDED
2#define HA_MARIA_INCLUDED
3/* Copyright (C) 2006,2004 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
17
18#ifdef USE_PRAGMA_INTERFACE
19#pragma interface /* gcc class implementation */
20#endif
21
22/* class for the maria handler */
23
24#include <maria.h>
25#include "handler.h"
26#include "table.h"
27
28#define HA_RECOVER_NONE 0 /* No automatic recover */
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
34C_MODE_START
35ICP_RESULT index_cond_func_maria(void *arg);
36C_MODE_END
37
38extern TYPELIB maria_recover_typelib;
39extern ulonglong maria_recover_options;
40
41class ha_maria :public handler
42{
43 MARIA_HA *file;
44 ulonglong int_table_flags;
45 MARIA_RECORD_POS remember_pos;
46 char *data_file_name, *index_file_name;
47 enum data_file_type data_file_type;
48 bool can_enable_indexes;
49 /**
50 If a transactional table is doing bulk insert with a single
51 UNDO_BULK_INSERT with/without repair.
52 */
53 uint8 bulk_insert_single_undo;
54 int repair(THD * thd, HA_CHECK *param, bool optimize);
55 int zerofill(THD * thd, HA_CHECK_OPT *check_opt);
56
57public:
58 ha_maria(handlerton *hton, TABLE_SHARE * table_arg);
59 ~ha_maria() {}
60 handler *clone(const char *name, MEM_ROOT *mem_root);
61 const char *index_type(uint key_number);
62 ulonglong table_flags() const
63 { return int_table_flags; }
64 ulong index_flags(uint inx, uint part, bool all_parts) const;
65 uint max_supported_keys() const
66 { return MARIA_MAX_KEY; }
67 uint max_supported_key_length() const;
68 uint max_supported_key_part_length() const
69 { return max_supported_key_length(); }
70 enum row_type get_row_type() const;
71 uint checksum() const;
72 void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
73 virtual double scan_time();
74
75 int open(const char *name, int mode, uint test_if_locked);
76 int close(void);
77 int write_row(uchar * buf);
78 int update_row(const uchar * old_data, const uchar * new_data);
79 int delete_row(const uchar * buf);
80 int index_read_map(uchar * buf, const uchar * key, key_part_map keypart_map,
81 enum ha_rkey_function find_flag);
82 int index_read_idx_map(uchar * buf, uint idx, const uchar * key,
83 key_part_map keypart_map,
84 enum ha_rkey_function find_flag);
85 int index_read_last_map(uchar * buf, const uchar * key,
86 key_part_map keypart_map);
87 int index_next(uchar * buf);
88 int index_prev(uchar * buf);
89 int index_first(uchar * buf);
90 int index_last(uchar * buf);
91 int index_next_same(uchar * buf, const uchar * key, uint keylen);
92 int ft_init()
93 {
94 if (!ft_handler)
95 return 1;
96 ft_handler->please->reinit_search(ft_handler);
97 return 0;
98 }
99 FT_INFO *ft_init_ext(uint flags, uint inx, String * key)
100 {
101 return maria_ft_init_search(flags, file, inx,
102 (uchar *) key->ptr(), key->length(),
103 key->charset(), table->record[0]);
104 }
105 int ft_read(uchar * buf);
106 int index_init(uint idx, bool sorted);
107 int index_end();
108 int rnd_init(bool scan);
109 int rnd_end(void);
110 int rnd_next(uchar * buf);
111 int rnd_pos(uchar * buf, uchar * pos);
112 int remember_rnd_pos();
113 int restart_rnd_next(uchar * buf);
114 void position(const uchar * record);
115 int info(uint);
116 int info(uint, my_bool);
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 start_stmt(THD *thd, thr_lock_type lock_type);
122 int delete_all_rows(void);
123 int disable_indexes(uint mode);
124 int enable_indexes(uint mode);
125 int indexes_are_disabled(void);
126 void start_bulk_insert(ha_rows rows, uint flags);
127 int end_bulk_insert();
128 ha_rows records_in_range(uint inx, key_range * min_key, key_range * max_key);
129 void update_create_info(HA_CREATE_INFO * create_info);
130 int create(const char *name, TABLE * form, HA_CREATE_INFO * create_info);
131 THR_LOCK_DATA **store_lock(THD * thd, THR_LOCK_DATA ** to,
132 enum thr_lock_type lock_type);
133 virtual void get_auto_increment(ulonglong offset, ulonglong increment,
134 ulonglong nb_desired_values,
135 ulonglong *first_value,
136 ulonglong *nb_reserved_values);
137 int rename_table(const char *from, const char *to);
138 int delete_table(const char *name);
139 void drop_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 is_changed() const;
146 bool auto_repair(int error) const
147 {
148 /* Always auto-repair moved tables (error == HA_ERR_OLD_FILE) */
149 return ((MY_TEST(maria_recover_options & HA_RECOVER_ANY) &&
150 error == HA_ERR_CRASHED_ON_USAGE) ||
151 error == HA_ERR_OLD_FILE);
152
153 }
154 int optimize(THD * thd, HA_CHECK_OPT * check_opt);
155 int restore(THD * thd, HA_CHECK_OPT * check_opt);
156 int backup(THD * thd, HA_CHECK_OPT * check_opt);
157 int assign_to_keycache(THD * thd, HA_CHECK_OPT * check_opt);
158 int preload_keys(THD * thd, HA_CHECK_OPT * check_opt);
159 bool check_if_incompatible_data(HA_CREATE_INFO * info, uint table_changes);
160#ifdef HAVE_REPLICATION
161 int dump(THD * thd, int fd);
162 int net_read_dump(NET * net);
163#endif
164#ifdef HAVE_QUERY_CACHE
165 my_bool register_query_cache_table(THD *thd, const char *table_key,
166 uint key_length,
167 qc_engine_callback
168 *engine_callback,
169 ulonglong *engine_data);
170#endif
171 MARIA_HA *file_ptr(void)
172 {
173 return file;
174 }
175 static int implicit_commit(THD *thd, bool new_trn);
176 /**
177 * Multi Range Read interface
178 */
179 int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
180 uint n_ranges, uint mode, HANDLER_BUFFER *buf);
181 int multi_range_read_next(range_id_t *range_info);
182 ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
183 void *seq_init_param,
184 uint n_ranges, uint *bufsz,
185 uint *flags, Cost_estimate *cost);
186 ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
187 uint key_parts, uint *bufsz,
188 uint *flags, Cost_estimate *cost);
189 int multi_range_read_explain_info(uint mrr_mode, char *str, size_t size);
190
191 /* Index condition pushdown implementation */
192 Item *idx_cond_push(uint keyno, Item* idx_cond);
193
194 int find_unique_row(uchar *record, uint unique_idx);
195private:
196 DsMrr_impl ds_mrr;
197 friend ICP_RESULT index_cond_func_maria(void *arg);
198};
199
200#endif /* HA_MARIA_INCLUDED */
201