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 02110-1335 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 
34 C_MODE_START
35 ICP_RESULT index_cond_func_maria(void *arg);
36 C_MODE_END
37 
38 extern TYPELIB maria_recover_typelib;
39 extern ulonglong maria_recover_options;
40 
41 class 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 
57 public:
58   ha_maria(handlerton *hton, TABLE_SHARE * table_arg);
~ha_maria()59   ~ha_maria() {}
60   handler *clone(const char *name, MEM_ROOT *mem_root);
61   const char *index_type(uint key_number);
table_flags()62   ulonglong table_flags() const
63   { return int_table_flags; }
64   ulong index_flags(uint inx, uint part, bool all_parts) const;
max_supported_keys()65   uint max_supported_keys() const
66   { return MARIA_MAX_KEY; }
67   uint max_supported_key_length() const;
max_supported_key_part_length()68   uint max_supported_key_part_length() const
69   { return max_supported_key_length(); }
70   enum row_type get_row_type() const;
71   void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share);
72   virtual double scan_time();
73 
74   int open(const char *name, int mode, uint test_if_locked);
75   int close(void);
76   int write_row(uchar * buf);
77   int update_row(const uchar * old_data, const uchar * new_data);
78   int delete_row(const uchar * buf);
79   int index_read_map(uchar * buf, const uchar * key, key_part_map keypart_map,
80 		     enum ha_rkey_function find_flag);
81   int index_read_idx_map(uchar * buf, uint idx, const uchar * key,
82 			 key_part_map keypart_map,
83 			 enum ha_rkey_function find_flag);
84   int index_read_last_map(uchar * buf, const uchar * key,
85 			  key_part_map keypart_map);
86   int index_next(uchar * buf);
87   int index_prev(uchar * buf);
88   int index_first(uchar * buf);
89   int index_last(uchar * buf);
90   int index_next_same(uchar * buf, const uchar * key, uint keylen);
ft_init()91   int ft_init()
92   {
93     if (!ft_handler)
94       return 1;
95     ft_handler->please->reinit_search(ft_handler);
96     return 0;
97   }
ft_init_ext(uint flags,uint inx,String * key)98   FT_INFO *ft_init_ext(uint flags, uint inx, String * key)
99   {
100     return maria_ft_init_search(flags, file, inx,
101                                 (uchar *) key->ptr(), key->length(),
102                                 key->charset(), table->record[0]);
103   }
104   int ft_read(uchar * buf);
105   int index_init(uint idx, bool sorted);
106   int index_end();
107   int rnd_init(bool scan);
108   int rnd_end(void);
109   int rnd_next(uchar * buf);
110   int rnd_pos(uchar * buf, uchar * pos);
111   int remember_rnd_pos();
112   int restart_rnd_next(uchar * buf);
113   void position(const uchar * record);
114   int info(uint);
115   int info(uint, my_bool);
116   int extra(enum ha_extra_function operation);
117   int extra_opt(enum ha_extra_function operation, ulong cache_size);
118   int reset(void);
119   int external_lock(THD * thd, int lock_type);
120   int start_stmt(THD *thd, thr_lock_type lock_type);
121   int delete_all_rows(void);
122   int disable_indexes(uint mode);
123   int enable_indexes(uint mode);
124   int indexes_are_disabled(void);
125   void start_bulk_insert(ha_rows rows, uint flags);
126   int end_bulk_insert();
127   ha_rows records_in_range(uint inx, key_range * min_key, key_range * max_key);
128   void update_create_info(HA_CREATE_INFO * create_info);
129   int create(const char *name, TABLE * form, HA_CREATE_INFO * create_info);
130   THR_LOCK_DATA **store_lock(THD * thd, THR_LOCK_DATA ** to,
131                              enum thr_lock_type lock_type);
132   virtual void get_auto_increment(ulonglong offset, ulonglong increment,
133                                   ulonglong nb_desired_values,
134                                   ulonglong *first_value,
135                                   ulonglong *nb_reserved_values);
136   int rename_table(const char *from, const char *to);
137   int delete_table(const char *name);
138   void drop_table(const char *name);
139   int check(THD * thd, HA_CHECK_OPT * check_opt);
140   int analyze(THD * thd, HA_CHECK_OPT * check_opt);
141   int repair(THD * thd, HA_CHECK_OPT * check_opt);
142   bool check_and_repair(THD * thd);
143   bool is_crashed() const;
144   bool is_changed() const;
auto_repair(int error)145   bool auto_repair(int error) const
146   {
147     /* Always auto-repair moved tables (error == HA_ERR_OLD_FILE) */
148     return ((MY_TEST(maria_recover_options & HA_RECOVER_ANY) &&
149              error == HA_ERR_CRASHED_ON_USAGE) ||
150             error == HA_ERR_OLD_FILE);
151 
152   }
153   int optimize(THD * thd, HA_CHECK_OPT * check_opt);
154   int assign_to_keycache(THD * thd, HA_CHECK_OPT * check_opt);
155   int preload_keys(THD * thd, HA_CHECK_OPT * check_opt);
156   bool check_if_incompatible_data(HA_CREATE_INFO * info, uint table_changes);
157 #ifdef HAVE_QUERY_CACHE
158   my_bool register_query_cache_table(THD *thd, const char *table_key,
159                                      uint key_length,
160                                      qc_engine_callback
161                                      *engine_callback,
162                                      ulonglong *engine_data);
163 #endif
file_ptr(void)164   MARIA_HA *file_ptr(void)
165   {
166     return file;
167   }
168   static int implicit_commit(THD *thd, bool new_trn);
169   /**
170    * Multi Range Read interface
171    */
172   int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
173                             uint n_ranges, uint mode, HANDLER_BUFFER *buf);
174   int multi_range_read_next(range_id_t *range_info);
175   ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
176                                       void *seq_init_param,
177                                       uint n_ranges, uint *bufsz,
178                                       uint *flags, Cost_estimate *cost);
179   ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
180                                 uint key_parts, uint *bufsz,
181                                 uint *flags, Cost_estimate *cost);
182   int multi_range_read_explain_info(uint mrr_mode, char *str, size_t size);
183 
184   /* Index condition pushdown implementation */
185   Item *idx_cond_push(uint keyno, Item* idx_cond);
186 
187   int find_unique_row(uchar *record, uint unique_idx);
188 private:
189   DsMrr_impl ds_mrr;
190   friend ICP_RESULT index_cond_func_maria(void *arg);
191   friend void reset_thd_trn(THD *thd);
192 };
193 
194 #endif /* HA_MARIA_INCLUDED */
195