1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
6
(at your option) any later version.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
/* Definitions for parameters to do with handler-routines */
21
#pragma interface /* gcc class implementation */
25
#define NO_HASH /* Not yet implemented */
28
// the following is for checking tables
31
#define HA_CHECK_NOT_IMPLEMENTED -1
32
#define HA_CHECK_CORRUPT -2
33
#define HA_CHECK_INTERNAL_ERROR -3
35
#define HA_REPAIR_OK 0
36
#define HA_REPAIR_NOT_IMPLEMENTED -1
37
#define HA_REPAIR_FAILED -2
38
#define HA_REPAIR_INTERNAL_ERROR -3
40
#define HA_OPTIMIZE_OK 0
41
#define HA_OPTIMIZE_NOT_IMPLEMENTED -1
42
#define HA_OPTIMIZE_FAILED -2
43
#define HA_OPTIMIZE_INTERNAL_ERROR -3
45
#define HA_ANALYZE_OK 0
46
#define HA_ANALYZE_NOT_IMPLEMENTED -1
47
#define HA_ANALYZE_FAILED -2
48
#define HA_ANALYZE_INTERNAL_ERROR -3
50
/* Bits in bas_flag to show what database can do */
52
#define HA_READ_NEXT 1 /* Read next record with same key */
53
#define HA_READ_PREV 2 /* Read prev. record with same key */
54
#define HA_READ_ORDER 4 /* Read through record-keys in order */
55
#define HA_READ_RND_SAME 8 /* Read RND-record to KEY-record
56
(To update with RND-read) */
57
#define HA_KEYPOS_TO_RNDPOS 16 /* ha_info gives pos to record */
58
#define HA_LASTKEY_ORDER 32 /* Next record gives next record
59
according last record read (even
60
if database is updated after read) */
61
#define HA_REC_NOT_IN_SEQ 64 /* ha_info don't return recnumber;
62
It returns a position to ha_r_rnd */
63
#define HA_BINARY_KEYS 128 /* Keys must be exact */
64
#define HA_RSAME_NO_INDEX 256 /* RSAME can't restore index */
65
#define HA_WRONG_ASCII_ORDER 512 /* Can't use sorting through key */
66
#define HA_HAVE_KEY_READ_ONLY 1024 /* Can read only keys (no record) */
67
#define HA_READ_NOT_EXACT_KEY 2048 /* Can read record after/before key */
68
#define HA_NO_INDEX 4096 /* No index needed for next/prev */
69
#define HA_LONGLONG_KEYS 8192 /* Can have longlong as key */
70
#define HA_KEY_READ_WRONG_STR 16384 /* keyread returns converted strings */
71
#define HA_NULL_KEY 32768 /* One can have keys with NULL */
72
#define HA_DUPP_POS 65536 /* ha_position() gives dupp row */
73
#define HA_NO_BLOBS 131072 /* Doesn't support blobs */
74
#define HA_BLOB_KEY (HA_NO_BLOBS*2) /* key on blob */
75
#define HA_AUTO_PART_KEY (HA_BLOB_KEY*2)
76
#define HA_REQUIRE_PRIMARY_KEY (HA_AUTO_PART_KEY*2)
77
#define HA_NOT_EXACT_COUNT (HA_REQUIRE_PRIMARY_KEY*2)
78
#define HA_NO_WRITE_DELAYED (HA_NOT_EXACT_COUNT*2)
79
#define HA_PRIMARY_KEY_IN_READ_INDEX (HA_NO_WRITE_DELAYED*2)
80
#define HA_DROP_BEFORE_CREATE (HA_PRIMARY_KEY_IN_READ_INDEX*2)
82
/* Parameters for open() (in register form->filestat) */
83
/* HA_GET_INFO does a implicit HA_ABORT_IF_LOCKED */
85
#define HA_OPEN_KEYFILE 1
86
#define HA_OPEN_RNDFILE 2
87
#define HA_GET_INDEX 4
88
#define HA_GET_INFO 8 /* do a ha_info() after open */
89
#define HA_READ_ONLY 16 /* File opened as readonly */
90
#define HA_TRY_READ_ONLY 32 /* Try readonly if can't */
91
/* open with read and write */
92
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
93
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
94
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
95
#define HA_OPEN_TEMPORARY 512
97
/* Error on write which is recoverable (Key exist) */
99
#define HA_WRITE_SKIPP 121 /* Duplicate key on write */
100
#define HA_READ_CHECK 123 /* Update with is recoverable */
101
#define HA_CANT_DO_THAT 131 /* Databasehandler can't do it */
103
/* Some key definitions */
104
#define HA_KEY_NULL_LENGTH 1
105
#define HA_KEY_BLOB_LENGTH 2
107
#define HA_LEX_CREATE_TMP_TABLE 1
108
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
109
#define HA_OPTION_NO_CHECKSUM (1L << 17)
110
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
111
#define HA_MAX_REC_LENGTH 65535
113
enum db_type { DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
114
DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
115
DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
116
DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
120
enum row_type { ROW_TYPE_DEFAULT, ROW_TYPE_FIXED, ROW_TYPE_DYNAMIC,
121
ROW_TYPE_COMPRESSED };
123
/* struct to hold information about the table that should be created */
125
/* Bits in used_fields */
126
#define HA_CREATE_USED_AUTO 1
127
#define HA_CREATE_USED_RAID 2
129
typedef struct st_ha_create_information
132
enum db_type db_type;
133
enum row_type row_type;
134
ulong avg_row_length;
135
ulonglong max_rows,min_rows;
136
ulonglong auto_increment_value;
137
char *comment,*password;
138
uint options; /* OR of HA_CREATE_ options */
139
uint raid_type,raid_chunks;
140
ulong raid_chunksize;
146
/* The handler for a table type. Will be included in the TABLE structure */
149
typedef struct st_table TABLE;
150
extern ulong myisam_sort_buffer_size;
152
typedef struct st_ha_check_opt
154
ulong sort_buffer_size;
161
sort_buffer_size = myisam_sort_buffer_size;
165
class handler :public Sql_alloc
168
struct st_table *table; /* The table definition */
172
byte *ref; /* Pointer to current row */
173
byte *dupp_ref; /* Pointer to dupp row */
174
uint ref_length; /* Length of ref (1-8) */
175
uint block_size; /* index block size */
176
ha_rows records; /* Records i datafilen */
177
ha_rows deleted; /* Deleted records */
178
ulonglong data_file_length; /* Length off data file */
179
ulonglong max_data_file_length; /* Length off data file */
180
ulonglong index_file_length;
181
ulonglong max_index_file_length;
182
ulonglong delete_length; /* Free bytes */
183
ulonglong auto_increment_value;
184
uint raid_type,raid_chunks;
185
ulong raid_chunksize;
186
uint errkey; /* Last dup key */
187
uint sortkey, key_used_on_scan;
188
time_t create_time; /* When table was created */
191
ulong mean_rec_length; /* physical reclength */
195
handler(TABLE *table_arg) : table(table_arg),active_index(MAX_REF_PARTS),
196
ref(0),ref_length(sizeof(my_off_t)), block_size(0),records(0),deleted(0),
197
data_file_length(0), max_data_file_length(0), index_file_length(0),
198
delete_length(0), auto_increment_value(0), raid_type(0),
199
key_used_on_scan(MAX_KEY),
200
create_time(0), check_time(0), update_time(0), mean_rec_length(0),
201
ft_relevance(0.0), ft_handler(0)
203
virtual ~handler(void) { my_free((char*) ref,MYF(MY_ALLOW_ZERO_PTR)); }
204
int ha_open(const char *name, int mode, int test_if_locked);
205
void update_timestamp(byte *record);
206
void update_auto_increment();
207
void print_error(int error, myf errflag);
208
uint get_dup_key(int error);
209
void change_table_ptr(TABLE *table_arg) { table=table_arg; }
210
virtual double scan_time()
211
{ return ulonglong2double(data_file_length) / IO_SIZE + 1; }
212
virtual double read_time(ha_rows rows) { return rows; }
213
virtual bool fast_key_read() { return 0;}
214
virtual bool has_transactions(){ return 0;}
216
virtual int index_init(uint idx) { active_index=idx; return 0;}
217
virtual int index_end() {return 0; }
218
uint get_index(void) const { return active_index; }
219
virtual int open(const char *name, int mode, int test_if_locked)=0;
220
virtual void initialize(void) {}
221
virtual int close(void)=0;
222
virtual int write_row(byte * buf)=0;
223
virtual int update_row(const byte * old_data, byte * new_data)=0;
224
virtual int delete_row(const byte * buf)=0;
225
virtual int index_read(byte * buf, const byte * key,
226
uint key_len, enum ha_rkey_function find_flag)=0;
227
virtual int index_read_idx(byte * buf, uint index, const byte * key,
228
uint key_len, enum ha_rkey_function find_flag)=0;
229
virtual int index_next(byte * buf)=0;
230
virtual int index_prev(byte * buf)=0;
231
virtual int index_first(byte * buf)=0;
232
virtual int index_last(byte * buf)=0;
233
virtual int index_next_same(byte *buf, const byte *key, uint keylen);
234
virtual int ft_init(uint inx,const byte *key, uint keylen, bool presort)
236
virtual int ft_read(byte *buf) { return -1; }
237
virtual int ft_close() { return -1; }
238
virtual int rnd_init(bool scan=1)=0;
239
virtual int rnd_end() { return 0; }
240
virtual int rnd_next(byte *buf)=0;
241
virtual int rnd_pos(byte * buf, byte *pos)=0;
242
virtual int rnd_first(byte *buf);
243
virtual int restart_rnd_next(byte *buf, byte *pos);
244
virtual ha_rows records_in_range(int inx,
245
const byte *start_key,uint start_key_len,
246
enum ha_rkey_function start_search_flag,
247
const byte *end_key,uint end_key_len,
248
enum ha_rkey_function end_search_flag)
249
{ return (ha_rows) 10; }
250
virtual void position(const byte *record)=0;
251
virtual my_off_t row_position() { return HA_OFFSET_ERROR; }
252
virtual void info(uint)=0;
253
virtual int extra(enum ha_extra_function operation)=0;
254
virtual int reset()=0;
255
virtual int external_lock(THD *thd, int lock_type)=0;
256
virtual int delete_all_rows();
257
virtual longlong get_auto_increment();
258
virtual void update_create_info(HA_CREATE_INFO *create_info) {}
259
virtual int check(THD* thd, HA_CHECK_OPT* check_opt );
260
virtual int repair(THD* thd, HA_CHECK_OPT* check_opt);
261
virtual int optimize(THD* thd);
262
virtual int analyze(THD* thd);
263
virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; }
264
// not implemented by default
265
virtual int net_read_dump(NET* net)
266
{ return ER_DUMP_NOT_IMPLEMENTED; }
268
/* The following can be called without an open handler */
269
virtual const char *table_type() const =0;
270
virtual const char **bas_ext() const =0;
271
virtual ulong option_flag() const =0;
272
virtual uint max_record_length() const =0;
273
virtual uint max_keys() const =0;
274
virtual uint max_key_parts() const =0;
275
virtual uint max_key_length()const =0;
276
virtual uint min_record_length(uint options) const { return 1; }
277
virtual bool low_byte_first() const { return 1; }
279
virtual int rename_table(const char *from, const char *to);
280
virtual int delete_table(const char *name);
281
virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0;
282
virtual uint lock_count(void) const { return 1; }
283
virtual THR_LOCK_DATA **store_lock(THD *thd,
285
enum thr_lock_type lock_type)=0;
288
/* Some extern variables used with handlers */
290
extern const char *ha_row_type[];
291
extern TYPELIB ha_table_typelib;
293
handler *get_new_handler(TABLE *table, enum db_type db_type);
294
my_off_t ha_get_ptr(byte *ptr, uint pack_length);
295
void ha_store_ptr(byte *buff, uint pack_length, my_off_t pos);
297
int ha_panic(enum ha_panic_function flag);
298
enum db_type ha_checktype(enum db_type database_type);
299
int ha_create_table(const char *name, HA_CREATE_INFO *create_info,
300
bool update_create_info);
301
int ha_delete_table(enum db_type db_type, const char *path);
302
void ha_key_cache(void);
303
int ha_commit(THD *thd);
304
int ha_rollback(THD *thd);
305
int ha_autocommit_or_rollback(THD *thd, int error);
306
bool ha_flush_logs(void);