17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_CURSOR_H
21
#define DRIZZLED_CURSOR_H
23
#include <drizzled/atomics.h>
24
#include <drizzled/definitions.h>
25
#include <drizzled/discrete_interval.h>
26
#include <drizzled/error_t.h>
27
#include <drizzled/ha_statistics.h>
28
#include <drizzled/handler_structs.h>
29
#include <drizzled/identifier.h>
30
#include <drizzled/key_map.h>
31
#include <drizzled/message/table.h>
32
#include <drizzled/sql_list.h>
33
#include <drizzled/thr_lock.h>
34
#include <drizzled/xid.h>
39
#include <drizzled/visibility.h>
44
#define HA_MAX_ALTER_FLAGS 40
46
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
21
/* 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
#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
51
/* Bits to show what an alter table will do */
52
#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,
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)
442
/* The handler for a table type. Will be included in the Table structure */
445
typedef struct st_table_share TABLE_SHARE;
446
struct st_foreign_key_info;
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
55
class Select_Lex_Unit;
64
typedef List<Item> List_item;
723
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 */
827
typedef struct st_savepoint SAVEPOINT;
828
extern uint32_t savepoint_alloc_size;
65
829
extern KEY_CREATE_INFO default_key_create_info;
67
831
/* Forward declaration for condition pushdown to storage engine */
68
832
typedef class Item COND;
70
typedef struct system_status_var system_status_var;
72
namespace optimizer { class CostVector; }
73
namespace plugin { class StorageEngine; }
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
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)
1034
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
76
1036
bitmap with first N+1 bits set
77
1037
(keypart_map for a key prefix of [0..N] keyparts)
80
inline key_part_map make_keypart_map(T a)
82
return (((key_part_map)2 << a) - 1);
1039
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
86
1041
bitmap with first N bits set
87
1042
(keypart_map for a key prefix of [0..N-1] keyparts)
90
inline key_part_map make_prev_keypart_map(T a)
92
return (((key_part_map)1 << a) - 1);
1044
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
96
The Cursor class is the interface for dynamically loadable
1047
The handler class is the interface for dynamically loadable
97
1048
storage engines. Do not add ifdefs and take care when adding or
98
1049
changing virtual functions to avoid vtable confusion
226
1168
Discrete_interval auto_inc_interval_for_cur_row;
228
Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
229
virtual ~Cursor(void);
230
virtual Cursor *clone(memory::Root *mem_root);
1170
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
1171
:table_share(share_arg), table(0),
1172
estimation_rows_to_insert(0), ht(ht_arg),
1173
ref(0), in_range_check_pushed_down(false),
1174
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1175
ref_length(sizeof(my_off_t)),
1177
locked(false), implicit_emptied(0),
1178
pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
1179
next_insert_id(0), insert_id_for_cur_row(0)
1181
virtual ~handler(void)
1183
assert(locked == false);
1184
/* TODO: assert(inited == NONE); */
1186
virtual handler *clone(MEM_ROOT *mem_root);
1187
/** This is called after create to allow us to set up cached variables */
1190
cached_table_flags= table_flags();
232
1192
/* ha_ methods: pubilc wrappers for private virtual API */
234
int ha_open(const identifier::Table &identifier, int mode, int test_if_locked);
235
int startIndexScan(uint32_t idx, bool sorted) __attribute__ ((warn_unused_result));
237
int startTableScan(bool scan) __attribute__ ((warn_unused_result));
1194
int ha_open(Table *table, const char *name, int mode, int test_if_locked);
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);
241
1225
/* this is necessary in many places, e.g. in HANDLER command */
242
int ha_index_or_rnd_end();
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; }
245
1232
These functions represent the public interface to *users* of the
246
Cursor class, hence they are *not* virtual. For the inheritance
247
interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
248
and doDeleteRecord() below.
1233
handler class, hence they are *not* virtual. For the inheritance
1234
interface, see the (private) functions write_row(), update_row(),
1235
and delete_row() below.
250
int ha_external_lock(Session *session, int lock_type);
251
int insertRecord(unsigned char * buf) __attribute__ ((warn_unused_result));
252
int updateRecord(const unsigned char * old_data, unsigned char * new_data) __attribute__ ((warn_unused_result));
253
int deleteRecord(const unsigned char * buf) __attribute__ ((warn_unused_result));
1237
int ha_external_lock(THD *thd, int lock_type);
1238
int ha_write_row(unsigned char * buf);
1239
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
1240
int ha_delete_row(const unsigned char * buf);
254
1241
void ha_release_auto_increment();
1243
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
256
1244
/** to be actually called to get 'check()' functionality*/
257
int ha_check(Session *session, HA_CHECK_OPT *check_opt);
259
void ha_start_bulk_insert(ha_rows rows);
260
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();
1257
int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
1258
uint32_t *dup_key_found);
261
1259
int ha_delete_all_rows();
262
1260
int ha_reset_auto_increment(uint64_t value);
263
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);
265
1264
int ha_disable_indexes(uint32_t mode);
266
1265
int ha_enable_indexes(uint32_t mode);
267
1266
int ha_discard_or_import_tablespace(bool discard);
268
void closeMarkForDelete(const char *name);
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);
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);
270
1277
void adjust_next_insert_id_after_explicit_value(uint64_t nr);
271
1278
int update_auto_increment();
1279
void print_keydup_error(uint32_t key_nr, const char *msg);
1280
virtual void print_error(int error, myf errflag);
1281
virtual bool get_error_message(int error, String *buf);
1282
uint32_t get_dup_key(int error);
1283
virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share)
273
1288
/* Estimates calculation */
274
1289
virtual double scan_time(void)
275
{ return static_cast<double>(stats.data_file_length) / IO_SIZE + 2; }
276
virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
277
{ return ranges + rows; }
1290
{ return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
1291
virtual double read_time(uint32_t index __attribute__((unused)),
1292
uint32_t ranges, ha_rows rows)
1293
{ return rows2double(ranges+rows); }
279
1295
virtual double index_only_read_time(uint32_t keynr, double records);
281
1297
virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
282
void *seq_init_param,
1298
void *seq_init_param,
283
1299
uint32_t n_ranges, uint32_t *bufsz,
284
uint32_t *flags, optimizer::CostVector *cost);
1300
uint32_t *flags, COST_VECT *cost);
285
1301
virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
286
uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
1302
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
287
1303
virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
288
uint32_t n_ranges, uint32_t mode);
1304
uint32_t n_ranges, uint32_t mode,
1305
HANDLER_BUFFER *buf);
289
1306
virtual int multi_range_read_next(char **range_info);
292
virtual const key_map *keys_to_use_for_scanning();
293
bool has_transactions();
1309
virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
1310
bool has_transactions()
1311
{ return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
1312
virtual uint32_t extra_rec_buf_length() const { return 0; }
296
1315
This method is used to analyse the error to see whether the error
297
1316
is ignorable or not, certain handlers can have more error that are
298
ignorable than others. E.g. the partition Cursor can get inserts
1317
ignorable than others. E.g. the partition handler can get inserts
299
1318
into a range where there is no partition and this is an ignorable
301
1320
HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
302
1321
same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
303
1322
a slightly different error message.
305
virtual bool is_fatal_error(int error, uint32_t flags);
1324
virtual bool is_fatal_error(int error, uint32_t flags)
1327
((flags & HA_CHECK_DUP_KEY) &&
1328
(error == HA_ERR_FOUND_DUPP_KEY ||
1329
error == HA_ERR_FOUND_DUPP_UNIQUE)))
308
1335
Number of rows in table. It will only be called if
309
1336
(table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
311
virtual ha_rows records();
312
virtual uint64_t tableSize();
313
virtual uint64_t rowSize();
1338
virtual ha_rows records() { return stats.records; }
315
1340
Return upper bound of current number of records in the table
316
1341
(max. of how many records one will retrieve when doing a full table scan)
580
1994
@return non-0 in case of failure, 0 in case of success.
581
1995
When lock_type is F_UNLCK, the return value is ignored.
583
virtual int external_lock(Session *, int)
1997
virtual int external_lock(THD *thd __attribute__((unused)),
1998
int lock_type __attribute__((unused)))
587
virtual void release_auto_increment(void) { return; }
2002
virtual void release_auto_increment(void) { return; };
588
2003
/** admin commands - called from mysql_admin_table */
589
virtual int check(Session *)
2004
virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
2006
virtual int check(THD* thd __attribute__((unused)),
2007
HA_CHECK_OPT* check_opt __attribute__((unused)))
590
2008
{ return HA_ADMIN_NOT_IMPLEMENTED; }
592
virtual void start_bulk_insert(ha_rows)
2011
In this method check_opt can be modified
2012
to specify CHECK option to use to call check()
2015
virtual int repair(THD* thd __attribute__((unused)),
2016
HA_CHECK_OPT* check_opt __attribute__((unused)))
2017
{ return HA_ADMIN_NOT_IMPLEMENTED; }
2018
virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
594
2020
virtual int end_bulk_insert(void) { return 0; }
595
virtual int index_read(unsigned char *, const unsigned char *,
596
uint32_t, enum ha_rkey_function)
2021
virtual int index_read(unsigned char * buf __attribute__((unused)),
2022
const unsigned char * key __attribute__((unused)),
2023
uint32_t key_len __attribute__((unused)),
2024
enum ha_rkey_function find_flag __attribute__((unused)))
597
2025
{ return HA_ERR_WRONG_COMMAND; }
598
virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
599
{ return (errno= HA_ERR_WRONG_COMMAND); }
2026
virtual int index_read_last(unsigned char * buf __attribute__((unused)),
2027
const unsigned char * key __attribute__((unused)),
2028
uint32_t key_len __attribute__((unused)))
2029
{ return (my_errno= HA_ERR_WRONG_COMMAND); }
2031
This method is similar to update_row, however the handler doesn't need
2032
to execute the updates at this point in time. The handler can be certain
2033
that another call to bulk_update_row will occur OR a call to
2034
exec_bulk_update before the set of updates in this query is concluded.
2036
@param old_data Old record
2037
@param new_data New record
2038
@param dup_key_found Number of duplicate keys found
2040
@retval 0 Bulk delete used by handler
2041
@retval 1 Bulk delete not used, normal operation used
2043
virtual int bulk_update_row(const unsigned char *old_data __attribute__((unused)),
2044
unsigned char *new_data __attribute__((unused)),
2045
uint32_t *dup_key_found __attribute__((unused)))
2048
return HA_ERR_WRONG_COMMAND;
601
2051
This is called to delete all rows in a table
602
If the Cursor don't support this, then this function will
2052
If the handler don't support this, then this function will
603
2053
return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
606
2056
virtual int delete_all_rows(void)
607
{ return (errno=HA_ERR_WRONG_COMMAND); }
2057
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
609
2059
Reset the auto-increment counter to the given value, i.e. the next row
610
2060
inserted will get the given value. This is called e.g. after TRUNCATE
611
2061
is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
612
2062
returned by storage engines that don't support this operation.
614
virtual int reset_auto_increment(uint64_t)
615
{ return HA_ERR_WRONG_COMMAND; }
617
virtual int analyze(Session *)
618
{ return HA_ADMIN_NOT_IMPLEMENTED; }
620
virtual int disable_indexes(uint32_t)
621
{ return HA_ERR_WRONG_COMMAND; }
623
virtual int enable_indexes(uint32_t)
624
{ return HA_ERR_WRONG_COMMAND; }
626
virtual int discard_or_import_tablespace(bool)
627
{ return (errno=HA_ERR_WRONG_COMMAND); }
630
@todo this is just for the HEAP engine, it should
631
be removed at some point in the future (and
632
no new engine should ever use it). Right
633
now HEAP does rely on it, so we cannot remove it.
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)))
2079
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
2080
virtual void prepare_for_alter(void) { return; }
635
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);
638
2161
extern const char *ha_row_type[];
2162
extern const char *tx_isolation_names[];
2163
extern const char *binlog_format_names[];
2164
extern TYPELIB tx_isolation_typelib;
2165
extern TYPELIB myisam_stats_method_typelib;
2166
extern uint32_t total_ha, total_ha_2pc;
2168
/* Wrapper functions */
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;
640
2204
/* basic stuff */
641
void ha_init_errors(void);
644
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
645
SortField *sortorder);
646
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
647
List<Item> &fields, List <Item> &all_fields, Order *order);
648
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
649
List<Item> &fields, List<Item> &all_fields, Order *order,
650
bool *hidden_group_fields);
651
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
652
Item **ref_pointer_array);
654
bool handle_select(Session *session, LEX *lex, select_result *result,
655
uint64_t setup_tables_done_option);
656
void free_underlaid_joins(Session *session, Select_Lex *select);
658
bool handle_derived(LEX *lex, bool (*processor)(Session *session,
661
bool derived_prepare(Session *session, LEX *lex, TableList *t);
662
bool derived_filling(Session *session, LEX *lex, TableList *t);
663
int prepare_create_field(CreateField *sql_field,
664
uint32_t *blob_columns,
665
int *timestamps, int *timestamps_with_niladic);
667
bool create_table(Session *session,
668
const identifier::Table &identifier,
669
HA_CREATE_INFO *create_info,
670
message::Table &table_proto,
671
AlterInfo *alter_info,
672
bool tmp_table, uint32_t select_field_count,
673
bool is_if_not_exists);
675
bool create_table_no_lock(Session *session,
676
const identifier::Table &identifier,
677
HA_CREATE_INFO *create_info,
678
message::Table &table_proto,
679
AlterInfo *alter_info,
680
bool tmp_table, uint32_t select_field_count,
681
bool is_if_not_exists);
683
bool create_like_table(Session* session,
684
identifier::Table::const_reference destination_identifier,
685
identifier::Table::const_reference source_identifier,
686
message::Table &create_table_proto,
687
bool is_if_not_exists,
690
bool rename_table(Session &session,
691
plugin::StorageEngine *base,
692
const identifier::Table &old_identifier,
693
const identifier::Table &new_identifier);
695
bool prepare_update(Session *session, TableList *table_list,
696
Item **conds, uint32_t order_num, Order *order);
697
int update_query(Session *session,TableList *tables,List<Item> &fields,
698
List<Item> &values,COND *conds,
699
uint32_t order_num, Order *order, ha_rows limit,
700
enum enum_duplicates handle_duplicates, bool ignore);
701
bool prepare_insert(Session *session, TableList *table_list, Table *table,
702
List<Item> &fields, List_item *values,
703
List<Item> &update_fields,
704
List<Item> &update_values, enum_duplicates duplic,
705
COND **where, bool select_insert,
706
bool check_fields, bool abort_on_warning);
707
bool insert_query(Session *session,TableList *table,List<Item> &fields,
708
List<List_item> &values, List<Item> &update_fields,
709
List<Item> &update_values, enum_duplicates flag,
711
int check_that_all_fields_are_given_values(Session *session, Table *entry,
712
TableList *table_list);
713
int prepare_delete(Session *session, TableList *table_list, Item **conds);
714
bool delete_query(Session *session, TableList *table_list, COND *conds,
715
SQL_LIST *order, ha_rows rows, uint64_t options,
716
bool reset_auto_increment);
717
bool truncate(Session& session, TableList *table_list);
718
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
719
uint32_t key_length, uint32_t db_flags, int *error);
720
TableShare *get_cached_table_share(const char *db, const char *table_name);
721
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
722
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
723
void close_handle_and_leave_table_as_lock(Table *table);
724
bool wait_for_tables(Session *session);
725
bool table_is_used(Table *table, bool wait_for_name_lock);
726
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
727
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
728
extern Field *not_found_field;
729
extern Field *view_ref_found;
732
find_field_in_tables(Session *session, Item_ident *item,
733
TableList *first_table, TableList *last_table,
734
Item **ref, find_item_error_report_type report_error,
735
bool register_tree_change);
737
find_field_in_table_ref(Session *session, TableList *table_list,
738
const char *name, uint32_t length,
739
const char *item_name, const char *db_name,
740
const char *table_name, Item **ref,
742
uint32_t *cached_field_index_ptr,
743
bool register_tree_change, TableList **actual_table);
745
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
746
bool allow_rowid, uint32_t *cached_field_index_ptr);
748
} /* namespace drizzled */
750
#endif /* DRIZZLED_CURSOR_H */
2205
int ha_init_errors(void);
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,
2216
const char *db, const char *table_name,
2217
HA_CREATE_INFO *create_info,
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);
2222
/* statistics and info */
2223
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
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,
2230
const char *wild, bool dir, List<LEX_STRING>* files);
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);
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);
2261
/* these are called by storage engines */
2262
void trans_register_ha(THD *thd, bool all, handlerton *ht);
2265
Storage engine has to assume the transaction will end up with 2pc if
2266
- there is more than one 2pc-capable storage engine available
2267
- 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))