1
/* Copyright (C) 2000,2004 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 */
20
#ifdef USE_PRAGMA_INTERFACE
21
#pragma interface /* gcc class implementation */
24
#include <ft_global.h>
28
#define NO_HASH /* Not yet implemented */
31
#if defined(HAVE_BERKELEY_DB) || defined(HAVE_INNOBASE_DB) || \
32
defined(HAVE_NDBCLUSTER_DB)
33
#define USING_TRANSACTIONS
36
// the following is for checking tables
38
#define HA_ADMIN_ALREADY_DONE 1
40
#define HA_ADMIN_NOT_IMPLEMENTED -1
41
#define HA_ADMIN_FAILED -2
42
#define HA_ADMIN_CORRUPT -3
43
#define HA_ADMIN_INTERNAL_ERROR -4
44
#define HA_ADMIN_INVALID -5
45
#define HA_ADMIN_REJECT -6
46
#define HA_ADMIN_TRY_ALTER -7
47
#define HA_ADMIN_WRONG_CHECKSUM -8
48
#define HA_ADMIN_NOT_BASE_TABLE -9
49
#define HA_ADMIN_NEEDS_UPGRADE -10
50
#define HA_ADMIN_NEEDS_ALTER -11
51
#define HA_ADMIN_NEEDS_CHECK -12
53
/* Bits in table_flags() to show what database can do */
56
Can switch index during the scan with ::rnd_same() - not used yet.
57
see mi_rsame/heap_rsame/myrg_rsame
59
#define HA_READ_RND_SAME (1 << 0)
60
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
61
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
62
#define HA_REC_NOT_IN_SEQ (1 << 3) /* ha_info don't return recnumber;
63
It returns a position to ha_r_rnd */
64
#define HA_CAN_GEOMETRY (1 << 4)
66
Reading keys in random order is as fast as reading keys in sort order
67
(Used in records.cc to decide if we should use a record cache and by
68
filesort to decide if we should sort key + data or key + pointer-to-row
70
#define HA_FAST_KEY_READ (1 << 5)
71
#define HA_NULL_IN_KEY (1 << 7) /* One can have keys with NULL */
72
#define HA_DUPP_POS (1 << 8) /* ha_position() gives dup row */
73
#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
74
#define HA_CAN_INDEX_BLOBS (1 << 10)
75
#define HA_AUTO_PART_KEY (1 << 11) /* auto-increment in multi-part key */
76
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
77
#define HA_NOT_EXACT_COUNT (1 << 13)
79
INSERT_DELAYED only works with handlers that uses MySQL internal table
82
#define HA_CAN_INSERT_DELAYED (1 << 14)
83
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
84
#define HA_CAN_RTREEKEYS (1 << 17)
85
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
86
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
87
#define HA_CAN_FULLTEXT (1 << 21)
88
#define HA_CAN_SQL_HANDLER (1 << 22)
89
#define HA_NO_AUTO_INCREMENT (1 << 23)
90
#define HA_HAS_CHECKSUM (1 << 24)
91
/* Table data are stored in separate files (for lower_case_table_names) */
92
#define HA_FILE_BASED (1 << 26)
93
#define HA_NO_VARCHAR (1 << 27)
94
#define HA_CAN_BIT_FIELD (1 << 28) /* supports bit fields */
95
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
96
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
99
/* bits in index_flags(index_number) for what you can do with index */
100
#define HA_READ_NEXT 1 /* TODO really use this flag */
101
#define HA_READ_PREV 2 /* supports ::index_prev */
102
#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
103
#define HA_READ_RANGE 8 /* can find all records in a range */
104
#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
105
#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
108
Index scan will not return records in rowid order. Not guaranteed to be
109
set for unordered (e.g. HASH) indexes.
111
#define HA_KEY_SCAN_NOT_ROR 128
114
/* operations for disable/enable indexes */
115
#define HA_KEY_SWITCH_NONUNIQ 0
116
#define HA_KEY_SWITCH_ALL 1
117
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
118
#define HA_KEY_SWITCH_ALL_SAVE 3
121
Note: the following includes binlog and closing 0.
122
so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
123
example + csv + heap + blackhole + federated + 0
124
(yes, the sum is deliberately inaccurate)
129
Bits in index_ddl_flags(KEY *wanted_index)
130
for what ddl you can do with index
131
If none is set, the wanted type of index is not supported
132
by the handler at all. See WorkLog 1563.
134
#define HA_DDL_SUPPORT 1 /* Supported by handler */
135
#define HA_DDL_WITH_LOCK 2 /* Can create/drop with locked table */
136
#define HA_DDL_ONLINE 4 /* Can create/drop without lock */
139
Parameters for open() (in register form->filestat)
140
HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
143
#define HA_OPEN_KEYFILE 1
144
#define HA_OPEN_RNDFILE 2
145
#define HA_GET_INDEX 4
146
#define HA_GET_INFO 8 /* do a ha_info() after open */
147
#define HA_READ_ONLY 16 /* File opened as readonly */
148
/* Try readonly if can't open with read and write */
149
#define HA_TRY_READ_ONLY 32
150
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
151
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
152
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
153
#define HA_OPEN_TEMPORARY 512
155
/* Errors on write which is recoverable (Key exist) */
156
#define HA_WRITE_SKIP 121 /* Duplicate key on write */
157
#define HA_READ_CHECK 123 /* Update with is recoverable */
158
#define HA_CANT_DO_THAT 131 /* Databasehandler can't do it */
160
/* Some key definitions */
161
#define HA_KEY_NULL_LENGTH 1
162
#define HA_KEY_BLOB_LENGTH 2
164
#define HA_LEX_CREATE_TMP_TABLE 1
165
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
166
#define HA_OPTION_NO_CHECKSUM (1L << 17)
167
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
168
#define HA_MAX_REC_LENGTH 65535
170
/* Table caching type */
171
#define HA_CACHE_TBL_NONTRANSACT 0
172
#define HA_CACHE_TBL_NOCACHE 1
173
#define HA_CACHE_TBL_ASKTRANSACT 2
174
#define HA_CACHE_TBL_TRANSACT 4
176
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
177
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
181
DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
182
DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
183
DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
184
DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
185
DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
186
DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
187
DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
188
DB_TYPE_FEDERATED_DB,
189
DB_TYPE_BLACKHOLE_DB,
190
DB_TYPE_DEFAULT // Must be last
193
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
194
ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
195
ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT };
197
/* struct to hold information about the table that should be created */
199
/* Bits in used_fields */
200
#define HA_CREATE_USED_AUTO (1L << 0)
201
#define HA_CREATE_USED_RAID (1L << 1)
202
#define HA_CREATE_USED_UNION (1L << 2)
203
#define HA_CREATE_USED_INSERT_METHOD (1L << 3)
204
#define HA_CREATE_USED_MIN_ROWS (1L << 4)
205
#define HA_CREATE_USED_MAX_ROWS (1L << 5)
206
#define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
207
#define HA_CREATE_USED_PACK_KEYS (1L << 7)
208
#define HA_CREATE_USED_CHARSET (1L << 8)
209
#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
210
#define HA_CREATE_USED_DATADIR (1L << 10)
211
#define HA_CREATE_USED_INDEXDIR (1L << 11)
212
#define HA_CREATE_USED_ENGINE (1L << 12)
213
#define HA_CREATE_USED_CHECKSUM (1L << 13)
214
#define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
215
#define HA_CREATE_USED_ROW_FORMAT (1L << 15)
216
#define HA_CREATE_USED_COMMENT (1L << 16)
217
#define HA_CREATE_USED_PASSWORD (1L << 17)
218
#define HA_CREATE_USED_CONNECTION (1L << 18)
220
typedef ulonglong my_xid; // this line is the same as in log_event.h
221
#define MYSQL_XID_PREFIX "MySQLXid"
222
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
223
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
224
#define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
226
#define XIDDATASIZE 128
227
#define MAXGTRIDSIZE 64
228
#define MAXBQUALSIZE 64
234
char data[XIDDATASIZE]; // not \0-terminated !
236
xid_t() {} /* Remove gcc warning */
237
bool eq(struct xid_t *xid)
238
{ return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
239
bool eq(long g, long b, const char *d)
240
{ return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
241
void set(struct xid_t *xid)
242
{ memcpy(this, xid, xid->length()); }
243
void set(long f, const char *g, long gl, const char *b, long bl)
246
memcpy(data, g, gtrid_length= gl);
247
memcpy(data+gl, b, bqual_length= bl);
249
void set(ulonglong xid)
253
set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
254
memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
256
memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
257
gtrid_length=MYSQL_XID_GTRID_LEN;
259
void set(long g, long b, const char *d)
264
memcpy(data, d, g+b);
266
bool is_null() { return formatID == -1; }
267
void null() { formatID= -1; }
268
my_xid quick_get_my_xid()
271
memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
276
return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 &&
277
!memcmp(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
278
!memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
279
quick_get_my_xid() : 0;
283
return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
284
gtrid_length+bqual_length;
288
return (byte *)>rid_length;
292
return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
295
typedef struct xid_t XID;
297
/* for recover() handlerton call */
298
#define MIN_XID_LIST_SIZE 128
300
#define MAX_XID_LIST_SIZE 256
302
#define MAX_XID_LIST_SIZE (1024*128)
306
handlerton is a singleton structure - one instance per storage engine -
307
to provide access to storage engine functionality that works on the
308
"global" level (unlike handler class that works on a per-table basis)
310
usually handlerton instance is defined statically in ha_xxx.cc as
312
static handlerton { ... } xxx_hton;
314
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
319
storage engine name as it should be printed to a user
324
Historical marker for if the engine is available of not
326
SHOW_COMP_OPTION state;
329
A comment used by SHOW to describe an engine.
334
Historical number used for frm file to determine the correct storage engine.
335
This is going away and new engines will just use "name" for this.
337
enum db_type db_type;
339
Method that initizlizes a storage engine
344
each storage engine has it's own memory area (actually a pointer)
345
in the thd, for storing per-connection information.
348
thd->ha_data[xxx_hton.slot]
350
slot number is initialized by MySQL after xxx_init() is called.
354
to store per-savepoint data storage engine is provided with an area
355
of a requested size (0 is ok here).
356
savepoint_offset must be initialized statically to the size of
357
the needed memory to store per-savepoint information.
358
After xxx_init it is changed to be an offset to savepoint storage
359
area and need not be used by storage engine.
360
see binlog_hton and binlog_savepoint_set/rollback for an example.
362
uint savepoint_offset;
366
close_connection is only called if
367
thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
368
this storage area - set it to something, so that MySQL would know
369
this storage engine was accessed in this connection
371
int (*close_connection)(THD *thd);
373
sv points to an uninitialized storage area of requested size
374
(see savepoint_offset description)
376
int (*savepoint_set)(THD *thd, void *sv);
378
sv points to a storage area, that was earlier passed
379
to the savepoint_set call
381
int (*savepoint_rollback)(THD *thd, void *sv);
382
int (*savepoint_release)(THD *thd, void *sv);
384
'all' is true if it's a real commit, that makes persistent changes
385
'all' is false if it's not in fact a commit but an end of the
386
statement that is part of the transaction.
387
NOTE 'all' is also false in auto-commit mode where 'end of statement'
388
and 'real commit' mean the same event.
390
int (*commit)(THD *thd, bool all);
391
int (*rollback)(THD *thd, bool all);
392
int (*prepare)(THD *thd, bool all);
393
int (*recover)(XID *xid_list, uint len);
394
int (*commit_by_xid)(XID *xid);
395
int (*rollback_by_xid)(XID *xid);
396
void *(*create_cursor_read_view)();
397
void (*set_cursor_read_view)(void *);
398
void (*close_cursor_read_view)(void *);
399
uint32 flags; /* global handler flags */
402
struct show_table_alias_st {
407
/* Possible flags of a handlerton */
408
#define HTON_NO_FLAGS 0
409
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
410
#define HTON_ALTER_NOT_SUPPORTED (1 << 1) //Engine does not support alter
411
#define HTON_CAN_RECREATE (1 << 2) //Delete all is used fro truncate
412
#define HTON_HIDDEN (1 << 3) //Engine does not appear in lists
414
typedef struct st_thd_trans
416
/* number of entries in the ht[] */
418
/* true is not all entries in the ht[] support 2pc */
420
/* storage engines that registered themselves for this transaction */
421
handlerton *ht[MAX_HA];
424
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
425
ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
427
typedef struct st_ha_create_information
429
CHARSET_INFO *table_charset, *default_table_charset;
430
LEX_STRING connect_string;
432
const char *password;
433
const char *data_file_name, *index_file_name;
435
ulonglong max_rows,min_rows;
436
ulonglong auto_increment_value;
438
ulong avg_row_length;
439
ulong raid_chunksize;
442
enum db_type db_type;
443
enum row_type row_type;
444
uint null_bits; /* NULL bits at start of record */
445
uint options; /* OR of HA_CREATE_ options */
446
uint raid_type,raid_chunks;
447
uint merge_insert_method;
448
uint extra_size; /* length of extra data segment */
449
bool table_existed; /* 1 in create if table existed */
450
bool frm_only; /* 1 if no ha_create_table() */
451
bool varchar; /* 1 if table has a VARCHAR */
455
/* The handler for a table type. Will be included in the TABLE structure */
458
typedef struct st_table TABLE;
459
struct st_foreign_key_info;
460
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
462
typedef struct st_savepoint SAVEPOINT;
463
extern ulong savepoint_alloc_size;
465
/* Forward declaration for condition pushdown to storage engine */
466
typedef class Item COND;
468
typedef struct st_ha_check_opt
470
st_ha_check_opt() {} /* Remove gcc warning */
471
ulong sort_buffer_size;
472
uint flags; /* isam layer flags (e.g. for myisamchk) */
473
uint sql_flags; /* sql layer flags - for something myisamchk cannot do */
474
KEY_CACHE *key_cache; /* new key cache when changing key cache */
480
This is a buffer area that the handler can use to store rows.
481
'end_of_used_area' should be kept updated after calls to
482
read-functions so that other parts of the code can use the
483
remaining area (until next read calls is issued).
486
typedef struct st_handler_buffer
488
const byte *buffer; /* Buffer one can start using */
489
const byte *buffer_end; /* End of buffer */
490
byte *end_of_used_area; /* End of area that was used by handler */
494
class handler :public Sql_alloc
497
struct st_table *table; /* The table definition */
499
virtual int index_init(uint idx) { active_index=idx; return 0; }
500
virtual int index_end() { active_index=MAX_KEY; return 0; }
502
rnd_init() can be called two times without rnd_end() in between
503
(it only makes sense if scan=1).
504
then the second call should prepare for the new table scan (e.g
505
if rnd_init allocates the cursor, second call should position it
506
to the start of the table, no need to deallocate and allocate it again
508
virtual int rnd_init(bool scan) =0;
509
virtual int rnd_end() { return 0; }
512
const handlerton *ht; /* storage engine of this handler */
513
byte *ref; /* Pointer to current row */
514
byte *dupp_ref; /* Pointer to dupp row */
515
ulonglong data_file_length; /* Length off data file */
516
ulonglong max_data_file_length; /* Length off data file */
517
ulonglong index_file_length;
518
ulonglong max_index_file_length;
519
ulonglong delete_length; /* Free bytes */
520
ulonglong auto_increment_value;
521
ha_rows records; /* Records in table */
522
ha_rows deleted; /* Deleted records */
523
ulong raid_chunksize;
524
ulong mean_rec_length; /* physical reclength */
525
time_t create_time; /* When table was created */
529
/* The following are for read_multi_range */
530
bool multi_range_sorted;
531
KEY_MULTI_RANGE *multi_range_curr;
532
KEY_MULTI_RANGE *multi_range_end;
533
HANDLER_BUFFER *multi_range_buffer;
535
/* The following are for read_range() */
536
key_range save_end_range, *end_range;
537
KEY_PART_INFO *range_key_part;
538
int key_compare_result_on_equal;
541
uint errkey; /* Last dup key */
542
uint sortkey, key_used_on_scan;
544
/* Length of ref (1-8 or the clustered key length) */
546
uint block_size; /* index block size */
547
uint raid_type,raid_chunks;
549
enum {NONE=0, INDEX, RND} inited;
550
bool auto_increment_column_changed;
551
bool implicit_emptied; /* Can be !=0 only if HEAP */
552
const COND *pushed_cond;
554
handler(const handlerton *ht_arg, TABLE *table_arg) :table(table_arg),
556
ref(0), data_file_length(0), max_data_file_length(0), index_file_length(0),
557
delete_length(0), auto_increment_value(0),
558
records(0), deleted(0), mean_rec_length(0),
559
create_time(0), check_time(0), update_time(0),
560
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
561
ref_length(sizeof(my_off_t)), block_size(0),
562
raid_type(0), ft_handler(0), inited(NONE), implicit_emptied(0),
565
virtual ~handler(void) { /* TODO: DBUG_ASSERT(inited == NONE); */ }
566
virtual handler *clone(MEM_ROOT *mem_root);
567
int ha_open(const char *name, int mode, int test_if_locked);
568
void adjust_next_insert_id_after_explicit_value(ulonglong nr);
569
int update_auto_increment();
570
virtual void print_error(int error, myf errflag);
571
virtual bool get_error_message(int error, String *buf);
572
uint get_dup_key(int error);
573
void change_table_ptr(TABLE *table_arg) { table=table_arg; }
574
virtual double scan_time()
575
{ return ulonglong2double(data_file_length) / IO_SIZE + 2; }
576
virtual double read_time(uint index, uint ranges, ha_rows rows)
577
{ return rows2double(ranges+rows); }
578
virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
579
virtual bool has_transactions(){ return 0;}
580
virtual uint extra_rec_buf_length() { return 0; }
583
Return upper bound of current number of records in the table
584
(max. of how many records one will retrieve when doing a full table scan)
585
If upper bound is not known, HA_POS_ERROR should be returned as a max
586
possible upper bound.
588
virtual ha_rows estimate_rows_upper_bound()
589
{ return records+EXTRA_RECORDS; }
592
Get the row type from the storage engine. If this method returns
593
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
595
virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
597
virtual const char *index_type(uint key_number) { DBUG_ASSERT(0); return "";}
599
int ha_index_init(uint idx)
601
DBUG_ENTER("ha_index_init");
602
DBUG_ASSERT(inited==NONE);
604
DBUG_RETURN(index_init(idx));
608
DBUG_ENTER("ha_index_end");
609
DBUG_ASSERT(inited==INDEX);
611
DBUG_RETURN(index_end());
613
int ha_rnd_init(bool scan)
615
DBUG_ENTER("ha_rnd_init");
616
DBUG_ASSERT(inited==NONE || (inited==RND && scan));
618
DBUG_RETURN(rnd_init(scan));
622
DBUG_ENTER("ha_rnd_end");
623
DBUG_ASSERT(inited==RND);
625
DBUG_RETURN(rnd_end());
627
/* this is necessary in many places, e.g. in HANDLER command */
628
int ha_index_or_rnd_end()
630
return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
632
uint get_index(void) const { return active_index; }
633
virtual int open(const char *name, int mode, uint test_if_locked)=0;
634
virtual int close(void)=0;
635
virtual int write_row(byte * buf) { return HA_ERR_WRONG_COMMAND; }
636
virtual int update_row(const byte * old_data, byte * new_data)
637
{ return HA_ERR_WRONG_COMMAND; }
638
virtual int delete_row(const byte * buf)
639
{ return HA_ERR_WRONG_COMMAND; }
640
virtual int index_read(byte * buf, const byte * key,
641
uint key_len, enum ha_rkey_function find_flag)
642
{ return HA_ERR_WRONG_COMMAND; }
643
virtual int index_read_idx(byte * buf, uint index, const byte * key,
644
uint key_len, enum ha_rkey_function find_flag);
645
virtual int index_next(byte * buf)
646
{ return HA_ERR_WRONG_COMMAND; }
647
virtual int index_prev(byte * buf)
648
{ return HA_ERR_WRONG_COMMAND; }
649
virtual int index_first(byte * buf)
650
{ return HA_ERR_WRONG_COMMAND; }
651
virtual int index_last(byte * buf)
652
{ return HA_ERR_WRONG_COMMAND; }
653
virtual int index_next_same(byte *buf, const byte *key, uint keylen);
654
virtual int index_read_last(byte * buf, const byte * key, uint key_len)
655
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
656
virtual int read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
657
KEY_MULTI_RANGE *ranges, uint range_count,
658
bool sorted, HANDLER_BUFFER *buffer);
659
virtual int read_multi_range_next(KEY_MULTI_RANGE **found_range_p);
660
virtual int read_range_first(const key_range *start_key,
661
const key_range *end_key,
662
bool eq_range, bool sorted);
663
virtual int read_range_next();
664
int compare_key(key_range *range);
665
virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
666
void ft_end() { ft_handler=NULL; }
667
virtual FT_INFO *ft_init_ext(uint flags, uint inx,String *key)
669
virtual int ft_read(byte *buf) { return HA_ERR_WRONG_COMMAND; }
670
virtual int rnd_next(byte *buf)=0;
671
virtual int rnd_pos(byte * buf, byte *pos)=0;
672
virtual int read_first_row(byte *buf, uint primary_key);
674
The following function is only needed for tables that may be temporary
677
virtual int restart_rnd_next(byte *buf, byte *pos)
678
{ return HA_ERR_WRONG_COMMAND; }
679
virtual int rnd_same(byte *buf, uint inx)
680
{ return HA_ERR_WRONG_COMMAND; }
681
virtual ha_rows records_in_range(uint inx, key_range *min_key,
683
{ return (ha_rows) 10; }
684
virtual void position(const byte *record)=0;
685
virtual int info(uint)=0; // see my_base.h for full description
686
virtual int extra(enum ha_extra_function operation)
688
virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
689
{ return extra(operation); }
690
virtual int reset() { return extra(HA_EXTRA_RESET); }
691
virtual int external_lock(THD *thd, int lock_type) { return 0; }
692
virtual void unlock_row() {}
693
virtual int start_stmt(THD *thd, thr_lock_type lock_type) {return 0;}
695
This is called to delete all rows in a table
696
If the handler don't support this, then this function will
697
return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
700
virtual int delete_all_rows()
701
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
702
virtual ulonglong get_auto_increment();
703
virtual void restore_auto_increment();
706
Reset the auto-increment counter to the given value, i.e. the next row
707
inserted will get the given value. This is called e.g. after TRUNCATE
708
is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
709
returned by storage engines that don't support this operation.
711
virtual int reset_auto_increment(ulonglong value)
712
{ return HA_ERR_WRONG_COMMAND; }
714
virtual void update_create_info(HA_CREATE_INFO *create_info) {}
716
/* to be implemented in handlers */
718
/* admin commands - called from mysql_admin_table */
719
virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
720
{ return HA_ADMIN_NOT_IMPLEMENTED; }
723
in these two methods check_opt can be modified
724
to specify CHECK option to use to call check()
727
virtual int check_for_upgrade(HA_CHECK_OPT *check_opt)
730
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
731
int check_old_types();
732
/* to be actually called to get 'check()' functionality*/
733
int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
735
virtual int backup(THD* thd, HA_CHECK_OPT* check_opt)
736
{ return HA_ADMIN_NOT_IMPLEMENTED; }
738
restore assumes .frm file must exist, and that generate_table() has been
739
called; It will just copy the data file and run repair.
741
virtual int restore(THD* thd, HA_CHECK_OPT* check_opt)
742
{ return HA_ADMIN_NOT_IMPLEMENTED; }
744
virtual int repair(THD* thd, HA_CHECK_OPT* check_opt)
745
{ return HA_ADMIN_NOT_IMPLEMENTED; }
747
int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
748
virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt)
749
{ return HA_ADMIN_NOT_IMPLEMENTED; }
750
virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt)
751
{ return HA_ADMIN_NOT_IMPLEMENTED; }
752
virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt)
753
{ return HA_ADMIN_NOT_IMPLEMENTED; }
754
virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt)
755
{ return HA_ADMIN_NOT_IMPLEMENTED; }
756
/* end of the list of admin commands */
758
virtual bool check_and_repair(THD *thd) { return HA_ERR_WRONG_COMMAND; }
759
virtual int dump(THD* thd, int fd = -1) { return HA_ERR_WRONG_COMMAND; }
760
virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
761
virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
762
virtual int indexes_are_disabled(void) {return 0;}
763
virtual void start_bulk_insert(ha_rows rows) {}
764
virtual int end_bulk_insert() {return 0; }
765
virtual int discard_or_import_tablespace(my_bool discard)
766
{return HA_ERR_WRONG_COMMAND;}
767
virtual int net_read_dump(NET* net) { return HA_ERR_WRONG_COMMAND; }
768
virtual char *update_table_comment(const char * comment)
769
{ return (char*) comment;}
770
virtual void append_create_info(String *packet) {}
771
virtual char* get_foreign_key_create_info()
772
{ return(NULL);} /* gets foreign key create string from InnoDB */
773
/* used in ALTER TABLE; 1 if changing storage engine is allowed */
774
virtual bool can_switch_engines() { return 1; }
775
/* used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
776
virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
778
virtual uint referenced_by_foreign_key() { return 0;}
779
virtual void init_table_handle_for_HANDLER()
780
{ return; } /* prepare InnoDB for HANDLER */
781
virtual void free_foreign_key_create_info(char* str) {}
782
/* The following can be called without an open handler */
783
virtual const char *table_type() const =0;
784
virtual const char **bas_ext() const =0;
785
virtual ulong table_flags(void) const =0;
786
virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
787
virtual ulong index_ddl_flags(KEY *wanted_index) const
788
{ return (HA_DDL_SUPPORT); }
789
virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
790
{ return (HA_ERR_WRONG_COMMAND); }
791
virtual int drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys)
792
{ return (HA_ERR_WRONG_COMMAND); }
794
uint max_record_length() const
795
{ return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
796
uint max_keys() const
797
{ return min(MAX_KEY, max_supported_keys()); }
798
uint max_key_parts() const
799
{ return min(MAX_REF_PARTS, max_supported_key_parts()); }
800
uint max_key_length() const
801
{ return min(MAX_KEY_LENGTH, max_supported_key_length()); }
802
uint max_key_part_length() const
803
{ return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
805
virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
806
virtual uint max_supported_keys() const { return 0; }
807
virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; }
808
virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; }
809
virtual uint max_supported_key_part_length() const { return 255; }
810
virtual uint min_record_length(uint options) const { return 1; }
812
virtual bool low_byte_first() const { return 1; }
813
virtual uint checksum() const { return 0; }
814
virtual bool is_crashed() const { return 0; }
815
virtual bool auto_repair() const { return 0; }
818
default rename_table() and delete_table() rename/delete files with a
819
given name and extensions from bas_ext()
821
virtual int rename_table(const char *from, const char *to);
822
virtual int delete_table(const char *name);
824
virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0;
826
/* lock_count() can be more than one if the table is a MERGE */
827
virtual uint lock_count(void) const { return 1; }
828
virtual THR_LOCK_DATA **store_lock(THD *thd,
830
enum thr_lock_type lock_type)=0;
832
/* Type of table for caching query */
833
virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
834
/* ask handler about permission to cache table when query is to be cached */
835
virtual my_bool register_query_cache_table(THD *thd, char *table_key,
839
ulonglong *engine_data)
846
true Primary key (if there is one) is clustered key covering all fields
849
virtual bool primary_key_is_clustered() { return FALSE; }
851
virtual int cmp_ref(const byte *ref1, const byte *ref2)
853
return memcmp(ref1, ref2, ref_length);
857
Condition pushdown to storage engines
861
Push condition down to the table handler.
864
cond Condition to be pushed. The condition tree must not be
865
modified by the by the caller.
867
The 'remainder' condition that caller must use to filter out records.
868
NULL means the handler will not return rows that do not match the
871
The pushed conditions form a stack (from which one can remove the
872
last pushed condition using cond_pop).
873
The table handler filters out rows using (pushed_cond1 AND pushed_cond2
874
AND ... AND pushed_condN)
875
or less restrictive condition, depending on handler's capabilities.
877
handler->extra(HA_EXTRA_RESET) call empties the condition stack.
878
Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
881
virtual const COND *cond_push(const COND *cond) { return cond; };
883
Pop the top condition from the condition stack of the handler instance.
886
Pops the top if condition stack, if stack is not empty
888
virtual void cond_pop() { return; };
891
/* Some extern variables used with handlers */
893
extern handlerton *sys_table_types[];
894
extern const char *ha_row_type[];
895
extern TYPELIB tx_isolation_typelib;
896
extern TYPELIB myisam_stats_method_typelib;
897
extern ulong total_ha, total_ha_2pc;
899
/* Wrapper functions */
900
#define ha_commit_stmt(thd) (ha_commit_trans((thd), FALSE))
901
#define ha_rollback_stmt(thd) (ha_rollback_trans((thd), FALSE))
902
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
903
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
906
enum db_type ha_resolve_by_name(const char *name, uint namelen);
907
const char *ha_get_storage_engine(enum db_type db_type);
908
handler *get_new_handler(TABLE *table, MEM_ROOT *alloc, enum db_type db_type);
909
enum db_type ha_checktype(THD *thd, enum db_type database_type,
910
bool no_substitute, bool report_error);
911
bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag);
915
TYPELIB *ha_known_exts(void);
916
int ha_panic(enum ha_panic_function flag);
917
int ha_update_statistics();
918
void ha_close_connection(THD* thd);
919
my_bool ha_storage_engine_is_enabled(enum db_type database_type);
920
bool ha_flush_logs(void);
921
void ha_drop_database(char* path);
922
int ha_create_table(const char *name, HA_CREATE_INFO *create_info,
923
bool update_create_info);
924
int ha_delete_table(THD *thd, enum db_type db_type, const char *path,
925
const char *alias, bool generate_warning);
928
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
929
int ha_discover(THD* thd, const char* dbname, const char* name,
930
const void** frmblob, uint* frmlen);
931
int ha_find_files(THD *thd,const char *db,const char *path,
932
const char *wild, bool dir,List<char>* files);
933
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
936
int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
937
int ha_resize_key_cache(KEY_CACHE *key_cache);
938
int ha_change_key_cache_param(KEY_CACHE *key_cache);
939
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
940
int ha_end_key_cache(KEY_CACHE *key_cache);
942
/* report to InnoDB that control passes to the client */
943
int ha_release_temporary_latches(THD *thd);
945
/* transactions: interface to handlerton functions */
946
int ha_start_consistent_snapshot(THD *thd);
947
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
948
int ha_commit_one_phase(THD *thd, bool all);
949
int ha_rollback_trans(THD *thd, bool all);
950
int ha_prepare(THD *thd);
951
int ha_recover(HASH *commit_list);
953
/* transactions: these functions never call handlerton functions directly */
954
int ha_commit_trans(THD *thd, bool all);
955
int ha_autocommit_or_rollback(THD *thd, int error);
956
int ha_enable_transaction(THD *thd, bool on);
959
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
960
int ha_savepoint(THD *thd, SAVEPOINT *sv);
961
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
963
/* these are called by storage engines */
964
void trans_register_ha(THD *thd, bool all, handlerton *ht);
967
Storage engine has to assume the transaction will end up with 2pc if
968
- there is more than one 2pc-capable storage engine available
969
- in the current transaction 2pc was not disabled yet
971
#define trans_need_2pc(thd, all) ((total_ha_2pc > 1) && \
972
!((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))