51
52
typedef struct st_table_share TABLE_SHARE;
52
53
struct st_foreign_key_info;
53
54
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
54
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
55
const char *file, uint32_t file_len,
56
const char *status, uint32_t status_len);
57
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
58
extern st_plugin_int *hton2plugin[MAX_HA];
61
handlerton is a singleton structure - one instance per storage engine -
62
to provide access to storage engine functionality that works on the
63
"global" level (unlike handler class that works on a per-table basis)
65
usually handlerton instance is defined statically in ha_xxx.cc as
67
static handlerton { ... } xxx_hton;
69
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
74
Historical marker for if the engine is available of not
76
SHOW_COMP_OPTION state;
79
Historical number used for frm file to determine the correct storage engine.
80
This is going away and new engines will just use "name" for this.
82
enum legacy_db_type db_type;
84
each storage engine has it's own memory area (actually a pointer)
85
in the session, for storing per-connection information.
88
session->ha_data[xxx_hton.slot]
90
slot number is initialized by MySQL after xxx_init() is called.
94
to store per-savepoint data storage engine is provided with an area
95
of a requested size (0 is ok here).
96
savepoint_offset must be initialized statically to the size of
97
the needed memory to store per-savepoint information.
98
After xxx_init it is changed to be an offset to savepoint storage
99
area and need not be used by storage engine.
100
see binlog_hton and binlog_savepoint_set/rollback for an example.
102
uint32_t savepoint_offset;
106
close_connection is only called if
107
session->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
108
this storage area - set it to something, so that MySQL would know
109
this storage engine was accessed in this connection
111
int (*close_connection)(handlerton *hton, Session *session);
113
sv points to an uninitialized storage area of requested size
114
(see savepoint_offset description)
116
int (*savepoint_set)(handlerton *hton, Session *session, void *sv);
118
sv points to a storage area, that was earlier passed
119
to the savepoint_set call
121
int (*savepoint_rollback)(handlerton *hton, Session *session, void *sv);
122
int (*savepoint_release)(handlerton *hton, Session *session, void *sv);
124
'all' is true if it's a real commit, that makes persistent changes
125
'all' is false if it's not in fact a commit but an end of the
126
statement that is part of the transaction.
127
NOTE 'all' is also false in auto-commit mode where 'end of statement'
128
and 'real commit' mean the same event.
130
int (*commit)(handlerton *hton, Session *session, bool all);
131
int (*rollback)(handlerton *hton, Session *session, bool all);
132
int (*prepare)(handlerton *hton, Session *session, bool all);
133
int (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
134
int (*commit_by_xid)(handlerton *hton, XID *xid);
135
int (*rollback_by_xid)(handlerton *hton, XID *xid);
136
void *(*create_cursor_read_view)(handlerton *hton, Session *session);
137
void (*set_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
138
void (*close_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
139
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
140
void (*drop_database)(handlerton *hton, char* path);
141
int (*start_consistent_snapshot)(handlerton *hton, Session *session);
142
bool (*flush_logs)(handlerton *hton);
143
bool (*show_status)(handlerton *hton, Session *session, stat_print_fn *print, enum ha_stat_type stat);
144
int (*fill_files_table)(handlerton *hton, Session *session,
147
uint32_t flags; /* global handler flags */
148
int (*release_temporary_latches)(handlerton *hton, Session *session);
150
int (*discover)(handlerton *hton, Session* session, const char *db,
152
unsigned char **frmblob,
154
int (*table_exists_in_engine)(handlerton *hton, Session* session, const char *db,
156
uint32_t license; /* Flag for Engine License */
157
void *data; /* Location for engines to keep personal structures */
166
/* true is not all entries in the ht[] support 2pc */
168
/* storage engines that registered in this transaction */
169
Ha_trx_info *ha_list;
171
The purpose of this flag is to keep track of non-transactional
172
tables that were modified in scope of:
173
- transaction, when the variable is a member of
174
Session::transaction.all
175
- top-level statement or sub-statement, when the variable is a
176
member of Session::transaction.stmt
177
This member has the following life cycle:
178
* stmt.modified_non_trans_table is used to keep track of
179
modified non-transactional tables of top-level statements. At
180
the end of the previous statement and at the beginning of the session,
181
it is reset to false. If such functions
182
as mysql_insert, mysql_update, mysql_delete etc modify a
183
non-transactional table, they set this flag to true. At the
184
end of the statement, the value of stmt.modified_non_trans_table
185
is merged with all.modified_non_trans_table and gets reset.
186
* all.modified_non_trans_table is reset at the end of transaction
188
* Since we do not have a dedicated context for execution of a
189
sub-statement, to keep track of non-transactional changes in a
190
sub-statement, we re-use stmt.modified_non_trans_table.
191
At entrance into a sub-statement, a copy of the value of
192
stmt.modified_non_trans_table (containing the changes of the
193
outer statement) is saved on stack. Then
194
stmt.modified_non_trans_table is reset to false and the
195
substatement is executed. Then the new value is merged with the
198
bool modified_non_trans_table;
200
void reset() { no_2pc= false; modified_non_trans_table= false; }
205
Either statement transaction or normal transaction - related
206
thread-specific storage engine data.
208
If a storage engine participates in a statement/transaction,
209
an instance of this class is present in
210
session->transaction.{stmt|all}.ha_list. The addition to
211
{stmt|all}.ha_list is made by trans_register_ha().
213
When it's time to commit or rollback, each element of ha_list
214
is used to access storage engine's prepare()/commit()/rollback()
215
methods, and also to evaluate if a full two phase commit is
218
@sa General description of transaction handling in handler.cc.
224
/** Register this storage engine in the given transaction context. */
225
void register_ha(Session_TRANS *trans, handlerton *ht_arg)
227
assert(m_flags == 0);
228
assert(m_ht == NULL);
229
assert(m_next == NULL);
232
m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
234
m_next= trans->ha_list;
235
trans->ha_list= this;
238
/** Clear, prepare for reuse. */
246
Ha_trx_info() { reset(); }
248
void set_trx_read_write()
250
assert(is_started());
251
m_flags|= (int) TRX_READ_WRITE;
253
bool is_trx_read_write() const
255
assert(is_started());
256
return m_flags & (int) TRX_READ_WRITE;
258
bool is_started() const { return m_ht != NULL; }
259
/** Mark this transaction read-write if the argument is read-write. */
260
void coalesce_trx_with(const Ha_trx_info *stmt_trx)
263
Must be called only after the transaction has been started.
264
Can be called many times, e.g. when we have many
265
read-write statements in a transaction.
267
assert(is_started());
268
if (stmt_trx->is_trx_read_write())
269
set_trx_read_write();
271
Ha_trx_info *next() const
273
assert(is_started());
276
handlerton *ht() const
278
assert(is_started());
282
enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
283
/** Auxiliary, used for ha_list management */
286
Although a given Ha_trx_info instance is currently always used
287
for the same storage engine, 'ht' is not-NULL only when the
288
corresponding storage is a part of a transaction.
292
Transaction flags related to this engine.
293
Not-null only if this instance is a part of transaction.
294
May assume a combination of enum values above.
296
unsigned char m_flags;
300
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
301
ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
304
uint64_t data_file_length;
305
uint64_t max_data_file_length;
306
uint64_t index_file_length;
307
uint64_t delete_length;
309
uint32_t mean_rec_length;
317
57
struct st_table_log_memory_entry;
320
typedef struct st_ha_create_information
322
const CHARSET_INFO *table_charset, *default_table_charset;
323
LEX_STRING connect_string;
325
const char *data_file_name, *index_file_name;
327
uint64_t max_rows,min_rows;
328
uint64_t auto_increment_value;
329
uint32_t table_options;
330
uint32_t avg_row_length;
331
uint32_t used_fields;
332
uint32_t key_block_size;
335
enum row_type row_type;
336
uint32_t null_bits; /* NULL bits at start of record */
337
uint32_t options; /* OR of HA_CREATE_ options */
338
uint32_t extra_size; /* length of extra data segment */
339
bool table_existed; /* 1 in create if table existed */
340
bool frm_only; /* 1 if no ha_create_table() */
341
bool varchar; /* 1 if table has a VARCHAR */
342
enum ha_choice page_checksum; /* If we have page_checksums */
345
typedef struct st_ha_alter_information
347
KEY *key_info_buffer;
349
uint32_t index_drop_count;
350
uint32_t *index_drop_buffer;
351
uint32_t index_add_count;
352
uint32_t *index_add_buffer;
357
typedef struct st_key_create_information
359
enum ha_key_alg algorithm;
361
LEX_STRING parser_name;
367
Class for maintaining hooks used inside operations on tables such
368
as: create table functions, delete table functions, and alter table
371
Class is using the Template Method pattern to separate the public
372
usage interface from the private inheritance interface. This
373
imposes no overhead, since the public non-virtual function is small
374
enough to be inlined.
376
The hooks are usually used for functions that does several things,
377
e.g., create_table_from_items(), which both create a table and lock
384
virtual ~TABLEOP_HOOKS() {}
386
inline void prelock(Table **tables, uint32_t count)
388
do_prelock(tables, count);
391
inline int postlock(Table **tables, uint32_t count)
393
return do_postlock(tables, count);
396
/* Function primitive that is called prior to locking tables */
397
virtual void do_prelock(Table **tables __attribute__((unused)),
398
uint32_t count __attribute__((unused)))
400
/* Default is to do nothing */
404
Primitive called after tables are locked.
406
If an error is returned, the tables will be unlocked and error
409
@return Error code or zero.
411
virtual int do_postlock(Table **tables __attribute__((unused)),
412
uint32_t count __attribute__((unused)))
414
return 0; /* Default is to do nothing */
418
59
typedef struct st_savepoint SAVEPOINT;
419
60
extern uint32_t savepoint_alloc_size;
420
61
extern KEY_CREATE_INFO default_key_create_info;
422
63
/* Forward declaration for condition pushdown to storage engine */
423
64
typedef class Item COND;
425
typedef struct st_ha_check_opt
427
st_ha_check_opt() {} /* Remove gcc warning */
428
uint32_t sort_buffer_size;
429
uint32_t flags; /* isam layer flags (e.g. for myisamchk) */
430
uint32_t sql_flags; /* sql layer flags - for something myisamchk cannot do */
431
KEY_CACHE *key_cache; /* new key cache when changing key cache */
438
This is a buffer area that the handler can use to store rows.
439
'end_of_used_area' should be kept updated after calls to
440
read-functions so that other parts of the code can use the
441
remaining area (until next read calls is issued).
444
typedef struct st_handler_buffer
446
unsigned char *buffer; /* Buffer one can start using */
447
unsigned char *buffer_end; /* End of buffer */
448
unsigned char *end_of_used_area; /* End of area that was used by handler */
451
66
typedef struct system_status_var SSV;
454
typedef void *range_seq_t;
456
typedef struct st_range_seq_if
459
Initialize the traversal of range sequence
463
init_params The seq_init_param parameter
464
n_ranges The number of ranges obtained
465
flags A combination of HA_MRR_SINGLE_POINT, HA_MRR_FIXED_KEY
468
An opaque value to be used as RANGE_SEQ_IF::next() parameter
470
range_seq_t (*init)(void *init_params, uint32_t n_ranges, uint32_t flags);
474
Get the next range in the range sequence
478
seq The value returned by RANGE_SEQ_IF::init()
479
range OUT Information about the next range
482
0 - Ok, the range structure filled with info about the next range
485
uint32_t (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
488
71
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
489
72
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
494
double io_count; /* number of I/O */
495
double avg_io_cost; /* cost of an average I/O oper. */
496
double cpu_cost; /* cost of operations in CPU */
497
double mem_cost; /* cost of used memory */
498
double import_cost; /* cost of remote operations */
501
enum { CPU_COEFF=1 };
502
enum { MEM_COEFF=1 };
503
enum { IMPORT_COEFF=1 };
505
COST_VECT() {} // keep gcc happy
509
return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
510
MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
516
io_count= cpu_cost= mem_cost= import_cost= 0.0;
519
void multiply(double m)
524
/* Don't multiply mem_cost */
527
void add(const COST_VECT* cost)
529
double io_count_sum= io_count + cost->io_count;
530
add_io(cost->io_count, cost->avg_io_cost);
531
io_count= io_count_sum;
532
cpu_cost += cost->cpu_cost;
534
void add_io(double add_io_cnt, double add_avg_cost)
536
double io_count_sum= io_count + add_io_cnt;
537
avg_io_cost= (io_count * avg_io_cost +
538
add_io_cnt * add_avg_cost) / io_count_sum;
539
io_count= io_count_sum;
543
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted,
551
uint64_t data_file_length; /* Length off data file */
552
uint64_t max_data_file_length; /* Length off data file */
553
uint64_t index_file_length;
554
uint64_t max_index_file_length;
555
uint64_t delete_length; /* Free bytes */
556
uint64_t auto_increment_value;
558
The number of records in the table.
559
0 - means the table has exactly 0 rows
560
other - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
561
the value is the exact number of records in the table
566
ha_rows deleted; /* Deleted records */
567
uint32_t mean_rec_length; /* physical reclength */
568
time_t create_time; /* When table was created */
571
uint32_t block_size; /* index block size */
574
data_file_length(0), max_data_file_length(0),
575
index_file_length(0), delete_length(0), auto_increment_value(0),
576
records(0), deleted(0), mean_rec_length(0), create_time(0),
577
check_time(0), update_time(0), block_size(0)
581
74
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
583
76
bitmap with first N+1 bits set
584
77
(keypart_map for a key prefix of [0..N] keyparts)
586
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
80
inline key_part_map make_keypart_map(T a)
82
return (((key_part_map)2 << a) - 1);
588
86
bitmap with first N bits set
589
87
(keypart_map for a key prefix of [0..N-1] keyparts)
591
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
90
inline key_part_map make_prev_keypart_map(T a)
92
return (((key_part_map)1 << a) - 1);
594
96
The handler class is the interface for dynamically loadable