17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_HANDLER_H
21
#define DRIZZLED_HANDLER_H
23
#include <drizzled/xid.h>
21
25
/* Definitions for parameters to do with handler-routines */
23
#ifdef USE_PRAGMA_INTERFACE
24
#pragma interface /* gcc class implementation */
27
#include <mysys/my_handler.h>
28
27
#include <storage/myisam/keycache.h>
31
#define NO_HASH /* Not yet implemented */
34
// the following is for checking tables
36
#define HA_ADMIN_ALREADY_DONE 1
38
#define HA_ADMIN_NOT_IMPLEMENTED -1
39
#define HA_ADMIN_FAILED -2
40
#define HA_ADMIN_CORRUPT -3
41
#define HA_ADMIN_INTERNAL_ERROR -4
42
#define HA_ADMIN_INVALID -5
43
#define HA_ADMIN_REJECT -6
44
#define HA_ADMIN_TRY_ALTER -7
45
#define HA_ADMIN_WRONG_CHECKSUM -8
46
#define HA_ADMIN_NOT_BASE_TABLE -9
47
#define HA_ADMIN_NEEDS_UPGRADE -10
48
#define HA_ADMIN_NEEDS_ALTER -11
49
#define HA_ADMIN_NEEDS_CHECK -12
28
#include <mysys/thr_lock.h>
29
#include <mysys/hash.h>
30
#include <drizzled/sql_string.h>
31
#include <drizzled/sql_list.h>
51
33
/* Bits to show what an alter table will do */
52
34
#include <drizzled/sql_bitmap.h>
54
#define HA_MAX_ALTER_FLAGS 39
36
#define HA_MAX_ALTER_FLAGS 40
55
37
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
57
#define HA_ADD_INDEX (0)
58
#define HA_DROP_INDEX (1)
59
#define HA_ALTER_INDEX (2)
60
#define HA_RENAME_INDEX (3)
61
#define HA_ADD_UNIQUE_INDEX (4)
62
#define HA_DROP_UNIQUE_INDEX (5)
63
#define HA_ALTER_UNIQUE_INDEX (6)
64
#define HA_RENAME_UNIQUE_INDEX (7)
65
#define HA_ADD_PK_INDEX (8)
66
#define HA_DROP_PK_INDEX (9)
67
#define HA_ALTER_PK_INDEX (10)
68
#define HA_ADD_COLUMN (11)
69
#define HA_DROP_COLUMN (12)
70
#define HA_CHANGE_COLUMN (13)
71
#define HA_ALTER_COLUMN_NAME (14)
72
#define HA_ALTER_COLUMN_TYPE (15)
73
#define HA_ALTER_COLUMN_ORDER (16)
74
#define HA_ALTER_COLUMN_NULLABLE (17)
75
#define HA_COLUMN_DEFAULT_VALUE (18)
76
#define HA_COLUMN_STORAGE (19)
77
#define HA_COLUMN_FORMAT (20)
78
#define HA_ADD_FOREIGN_KEY (21)
79
#define HA_DROP_FOREIGN_KEY (22)
80
#define HA_ALTER_FOREIGN_KEY (23)
81
#define HA_ADD_CONSTRAINT (24)
82
#define HA_CHANGE_CHARACTER_SET (30)
83
#define HA_SET_DEFAULT_CHARACTER_SET (31)
84
#define HA_CHANGE_AUTOINCREMENT_VALUE (32)
85
#define HA_ALTER_STORAGE (33)
86
#define HA_ALTER_TABLESPACE (34)
87
#define HA_ALTER_ROW_FORMAT (35)
88
#define HA_RENAME_TABLE (36)
89
#define HA_ALTER_STORAGE_ENGINE (37)
90
#define HA_RECREATE (38)
91
/* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
93
/* Return values for check_if_supported_alter */
95
#define HA_ALTER_ERROR -1
96
#define HA_ALTER_SUPPORTED_WAIT_LOCK 0
97
#define HA_ALTER_SUPPORTED_NO_LOCK 1
98
#define HA_ALTER_NOT_SUPPORTED 2
100
/* Bits in table_flags() to show what database can do */
102
#define HA_NO_TRANSACTIONS (1 << 0) /* Doesn't support transactions */
103
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
104
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
106
The following should be set if the following is not true when scanning
107
a table with rnd_next()
108
- We will see all rows (including deleted ones)
109
- Row positions are 'table->s->db_record_offset' apart
110
If this flag is not set, filesort will do a postion() call for each matched
111
row to be able to find the row later.
113
#define HA_REC_NOT_IN_SEQ (1 << 3)
116
Reading keys in random order is as fast as reading keys in sort order
117
(Used in records.cc to decide if we should use a record cache and by
118
filesort to decide if we should sort key + data or key + pointer-to-row
120
#define HA_FAST_KEY_READ (1 << 5)
122
Set the following flag if we on delete should force all key to be read
123
and on update read all keys that changes
125
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
126
#define HA_NULL_IN_KEY (1 << 7) /* One can have keys with NULL */
127
#define HA_DUPLICATE_POS (1 << 8) /* ha_position() gives dup row */
128
#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
129
#define HA_CAN_INDEX_BLOBS (1 << 10)
130
#define HA_AUTO_PART_KEY (1 << 11) /* auto-increment in multi-part key */
131
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
132
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
134
If we get the primary key columns for free when we do an index read
135
It also implies that we have to retrive the primary key when using
136
position() and rnd_pos().
138
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
140
If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
141
uses a primary key. Without primary key, we can't call position().
143
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16)
144
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
146
The following is we need to a primary key to delete (and update) a row.
147
If there is no primary key, all columns needs to be read on update and delete
149
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
150
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
151
#define HA_NO_AUTO_INCREMENT (1 << 23)
152
#define HA_HAS_CHECKSUM (1 << 24)
153
/* Table data are stored in separate files (for lower_case_table_names) */
154
#define HA_FILE_BASED (1 << 26)
155
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
156
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
157
#define HA_NO_COPY_ON_ALTER (INT64_C(1) << 31)
158
#define HA_HAS_RECORDS (INT64_C(1) << 32) /* records() gives exact count*/
159
#define HA_MRR_CANT_SORT (INT64_C(1) << 34)
162
Engine is capable of row-format and statement-format logging,
165
#define HA_BINLOG_ROW_CAPABLE (INT64_C(1) << 35)
166
#define HA_BINLOG_STMT_CAPABLE (INT64_C(1) << 36)
168
#define HA_ONLINE_ALTER (INT64_C(1) << 37)
171
Set of all binlog flags. Currently only contain the capabilities
174
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
176
/* bits in index_flags(index_number) for what you can do with index */
177
#define HA_READ_NEXT 1 /* TODO really use this flag */
178
#define HA_READ_PREV 2 /* supports ::index_prev */
179
#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
180
#define HA_READ_RANGE 8 /* can find all records in a range */
181
#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
182
#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
184
Index scan will not return records in rowid order. Not guaranteed to be
185
set for unordered (e.g. HASH) indexes.
187
#define HA_KEY_SCAN_NOT_ROR 128
188
#define HA_DO_INDEX_COND_PUSHDOWN 256 /* Supports Index Condition Pushdown */
193
HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
195
HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
196
exists but they are not necessarily done online.
198
HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
199
the new partition and to the old partitions when updating through the
200
old partitioning schema while performing a change of the partitioning.
201
This means that we can support updating of the table while performing
202
the copy phase of the change. For no lock at all also a double write
203
from new to old must exist and this is not required when this flag is
205
This is actually removed even before it was introduced the first time.
206
The new idea is that handlers will handle the lock level already in
207
store_lock for ALTER Table partitions.
209
HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
210
care of changing the partitions online and in one phase. Thus all phases
211
needed to handle the change are implemented inside the storage engine.
212
The storage engine must also support auto-discovery since the frm file
213
is changed as part of the change and this change must be controlled by
214
the storage engine. A typical engine to support this is NDB (through
217
#define HA_PARTITION_FUNCTION_SUPPORTED (1L << 1)
218
#define HA_FAST_CHANGE_PARTITION (1L << 2)
219
#define HA_PARTITION_ONE_PHASE (1L << 3)
221
/* operations for disable/enable indexes */
222
#define HA_KEY_SWITCH_NONUNIQ 0
223
#define HA_KEY_SWITCH_ALL 1
224
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
225
#define HA_KEY_SWITCH_ALL_SAVE 3
228
Note: the following includes binlog and closing 0.
229
so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
230
example + csv + heap + blackhole + federated + 0
231
(yes, the sum is deliberately inaccurate)
232
TODO remove the limit, use dynarrays
237
Parameters for open() (in register form->filestat)
238
HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
241
#define HA_OPEN_KEYFILE 1
242
#define HA_OPEN_RNDFILE 2
243
#define HA_GET_INDEX 4
244
#define HA_GET_INFO 8 /* do a ha_info() after open */
245
#define HA_READ_ONLY 16 /* File opened as readonly */
246
/* Try readonly if can't open with read and write */
247
#define HA_TRY_READ_ONLY 32
248
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
249
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
250
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
251
#define HA_OPEN_TEMPORARY 512
253
/* For transactional LOCK Table. handler::lock_table() */
254
#define HA_LOCK_IN_SHARE_MODE F_RDLCK
255
#define HA_LOCK_IN_EXCLUSIVE_MODE F_WRLCK
257
/* Some key definitions */
258
#define HA_KEY_NULL_LENGTH 1
259
#define HA_KEY_BLOB_LENGTH 2
261
#define HA_LEX_CREATE_TMP_TABLE 1
262
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
263
#define HA_LEX_CREATE_TABLE_LIKE 4
264
#define HA_OPTION_NO_CHECKSUM (1L << 17)
265
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
266
#define HA_MAX_REC_LENGTH 65535
268
/* Table caching type */
269
#define HA_CACHE_TBL_NONTRANSACT 0
270
#define HA_CACHE_TBL_NOCACHE 1
271
#define HA_CACHE_TBL_ASKTRANSACT 2
272
#define HA_CACHE_TBL_TRANSACT 4
274
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
275
#define DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
277
/* Flags for method is_fatal_error */
278
#define HA_CHECK_DUP_KEY 1
279
#define HA_CHECK_DUP_UNIQUE 2
280
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
285
DB_TYPE_FIRST_DYNAMIC=42,
286
DB_TYPE_DEFAULT=127 // Must be last
289
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
290
ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
291
ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE };
293
enum column_format_type { COLUMN_FORMAT_TYPE_NOT_USED= -1,
294
COLUMN_FORMAT_TYPE_DEFAULT= 0,
295
COLUMN_FORMAT_TYPE_FIXED= 1,
296
COLUMN_FORMAT_TYPE_DYNAMIC= 2 };
298
enum enum_binlog_func {
303
BFN_BINLOG_PURGE_FILE= 5
306
enum enum_binlog_command {
316
/* struct to hold information about the table that should be created */
318
/* Bits in used_fields */
319
#define HA_CREATE_USED_AUTO (1L << 0)
321
#define HA_CREATE_USED_RAID (1L << 1) /* Historical, no longer supported */
322
#define HA_CREATE_USED_UNION (1L << 2)
323
#define HA_CREATE_USED_PASSWORD (1L << 17)
325
#define HA_CREATE_USED_INSERT_METHOD (1L << 3)
326
#define HA_CREATE_USED_MIN_ROWS (1L << 4)
327
#define HA_CREATE_USED_MAX_ROWS (1L << 5)
328
#define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
329
#define HA_CREATE_USED_PACK_KEYS (1L << 7)
330
#define HA_CREATE_USED_CHARSET (1L << 8)
331
#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
332
#define HA_CREATE_USED_DATADIR (1L << 10)
333
#define HA_CREATE_USED_INDEXDIR (1L << 11)
334
#define HA_CREATE_USED_ENGINE (1L << 12)
335
#define HA_CREATE_USED_CHECKSUM (1L << 13)
336
#define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
337
#define HA_CREATE_USED_ROW_FORMAT (1L << 15)
338
#define HA_CREATE_USED_COMMENT (1L << 16)
339
#define HA_CREATE_USED_CONNECTION (1L << 18)
340
#define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19)
341
#define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21)
342
#define HA_CREATE_USED_BLOCK_SIZE (1L << 22)
344
typedef uint64_t my_xid; // this line is the same as in log_event.h
345
#define DRIZZLE_XID_PREFIX "MySQLXid"
346
#define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
347
#define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
348
#define DRIZZLE_XID_GTRID_LEN (DRIZZLE_XID_OFFSET+sizeof(my_xid))
350
#define XIDDATASIZE DRIZZLE_XIDDATASIZE
351
#define MAXGTRIDSIZE 64
352
#define MAXBQUALSIZE 64
354
#define COMPATIBLE_DATA_YES 0
355
#define COMPATIBLE_DATA_NO 1
357
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
40
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
358
41
uint32_t key_length,
359
42
uint64_t *engine_data);
362
struct xid_t is binary compatible with the XID structure as
363
in the X/Open CAE Specification, Distributed Transaction Processing:
364
The XA Specification, X/Open Company Ltd., 1991.
365
http://www.opengroup.org/bookstore/catalog/c193.htm
367
@see DRIZZLE_XID in mysql/plugin.h
373
char data[XIDDATASIZE]; // not \0-terminated !
375
xid_t() {} /* Remove gcc warning */
376
bool eq(struct xid_t *xid)
377
{ return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
378
bool eq(long g, long b, const char *d)
379
{ return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
380
void set(struct xid_t *xid)
381
{ memcpy(this, xid, xid->length()); }
382
void set(long f, const char *g, long gl, const char *b, long bl)
385
memcpy(data, g, gtrid_length= gl);
386
memcpy(data+gl, b, bqual_length= bl);
388
void set(uint64_t xid)
392
set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
393
memcpy(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
395
memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
396
gtrid_length=DRIZZLE_XID_GTRID_LEN;
398
void set(long g, long b, const char *d)
403
memcpy(data, d, g+b);
405
bool is_null() { return formatID == -1; }
406
void null() { formatID= -1; }
407
my_xid quick_get_my_xid()
410
memcpy(&tmp, data+DRIZZLE_XID_OFFSET, sizeof(tmp));
415
return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
416
!memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
417
!memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
418
quick_get_my_xid() : 0;
422
return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
423
gtrid_length+bqual_length;
427
return (unsigned char *)>rid_length;
429
uint32_t key_length()
431
return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
434
typedef struct xid_t XID;
436
/* for recover() handlerton call */
437
#define MIN_XID_LIST_SIZE 128
438
#define MAX_XID_LIST_SIZE (1024*128)
440
45
struct handlerton;
442
47
/* The handler for a table type. Will be included in the Table structure */
445
51
typedef struct st_table_share TABLE_SHARE;
446
52
struct st_foreign_key_info;
447
53
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
448
typedef bool (stat_print_fn)(THD *thd, const char *type, uint32_t type_len,
54
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
449
55
const char *file, uint32_t file_len,
450
56
const char *status, uint32_t status_len);
451
57
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
521
127
NOTE 'all' is also false in auto-commit mode where 'end of statement'
522
128
and 'real commit' mean the same event.
524
int (*commit)(handlerton *hton, THD *thd, bool all);
525
int (*rollback)(handlerton *hton, THD *thd, bool all);
526
int (*prepare)(handlerton *hton, THD *thd, bool all);
130
int (*commit)(handlerton *hton, Session *session, bool all);
131
int (*rollback)(handlerton *hton, Session *session, bool all);
132
int (*prepare)(handlerton *hton, Session *session, bool all);
527
133
int (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
528
134
int (*commit_by_xid)(handlerton *hton, XID *xid);
529
135
int (*rollback_by_xid)(handlerton *hton, XID *xid);
530
void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
531
void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
532
void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
136
void *(*create_cursor_read_view)(handlerton *hton, Session *session);
137
void (*set_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
138
void (*close_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
533
139
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
534
140
void (*drop_database)(handlerton *hton, char* path);
535
int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
141
int (*start_consistent_snapshot)(handlerton *hton, Session *session);
536
142
bool (*flush_logs)(handlerton *hton);
537
bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
538
int (*fill_files_table)(handlerton *hton, THD *thd,
143
bool (*show_status)(handlerton *hton, Session *session, stat_print_fn *print, enum ha_stat_type stat);
144
int (*fill_files_table)(handlerton *hton, Session *session,
539
145
TableList *tables,
540
146
class Item *cond);
541
147
uint32_t flags; /* global handler flags */
542
int (*release_temporary_latches)(handlerton *hton, THD *thd);
148
int (*release_temporary_latches)(handlerton *hton, Session *session);
544
int (*discover)(handlerton *hton, THD* thd, const char *db,
150
int (*discover)(handlerton *hton, Session* session, const char *db,
545
151
const char *name,
546
152
unsigned char **frmblob,
548
int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
154
int (*table_exists_in_engine)(handlerton *hton, Session* session, const char *db,
549
155
const char *name);
550
156
uint32_t license; /* Flag for Engine License */
551
157
void *data; /* Location for engines to keep personal structures */
555
/* Possible flags of a handlerton (there can be 32 of them) */
556
#define HTON_NO_FLAGS 0
557
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
558
#define HTON_ALTER_NOT_SUPPORTED (1 << 1) //Engine does not support alter
559
#define HTON_CAN_RECREATE (1 << 2) //Delete all is used fro truncate
560
#define HTON_HIDDEN (1 << 3) //Engine does not appear in lists
561
#define HTON_FLUSH_AFTER_RENAME (1 << 4)
562
#define HTON_NOT_USER_SELECTABLE (1 << 5)
563
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
564
#define HTON_SUPPORT_LOG_TABLES (1 << 7) //Engine supports log tables
565
#define HTON_NO_PARTITION (1 << 8) //You can not partition these tables
567
162
class Ha_trx_info;
571
166
/* true is not all entries in the ht[] support 2pc */