1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/** @file ha_example.h
19
The ha_example engine is a stubbed storage engine for example purposes only;
20
it does nothing at this point. Its purpose is to provide a source
21
code illustration of how to begin writing new storage engines; see also
22
/storage/example/ha_example.cc.
25
Please read ha_example.cc before reading this file.
26
Reminder: The example storage engine implements all methods that are *required*
27
to be implemented. For a full list of all methods that you can implement, see
31
/sql/handler.h and /storage/example/ha_example.cc
34
#ifdef USE_PRAGMA_INTERFACE
35
#pragma interface /* gcc class implementation */
39
EXAMPLE_SHARE is a structure that will be shared among all open handlers.
40
This example implements the minimum of what you will probably need.
42
typedef struct st_example_share {
44
uint table_name_length,use_count;
45
pthread_mutex_t mutex;
50
Class definition for the storage engine
52
class ha_example: public handler
54
THR_LOCK_DATA lock; ///< MySQL lock
55
EXAMPLE_SHARE *share; ///< Shared lock info
58
ha_example(handlerton *hton, TABLE_SHARE *table_arg);
64
The name that will be used for display purposes.
66
const char *table_type() const { return "EXAMPLE"; }
69
The name of the index type that will be used for display.
70
Don't implement this method unless you really have indexes.
72
const char *index_type(uint inx) { return "HASH"; }
77
const char **bas_ext() const;
80
This is a list of flags that indicate what functionality the storage engine
81
implements. The current table flags are documented in handler.h
83
ulonglong table_flags() const
86
We are saying that this engine is just row capable to have an
87
engine that can only handle row-based logging. This is used in
90
return HA_BINLOG_ROW_CAPABLE;
94
This is a bitmap of flags that indicates how the storage engine
95
implements indexes. The current index flags are documented in
96
handler.h. If you do not implement indexes, just return zero here.
99
part is the key part to check. First key part is 0.
100
If all_parts is set, MySQL wants to know the flags for the combined
101
index, up to and including 'part'.
103
ulong index_flags(uint inx, uint part, bool all_parts) const
109
unireg.cc will call max_supported_record_length(), max_supported_keys(),
110
max_supported_key_parts(), uint max_supported_key_length()
111
to make sure that the storage engine can handle the data it is about to
112
send. Return *real* limits of your storage engine here; MySQL will do
113
min(your_limits, MySQL_limits) automatically.
115
uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
118
unireg.cc will call this to make sure that the storage engine can handle
119
the data it is about to send. Return *real* limits of your storage engine
120
here; MySQL will do min(your_limits, MySQL_limits) automatically.
123
There is no need to implement ..._key_... methods if your engine doesn't
126
uint max_supported_keys() const { return 0; }
129
unireg.cc will call this to make sure that the storage engine can handle
130
the data it is about to send. Return *real* limits of your storage engine
131
here; MySQL will do min(your_limits, MySQL_limits) automatically.
134
There is no need to implement ..._key_... methods if your engine doesn't
137
uint max_supported_key_parts() const { return 0; }
140
unireg.cc will call this to make sure that the storage engine can handle
141
the data it is about to send. Return *real* limits of your storage engine
142
here; MySQL will do min(your_limits, MySQL_limits) automatically.
145
There is no need to implement ..._key_... methods if your engine doesn't
148
uint max_supported_key_length() const { return 0; }
151
Called in test_quick_select to determine if indexes should be used.
153
virtual double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; }
156
This method will never be called if you do not implement indexes.
158
virtual double read_time(ha_rows rows) { return (double) rows / 20.0+1; }
161
Everything below are methods that we implement in ha_example.cc.
163
Most of these methods are not obligatory, skip them and
164
MySQL will treat them as not implemented
167
We implement this in ha_example.cc; it's a required method.
169
int open(const char *name, int mode, uint test_if_locked); // required
172
We implement this in ha_example.cc; it's a required method.
174
int close(void); // required
177
We implement this in ha_example.cc. It's not an obligatory method;
178
skip it and and MySQL will treat it as not implemented.
180
int write_row(uchar *buf);
183
We implement this in ha_example.cc. It's not an obligatory method;
184
skip it and and MySQL will treat it as not implemented.
186
int update_row(const uchar *old_data, uchar *new_data);
189
We implement this in ha_example.cc. It's not an obligatory method;
190
skip it and and MySQL will treat it as not implemented.
192
int delete_row(const uchar *buf);
195
We implement this in ha_example.cc. It's not an obligatory method;
196
skip it and and MySQL will treat it as not implemented.
198
int index_read_map(uchar *buf, const uchar *key,
199
key_part_map keypart_map, enum ha_rkey_function find_flag);
202
We implement this in ha_example.cc. It's not an obligatory method;
203
skip it and and MySQL will treat it as not implemented.
205
int index_next(uchar *buf);
208
We implement this in ha_example.cc. It's not an obligatory method;
209
skip it and and MySQL will treat it as not implemented.
211
int index_prev(uchar *buf);
214
We implement this in ha_example.cc. It's not an obligatory method;
215
skip it and and MySQL will treat it as not implemented.
217
int index_first(uchar *buf);
220
We implement this in ha_example.cc. It's not an obligatory method;
221
skip it and and MySQL will treat it as not implemented.
223
int index_last(uchar *buf);
226
Unlike index_init(), rnd_init() can be called two consecutive times
227
without rnd_end() in between (it only makes sense if scan=1). In this
228
case, the second call should prepare for the new table scan (e.g if
229
rnd_init() allocates the cursor, the second call should position the
230
cursor to the start of the table; no need to deallocate and allocate
231
it again. This is a required method.
233
int rnd_init(bool scan); //required
235
int rnd_next(uchar *buf); ///< required
236
int rnd_pos(uchar *buf, uchar *pos); ///< required
237
void position(const uchar *record); ///< required
238
int info(uint); ///< required
239
int extra(enum ha_extra_function operation);
240
int external_lock(THD *thd, int lock_type); ///< required
241
int delete_all_rows(void);
242
ha_rows records_in_range(uint inx, key_range *min_key,
244
int delete_table(const char *from);
245
int rename_table(const char * from, const char * to);
246
int create(const char *name, TABLE *form,
247
HA_CREATE_INFO *create_info); ///< required
249
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
250
enum thr_lock_type lock_type); ///< required