1
/*****************************************************************************
3
Copyright (c) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
20
This file is based on ha_berkeley.h of MySQL distribution
22
This file defines the Innodb handler: the interface between MySQL and
26
#ifndef INNODB_HANDLER_HA_INNODB_H
27
#define INNODB_HANDLER_HA_INNODB_H
29
#include <drizzled/handler.h>
30
#include <mysys/thr_lock.h>
32
#ifdef USE_PRAGMA_INTERFACE
33
#pragma interface /* gcc class implementation */
36
typedef struct st_innobase_share {
38
pthread_mutex_t mutex;
39
const char* table_name;
41
void* table_name_hash;
45
struct dict_index_struct;
46
struct row_prebuilt_struct;
48
typedef struct dict_index_struct dict_index_t;
49
typedef struct row_prebuilt_struct row_prebuilt_t;
51
/* The class defining a handle to an Innodb table */
52
class ha_innobase: public handler
54
row_prebuilt_t* prebuilt; /* prebuilt struct in InnoDB, used
55
to save CPU time with prebuilt data
57
Session* user_session; /* the thread handle of the user
58
currently using the handle; this is
59
set in external_lock function */
61
INNOBASE_SHARE *share;
63
unsigned char* upd_buff; /* buffer used in updates */
64
unsigned char* key_val_buff; /* buffer used in converting
65
search key values from MySQL format
67
ulong upd_and_key_val_buff_len;
68
/* the length of each of the previous
70
Table_flags int_table_flags;
72
ulong start_of_scan; /* this is set to 1 when we are
73
starting a table scan but have not
74
yet fetched any row, else 0 */
75
uint last_match_mode;/* match mode of the latest search:
76
ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
78
uint num_write_row; /* number of write_row() calls */
80
uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
81
const unsigned char* record);
82
void update_session(Session* session);
83
void update_session();
84
int change_active_index(uint32_t keynr);
85
int general_fetch(unsigned char* buf, uint32_t direction, uint32_t match_mode);
86
ulint innobase_lock_autoinc();
87
uint64_t innobase_peek_autoinc();
88
ulint innobase_set_max_autoinc(uint64_t auto_inc);
89
ulint innobase_reset_autoinc(uint64_t auto_inc);
90
ulint innobase_get_autoinc(uint64_t* value);
91
ulint innobase_update_autoinc(uint64_t auto_inc);
92
ulint innobase_initialize_autoinc();
93
dict_index_t* innobase_get_index(uint keynr);
94
uint64_t innobase_get_int_col_max_value(const Field* field);
96
/* Init values for the class: */
98
ha_innobase(StorageEngine *engine, TableShare *table_arg);
101
Get the row type from the storage engine. If this method returns
102
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
104
enum row_type get_row_type() const;
106
const char* index_type(uint key_number);
107
Table_flags table_flags() const;
108
uint32_t index_flags(uint idx, uint part, bool all_parts) const;
109
uint32_t max_supported_keys() const;
110
uint32_t max_supported_key_length() const;
111
uint32_t max_supported_key_part_length() const;
112
const key_map* keys_to_use_for_scanning();
114
int open(const char *name, int mode, uint test_if_locked);
117
double read_time(uint index, uint ranges, ha_rows rows);
119
int write_row(unsigned char * buf);
120
int update_row(const unsigned char * old_data, unsigned char * new_data);
121
int delete_row(const unsigned char * buf);
122
bool was_semi_consistent_read();
123
void try_semi_consistent_read(bool yes);
126
#ifdef ROW_MERGE_IS_INDEX_USABLE
127
/** Check if an index can be used by this transaction.
128
* @param keynr key number to check
129
* @return true if available, false if the index
130
* does not contain old records that exist
131
* in the read view of this transaction */
132
bool is_index_available(uint keynr);
133
#endif /* ROW_MERGE_IS_INDEX_USABLE */
134
int index_init(uint index, bool sorted);
136
int index_read(unsigned char * buf, const unsigned char * key,
137
uint key_len, enum ha_rkey_function find_flag);
138
int index_read_idx(unsigned char * buf, uint index, const unsigned char * key,
139
uint key_len, enum ha_rkey_function find_flag);
140
int index_read_last(unsigned char * buf, const unsigned char * key, uint key_len);
141
int index_next(unsigned char * buf);
142
int index_next_same(unsigned char * buf, const unsigned char *key, uint keylen);
143
int index_prev(unsigned char * buf);
144
int index_first(unsigned char * buf);
145
int index_last(unsigned char * buf);
147
int rnd_init(bool scan);
149
int rnd_next(unsigned char *buf);
150
int rnd_pos(unsigned char * buf, unsigned char *pos);
152
void position(const unsigned char *record);
154
int analyze(Session* session,HA_CHECK_OPT* check_opt);
155
int optimize(Session* session,HA_CHECK_OPT* check_opt);
156
int discard_or_import_tablespace(bool discard);
157
int extra(enum ha_extra_function operation);
159
int external_lock(Session *session, int lock_type);
160
int start_stmt(Session *session, thr_lock_type lock_type);
161
void position(unsigned char *record);
162
ha_rows records_in_range(uint inx, key_range *min_key, key_range
164
ha_rows estimate_rows_upper_bound();
166
void update_create_info(HA_CREATE_INFO* create_info);
167
int delete_all_rows();
168
int check(Session* session, HA_CHECK_OPT* check_opt);
169
char* update_table_comment(const char* comment);
170
char* get_foreign_key_create_info();
171
int get_foreign_key_list(Session *session, List<FOREIGN_KEY_INFO> *f_key_list);
172
bool can_switch_engines();
173
uint referenced_by_foreign_key();
174
void free_foreign_key_create_info(char* str);
175
THR_LOCK_DATA **store_lock(Session *session, THR_LOCK_DATA **to,
176
enum thr_lock_type lock_type);
177
void init_table_handle_for_HANDLER();
178
virtual void get_auto_increment(uint64_t offset, uint64_t increment,
179
uint64_t nb_desired_values,
180
uint64_t *first_value,
181
uint64_t *nb_reserved_values);
182
int reset_auto_increment(uint64_t value);
184
virtual bool get_error_message(int error, String *buf);
186
bool primary_key_is_clustered();
187
int cmp_ref(const unsigned char *ref1, const unsigned char *ref2);
188
/** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
189
int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
190
int prepare_drop_index(TABLE *table_arg, uint *key_num,
192
int final_drop_index(TABLE *table_arg);
196
* Multi Range Read interface
198
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
199
uint32_t n_ranges, uint32_t mode,
200
HANDLER_BUFFER *buf);
201
int multi_range_read_next(char **range_info);
202
ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
203
void *seq_init_param,
204
uint32_t n_ranges, uint32_t *bufsz,
205
uint32_t *flags, COST_VECT *cost);
206
int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
207
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
210
int read_range_first(const key_range *start_key, const key_range *end_key,
211
bool eq_range_arg, bool sorted);
212
int read_range_next();
213
Item *idx_cond_push(uint32_t keyno, Item* idx_cond);
219
struct charset_info_st *session_charset(Session *session);
220
char **session_query(Session *session);
222
/** Get the file name of the MySQL binlog.
223
* @return the name of the binlog file
225
const char* drizzle_bin_log_file_name(void);
227
/** Get the current position of the MySQL binlog.
228
* @return byte offset from the beginning of the binlog
230
uint64_t drizzle_bin_log_file_pos(void);
233
Check if a user thread is a replication slave thread
234
@param session user thread
235
@retval 0 the user thread is not a replication slave thread
236
@retval 1 the user thread is a replication slave thread
238
int session_slave_thread(const Session *session);
241
Check if a user thread is running a non-transactional update
242
@param session user thread
243
@retval 0 the user thread is not running a non-transactional update
244
@retval 1 the user thread is running a non-transactional update
246
int session_non_transactional_update(const Session *session);
249
Get the user thread's binary logging format
250
@param session user thread
251
@return Value to be used as index into the binlog_format_names array
253
int session_binlog_format(const Session *session);
256
Mark transaction to rollback and mark error as fatal to a sub-statement.
257
@param session Thread handle
258
@param all TRUE <=> rollback main transaction.
260
void session_mark_transaction_to_rollback(Session *session, bool all);
263
typedef struct trx_struct trx_t;
264
/************************************************************************
265
Converts an InnoDB error code to a MySQL error code and also tells to MySQL
266
about a possible transaction rollback inside InnoDB caused by a lock wait
267
timeout or a deadlock. */
270
convert_error_code_to_mysql(
271
/*========================*/
272
/* out: MySQL error code */
273
int error, /* in: InnoDB error code */
274
ulint flags, /* in: InnoDB table flags, or 0 */
275
Session *session); /* in: user thread handle or NULL */
277
/*************************************************************************
278
Allocates an InnoDB transaction for a MySQL handler object. */
281
innobase_trx_allocate(
282
/*==================*/
283
/* out: InnoDB transaction handle */
284
Session *session); /* in: user thread handle */
285
#endif /* INNODB_HANDLER_HA_INNODB_H */