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>
24
#include <drizzled/discrete_interval.h>
26
21
/* Definitions for parameters to do with handler-routines */
28
#include <mysys/thr_lock.h>
29
#include <mysys/hash.h>
30
#include <drizzled/sql_string.h>
31
#include <drizzled/sql_list.h>
32
#include <drizzled/plugin/storage_engine.h>
33
#include <drizzled/handler_structs.h>
34
#include <drizzled/ha_statistics.h>
35
#include <drizzled/atomics.h>
37
#include <drizzled/message/table.pb.h>
23
#ifdef USE_PRAGMA_INTERFACE
24
#pragma interface /* gcc class implementation */
27
#include <mysys/my_handler.h>
28
#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
39
51
/* Bits to show what an alter table will do */
40
52
#include <drizzled/sql_bitmap.h>
42
#include <drizzled/handler.h>
47
#define HA_MAX_ALTER_FLAGS 40
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
52
extern drizzled::atomic<uint32_t> refresh_version; /* Increments on each reload */
55
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
54
#define HA_MAX_ALTER_FLAGS 39
55
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,
56
358
uint32_t key_length,
57
359
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)
60
442
/* The handler for a table type. Will be included in the Table structure */
65
class Select_Lex_Unit;
445
typedef struct st_table_share TABLE_SHARE;
66
446
struct st_foreign_key_info;
67
447
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
448
typedef bool (stat_print_fn)(THD *thd, const char *type, uint32_t type_len,
449
const char *file, uint32_t file_len,
450
const char *status, uint32_t status_len);
451
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
452
extern st_plugin_int *hton2plugin[MAX_HA];
455
handlerton is a singleton structure - one instance per storage engine -
456
to provide access to storage engine functionality that works on the
457
"global" level (unlike handler class that works on a per-table basis)
459
usually handlerton instance is defined statically in ha_xxx.cc as
461
static handlerton { ... } xxx_hton;
463
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
468
Historical marker for if the engine is available of not
470
SHOW_COMP_OPTION state;
473
Historical number used for frm file to determine the correct storage engine.
474
This is going away and new engines will just use "name" for this.
476
enum legacy_db_type db_type;
478
each storage engine has it's own memory area (actually a pointer)
479
in the thd, for storing per-connection information.
482
thd->ha_data[xxx_hton.slot]
484
slot number is initialized by MySQL after xxx_init() is called.
488
to store per-savepoint data storage engine is provided with an area
489
of a requested size (0 is ok here).
490
savepoint_offset must be initialized statically to the size of
491
the needed memory to store per-savepoint information.
492
After xxx_init it is changed to be an offset to savepoint storage
493
area and need not be used by storage engine.
494
see binlog_hton and binlog_savepoint_set/rollback for an example.
496
uint32_t savepoint_offset;
500
close_connection is only called if
501
thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
502
this storage area - set it to something, so that MySQL would know
503
this storage engine was accessed in this connection
505
int (*close_connection)(handlerton *hton, THD *thd);
507
sv points to an uninitialized storage area of requested size
508
(see savepoint_offset description)
510
int (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
512
sv points to a storage area, that was earlier passed
513
to the savepoint_set call
515
int (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
516
int (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
518
'all' is true if it's a real commit, that makes persistent changes
519
'all' is false if it's not in fact a commit but an end of the
520
statement that is part of the transaction.
521
NOTE 'all' is also false in auto-commit mode where 'end of statement'
522
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);
527
int (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
528
int (*commit_by_xid)(handlerton *hton, XID *xid);
529
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);
533
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
534
void (*drop_database)(handlerton *hton, char* path);
535
int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
536
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,
541
uint32_t flags; /* global handler flags */
542
int (*release_temporary_latches)(handlerton *hton, THD *thd);
544
int (*discover)(handlerton *hton, THD* thd, const char *db,
546
unsigned char **frmblob,
548
int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
550
uint32_t license; /* Flag for Engine License */
551
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
571
/* true is not all entries in the ht[] support 2pc */
573
/* storage engines that registered in this transaction */
574
Ha_trx_info *ha_list;
576
The purpose of this flag is to keep track of non-transactional
577
tables that were modified in scope of:
578
- transaction, when the variable is a member of
580
- top-level statement or sub-statement, when the variable is a
581
member of THD::transaction.stmt
582
This member has the following life cycle:
583
* stmt.modified_non_trans_table is used to keep track of
584
modified non-transactional tables of top-level statements. At
585
the end of the previous statement and at the beginning of the session,
586
it is reset to false. If such functions
587
as mysql_insert, mysql_update, mysql_delete etc modify a
588
non-transactional table, they set this flag to true. At the
589
end of the statement, the value of stmt.modified_non_trans_table
590
is merged with all.modified_non_trans_table and gets reset.
591
* all.modified_non_trans_table is reset at the end of transaction
593
* Since we do not have a dedicated context for execution of a
594
sub-statement, to keep track of non-transactional changes in a
595
sub-statement, we re-use stmt.modified_non_trans_table.
596
At entrance into a sub-statement, a copy of the value of
597
stmt.modified_non_trans_table (containing the changes of the
598
outer statement) is saved on stack. Then
599
stmt.modified_non_trans_table is reset to false and the
600
substatement is executed. Then the new value is merged with the
603
bool modified_non_trans_table;
605
void reset() { no_2pc= false; modified_non_trans_table= false; }
610
Either statement transaction or normal transaction - related
611
thread-specific storage engine data.
613
If a storage engine participates in a statement/transaction,
614
an instance of this class is present in
615
thd->transaction.{stmt|all}.ha_list. The addition to
616
{stmt|all}.ha_list is made by trans_register_ha().
618
When it's time to commit or rollback, each element of ha_list
619
is used to access storage engine's prepare()/commit()/rollback()
620
methods, and also to evaluate if a full two phase commit is
623
@sa General description of transaction handling in handler.cc.
629
/** Register this storage engine in the given transaction context. */
630
void register_ha(THD_TRANS *trans, handlerton *ht_arg)
632
assert(m_flags == 0);
633
assert(m_ht == NULL);
634
assert(m_next == NULL);
637
m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
639
m_next= trans->ha_list;
640
trans->ha_list= this;
643
/** Clear, prepare for reuse. */
651
Ha_trx_info() { reset(); }
653
void set_trx_read_write()
655
assert(is_started());
656
m_flags|= (int) TRX_READ_WRITE;
658
bool is_trx_read_write() const
660
assert(is_started());
661
return m_flags & (int) TRX_READ_WRITE;
663
bool is_started() const { return m_ht != NULL; }
664
/** Mark this transaction read-write if the argument is read-write. */
665
void coalesce_trx_with(const Ha_trx_info *stmt_trx)
668
Must be called only after the transaction has been started.
669
Can be called many times, e.g. when we have many
670
read-write statements in a transaction.
672
assert(is_started());
673
if (stmt_trx->is_trx_read_write())
674
set_trx_read_write();
676
Ha_trx_info *next() const
678
assert(is_started());
681
handlerton *ht() const
683
assert(is_started());
687
enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
688
/** Auxiliary, used for ha_list management */
691
Although a given Ha_trx_info instance is currently always used
692
for the same storage engine, 'ht' is not-NULL only when the
693
corresponding storage is a part of a transaction.
697
Transaction flags related to this engine.
698
Not-null only if this instance is a part of transaction.
699
May assume a combination of enum values above.
701
unsigned char m_flags;
705
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
706
ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
709
uint64_t data_file_length;
710
uint64_t max_data_file_length;
711
uint64_t index_file_length;
712
uint64_t delete_length;
714
uint32_t mean_rec_length;
721
#define UNDEF_NODEGROUP 65535
71
723
struct st_table_log_memory_entry;
80
typedef struct st_sort_field SORT_FIELD;
82
typedef List<Item> List_item;
725
#define NOT_A_PARTITION_ID ((uint32_t)-1)
727
enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
729
typedef struct st_ha_create_information
731
const CHARSET_INFO *table_charset, *default_table_charset;
732
LEX_STRING connect_string;
734
const char *data_file_name, *index_file_name;
736
uint64_t max_rows,min_rows;
737
uint64_t auto_increment_value;
738
uint32_t table_options;
739
uint32_t avg_row_length;
740
uint32_t used_fields;
741
uint32_t key_block_size;
744
enum row_type row_type;
745
uint32_t null_bits; /* NULL bits at start of record */
746
uint32_t options; /* OR of HA_CREATE_ options */
747
uint32_t extra_size; /* length of extra data segment */
748
bool table_existed; /* 1 in create if table existed */
749
bool frm_only; /* 1 if no ha_create_table() */
750
bool varchar; /* 1 if table has a VARCHAR */
751
enum ha_choice page_checksum; /* If we have page_checksums */
754
typedef struct st_ha_alter_information
756
KEY *key_info_buffer;
758
uint32_t index_drop_count;
759
uint32_t *index_drop_buffer;
760
uint32_t index_add_count;
761
uint32_t *index_add_buffer;
766
typedef struct st_key_create_information
768
enum ha_key_alg algorithm;
770
LEX_STRING parser_name;
776
Class for maintaining hooks used inside operations on tables such
777
as: create table functions, delete table functions, and alter table
780
Class is using the Template Method pattern to separate the public
781
usage interface from the private inheritance interface. This
782
imposes no overhead, since the public non-virtual function is small
783
enough to be inlined.
785
The hooks are usually used for functions that does several things,
786
e.g., create_table_from_items(), which both create a table and lock
793
virtual ~TABLEOP_HOOKS() {}
795
inline void prelock(Table **tables, uint32_t count)
797
do_prelock(tables, count);
800
inline int postlock(Table **tables, uint32_t count)
802
return do_postlock(tables, count);
805
/* Function primitive that is called prior to locking tables */
806
virtual void do_prelock(Table **tables __attribute__((unused)),
807
uint32_t count __attribute__((unused)))
809
/* Default is to do nothing */
813
Primitive called after tables are locked.
815
If an error is returned, the tables will be unlocked and error
818
@return Error code or zero.
820
virtual int do_postlock(Table **tables __attribute__((unused)),
821
uint32_t count __attribute__((unused)))
823
return 0; /* Default is to do nothing */
84
827
typedef struct st_savepoint SAVEPOINT;
85
828
extern uint32_t savepoint_alloc_size;
88
831
/* Forward declaration for condition pushdown to storage engine */
89
832
typedef class Item COND;
834
typedef struct st_ha_check_opt
836
st_ha_check_opt() {} /* Remove gcc warning */
837
uint32_t sort_buffer_size;
838
uint32_t flags; /* isam layer flags (e.g. for myisamchk) */
839
uint32_t sql_flags; /* sql layer flags - for something myisamchk cannot do */
840
KEY_CACHE *key_cache; /* new key cache when changing key cache */
847
This is a buffer area that the handler can use to store rows.
848
'end_of_used_area' should be kept updated after calls to
849
read-functions so that other parts of the code can use the
850
remaining area (until next read calls is issued).
853
typedef struct st_handler_buffer
855
unsigned char *buffer; /* Buffer one can start using */
856
unsigned char *buffer_end; /* End of buffer */
857
unsigned char *end_of_used_area; /* End of area that was used by handler */
91
860
typedef struct system_status_var SSV;
863
typedef void *range_seq_t;
865
typedef struct st_range_seq_if
868
Initialize the traversal of range sequence
872
init_params The seq_init_param parameter
873
n_ranges The number of ranges obtained
874
flags A combination of HA_MRR_SINGLE_POINT, HA_MRR_FIXED_KEY
877
An opaque value to be used as RANGE_SEQ_IF::next() parameter
879
range_seq_t (*init)(void *init_params, uint32_t n_ranges, uint32_t flags);
883
Get the next range in the range sequence
887
seq The value returned by RANGE_SEQ_IF::init()
888
range OUT Information about the next range
891
0 - Ok, the range structure filled with info about the next range
894
uint32_t (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
897
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
898
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
903
double io_count; /* number of I/O */
904
double avg_io_cost; /* cost of an average I/O oper. */
905
double cpu_cost; /* cost of operations in CPU */
906
double mem_cost; /* cost of used memory */
907
double import_cost; /* cost of remote operations */
910
enum { CPU_COEFF=1 };
911
enum { MEM_COEFF=1 };
912
enum { IMPORT_COEFF=1 };
914
COST_VECT() {} // keep gcc happy
918
return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
919
MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
925
io_count= cpu_cost= mem_cost= import_cost= 0.0;
928
void multiply(double m)
933
/* Don't multiply mem_cost */
936
void add(const COST_VECT* cost)
938
double io_count_sum= io_count + cost->io_count;
939
add_io(cost->io_count, cost->avg_io_cost);
940
io_count= io_count_sum;
941
cpu_cost += cost->cpu_cost;
943
void add_io(double add_io_cnt, double add_avg_cost)
945
double io_count_sum= io_count + add_io_cnt;
946
avg_io_cost= (io_count * avg_io_cost +
947
add_io_cnt * add_avg_cost) / io_count_sum;
948
io_count= io_count_sum;
952
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted,
956
The below two are not used (and not handled) in this milestone of this WL
957
entry because there seems to be no use for them at this stage of
960
#define HA_MRR_SINGLE_POINT 1
961
#define HA_MRR_FIXED_KEY 2
964
Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
967
#define HA_MRR_NO_ASSOCIATION 4
970
The MRR user will provide ranges in key order, and MRR implementation
971
must return rows in key order.
973
#define HA_MRR_SORTED 8
975
/* MRR implementation doesn't have to retrieve full records */
976
#define HA_MRR_INDEX_ONLY 16
979
The passed memory buffer is of maximum possible size, the caller can't
980
assume larger buffer.
982
#define HA_MRR_LIMITS 32
986
Flag set <=> default MRR implementation is used
987
(The choice is made by **_info[_const]() function which may set this
988
flag. SQL layer remembers the flag value and then passes it to
989
multi_read_range_init().
991
#define HA_MRR_USE_DEFAULT_IMPL 64
994
Used only as parameter to multi_range_read_info():
995
Flag set <=> the caller guarantees that the bounds of the scanned ranges
996
will not have NULL values.
998
#define HA_MRR_NO_NULL_ENDPOINTS 128
1004
uint64_t data_file_length; /* Length off data file */
1005
uint64_t max_data_file_length; /* Length off data file */
1006
uint64_t index_file_length;
1007
uint64_t max_index_file_length;
1008
uint64_t delete_length; /* Free bytes */
1009
uint64_t auto_increment_value;
1011
The number of records in the table.
1012
0 - means the table has exactly 0 rows
1013
other - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
1014
the value is the exact number of records in the table
1019
ha_rows deleted; /* Deleted records */
1020
uint32_t mean_rec_length; /* physical reclength */
1021
time_t create_time; /* When table was created */
1024
uint32_t block_size; /* index block size */
1027
data_file_length(0), max_data_file_length(0),
1028
index_file_length(0), delete_length(0), auto_increment_value(0),
1029
records(0), deleted(0), mean_rec_length(0), create_time(0),
1030
check_time(0), update_time(0), block_size(0)
95
1034
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
97
1036
bitmap with first N+1 bits set
98
1037
(keypart_map for a key prefix of [0..N] keyparts)
101
inline key_part_map make_keypart_map(T a)
103
return (((key_part_map)2 << a) - 1);
1039
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
107
1041
bitmap with first N bits set
108
1042
(keypart_map for a key prefix of [0..N-1] keyparts)
111
inline key_part_map make_prev_keypart_map(T a)
113
return (((key_part_map)1 << a) - 1);
1044
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
117
1047
The handler class is the interface for dynamically loadable
237
1168
Discrete_interval auto_inc_interval_for_cur_row;
239
handler(drizzled::plugin::StorageEngine *engine_arg, TableShare *share_arg)
1170
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
240
1171
:table_share(share_arg), table(0),
241
estimation_rows_to_insert(0), engine(engine_arg),
1172
estimation_rows_to_insert(0), ht(ht_arg),
242
1173
ref(0), in_range_check_pushed_down(false),
243
1174
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
244
1175
ref_length(sizeof(my_off_t)),
246
1177
locked(false), implicit_emptied(0),
1178
pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
247
1179
next_insert_id(0), insert_id_for_cur_row(0)
249
virtual ~handler(void);
1181
virtual ~handler(void)
1183
assert(locked == false);
1184
/* TODO: assert(inited == NONE); */
250
1186
virtual handler *clone(MEM_ROOT *mem_root);
251
1187
/** This is called after create to allow us to set up cached variables */
254
1190
cached_table_flags= table_flags();
257
1192
/* ha_ methods: pubilc wrappers for private virtual API */
259
1194
int ha_open(Table *table, const char *name, int mode, int test_if_locked);
260
int ha_index_init(uint32_t idx, bool sorted);
262
int ha_rnd_init(bool scan);
1195
int ha_index_init(uint32_t idx, bool sorted)
1198
assert(inited==NONE);
1199
if (!(result= index_init(idx, sorted)))
1206
assert(inited==INDEX);
1209
return(index_end());
1211
int ha_rnd_init(bool scan)
1214
assert(inited==NONE || (inited==RND && scan));
1215
inited= (result= rnd_init(scan)) ? NONE: RND;
1220
assert(inited==RND);
266
1225
/* this is necessary in many places, e.g. in HANDLER command */
267
int ha_index_or_rnd_end();
268
Table_flags ha_table_flags() const;
1226
int ha_index_or_rnd_end()
1228
return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
1230
Table_flags ha_table_flags() const { return cached_table_flags; }
271
1232
These functions represent the public interface to *users* of the
272
1233
handler class, hence they are *not* virtual. For the inheritance
273
1234
interface, see the (private) functions write_row(), update_row(),
274
1235
and delete_row() below.
276
int ha_external_lock(Session *session, int lock_type);
1237
int ha_external_lock(THD *thd, int lock_type);
277
1238
int ha_write_row(unsigned char * buf);
278
1239
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
279
1240
int ha_delete_row(const unsigned char * buf);
280
1241
void ha_release_auto_increment();
1243
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
282
1244
/** to be actually called to get 'check()' functionality*/
283
int ha_check(Session *session, HA_CHECK_OPT *check_opt);
285
void ha_start_bulk_insert(ha_rows rows);
286
int ha_end_bulk_insert();
1245
int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
1246
int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
1247
void ha_start_bulk_insert(ha_rows rows)
1249
estimation_rows_to_insert= rows;
1250
start_bulk_insert(rows);
1252
int ha_end_bulk_insert()
1254
estimation_rows_to_insert= 0;
1255
return end_bulk_insert();
287
1257
int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
288
1258
uint32_t *dup_key_found);
289
1259
int ha_delete_all_rows();
290
1260
int ha_reset_auto_increment(uint64_t value);
291
int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
292
int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
1261
int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
1262
int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
1263
bool ha_check_and_repair(THD *thd);
294
1264
int ha_disable_indexes(uint32_t mode);
295
1265
int ha_enable_indexes(uint32_t mode);
296
1266
int ha_discard_or_import_tablespace(bool discard);
1267
void ha_prepare_for_alter();
1268
int ha_rename_table(const char *from, const char *to);
1269
int ha_delete_table(const char *name);
297
1270
void ha_drop_table(const char *name);
1272
int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
1274
int ha_create_handler_files(const char *name, const char *old_name,
1275
int action_flag, HA_CREATE_INFO *info);
299
1277
void adjust_next_insert_id_after_explicit_value(uint64_t nr);
300
1278
int update_auto_increment();
301
1279
void print_keydup_error(uint32_t key_nr, const char *msg);
302
1280
virtual void print_error(int error, myf errflag);
303
1281
virtual bool get_error_message(int error, String *buf);
304
1282
uint32_t get_dup_key(int error);
305
virtual void change_table_ptr(Table *table_arg, TableShare *share);
1283
virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share)
307
1288
/* Estimates calculation */
308
1289
virtual double scan_time(void)
309
1290
{ return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
310
virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
1291
virtual double read_time(uint32_t index __attribute__((unused)),
1292
uint32_t ranges, ha_rows rows)
311
1293
{ return rows2double(ranges+rows); }
313
1295
virtual double index_only_read_time(uint32_t keynr, double records);
315
1297
virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
316
void *seq_init_param,
1298
void *seq_init_param,
317
1299
uint32_t n_ranges, uint32_t *bufsz,
318
1300
uint32_t *flags, COST_VECT *cost);
319
1301
virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
774
2061
is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
775
2062
returned by storage engines that don't support this operation.
777
virtual int reset_auto_increment(uint64_t)
778
{ return HA_ERR_WRONG_COMMAND; }
779
virtual int optimize(Session *, HA_CHECK_OPT *)
780
{ return HA_ADMIN_NOT_IMPLEMENTED; }
781
virtual int analyze(Session *, HA_CHECK_OPT *)
782
{ return HA_ADMIN_NOT_IMPLEMENTED; }
784
virtual int disable_indexes(uint32_t)
785
{ return HA_ERR_WRONG_COMMAND; }
786
virtual int enable_indexes(uint32_t)
787
{ return HA_ERR_WRONG_COMMAND; }
788
virtual int discard_or_import_tablespace(bool)
2064
virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
2065
{ return HA_ERR_WRONG_COMMAND; }
2066
virtual int optimize(THD* thd __attribute__((unused)),
2067
HA_CHECK_OPT* check_opt __attribute__((unused)))
2068
{ return HA_ADMIN_NOT_IMPLEMENTED; }
2069
virtual int analyze(THD* thd __attribute__((unused)),
2070
HA_CHECK_OPT* check_opt __attribute__((unused)))
2071
{ return HA_ADMIN_NOT_IMPLEMENTED; }
2072
virtual bool check_and_repair(THD *thd __attribute__((unused)))
2074
virtual int disable_indexes(uint32_t mode __attribute__((unused)))
2075
{ return HA_ERR_WRONG_COMMAND; }
2076
virtual int enable_indexes(uint32_t mode __attribute__((unused)))
2077
{ return HA_ERR_WRONG_COMMAND; }
2078
virtual int discard_or_import_tablespace(bool discard __attribute__((unused)))
789
2079
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
2080
virtual void prepare_for_alter(void) { return; }
790
2081
virtual void drop_table(const char *name);
2082
virtual int create(const char *name __attribute__((unused)),
2083
Table *form __attribute__((unused)),
2084
HA_CREATE_INFO *info __attribute__((unused)))=0;
2086
virtual int create_handler_files(const char *name __attribute__((unused)),
2087
const char *old_name __attribute__((unused)),
2088
int action_flag __attribute__((unused)),
2089
HA_CREATE_INFO *info __attribute__((unused)))
2096
A Disk-Sweep MRR interface implementation
2098
This implementation makes range (and, in the future, 'ref') scans to read
2099
table rows in disk sweeps.
2101
Currently it is used by MyISAM and InnoDB. Potentially it can be used with
2102
any table handler that has non-clustered indexes and on-disk rows.
2108
typedef void (handler::*range_check_toggle_func_t)(bool on);
2113
handler *h; /* The "owner" handler object. It is used for scanning the index */
2114
Table *table; /* Always equal to h->table */
2117
Secondary handler object. It is used to retrieve full table rows by
2122
/* Buffer to store rowids, or (rowid, range_id) pairs */
2123
unsigned char *rowids_buf;
2124
unsigned char *rowids_buf_cur; /* Current position when reading/writing */
2125
unsigned char *rowids_buf_last; /* When reading: end of used buffer space */
2126
unsigned char *rowids_buf_end; /* End of the buffer */
2128
bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
2130
/* true <=> need range association, buffer holds {rowid, range_id} pairs */
2133
bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
2135
void init(handler *h_arg, Table *table_arg)
2140
int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
2141
void *seq_init_param, uint32_t n_ranges, uint32_t mode,
2142
HANDLER_BUFFER *buf);
2144
int dsmrr_fill_buffer(handler *h);
2145
int dsmrr_next(handler *h, char **range_info);
2147
int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
2148
uint32_t *flags, COST_VECT *cost);
2150
ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
2151
void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
2152
uint32_t *flags, COST_VECT *cost);
2154
bool key_uses_partial_cols(uint32_t keyno);
2155
bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz,
2157
bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
2158
uint32_t *buffer_size, COST_VECT *cost);
793
2161
extern const char *ha_row_type[];
794
2162
extern const char *tx_isolation_names[];
795
2163
extern const char *binlog_format_names[];
796
2164
extern TYPELIB tx_isolation_typelib;
2165
extern TYPELIB myisam_stats_method_typelib;
797
2166
extern uint32_t total_ha, total_ha_2pc;
799
2168
/* Wrapper functions */
800
#define ha_commit(session) (ha_commit_trans((session), true))
801
#define ha_rollback(session) (ha_rollback_trans((session), true))
2169
#define ha_commit(thd) (ha_commit_trans((thd), true))
2170
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
2173
handlerton *ha_default_handlerton(THD *thd);
2174
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
2175
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
2176
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
2177
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
2178
handlerton *db_type);
2179
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
2180
bool no_substitute, bool report_error);
2183
static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type)
2185
return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
2188
static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type)
2190
return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
2193
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32_t flag)
2195
return db_type == NULL ? false : test(db_type->flags & flag);
2198
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
2200
return (db_type && db_type->create) ?
2201
(db_type->state == SHOW_OPTION_YES) : false;
803
2204
/* basic stuff */
804
2205
int ha_init_errors(void);
805
2206
int ha_init(void);
806
2207
int ha_end(void);
808
void add_storage_engine(drizzled::plugin::StorageEngine *engine);
809
void remove_storage_engine(drizzled::plugin::StorageEngine *engine);
811
int ha_create_table(Session *session, const char *path,
2208
int ha_initialize_handlerton(st_plugin_int *plugin);
2209
int ha_finalize_handlerton(st_plugin_int *plugin);
2211
TYPELIB *ha_known_exts(void);
2212
void ha_close_connection(THD* thd);
2213
bool ha_flush_logs(handlerton *db_type);
2214
void ha_drop_database(char* path);
2215
int ha_create_table(THD *thd, const char *path,
812
2216
const char *db, const char *table_name,
813
2217
HA_CREATE_INFO *create_info,
814
bool update_create_info,
815
drizzled::message::Table *table_proto);
2218
bool update_create_info);
2219
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
2220
const char *db, const char *alias, bool generate_warning);
817
2222
/* statistics and info */
818
bool ha_show_status(Session *session, drizzled::plugin::StorageEngine *db_type, enum ha_stat_type stat);
2223
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
820
int ha_find_files(Session *session,const char *db,const char *path,
2226
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
2227
int ha_discover(THD* thd, const char* dbname, const char* name,
2228
unsigned char** frmblob, size_t* frmlen);
2229
int ha_find_files(THD *thd,const char *db,const char *path,
821
2230
const char *wild, bool dir, List<LEX_STRING>* files);
823
/* transactions: interface to plugin::StorageEngine functions */
824
int ha_commit_one_phase(Session *session, bool all);
825
int ha_rollback_trans(Session *session, bool all);
827
/* transactions: these functions never call plugin::StorageEngine functions directly */
828
int ha_commit_trans(Session *session, bool all);
829
int ha_autocommit_or_rollback(Session *session, int error);
830
int ha_enable_transaction(Session *session, bool on);
2231
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
2234
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
2235
int ha_resize_key_cache(KEY_CACHE *key_cache);
2236
int ha_change_key_cache_param(KEY_CACHE *key_cache);
2237
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
2238
int ha_end_key_cache(KEY_CACHE *key_cache);
2240
/* report to InnoDB that control passes to the client */
2241
int ha_release_temporary_latches(THD *thd);
2243
/* transactions: interface to handlerton functions */
2244
int ha_start_consistent_snapshot(THD *thd);
2245
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
2246
int ha_commit_one_phase(THD *thd, bool all);
2247
int ha_rollback_trans(THD *thd, bool all);
2248
int ha_prepare(THD *thd);
2249
int ha_recover(HASH *commit_list);
2251
/* transactions: these functions never call handlerton functions directly */
2252
int ha_commit_trans(THD *thd, bool all);
2253
int ha_autocommit_or_rollback(THD *thd, int error);
2254
int ha_enable_transaction(THD *thd, bool on);
832
2256
/* savepoints */
833
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
834
int ha_savepoint(Session *session, SAVEPOINT *sv);
835
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
2257
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
2258
int ha_savepoint(THD *thd, SAVEPOINT *sv);
2259
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
837
2261
/* these are called by storage engines */
838
void trans_register_ha(Session *session, bool all, drizzled::plugin::StorageEngine *engine);
840
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
841
bool tablename_to_filename(const char *from, char *to, size_t to_length);
2262
void trans_register_ha(THD *thd, bool all, handlerton *ht);
845
2265
Storage engine has to assume the transaction will end up with 2pc if
846
2266
- there is more than one 2pc-capable storage engine available
847
2267
- in the current transaction 2pc was not disabled yet
849
#define trans_need_2pc(session, all) ((total_ha_2pc > 1) && \
850
!((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
853
bool mysql_xa_recover(Session *session);
855
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
856
SORT_FIELD *sortorder);
857
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
858
List<Item> &fields, List <Item> &all_fields, order_st *order);
859
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
860
List<Item> &fields, List<Item> &all_fields, order_st *order,
861
bool *hidden_group_fields);
862
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
863
Item **ref_pointer_array);
865
bool handle_select(Session *session, LEX *lex, select_result *result,
866
uint64_t setup_tables_done_option);
867
bool mysql_select(Session *session, Item ***rref_pointer_array,
868
TableList *tables, uint32_t wild_num, List<Item> &list,
869
COND *conds, uint32_t og_num, order_st *order, order_st *group,
870
Item *having, uint64_t select_type,
871
select_result *result, Select_Lex_Unit *unit,
872
Select_Lex *select_lex);
873
void free_underlaid_joins(Session *session, Select_Lex *select);
874
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
875
select_result *result);
876
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
877
select_result *result);
879
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
882
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
883
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
884
void sp_prepare_create_field(Session *session, CreateField *sql_field);
885
int prepare_create_field(CreateField *sql_field,
886
uint32_t *blob_columns,
887
int *timestamps, int *timestamps_with_niladic,
888
int64_t table_flags);
889
bool mysql_create_table(Session *session,const char *db, const char *table_name,
890
HA_CREATE_INFO *create_info,
891
drizzled::message::Table *table_proto,
892
AlterInfo *alter_info,
893
bool tmp_table, uint32_t select_field_count);
894
bool mysql_create_table_no_lock(Session *session, const char *db,
895
const char *table_name,
896
HA_CREATE_INFO *create_info,
897
drizzled::message::Table *table_proto,
898
AlterInfo *alter_info,
899
bool tmp_table, uint32_t select_field_count);
901
bool mysql_recreate_table(Session *session, TableList *table_list);
902
bool mysql_create_like_table(Session *session, TableList *table,
903
TableList *src_table,
904
HA_CREATE_INFO *create_info);
905
bool mysql_rename_table(drizzled::plugin::StorageEngine *base, const char *old_db,
906
const char * old_name, const char *new_db,
907
const char * new_name, uint32_t flags);
908
bool mysql_prepare_update(Session *session, TableList *table_list,
909
Item **conds, uint32_t order_num, order_st *order);
910
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
911
List<Item> &values,COND *conds,
912
uint32_t order_num, order_st *order, ha_rows limit,
913
enum enum_duplicates handle_duplicates, bool ignore);
914
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
915
List<Item> &fields, List_item *values,
916
List<Item> &update_fields,
917
List<Item> &update_values, enum_duplicates duplic,
918
COND **where, bool select_insert,
919
bool check_fields, bool abort_on_warning);
920
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
921
List<List_item> &values, List<Item> &update_fields,
922
List<Item> &update_values, enum_duplicates flag,
924
int check_that_all_fields_are_given_values(Session *session, Table *entry,
925
TableList *table_list);
926
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
927
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
928
SQL_LIST *order, ha_rows rows, uint64_t options,
929
bool reset_auto_increment);
930
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
931
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
932
uint32_t key_length, uint32_t db_flags, int *error);
933
TableShare *get_cached_table_share(const char *db, const char *table_name);
934
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
935
Table *table_cache_insert_placeholder(Session *session, const char *key,
936
uint32_t key_length);
937
bool lock_table_name_if_not_cached(Session *session, const char *db,
938
const char *table_name, Table **table);
939
bool reopen_table(Table *table);
940
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
941
void close_data_files_and_morph_locks(Session *session, const char *db,
942
const char *table_name);
943
void close_handle_and_leave_table_as_lock(Table *table);
944
bool wait_for_tables(Session *session);
945
bool table_is_used(Table *table, bool wait_for_name_lock);
946
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
947
void abort_locked_tables(Session *session,const char *db, const char *table_name);
948
extern Field *not_found_field;
949
extern Field *view_ref_found;
952
find_field_in_tables(Session *session, Item_ident *item,
953
TableList *first_table, TableList *last_table,
954
Item **ref, find_item_error_report_type report_error,
955
bool register_tree_change);
957
find_field_in_table_ref(Session *session, TableList *table_list,
958
const char *name, uint32_t length,
959
const char *item_name, const char *db_name,
960
const char *table_name, Item **ref,
962
uint32_t *cached_field_index_ptr,
963
bool register_tree_change, TableList **actual_table);
965
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
966
bool allow_rowid, uint32_t *cached_field_index_ptr);
968
find_field_in_table_sef(Table *table, const char *name);
971
#endif /* DRIZZLED_HANDLER_H */
2269
#define trans_need_2pc(thd, all) ((total_ha_2pc > 1) && \
2270
!((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))