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>
21
26
/* 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
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
29
#include <mysys/thr_lock.h>
30
#include <mysys/hash.h>
31
#include <drizzled/sql_string.h>
32
#include <drizzled/sql_list.h>
33
#include <drizzled/plugin/storage_engine.h>
34
#include <drizzled/handler_structs.h>
35
#include <drizzled/ha_statistics.h>
51
37
/* Bits to show what an alter table will do */
52
38
#include <drizzled/sql_bitmap.h>
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,
42
#define HA_MAX_ALTER_FLAGS 40
43
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
46
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
358
47
uint32_t key_length,
359
48
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)
442
51
/* The handler for a table type. Will be included in the Table structure */
445
typedef struct st_table_share TABLE_SHARE;
56
class Select_Lex_Unit;
446
57
struct st_foreign_key_info;
447
58
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
723
62
struct st_table_log_memory_entry;
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 */
71
typedef struct st_sort_field SORT_FIELD;
73
typedef List<Item> List_item;
827
75
typedef struct st_savepoint SAVEPOINT;
828
76
extern uint32_t savepoint_alloc_size;
831
79
/* Forward declaration for condition pushdown to storage engine */
832
80
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 */
860
82
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
86
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
898
87
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)
1034
89
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
1036
91
bitmap with first N+1 bits set
1037
92
(keypart_map for a key prefix of [0..N] keyparts)
1039
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
95
inline key_part_map make_keypart_map(T a)
97
return (((key_part_map)2 << a) - 1);
1041
101
bitmap with first N bits set
1042
102
(keypart_map for a key prefix of [0..N-1] keyparts)
1044
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
105
inline key_part_map make_prev_keypart_map(T a)
107
return (((key_part_map)1 << a) - 1);
1047
111
The handler class is the interface for dynamically loadable
2238
1157
int ha_end_key_cache(KEY_CACHE *key_cache);
2240
1159
/* report to InnoDB that control passes to the client */
2241
int ha_release_temporary_latches(THD *thd);
1160
int ha_release_temporary_latches(Session *session);
2243
/* transactions: interface to handlerton functions */
2244
int ha_start_consistent_snapshot(THD *thd);
1162
/* transactions: interface to StorageEngine functions */
1163
int ha_start_consistent_snapshot(Session *session);
2245
1164
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);
1165
int ha_commit_one_phase(Session *session, bool all);
1166
int ha_rollback_trans(Session *session, bool all);
1167
int ha_prepare(Session *session);
2249
1168
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);
1170
/* transactions: these functions never call StorageEngine functions directly */
1171
int ha_commit_trans(Session *session, bool all);
1172
int ha_autocommit_or_rollback(Session *session, int error);
1173
int ha_enable_transaction(Session *session, bool on);
2256
1175
/* savepoints */
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);
1176
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
1177
int ha_savepoint(Session *session, SAVEPOINT *sv);
1178
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
2261
1180
/* these are called by storage engines */
2262
void trans_register_ha(THD *thd, bool all, handlerton *ht);
1181
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
1183
void table_case_convert(char * name, uint32_t length);
1184
const char *table_case_name(HA_CREATE_INFO *info, const char *name);
1186
extern ulong specialflag;
1187
extern uint32_t lower_case_table_names;
1188
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
1189
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
1192
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
1193
bool mysql_ha_close(Session *session, TableList *tables);
1194
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
1195
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1196
void mysql_ha_flush(Session *session);
1197
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
1198
void mysql_ha_cleanup(Session *session);
2265
1201
Storage engine has to assume the transaction will end up with 2pc if
2266
1202
- there is more than one 2pc-capable storage engine available
2267
1203
- in the current transaction 2pc was not disabled yet
2269
#define trans_need_2pc(thd, all) ((total_ha_2pc > 1) && \
2270
!((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
1205
#define trans_need_2pc(session, all) ((total_ha_2pc > 1) && \
1206
!((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
1209
bool mysql_xa_recover(Session *session);
1211
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
1212
SORT_FIELD *sortorder);
1213
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
1214
List<Item> &fields, List <Item> &all_fields, order_st *order);
1215
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
1216
List<Item> &fields, List<Item> &all_fields, order_st *order,
1217
bool *hidden_group_fields);
1218
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
1219
Item **ref_pointer_array);
1221
bool handle_select(Session *session, LEX *lex, select_result *result,
1222
uint64_t setup_tables_done_option);
1223
bool mysql_select(Session *session, Item ***rref_pointer_array,
1224
TableList *tables, uint32_t wild_num, List<Item> &list,
1225
COND *conds, uint32_t og_num, order_st *order, order_st *group,
1226
Item *having, uint64_t select_type,
1227
select_result *result, Select_Lex_Unit *unit,
1228
Select_Lex *select_lex);
1229
void free_underlaid_joins(Session *session, Select_Lex *select);
1230
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
1231
select_result *result);
1232
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
1233
select_result *result);
1234
bool mysql_union(Session *session, LEX *lex, select_result *result,
1235
Select_Lex_Unit *unit, uint64_t setup_tables_done_option);
1236
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
1239
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
1240
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
1241
void sp_prepare_create_field(Session *session, Create_field *sql_field);
1242
int prepare_create_field(Create_field *sql_field,
1243
uint32_t *blob_columns,
1244
int *timestamps, int *timestamps_with_niladic,
1245
int64_t table_flags);
1246
bool mysql_create_table(Session *session,const char *db, const char *table_name,
1247
HA_CREATE_INFO *create_info,
1248
Alter_info *alter_info,
1249
bool tmp_table, uint32_t select_field_count);
1250
bool mysql_create_table_no_lock(Session *session, const char *db,
1251
const char *table_name,
1252
HA_CREATE_INFO *create_info,
1253
Alter_info *alter_info,
1254
bool tmp_table, uint32_t select_field_count,
1255
bool lock_open_lock);
1257
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
1258
HA_CREATE_INFO *create_info,
1259
TableList *table_list,
1260
Alter_info *alter_info,
1261
uint32_t order_num, order_st *order, bool ignore);
1262
bool mysql_recreate_table(Session *session, TableList *table_list);
1263
bool mysql_create_like_table(Session *session, TableList *table,
1264
TableList *src_table,
1265
HA_CREATE_INFO *create_info);
1266
bool mysql_rename_table(StorageEngine *base, const char *old_db,
1267
const char * old_name, const char *new_db,
1268
const char * new_name, uint32_t flags);
1269
bool mysql_prepare_update(Session *session, TableList *table_list,
1270
Item **conds, uint32_t order_num, order_st *order);
1271
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
1272
List<Item> &values,COND *conds,
1273
uint32_t order_num, order_st *order, ha_rows limit,
1274
enum enum_duplicates handle_duplicates, bool ignore);
1275
bool mysql_multi_update(Session *session, TableList *table_list,
1276
List<Item> *fields, List<Item> *values,
1277
COND *conds, uint64_t options,
1278
enum enum_duplicates handle_duplicates, bool ignore,
1279
Select_Lex_Unit *unit, Select_Lex *select_lex);
1280
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
1281
List<Item> &fields, List_item *values,
1282
List<Item> &update_fields,
1283
List<Item> &update_values, enum_duplicates duplic,
1284
COND **where, bool select_insert,
1285
bool check_fields, bool abort_on_warning);
1286
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
1287
List<List_item> &values, List<Item> &update_fields,
1288
List<Item> &update_values, enum_duplicates flag,
1290
int check_that_all_fields_are_given_values(Session *session, Table *entry,
1291
TableList *table_list);
1292
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
1293
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
1294
SQL_LIST *order, ha_rows rows, uint64_t options,
1295
bool reset_auto_increment);
1296
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
1297
uint32_t create_table_def_key(Session *session, char *key, TableList *table_list,
1299
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
1300
uint32_t key_length, uint32_t db_flags, int *error);
1301
void release_table_share(TABLE_SHARE *share, enum release_type type);
1302
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
1303
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update,
1304
uint32_t lock_flags);
1305
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
1306
bool name_lock_locked_table(Session *session, TableList *tables);
1307
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
1308
Table *table_cache_insert_placeholder(Session *session, const char *key,
1309
uint32_t key_length);
1310
bool lock_table_name_if_not_cached(Session *session, const char *db,
1311
const char *table_name, Table **table);
1312
Table *find_locked_table(Session *session, const char *db,const char *table_name);
1313
void detach_merge_children(Table *table, bool clear_refs);
1314
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
1315
TableList *new_child_list, TableList **new_last);
1316
bool reopen_table(Table *table);
1317
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
1318
void close_data_files_and_morph_locks(Session *session, const char *db,
1319
const char *table_name);
1320
void close_handle_and_leave_table_as_lock(Table *table);
1321
bool open_new_frm(Session *session, TABLE_SHARE *share, const char *alias,
1322
uint32_t db_stat, uint32_t prgflag,
1323
uint32_t ha_open_flags, Table *outparam,
1324
TableList *table_desc, MEM_ROOT *mem_root);
1325
bool wait_for_tables(Session *session);
1326
bool table_is_used(Table *table, bool wait_for_name_lock);
1327
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
1328
void abort_locked_tables(Session *session,const char *db, const char *table_name);
1329
extern Field *not_found_field;
1330
extern Field *view_ref_found;
1333
find_field_in_tables(Session *session, Item_ident *item,
1334
TableList *first_table, TableList *last_table,
1335
Item **ref, find_item_error_report_type report_error,
1336
bool check_privileges, bool register_tree_change);
1338
find_field_in_table_ref(Session *session, TableList *table_list,
1339
const char *name, uint32_t length,
1340
const char *item_name, const char *db_name,
1341
const char *table_name, Item **ref,
1342
bool check_privileges, bool allow_rowid,
1343
uint32_t *cached_field_index_ptr,
1344
bool register_tree_change, TableList **actual_table);
1346
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
1347
bool allow_rowid, uint32_t *cached_field_index_ptr);
1349
find_field_in_table_sef(Table *table, const char *name);
1350
int update_virtual_fields_marked_for_write(Table *table,
1351
bool ignore_stored=true);
1354
#endif /* DRIZZLED_HANDLER_H */