1
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
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 */
17
/* Definitions for parameters to do with handler-routines */
19
#ifdef USE_PRAGMA_INTERFACE
20
#pragma interface /* gcc class implementation */
23
#include <my_handler.h>
24
#include <ft_global.h>
28
#define NO_HASH /* Not yet implemented */
31
#define USING_TRANSACTIONS
33
// the following is for checking tables
35
#define HA_ADMIN_ALREADY_DONE 1
37
#define HA_ADMIN_NOT_IMPLEMENTED -1
38
#define HA_ADMIN_FAILED -2
39
#define HA_ADMIN_CORRUPT -3
40
#define HA_ADMIN_INTERNAL_ERROR -4
41
#define HA_ADMIN_INVALID -5
42
#define HA_ADMIN_REJECT -6
43
#define HA_ADMIN_TRY_ALTER -7
44
#define HA_ADMIN_WRONG_CHECKSUM -8
45
#define HA_ADMIN_NOT_BASE_TABLE -9
46
#define HA_ADMIN_NEEDS_UPGRADE -10
47
#define HA_ADMIN_NEEDS_ALTER -11
48
#define HA_ADMIN_NEEDS_CHECK -12
50
/* Bits in table_flags() to show what database can do */
52
#define HA_NO_TRANSACTIONS (1 << 0) /* Doesn't support transactions */
53
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
54
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
56
The following should be set if the following is not true when scanning
57
a table with rnd_next()
58
- We will see all rows (including deleted ones)
59
- Row positions are 'table->s->db_record_offset' apart
60
If this flag is not set, filesort will do a postion() call for each matched
61
row to be able to find the row later.
63
#define HA_REC_NOT_IN_SEQ (1 << 3)
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)
72
Set the following flag if we on delete should force all key to be read
73
and on update read all keys that changes
75
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
76
#define HA_NULL_IN_KEY (1 << 7) /* One can have keys with NULL */
77
#define HA_DUPLICATE_POS (1 << 8) /* ha_position() gives dup row */
78
#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
79
#define HA_CAN_INDEX_BLOBS (1 << 10)
80
#define HA_AUTO_PART_KEY (1 << 11) /* auto-increment in multi-part key */
81
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
82
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
84
INSERT_DELAYED only works with handlers that uses MySQL internal table
87
#define HA_CAN_INSERT_DELAYED (1 << 14)
89
If we get the primary key columns for free when we do an index read
90
It also implies that we have to retrive the primary key when using
91
position() and rnd_pos().
93
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
95
If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
96
uses a primary key. Without primary key, we can't call position().
98
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16)
99
#define HA_CAN_RTREEKEYS (1 << 17)
100
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
102
The following is we need to a primary key to delete (and update) a row.
103
If there is no primary key, all columns needs to be read on update and delete
105
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
106
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
107
#define HA_CAN_FULLTEXT (1 << 21)
108
#define HA_CAN_SQL_HANDLER (1 << 22)
109
#define HA_NO_AUTO_INCREMENT (1 << 23)
110
#define HA_HAS_CHECKSUM (1 << 24)
111
/* Table data are stored in separate files (for lower_case_table_names) */
112
#define HA_FILE_BASED (1 << 26)
113
#define HA_NO_VARCHAR (1 << 27)
114
#define HA_CAN_BIT_FIELD (1 << 28) /* supports bit fields */
115
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
116
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
117
#define HA_NO_COPY_ON_ALTER (LL(1) << 31)
118
#define HA_HAS_RECORDS (LL(1) << 32) /* records() gives exact count*/
119
/* Has it's own method of binlog logging */
120
#define HA_HAS_OWN_BINLOGGING (LL(1) << 33)
122
Engine is capable of row-format and statement-format logging,
125
#define HA_BINLOG_ROW_CAPABLE (LL(1) << 34)
126
#define HA_BINLOG_STMT_CAPABLE (LL(1) << 35)
129
Set of all binlog flags. Currently only contain the capabilities
132
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
134
/* bits in index_flags(index_number) for what you can do with index */
135
#define HA_READ_NEXT 1 /* TODO really use this flag */
136
#define HA_READ_PREV 2 /* supports ::index_prev */
137
#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
138
#define HA_READ_RANGE 8 /* can find all records in a range */
139
#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
140
#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
143
bits in alter_table_flags:
146
These bits are set if different kinds of indexes can be created
147
off-line without re-create of the table (but with a table lock).
149
#define HA_ONLINE_ADD_INDEX_NO_WRITES (1L << 0) /*add index w/lock*/
150
#define HA_ONLINE_DROP_INDEX_NO_WRITES (1L << 1) /*drop index w/lock*/
151
#define HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES (1L << 2) /*add unique w/lock*/
152
#define HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES (1L << 3) /*drop uniq. w/lock*/
153
#define HA_ONLINE_ADD_PK_INDEX_NO_WRITES (1L << 4) /*add prim. w/lock*/
154
#define HA_ONLINE_DROP_PK_INDEX_NO_WRITES (1L << 5) /*drop prim. w/lock*/
156
These are set if different kinds of indexes can be created on-line
157
(without a table lock). If a handler is capable of one or more of
158
these, it should also set the corresponding *_NO_WRITES bit(s).
160
#define HA_ONLINE_ADD_INDEX (1L << 6) /*add index online*/
161
#define HA_ONLINE_DROP_INDEX (1L << 7) /*drop index online*/
162
#define HA_ONLINE_ADD_UNIQUE_INDEX (1L << 8) /*add unique online*/
163
#define HA_ONLINE_DROP_UNIQUE_INDEX (1L << 9) /*drop uniq. online*/
164
#define HA_ONLINE_ADD_PK_INDEX (1L << 10)/*add prim. online*/
165
#define HA_ONLINE_DROP_PK_INDEX (1L << 11)/*drop prim. online*/
167
HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
169
HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
170
exists but they are not necessarily done online.
172
HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
173
the new partition and to the old partitions when updating through the
174
old partitioning schema while performing a change of the partitioning.
175
This means that we can support updating of the table while performing
176
the copy phase of the change. For no lock at all also a double write
177
from new to old must exist and this is not required when this flag is
179
This is actually removed even before it was introduced the first time.
180
The new idea is that handlers will handle the lock level already in
181
store_lock for ALTER TABLE partitions.
183
HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
184
care of changing the partitions online and in one phase. Thus all phases
185
needed to handle the change are implemented inside the storage engine.
186
The storage engine must also support auto-discovery since the frm file
187
is changed as part of the change and this change must be controlled by
188
the storage engine. A typical engine to support this is NDB (through
191
#define HA_PARTITION_FUNCTION_SUPPORTED (1L << 12)
192
#define HA_FAST_CHANGE_PARTITION (1L << 13)
193
#define HA_PARTITION_ONE_PHASE (1L << 14)
196
Index scan will not return records in rowid order. Not guaranteed to be
197
set for unordered (e.g. HASH) indexes.
199
#define HA_KEY_SCAN_NOT_ROR 128
201
/* operations for disable/enable indexes */
202
#define HA_KEY_SWITCH_NONUNIQ 0
203
#define HA_KEY_SWITCH_ALL 1
204
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
205
#define HA_KEY_SWITCH_ALL_SAVE 3
208
Note: the following includes binlog and closing 0.
209
so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
210
example + csv + heap + blackhole + federated + 0
211
(yes, the sum is deliberately inaccurate)
212
TODO remove the limit, use dynarrays
217
Parameters for open() (in register form->filestat)
218
HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
221
#define HA_OPEN_KEYFILE 1
222
#define HA_OPEN_RNDFILE 2
223
#define HA_GET_INDEX 4
224
#define HA_GET_INFO 8 /* do a ha_info() after open */
225
#define HA_READ_ONLY 16 /* File opened as readonly */
226
/* Try readonly if can't open with read and write */
227
#define HA_TRY_READ_ONLY 32
228
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
229
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
230
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
231
#define HA_OPEN_TEMPORARY 512
233
/* Some key definitions */
234
#define HA_KEY_NULL_LENGTH 1
235
#define HA_KEY_BLOB_LENGTH 2
237
#define HA_LEX_CREATE_TMP_TABLE 1
238
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
239
#define HA_LEX_CREATE_TABLE_LIKE 4
240
#define HA_OPTION_NO_CHECKSUM (1L << 17)
241
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
242
#define HA_MAX_REC_LENGTH 65535
244
/* Table caching type */
245
#define HA_CACHE_TBL_NONTRANSACT 0
246
#define HA_CACHE_TBL_NOCACHE 1
247
#define HA_CACHE_TBL_ASKTRANSACT 2
248
#define HA_CACHE_TBL_TRANSACT 4
250
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
251
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
253
/* Flags for method is_fatal_error */
254
#define HA_CHECK_DUP_KEY 1
255
#define HA_CHECK_DUP_UNIQUE 2
256
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
260
DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
261
DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
262
DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
263
DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
264
DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
265
DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
266
DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
267
DB_TYPE_FEDERATED_DB,
268
DB_TYPE_BLACKHOLE_DB,
269
DB_TYPE_PARTITION_DB,
273
DB_TYPE_TABLE_FUNCTION,
277
DB_TYPE_FIRST_DYNAMIC=42,
278
DB_TYPE_DEFAULT=127 // Must be last
281
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
282
ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
283
ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
284
/** Unused. Reserved for future versions. */
287
enum enum_binlog_func {
292
BFN_BINLOG_PURGE_FILE= 5
295
enum enum_binlog_command {
305
/* struct to hold information about the table that should be created */
307
/* Bits in used_fields */
308
#define HA_CREATE_USED_AUTO (1L << 0)
309
#define HA_CREATE_USED_RAID (1L << 1) //RAID is no longer availble
310
#define HA_CREATE_USED_UNION (1L << 2)
311
#define HA_CREATE_USED_INSERT_METHOD (1L << 3)
312
#define HA_CREATE_USED_MIN_ROWS (1L << 4)
313
#define HA_CREATE_USED_MAX_ROWS (1L << 5)
314
#define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
315
#define HA_CREATE_USED_PACK_KEYS (1L << 7)
316
#define HA_CREATE_USED_CHARSET (1L << 8)
317
#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
318
#define HA_CREATE_USED_DATADIR (1L << 10)
319
#define HA_CREATE_USED_INDEXDIR (1L << 11)
320
#define HA_CREATE_USED_ENGINE (1L << 12)
321
#define HA_CREATE_USED_CHECKSUM (1L << 13)
322
#define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
323
#define HA_CREATE_USED_ROW_FORMAT (1L << 15)
324
#define HA_CREATE_USED_COMMENT (1L << 16)
325
#define HA_CREATE_USED_PASSWORD (1L << 17)
326
#define HA_CREATE_USED_CONNECTION (1L << 18)
327
#define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19)
328
/** Unused. Reserved for future versions. */
329
#define HA_CREATE_USED_TRANSACTIONAL (1L << 20)
330
/** Unused. Reserved for future versions. */
331
#define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21)
333
typedef ulonglong my_xid; // this line is the same as in log_event.h
334
#define MYSQL_XID_PREFIX "MySQLXid"
335
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
336
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
337
#define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
339
#define XIDDATASIZE MYSQL_XIDDATASIZE
340
#define MAXGTRIDSIZE 64
341
#define MAXBQUALSIZE 64
343
#define COMPATIBLE_DATA_YES 0
344
#define COMPATIBLE_DATA_NO 1
347
struct xid_t is binary compatible with the XID structure as
348
in the X/Open CAE Specification, Distributed Transaction Processing:
349
The XA Specification, X/Open Company Ltd., 1991.
350
http://www.opengroup.org/bookstore/catalog/c193.htm
352
@see MYSQL_XID in mysql/plugin.h
358
char data[XIDDATASIZE]; // not \0-terminated !
360
xid_t() {} /* Remove gcc warning */
361
bool eq(struct xid_t *xid)
362
{ return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
363
bool eq(long g, long b, const char *d)
364
{ return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
365
void set(struct xid_t *xid)
366
{ memcpy(this, xid, xid->length()); }
367
void set(long f, const char *g, long gl, const char *b, long bl)
370
memcpy(data, g, gtrid_length= gl);
371
memcpy(data+gl, b, bqual_length= bl);
373
void set(ulonglong xid)
377
set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
378
memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
380
memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
381
gtrid_length=MYSQL_XID_GTRID_LEN;
383
void set(long g, long b, const char *d)
388
memcpy(data, d, g+b);
390
bool is_null() { return formatID == -1; }
391
void null() { formatID= -1; }
392
my_xid quick_get_my_xid()
395
memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
400
return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 &&
401
!memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
402
quick_get_my_xid() : 0;
406
return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
407
gtrid_length+bqual_length;
411
return (uchar *)>rid_length;
415
return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
418
typedef struct xid_t XID;
420
/* for recover() handlerton call */
421
#define MIN_XID_LIST_SIZE 128
423
#define MAX_XID_LIST_SIZE 256
425
#define MAX_XID_LIST_SIZE (1024*128)
429
These structures are used to pass information from a set of SQL commands
430
on add/drop/change tablespace definitions to the proper hton.
432
#define UNDEF_NODEGROUP 65535
435
TS_CMD_NOT_DEFINED = -1,
436
CREATE_TABLESPACE = 0,
437
ALTER_TABLESPACE = 1,
438
CREATE_LOGFILE_GROUP = 2,
439
ALTER_LOGFILE_GROUP = 3,
441
DROP_LOGFILE_GROUP = 5,
442
CHANGE_FILE_TABLESPACE = 6,
443
ALTER_ACCESS_MODE_TABLESPACE = 7
446
enum ts_alter_tablespace_type
448
TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
449
ALTER_TABLESPACE_ADD_FILE = 1,
450
ALTER_TABLESPACE_DROP_FILE = 2
453
enum tablespace_access_mode
458
TS_NOT_ACCESSIBLE = 2
462
class st_alter_tablespace : public Sql_alloc
465
const char *tablespace_name;
466
const char *logfile_group_name;
467
enum ts_command_type ts_cmd_type;
468
enum ts_alter_tablespace_type ts_alter_tablespace_type;
469
const char *data_file_name;
470
const char *undo_file_name;
471
const char *redo_file_name;
472
ulonglong extent_size;
473
ulonglong undo_buffer_size;
474
ulonglong redo_buffer_size;
475
ulonglong initial_size;
476
ulonglong autoextend_size;
479
handlerton *storage_engine;
480
bool wait_until_completed;
481
const char *ts_comment;
482
enum tablespace_access_mode ts_access_mode;
483
st_alter_tablespace()
485
tablespace_name= NULL;
486
logfile_group_name= "DEFAULT_LG"; //Default log file group
487
ts_cmd_type= TS_CMD_NOT_DEFINED;
488
data_file_name= NULL;
489
undo_file_name= NULL;
490
redo_file_name= NULL;
491
extent_size= 1024*1024; //Default 1 MByte
492
undo_buffer_size= 8*1024*1024; //Default 8 MByte
493
redo_buffer_size= 8*1024*1024; //Default 8 MByte
494
initial_size= 128*1024*1024; //Default 128 MByte
495
autoextend_size= 0; //No autoextension as default
496
max_size= 0; //Max size == initial size => no extension
497
storage_engine= NULL;
498
nodegroup_id= UNDEF_NODEGROUP;
499
wait_until_completed= TRUE;
501
ts_access_mode= TS_NOT_DEFINED;
505
/* The handler for a table type. Will be included in the TABLE structure */
508
typedef struct st_table TABLE;
509
typedef struct st_table_share TABLE_SHARE;
510
struct st_foreign_key_info;
511
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
512
typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len,
513
const char *file, uint file_len,
514
const char *status, uint status_len);
515
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
516
extern st_plugin_int *hton2plugin[MAX_HA];
518
/* Transaction log maintains type definitions */
521
HA_LOG_STATUS_FREE= 0, /* log is free and can be deleted */
522
HA_LOG_STATUS_INUSE= 1, /* log can't be deleted because it is in use */
523
HA_LOG_STATUS_NOSUCHLOG= 2 /* no such log (can't be returned by
524
the log iterator status) */
527
Function for signaling that the log file changed its state from
528
LOG_STATUS_INUSE to LOG_STATUS_FREE
530
Now it do nothing, will be implemented as part of new transaction
531
log management for engines.
532
TODO: implement the function.
534
void signal_log_not_needed(struct handlerton, char *log_file);
536
Data of transaction log iterator.
538
struct handler_log_file_data {
540
enum log_status status;
544
enum handler_iterator_type
546
/* request of transaction log iterator */
547
HA_TRANSACTLOG_ITERATOR= 1
549
enum handler_create_iterator_result
551
HA_ITERATOR_OK, /* iterator created */
552
HA_ITERATOR_UNSUPPORTED, /* such type of iterator is not supported */
553
HA_ITERATOR_ERROR /* error during iterator creation */
557
Iterator structure. Can be used by handler/handlerton for different purposes.
559
Iterator should be created in the way to point "before" the first object
560
it iterate, so next() call move it to the first object or return !=0 if
561
there is nothing to iterate through.
563
struct handler_iterator {
565
Moves iterator to next record and return 0 or return !=0
566
if there is no records.
567
iterator_object will be filled by this function if next() returns 0.
568
Content of the iterator_object depend on iterator type.
570
int (*next)(struct handler_iterator *, void *iterator_object);
572
Free resources allocated by iterator, after this call iterator
575
void (*destroy)(struct handler_iterator *);
577
Pointer to buffer for the iterator to use.
578
Should be allocated by function which created the iterator and
579
destroied by freed by above "destroy" call
585
handlerton is a singleton structure - one instance per storage engine -
586
to provide access to storage engine functionality that works on the
587
"global" level (unlike handler class that works on a per-table basis)
589
usually handlerton instance is defined statically in ha_xxx.cc as
591
static handlerton { ... } xxx_hton;
593
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
598
Historical marker for if the engine is available of not
600
SHOW_COMP_OPTION state;
603
Historical number used for frm file to determine the correct storage engine.
604
This is going away and new engines will just use "name" for this.
606
enum legacy_db_type db_type;
608
each storage engine has it's own memory area (actually a pointer)
609
in the thd, for storing per-connection information.
612
thd->ha_data[xxx_hton.slot]
614
slot number is initialized by MySQL after xxx_init() is called.
618
to store per-savepoint data storage engine is provided with an area
619
of a requested size (0 is ok here).
620
savepoint_offset must be initialized statically to the size of
621
the needed memory to store per-savepoint information.
622
After xxx_init it is changed to be an offset to savepoint storage
623
area and need not be used by storage engine.
624
see binlog_hton and binlog_savepoint_set/rollback for an example.
626
uint savepoint_offset;
630
close_connection is only called if
631
thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
632
this storage area - set it to something, so that MySQL would know
633
this storage engine was accessed in this connection
635
int (*close_connection)(handlerton *hton, THD *thd);
637
sv points to an uninitialized storage area of requested size
638
(see savepoint_offset description)
640
int (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
642
sv points to a storage area, that was earlier passed
643
to the savepoint_set call
645
int (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
646
int (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
648
'all' is true if it's a real commit, that makes persistent changes
649
'all' is false if it's not in fact a commit but an end of the
650
statement that is part of the transaction.
651
NOTE 'all' is also false in auto-commit mode where 'end of statement'
652
and 'real commit' mean the same event.
654
int (*commit)(handlerton *hton, THD *thd, bool all);
655
int (*rollback)(handlerton *hton, THD *thd, bool all);
656
int (*prepare)(handlerton *hton, THD *thd, bool all);
657
int (*recover)(handlerton *hton, XID *xid_list, uint len);
658
int (*commit_by_xid)(handlerton *hton, XID *xid);
659
int (*rollback_by_xid)(handlerton *hton, XID *xid);
660
void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
661
void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
662
void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
663
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
664
void (*drop_database)(handlerton *hton, char* path);
665
int (*panic)(handlerton *hton, enum ha_panic_function flag);
666
int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
667
bool (*flush_logs)(handlerton *hton);
668
bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
669
uint (*partition_flags)();
670
uint (*alter_table_flags)(uint flags);
671
int (*alter_tablespace)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info);
672
int (*fill_files_table)(handlerton *hton, THD *thd,
675
uint32 flags; /* global handler flags */
677
Those handlerton functions below are properly initialized at handler
680
int (*binlog_func)(handlerton *hton, THD *thd, enum_binlog_func fn, void *arg);
681
void (*binlog_log_query)(handlerton *hton, THD *thd,
682
enum_binlog_command binlog_command,
683
const char *query, uint query_length,
684
const char *db, const char *table_name);
685
int (*release_temporary_latches)(handlerton *hton, THD *thd);
689
If log_status is null then the handler do not support transaction
690
log information (i.e. log iterator can't be created).
691
(see example of implementation in handler.cc, TRANS_LOG_MGM_EXAMPLE_CODE)
694
enum log_status (*get_log_status)(handlerton *hton, char *log);
698
Presence of the pointer should be checked before using
700
enum handler_create_iterator_result
701
(*create_iterator)(handlerton *hton, enum handler_iterator_type type,
702
struct handler_iterator *fill_this_in);
703
int (*discover)(handlerton *hton, THD* thd, const char *db,
707
int (*find_files)(handlerton *hton, THD *thd,
710
const char *wild, bool dir, List<LEX_STRING> *files);
711
int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
713
uint32 license; /* Flag for Engine License */
714
void *data; /* Location for engines to keep personal structures */
718
/* Possible flags of a handlerton (there can be 32 of them) */
719
#define HTON_NO_FLAGS 0
720
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
721
#define HTON_ALTER_NOT_SUPPORTED (1 << 1) //Engine does not support alter
722
#define HTON_CAN_RECREATE (1 << 2) //Delete all is used fro truncate
723
#define HTON_HIDDEN (1 << 3) //Engine does not appear in lists
724
#define HTON_FLUSH_AFTER_RENAME (1 << 4)
725
#define HTON_NOT_USER_SELECTABLE (1 << 5)
726
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
727
#define HTON_SUPPORT_LOG_TABLES (1 << 7) //Engine supports log tables
728
#define HTON_NO_PARTITION (1 << 8) //You can not partition these tables
734
/* true is not all entries in the ht[] support 2pc */
736
/* storage engines that registered in this transaction */
737
Ha_trx_info *ha_list;
739
The purpose of this flag is to keep track of non-transactional
740
tables that were modified in scope of:
741
- transaction, when the variable is a member of
743
- top-level statement or sub-statement, when the variable is a
744
member of THD::transaction.stmt
745
This member has the following life cycle:
746
* stmt.modified_non_trans_table is used to keep track of
747
modified non-transactional tables of top-level statements. At
748
the end of the previous statement and at the beginning of the session,
749
it is reset to FALSE. If such functions
750
as mysql_insert, mysql_update, mysql_delete etc modify a
751
non-transactional table, they set this flag to TRUE. At the
752
end of the statement, the value of stmt.modified_non_trans_table
753
is merged with all.modified_non_trans_table and gets reset.
754
* all.modified_non_trans_table is reset at the end of transaction
756
* Since we do not have a dedicated context for execution of a
757
sub-statement, to keep track of non-transactional changes in a
758
sub-statement, we re-use stmt.modified_non_trans_table.
759
At entrance into a sub-statement, a copy of the value of
760
stmt.modified_non_trans_table (containing the changes of the
761
outer statement) is saved on stack. Then
762
stmt.modified_non_trans_table is reset to FALSE and the
763
substatement is executed. Then the new value is merged with the
766
bool modified_non_trans_table;
768
void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
773
Either statement transaction or normal transaction - related
774
thread-specific storage engine data.
776
If a storage engine participates in a statement/transaction,
777
an instance of this class is present in
778
thd->transaction.{stmt|all}.ha_list. The addition to
779
{stmt|all}.ha_list is made by trans_register_ha().
781
When it's time to commit or rollback, each element of ha_list
782
is used to access storage engine's prepare()/commit()/rollback()
783
methods, and also to evaluate if a full two phase commit is
786
@sa General description of transaction handling in handler.cc.
792
/** Register this storage engine in the given transaction context. */
793
void register_ha(THD_TRANS *trans, handlerton *ht_arg)
795
DBUG_ASSERT(m_flags == 0);
796
DBUG_ASSERT(m_ht == NULL);
797
DBUG_ASSERT(m_next == NULL);
800
m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
802
m_next= trans->ha_list;
803
trans->ha_list= this;
806
/** Clear, prepare for reuse. */
814
Ha_trx_info() { reset(); }
816
void set_trx_read_write()
818
DBUG_ASSERT(is_started());
819
m_flags|= (int) TRX_READ_WRITE;
821
bool is_trx_read_write() const
823
DBUG_ASSERT(is_started());
824
return m_flags & (int) TRX_READ_WRITE;
826
bool is_started() const { return m_ht != NULL; }
827
/** Mark this transaction read-write if the argument is read-write. */
828
void coalesce_trx_with(const Ha_trx_info *stmt_trx)
831
Must be called only after the transaction has been started.
832
Can be called many times, e.g. when we have many
833
read-write statements in a transaction.
835
DBUG_ASSERT(is_started());
836
if (stmt_trx->is_trx_read_write())
837
set_trx_read_write();
839
Ha_trx_info *next() const
841
DBUG_ASSERT(is_started());
844
handlerton *ht() const
846
DBUG_ASSERT(is_started());
850
enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
851
/** Auxiliary, used for ha_list management */
854
Although a given Ha_trx_info instance is currently always used
855
for the same storage engine, 'ht' is not-NULL only when the
856
corresponding storage is a part of a transaction.
860
Transaction flags related to this engine.
861
Not-null only if this instance is a part of transaction.
862
May assume a combination of enum values above.
868
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
869
ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
872
enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 };
876
ulonglong data_file_length;
877
ulonglong max_data_file_length;
878
ulonglong index_file_length;
879
ulonglong delete_length;
881
ulong mean_rec_length;
888
#define UNDEF_NODEGROUP 65535
890
struct st_table_log_memory_entry;
892
class partition_info;
894
struct st_partition_iter;
895
#define NOT_A_PARTITION_ID ((uint32)-1)
897
enum enum_ha_unused { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
899
typedef struct st_ha_create_information
901
CHARSET_INFO *table_charset, *default_table_charset;
902
LEX_STRING connect_string;
903
const char *password, *tablespace;
905
const char *data_file_name, *index_file_name;
907
ulonglong max_rows,min_rows;
908
ulonglong auto_increment_value;
910
ulong avg_row_length;
912
ulong key_block_size;
916
Row type of the table definition.
918
Defaults to ROW_TYPE_DEFAULT for all non-ALTER statements.
919
For ALTER TABLE defaults to ROW_TYPE_NOT_USED (means "keep the current").
921
Can be changed either explicitly by the parser.
922
If nothing speficied inherits the value of the original table (if present).
924
enum row_type row_type;
925
uint null_bits; /* NULL bits at start of record */
926
uint options; /* OR of HA_CREATE_ options */
927
uint merge_insert_method;
928
uint extra_size; /* length of extra data segment */
929
enum enum_ha_unused unused1;
930
bool table_existed; /* 1 in create if table existed */
931
bool frm_only; /* 1 if no ha_create_table() */
932
bool varchar; /* 1 if table has a VARCHAR */
933
enum ha_storage_media storage_media; /* DEFAULT, DISK or MEMORY */
934
enum enum_ha_unused unused2;
938
typedef struct st_key_create_information
940
enum ha_key_alg algorithm;
942
LEX_STRING parser_name;
947
Class for maintaining hooks used inside operations on tables such
948
as: create table functions, delete table functions, and alter table
951
Class is using the Template Method pattern to separate the public
952
usage interface from the private inheritance interface. This
953
imposes no overhead, since the public non-virtual function is small
954
enough to be inlined.
956
The hooks are usually used for functions that does several things,
957
e.g., create_table_from_items(), which both create a table and lock
964
virtual ~TABLEOP_HOOKS() {}
966
inline void prelock(TABLE **tables, uint count)
968
do_prelock(tables, count);
971
inline int postlock(TABLE **tables, uint count)
973
return do_postlock(tables, count);
976
/* Function primitive that is called prior to locking tables */
977
virtual void do_prelock(TABLE **tables, uint count)
979
/* Default is to do nothing */
983
Primitive called after tables are locked.
985
If an error is returned, the tables will be unlocked and error
988
@return Error code or zero.
990
virtual int do_postlock(TABLE **tables, uint count)
992
return 0; /* Default is to do nothing */
996
typedef struct st_savepoint SAVEPOINT;
997
extern ulong savepoint_alloc_size;
998
extern KEY_CREATE_INFO default_key_create_info;
1000
/* Forward declaration for condition pushdown to storage engine */
1001
typedef class Item COND;
1003
typedef struct st_ha_check_opt
1005
st_ha_check_opt() {} /* Remove gcc warning */
1006
ulong sort_buffer_size;
1007
uint flags; /* isam layer flags (e.g. for myisamchk) */
1008
uint sql_flags; /* sql layer flags - for something myisamchk cannot do */
1009
KEY_CACHE *key_cache; /* new key cache when changing key cache */
1016
This is a buffer area that the handler can use to store rows.
1017
'end_of_used_area' should be kept updated after calls to
1018
read-functions so that other parts of the code can use the
1019
remaining area (until next read calls is issued).
1022
typedef struct st_handler_buffer
1024
const uchar *buffer; /* Buffer one can start using */
1025
const uchar *buffer_end; /* End of buffer */
1026
uchar *end_of_used_area; /* End of area that was used by handler */
1029
typedef struct system_status_var SSV;
1034
ulonglong data_file_length; /* Length off data file */
1035
ulonglong max_data_file_length; /* Length off data file */
1036
ulonglong index_file_length;
1037
ulonglong max_index_file_length;
1038
ulonglong delete_length; /* Free bytes */
1039
ulonglong auto_increment_value;
1041
The number of records in the table.
1042
0 - means the table has exactly 0 rows
1043
other - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
1044
the value is the exact number of records in the table
1049
ha_rows deleted; /* Deleted records */
1050
ulong mean_rec_length; /* physical reclength */
1051
ulong create_time; /* When table was created */
1054
uint block_size; /* index block size */
1057
data_file_length(0), max_data_file_length(0),
1058
index_file_length(0), delete_length(0), auto_increment_value(0),
1059
records(0), deleted(0), mean_rec_length(0), create_time(0),
1060
check_time(0), update_time(0), block_size(0)
1064
uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
1066
bitmap with first N+1 bits set
1067
(keypart_map for a key prefix of [0..N] keyparts)
1069
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
1071
bitmap with first N bits set
1072
(keypart_map for a key prefix of [0..N-1] keyparts)
1074
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
1077
The handler class is the interface for dynamically loadable
1078
storage engines. Do not add ifdefs and take care when adding or
1079
changing virtual functions to avoid vtable confusion
1082
class handler :public Sql_alloc
1085
typedef ulonglong Table_flags;
1087
struct st_table_share *table_share; /* The table definition */
1088
struct st_table *table; /* The current open table */
1089
Table_flags cached_table_flags; /* Set on init() and open() */
1091
ha_rows estimation_rows_to_insert;
1093
handlerton *ht; /* storage engine of this handler */
1094
uchar *ref; /* Pointer to current row */
1095
uchar *dup_ref; /* Pointer to duplicate row */
1097
ha_statistics stats;
1099
/** The following are for read_multi_range */
1100
bool multi_range_sorted;
1101
KEY_MULTI_RANGE *multi_range_curr;
1102
KEY_MULTI_RANGE *multi_range_end;
1103
HANDLER_BUFFER *multi_range_buffer;
1105
/** The following are for read_range() */
1106
key_range save_end_range, *end_range;
1107
KEY_PART_INFO *range_key_part;
1108
int key_compare_result_on_equal;
1111
uint errkey; /* Last dup key */
1112
uint key_used_on_scan;
1114
/** Length of ref (1-8 or the clustered key length) */
1116
FT_INFO *ft_handler;
1117
enum {NONE=0, INDEX, RND} inited;
1119
bool implicit_emptied; /* Can be !=0 only if HEAP */
1120
const COND *pushed_cond;
1122
next_insert_id is the next value which should be inserted into the
1123
auto_increment column: in a inserting-multi-row statement (like INSERT
1124
SELECT), for the first row where the autoinc value is not specified by the
1125
statement, get_auto_increment() called and asked to generate a value,
1126
next_insert_id is set to the next value, then for all other rows
1127
next_insert_id is used (and increased each time) without calling
1128
get_auto_increment().
1130
ulonglong next_insert_id;
1132
insert id for the current row (*autogenerated*; if not
1133
autogenerated, it's 0).
1134
At first successful insertion, this variable is stored into
1135
THD::first_successful_insert_id_in_cur_stmt.
1137
ulonglong insert_id_for_cur_row;
1139
Interval returned by get_auto_increment() and being consumed by the
1142
Discrete_interval auto_inc_interval_for_cur_row;
1144
Number of reserved auto-increment intervals. Serves as a heuristic
1145
when we have no estimation of how many records the statement will insert:
1146
the more intervals we have reserved, the bigger the next one. Reset in
1147
handler::ha_release_auto_increment().
1149
uint auto_inc_intervals_count;
1151
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
1152
:table_share(share_arg), table(0),
1153
estimation_rows_to_insert(0), ht(ht_arg),
1154
ref(0), key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1155
ref_length(sizeof(my_off_t)),
1156
ft_handler(0), inited(NONE),
1157
locked(FALSE), implicit_emptied(0),
1158
pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0),
1159
auto_inc_intervals_count(0)
1161
virtual ~handler(void)
1163
DBUG_ASSERT(locked == FALSE);
1164
/* TODO: DBUG_ASSERT(inited == NONE); */
1166
virtual handler *clone(MEM_ROOT *mem_root);
1167
/** This is called after create to allow us to set up cached variables */
1170
cached_table_flags= table_flags();
1172
/* ha_ methods: pubilc wrappers for private virtual API */
1174
int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
1175
int ha_index_init(uint idx, bool sorted)
1178
DBUG_ENTER("ha_index_init");
1179
DBUG_ASSERT(inited==NONE);
1180
if (!(result= index_init(idx, sorted)))
1182
DBUG_RETURN(result);
1186
DBUG_ENTER("ha_index_end");
1187
DBUG_ASSERT(inited==INDEX);
1189
DBUG_RETURN(index_end());
1191
int ha_rnd_init(bool scan)
1194
DBUG_ENTER("ha_rnd_init");
1195
DBUG_ASSERT(inited==NONE || (inited==RND && scan));
1196
inited= (result= rnd_init(scan)) ? NONE: RND;
1197
DBUG_RETURN(result);
1201
DBUG_ENTER("ha_rnd_end");
1202
DBUG_ASSERT(inited==RND);
1204
DBUG_RETURN(rnd_end());
1207
/* this is necessary in many places, e.g. in HANDLER command */
1208
int ha_index_or_rnd_end()
1210
return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
1213
The cached_table_flags is set at ha_open and ha_external_lock
1215
Table_flags ha_table_flags() const { return cached_table_flags; }
1217
These functions represent the public interface to *users* of the
1218
handler class, hence they are *not* virtual. For the inheritance
1219
interface, see the (private) functions write_row(), update_row(),
1220
and delete_row() below.
1222
int ha_external_lock(THD *thd, int lock_type);
1223
int ha_write_row(uchar * buf);
1224
int ha_update_row(const uchar * old_data, uchar * new_data);
1225
int ha_delete_row(const uchar * buf);
1226
void ha_release_auto_increment();
1228
int check_collation_compatibility();
1229
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
1230
/** to be actually called to get 'check()' functionality*/
1231
int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
1232
int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
1233
void ha_start_bulk_insert(ha_rows rows)
1235
estimation_rows_to_insert= rows;
1236
start_bulk_insert(rows);
1238
int ha_end_bulk_insert()
1240
estimation_rows_to_insert= 0;
1241
return end_bulk_insert();
1243
int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
1244
uint *dup_key_found);
1245
int ha_delete_all_rows();
1246
int ha_reset_auto_increment(ulonglong value);
1247
int ha_backup(THD* thd, HA_CHECK_OPT* check_opt);
1248
int ha_restore(THD* thd, HA_CHECK_OPT* check_opt);
1249
int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
1250
int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
1251
bool ha_check_and_repair(THD *thd);
1252
int ha_disable_indexes(uint mode);
1253
int ha_enable_indexes(uint mode);
1254
int ha_discard_or_import_tablespace(my_bool discard);
1255
void ha_prepare_for_alter();
1256
int ha_rename_table(const char *from, const char *to);
1257
int ha_delete_table(const char *name);
1258
void ha_drop_table(const char *name);
1260
int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info);
1262
int ha_create_handler_files(const char *name, const char *old_name,
1263
int action_flag, HA_CREATE_INFO *info);
1265
int ha_change_partitions(HA_CREATE_INFO *create_info,
1267
ulonglong * const copied,
1268
ulonglong * const deleted,
1269
const uchar *pack_frm_data,
1270
size_t pack_frm_len);
1271
int ha_drop_partitions(const char *path);
1272
int ha_rename_partitions(const char *path);
1274
void adjust_next_insert_id_after_explicit_value(ulonglong nr);
1275
int update_auto_increment();
1276
void print_keydup_error(uint key_nr, const char *msg);
1277
virtual void print_error(int error, myf errflag);
1278
virtual bool get_error_message(int error, String *buf);
1279
uint get_dup_key(int error);
1280
virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
1285
virtual double scan_time()
1286
{ return ulonglong2double(stats.data_file_length) / IO_SIZE + 2; }
1287
virtual double read_time(uint index, uint ranges, ha_rows rows)
1288
{ return rows2double(ranges+rows); }
1289
virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
1290
bool has_transactions()
1291
{ return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
1292
virtual uint extra_rec_buf_length() const { return 0; }
1295
This method is used to analyse the error to see whether the error
1296
is ignorable or not, certain handlers can have more error that are
1297
ignorable than others. E.g. the partition handler can get inserts
1298
into a range where there is no partition and this is an ignorable
1300
HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
1301
same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
1302
a slightly different error message.
1304
virtual bool is_fatal_error(int error, uint flags)
1307
((flags & HA_CHECK_DUP_KEY) &&
1308
(error == HA_ERR_FOUND_DUPP_KEY ||
1309
error == HA_ERR_FOUND_DUPP_UNIQUE)))
1315
Number of rows in table. It will only be called if
1316
(table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
1318
virtual ha_rows records() { return stats.records; }
1320
Return upper bound of current number of records in the table
1321
(max. of how many records one will retrieve when doing a full table scan)
1322
If upper bound is not known, HA_POS_ERROR should be returned as a max
1323
possible upper bound.
1325
virtual ha_rows estimate_rows_upper_bound()
1326
{ return stats.records+EXTRA_RECORDS; }
1329
Get the row type from the storage engine. If this method returns
1330
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
1332
virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
1334
virtual const char *index_type(uint key_number) { DBUG_ASSERT(0); return "";}
1338
Signal that the table->read_set and table->write_set table maps changed
1339
The handler is allowed to set additional bits in the above map in this
1340
call. Normally the handler should ignore all calls until we have done
1341
a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
1342
as there may be several calls to this routine.
1344
virtual void column_bitmaps_signal();
1345
uint get_index(void) const { return active_index; }
1346
virtual int close(void)=0;
1349
@retval 0 Bulk update used by handler
1350
@retval 1 Bulk update not used, normal operation used
1352
virtual bool start_bulk_update() { return 1; }
1354
@retval 0 Bulk delete used by handler
1355
@retval 1 Bulk delete not used, normal operation used
1357
virtual bool start_bulk_delete() { return 1; }
1359
After this call all outstanding updates must be performed. The number
1360
of duplicate key errors are reported in the duplicate key parameter.
1361
It is allowed to continue to the batched update after this call, the
1362
handler has to wait until end_bulk_update with changing state.
1364
@param dup_key_found Number of duplicate keys found
1367
@retval >0 Error code
1369
virtual int exec_bulk_update(uint *dup_key_found)
1372
return HA_ERR_WRONG_COMMAND;
1375
Perform any needed clean-up, no outstanding updates are there at the
1378
virtual void end_bulk_update() { return; }
1380
Execute all outstanding deletes and close down the bulk delete.
1383
@retval >0 Error code
1385
virtual int end_bulk_delete()
1388
return HA_ERR_WRONG_COMMAND;
1392
Positions an index cursor to the index specified in the handle. Fetches the
1393
row if available. If the key value is null, begin at the first key of the
1396
virtual int index_read_map(uchar * buf, const uchar * key,
1397
key_part_map keypart_map,
1398
enum ha_rkey_function find_flag)
1400
uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1401
return index_read(buf, key, key_len, find_flag);
1405
Positions an index cursor to the index specified in the handle. Fetches the
1406
row if available. If the key value is null, begin at the first key of the
1409
virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key,
1410
key_part_map keypart_map,
1411
enum ha_rkey_function find_flag);
1412
virtual int index_next(uchar * buf)
1413
{ return HA_ERR_WRONG_COMMAND; }
1414
virtual int index_prev(uchar * buf)
1415
{ return HA_ERR_WRONG_COMMAND; }
1416
virtual int index_first(uchar * buf)
1417
{ return HA_ERR_WRONG_COMMAND; }
1418
virtual int index_last(uchar * buf)
1419
{ return HA_ERR_WRONG_COMMAND; }
1420
virtual int index_next_same(uchar *buf, const uchar *key, uint keylen);
1423
The following functions works like index_read, but it find the last
1424
row with the current key value or prefix.
1426
virtual int index_read_last_map(uchar * buf, const uchar * key,
1427
key_part_map keypart_map)
1429
uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1430
return index_read_last(buf, key, key_len);
1432
virtual int read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
1433
KEY_MULTI_RANGE *ranges, uint range_count,
1434
bool sorted, HANDLER_BUFFER *buffer);
1435
virtual int read_multi_range_next(KEY_MULTI_RANGE **found_range_p);
1436
virtual int read_range_first(const key_range *start_key,
1437
const key_range *end_key,
1438
bool eq_range, bool sorted);
1439
virtual int read_range_next();
1440
int compare_key(key_range *range);
1441
virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
1442
void ft_end() { ft_handler=NULL; }
1443
virtual FT_INFO *ft_init_ext(uint flags, uint inx,String *key)
1445
virtual int ft_read(uchar *buf) { return HA_ERR_WRONG_COMMAND; }
1446
virtual int rnd_next(uchar *buf)=0;
1447
virtual int rnd_pos(uchar * buf, uchar *pos)=0;
1449
One has to use this method when to find
1450
random position by record as the plain
1451
position() call doesn't work for some
1452
handlers for random position.
1454
virtual int rnd_pos_by_record(uchar *record)
1457
return rnd_pos(record, ref);
1459
virtual int read_first_row(uchar *buf, uint primary_key);
1461
The following function is only needed for tables that may be temporary
1462
tables during joins.
1464
virtual int restart_rnd_next(uchar *buf, uchar *pos)
1465
{ return HA_ERR_WRONG_COMMAND; }
1466
virtual int rnd_same(uchar *buf, uint inx)
1467
{ return HA_ERR_WRONG_COMMAND; }
1468
virtual ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key)
1469
{ return (ha_rows) 10; }
1470
virtual void position(const uchar *record)=0;
1471
virtual int info(uint)=0; // see my_base.h for full description
1472
virtual void get_dynamic_partition_info(PARTITION_INFO *stat_info,
1474
virtual int extra(enum ha_extra_function operation)
1476
virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
1477
{ return extra(operation); }
1480
In an UPDATE or DELETE, if the row under the cursor was locked by another
1481
transaction, and the engine used an optimistic read of the last
1482
committed row value under the cursor, then the engine returns 1 from this
1483
function. MySQL must NOT try to update this optimistic value. If the
1484
optimistic value does not match the WHERE condition, MySQL can decide to
1485
skip over this row. Currently only works for InnoDB. This can be used to
1486
avoid unnecessary lock waits.
1488
If this method returns nonzero, it will also signal the storage
1489
engine that the next read will be a locking re-read of the row.
1491
virtual bool was_semi_consistent_read() { return 0; }
1493
Tell the engine whether it should avoid unnecessary lock waits.
1494
If yes, in an UPDATE or DELETE, if the row under the cursor was locked
1495
by another transaction, the engine may try an optimistic read of
1496
the last committed row value under the cursor.
1498
virtual void try_semi_consistent_read(bool) {}
1499
virtual void unlock_row() {}
1500
virtual int start_stmt(THD *thd, thr_lock_type lock_type) {return 0;}
1501
virtual void get_auto_increment(ulonglong offset, ulonglong increment,
1502
ulonglong nb_desired_values,
1503
ulonglong *first_value,
1504
ulonglong *nb_reserved_values);
1505
void set_next_insert_id(ulonglong id)
1507
DBUG_PRINT("info",("auto_increment: next value %lu", (ulong)id));
1510
void restore_auto_increment(ulonglong prev_insert_id)
1513
Insertion of a row failed, re-use the lastly generated auto_increment
1514
id, for the next row. This is achieved by resetting next_insert_id to
1515
what it was before the failed insertion (that old value is provided by
1516
the caller). If that value was 0, it was the first row of the INSERT;
1517
then if insert_id_for_cur_row contains 0 it means no id was generated
1518
for this first row, so no id was generated since the INSERT started, so
1519
we should set next_insert_id to 0; if insert_id_for_cur_row is not 0, it
1520
is the generated id of the first and failed row, so we use it.
1522
next_insert_id= (prev_insert_id > 0) ? prev_insert_id :
1523
insert_id_for_cur_row;
1526
virtual void update_create_info(HA_CREATE_INFO *create_info) {}
1527
int check_old_types();
1528
virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt)
1529
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1530
virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt)
1531
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1532
/* end of the list of admin commands */
1534
virtual int dump(THD* thd, int fd = -1) { return HA_ERR_WRONG_COMMAND; }
1535
virtual int indexes_are_disabled(void) {return 0;}
1536
virtual int net_read_dump(NET* net) { return HA_ERR_WRONG_COMMAND; }
1537
virtual char *update_table_comment(const char * comment)
1538
{ return (char*) comment;}
1539
virtual void append_create_info(String *packet) {}
1541
If index == MAX_KEY then a check for table is made and if index <
1542
MAX_KEY then a check is made if the table has foreign keys and if
1543
a foreign key uses this index (and thus the index cannot be dropped).
1545
@param index Index to check if foreign key uses it
1547
@retval TRUE Foreign key defined on table or index
1548
@retval FALSE No foreign key defined
1550
virtual bool is_fk_defined_on_table_or_index(uint index)
1552
virtual char* get_foreign_key_create_info()
1553
{ return(NULL);} /* gets foreign key create string from InnoDB */
1554
virtual char* get_tablespace_name(THD *thd, char *name, uint name_len)
1555
{ return(NULL);} /* gets tablespace name from handler */
1556
/** used in ALTER TABLE; 1 if changing storage engine is allowed */
1557
virtual bool can_switch_engines() { return 1; }
1558
/** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
1559
virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
1561
virtual uint referenced_by_foreign_key() { return 0;}
1562
virtual void init_table_handle_for_HANDLER()
1563
{ return; } /* prepare InnoDB for HANDLER */
1564
virtual void free_foreign_key_create_info(char* str) {}
1565
/** The following can be called without an open handler */
1566
virtual const char *table_type() const =0;
1568
If frm_error() is called then we will use this to find out what file
1569
extentions exist for the storage engine. This is also used by the default
1570
rename_table and delete_table method in handler.cc.
1572
For engines that have two file name extentions (separate meta/index file
1573
and data file), the order of elements is relevant. First element of engine
1574
file name extentions array should be meta/index file extention. Second
1575
element - data file extention. This order is assumed by
1576
prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
1578
virtual const char **bas_ext() const =0;
1580
virtual int get_default_no_partitions(HA_CREATE_INFO *info) { return 1;}
1581
virtual void set_auto_partitions(partition_info *part_info) { return; }
1582
virtual bool get_no_parts(const char *name,
1588
virtual void set_part_info(partition_info *part_info) {return;}
1590
virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
1592
virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
1593
{ return (HA_ERR_WRONG_COMMAND); }
1594
virtual int prepare_drop_index(TABLE *table_arg, uint *key_num,
1596
{ return (HA_ERR_WRONG_COMMAND); }
1597
virtual int final_drop_index(TABLE *table_arg)
1598
{ return (HA_ERR_WRONG_COMMAND); }
1600
uint max_record_length() const
1601
{ return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
1602
uint max_keys() const
1603
{ return min(MAX_KEY, max_supported_keys()); }
1604
uint max_key_parts() const
1605
{ return min(MAX_REF_PARTS, max_supported_key_parts()); }
1606
uint max_key_length() const
1607
{ return min(MAX_KEY_LENGTH, max_supported_key_length()); }
1608
uint max_key_part_length() const
1609
{ return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
1611
virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
1612
virtual uint max_supported_keys() const { return 0; }
1613
virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; }
1614
virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; }
1615
virtual uint max_supported_key_part_length() const { return 255; }
1616
virtual uint min_record_length(uint options) const { return 1; }
1618
virtual bool low_byte_first() const { return 1; }
1619
virtual uint checksum() const { return 0; }
1620
virtual bool is_crashed() const { return 0; }
1621
virtual bool auto_repair() const { return 0; }
1624
#define CHF_CREATE_FLAG 0
1625
#define CHF_DELETE_FLAG 1
1626
#define CHF_RENAME_FLAG 2
1627
#define CHF_INDEX_FLAG 3
1631
@note lock_count() can return > 1 if the table is MERGE or partitioned.
1633
virtual uint lock_count(void) const { return 1; }
1635
Is not invoked for non-transactional temporary tables.
1637
@note store_lock() can return more than one lock if the table is MERGE
1640
@note that one can NOT rely on table->in_use in store_lock(). It may
1641
refer to a different thread if called from mysql_lock_abort_for_thread().
1643
@note If the table is MERGE, store_lock() can return less locks
1644
than lock_count() claimed. This can happen when the MERGE children
1645
are not attached when this is called from another thread.
1647
virtual THR_LOCK_DATA **store_lock(THD *thd,
1649
enum thr_lock_type lock_type)=0;
1651
/** Type of table for caching query */
1652
virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
1656
@brief Register a named table with a call back function to the query cache.
1658
@param thd The thread handle
1659
@param table_key A pointer to the table name in the table cache
1660
@param key_length The length of the table name
1661
@param[out] engine_callback The pointer to the storage engine call back
1663
@param[out] engine_data Storage engine specific data which could be
1666
This method offers the storage engine, the possibility to store a reference
1667
to a table name which is going to be used with query cache.
1668
The method is called each time a statement is written to the cache and can
1669
be used to verify if a specific statement is cachable. It also offers
1670
the possibility to register a generic (but static) call back function which
1671
is called each time a statement is matched against the query cache.
1673
@note If engine_data supplied with this function is different from
1674
engine_data supplied with the callback function, and the callback returns
1675
FALSE, a table invalidation on the current table will occur.
1677
@return Upon success the engine_callback will point to the storage engine
1678
call back function, if any, and engine_data will point to any storage
1679
engine data used in the specific implementation.
1680
@retval TRUE Success
1681
@retval FALSE The specified table or current statement should not be
1685
virtual my_bool register_query_cache_table(THD *thd, char *table_key,
1689
ulonglong *engine_data)
1691
*engine_callback= 0;
1697
@retval TRUE Primary key (if there is one) is clustered
1698
key covering all fields
1699
@retval FALSE otherwise
1701
virtual bool primary_key_is_clustered() { return FALSE; }
1702
virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
1704
return memcmp(ref1, ref2, ref_length);
1708
Condition pushdown to storage engines
1712
Push condition down to the table handler.
1714
@param cond Condition to be pushed. The condition tree must not be
1715
modified by the by the caller.
1718
The 'remainder' condition that caller must use to filter out records.
1719
NULL means the handler will not return rows that do not match the
1723
The pushed conditions form a stack (from which one can remove the
1724
last pushed condition using cond_pop).
1725
The table handler filters out rows using (pushed_cond1 AND pushed_cond2
1726
AND ... AND pushed_condN)
1727
or less restrictive condition, depending on handler's capabilities.
1729
handler->ha_reset() call empties the condition stack.
1730
Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
1733
virtual const COND *cond_push(const COND *cond) { return cond; };
1735
Pop the top condition from the condition stack of the handler instance.
1737
Pops the top if condition stack, if stack is not empty.
1739
virtual void cond_pop() { return; };
1740
virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
1742
{ return COMPATIBLE_DATA_NO; }
1745
use_hidden_primary_key() is called in case of an update/delete when
1746
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
1747
but we don't have a primary key
1749
virtual void use_hidden_primary_key();
1750
virtual uint alter_table_flags(uint flags)
1752
if (ht->alter_table_flags)
1753
return ht->alter_table_flags(flags);
1758
/* Service methods for use by storage engines. */
1759
void ha_statistic_increment(ulong SSV::*offset) const;
1760
void **ha_data(THD *) const;
1761
THD *ha_thd(void) const;
1764
Default rename_table() and delete_table() rename/delete files with a
1765
given name and extensions from bas_ext().
1767
These methods can be overridden, but their default implementation
1768
provide useful functionality.
1770
virtual int rename_table(const char *from, const char *to);
1772
Delete a table in the engine. Called for base as well as temporary
1775
virtual int delete_table(const char *name);
1777
/* Private helpers */
1778
inline void mark_trx_read_write();
1781
Low-level primitives for storage engines. These should be
1782
overridden by the storage engine class. To call these methods, use
1783
the corresponding 'ha_*' method above.
1786
virtual int open(const char *name, int mode, uint test_if_locked)=0;
1787
virtual int index_init(uint idx, bool sorted) { active_index= idx; return 0; }
1788
virtual int index_end() { active_index= MAX_KEY; return 0; }
1790
rnd_init() can be called two times without rnd_end() in between
1791
(it only makes sense if scan=1).
1792
then the second call should prepare for the new table scan (e.g
1793
if rnd_init allocates the cursor, second call should position it
1794
to the start of the table, no need to deallocate and allocate it again
1796
virtual int rnd_init(bool scan)= 0;
1797
virtual int rnd_end() { return 0; }
1798
virtual int write_row(uchar *buf __attribute__((unused)))
1800
return HA_ERR_WRONG_COMMAND;
1803
virtual int update_row(const uchar *old_data __attribute__((unused)),
1804
uchar *new_data __attribute__((unused)))
1806
return HA_ERR_WRONG_COMMAND;
1809
virtual int delete_row(const uchar *buf __attribute__((unused)))
1811
return HA_ERR_WRONG_COMMAND;
1814
Reset state of file to after 'open'.
1815
This function is called after every statement for all tables used
1818
virtual int reset() { return 0; }
1819
virtual Table_flags table_flags(void) const= 0;
1821
Is not invoked for non-transactional temporary tables.
1823
Tells the storage engine that we intend to read or write data
1824
from the table. This call is prefixed with a call to handler::store_lock()
1825
and is invoked only for those handler instances that stored the lock.
1827
Calls to rnd_init/index_init are prefixed with this call. When table
1828
IO is complete, we call external_lock(F_UNLCK).
1829
A storage engine writer should expect that each call to
1830
::external_lock(F_[RD|WR]LOCK is followed by a call to
1831
::external_lock(F_UNLCK). If it is not, it is a bug in MySQL.
1833
The name and signature originate from the first implementation
1834
in MyISAM, which would call fcntl to set/clear an advisory
1835
lock on the data file in this method.
1837
@param lock_type F_RDLCK, F_WRLCK, F_UNLCK
1839
@return non-0 in case of failure, 0 in case of success.
1840
When lock_type is F_UNLCK, the return value is ignored.
1842
virtual int external_lock(THD *thd __attribute__((unused)),
1843
int lock_type __attribute__((unused)))
1847
virtual void release_auto_increment() { return; };
1848
/** admin commands - called from mysql_admin_table */
1849
virtual int check_for_upgrade(HA_CHECK_OPT *check_opt)
1851
virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
1852
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1855
In this method check_opt can be modified
1856
to specify CHECK option to use to call check()
1859
virtual int repair(THD* thd, HA_CHECK_OPT* check_opt)
1860
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1861
virtual void start_bulk_insert(ha_rows rows) {}
1862
virtual int end_bulk_insert() { return 0; }
1863
virtual int index_read(uchar * buf, const uchar * key, uint key_len,
1864
enum ha_rkey_function find_flag)
1865
{ return HA_ERR_WRONG_COMMAND; }
1866
virtual int index_read_last(uchar * buf, const uchar * key, uint key_len)
1867
{ return (my_errno= HA_ERR_WRONG_COMMAND); }
1869
This method is similar to update_row, however the handler doesn't need
1870
to execute the updates at this point in time. The handler can be certain
1871
that another call to bulk_update_row will occur OR a call to
1872
exec_bulk_update before the set of updates in this query is concluded.
1874
@param old_data Old record
1875
@param new_data New record
1876
@param dup_key_found Number of duplicate keys found
1878
@retval 0 Bulk delete used by handler
1879
@retval 1 Bulk delete not used, normal operation used
1881
virtual int bulk_update_row(const uchar *old_data, uchar *new_data,
1882
uint *dup_key_found)
1885
return HA_ERR_WRONG_COMMAND;
1888
This is called to delete all rows in a table
1889
If the handler don't support this, then this function will
1890
return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
1891
by one. It should reset auto_increment if
1892
thd->lex->sql_command == SQLCOM_TRUNCATE.
1894
virtual int delete_all_rows()
1895
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
1897
Reset the auto-increment counter to the given value, i.e. the next row
1898
inserted will get the given value. This is called e.g. after TRUNCATE
1899
is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
1900
returned by storage engines that don't support this operation.
1902
virtual int reset_auto_increment(ulonglong value)
1903
{ return HA_ERR_WRONG_COMMAND; }
1904
virtual int backup(THD* thd, HA_CHECK_OPT* check_opt)
1905
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1907
Restore assumes .frm file must exist, and that generate_table() has been
1908
called; It will just copy the data file and run repair.
1910
virtual int restore(THD* thd, HA_CHECK_OPT* check_opt)
1911
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1912
virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt)
1913
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1914
virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt)
1915
{ return HA_ADMIN_NOT_IMPLEMENTED; }
1916
virtual bool check_and_repair(THD *thd) { return TRUE; }
1917
virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
1918
virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
1919
virtual int discard_or_import_tablespace(my_bool discard)
1920
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
1921
virtual void prepare_for_alter() { return; }
1922
virtual void drop_table(const char *name);
1923
virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0;
1925
virtual int create_handler_files(const char *name, const char *old_name,
1926
int action_flag, HA_CREATE_INFO *info)
1929
virtual int change_partitions(HA_CREATE_INFO *create_info,
1931
ulonglong * const copied,
1932
ulonglong * const deleted,
1933
const uchar *pack_frm_data,
1934
size_t pack_frm_len)
1935
{ return HA_ERR_WRONG_COMMAND; }
1936
virtual int drop_partitions(const char *path)
1937
{ return HA_ERR_WRONG_COMMAND; }
1938
virtual int rename_partitions(const char *path)
1939
{ return HA_ERR_WRONG_COMMAND; }
1943
/* Some extern variables used with handlers */
1945
extern const char *ha_row_type[];
1946
extern MYSQL_PLUGIN_IMPORT const char *tx_isolation_names[];
1947
extern MYSQL_PLUGIN_IMPORT const char *binlog_format_names[];
1948
extern TYPELIB tx_isolation_typelib;
1949
extern TYPELIB myisam_stats_method_typelib;
1950
extern ulong total_ha, total_ha_2pc;
1952
/* Wrapper functions */
1953
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
1954
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
1957
handlerton *ha_default_handlerton(THD *thd);
1958
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
1959
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
1960
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
1961
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
1962
handlerton *db_type);
1963
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
1964
bool no_substitute, bool report_error);
1967
static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type)
1969
return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
1972
static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type)
1974
return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
1977
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
1979
return db_type == NULL ? FALSE : test(db_type->flags & flag);
1982
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
1984
return (db_type && db_type->create) ?
1985
(db_type->state == SHOW_OPTION_YES) : FALSE;
1989
int ha_init_errors(void);
1992
int ha_initialize_handlerton(st_plugin_int *plugin);
1993
int ha_finalize_handlerton(st_plugin_int *plugin);
1995
TYPELIB *ha_known_exts(void);
1996
int ha_panic(enum ha_panic_function flag);
1997
void ha_close_connection(THD* thd);
1998
bool ha_flush_logs(handlerton *db_type);
1999
void ha_drop_database(char* path);
2000
int ha_create_table(THD *thd, const char *path,
2001
const char *db, const char *table_name,
2002
HA_CREATE_INFO *create_info,
2003
bool update_create_info);
2004
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
2005
const char *db, const char *alias, bool generate_warning);
2007
/* statistics and info */
2008
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
2011
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
2012
int ha_discover(THD* thd, const char* dbname, const char* name,
2013
uchar** frmblob, size_t* frmlen);
2014
int ha_find_files(THD *thd,const char *db,const char *path,
2015
const char *wild, bool dir, List<LEX_STRING>* files);
2016
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
2019
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
2020
int ha_resize_key_cache(KEY_CACHE *key_cache);
2021
int ha_change_key_cache_param(KEY_CACHE *key_cache);
2022
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
2023
int ha_end_key_cache(KEY_CACHE *key_cache);
2025
/* report to InnoDB that control passes to the client */
2026
int ha_release_temporary_latches(THD *thd);
2028
/* transactions: interface to handlerton functions */
2029
int ha_start_consistent_snapshot(THD *thd);
2030
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
2031
int ha_commit_one_phase(THD *thd, bool all);
2032
int ha_rollback_trans(THD *thd, bool all);
2033
int ha_prepare(THD *thd);
2034
int ha_recover(HASH *commit_list);
2036
/* transactions: these functions never call handlerton functions directly */
2037
int ha_commit_trans(THD *thd, bool all);
2038
int ha_autocommit_or_rollback(THD *thd, int error);
2039
int ha_enable_transaction(THD *thd, bool on);
2042
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
2043
int ha_savepoint(THD *thd, SAVEPOINT *sv);
2044
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
2046
/* these are called by storage engines */
2047
void trans_register_ha(THD *thd, bool all, handlerton *ht);
2050
Storage engine has to assume the transaction will end up with 2pc if
2051
- there is more than one 2pc-capable storage engine available
2052
- in the current transaction 2pc was not disabled yet
2054
#define trans_need_2pc(thd, all) ((total_ha_2pc > 1) && \
2055
!((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
2057
#ifdef HAVE_NDB_BINLOG
2058
int ha_reset_logs(THD *thd);
2059
int ha_binlog_index_purge_file(THD *thd, const char *file);
2060
void ha_reset_slave(THD *thd);
2061
void ha_binlog_log_query(THD *thd, handlerton *db_type,
2062
enum_binlog_command binlog_command,
2063
const char *query, uint query_length,
2064
const char *db, const char *table_name);
2065
void ha_binlog_wait(THD *thd);
2066
int ha_binlog_end(THD *thd);
2068
#define ha_reset_logs(a) do {} while (0)
2069
#define ha_binlog_index_purge_file(a,b) do {} while (0)
2070
#define ha_reset_slave(a) do {} while (0)
2071
#define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
2072
#define ha_binlog_wait(a) do {} while (0)
2073
#define ha_binlog_end(a) do {} while (0)