1
/* Copyright (C) 2000-2005 MySQL AB && Innobase Oy
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
This file is based on ha_berkeley.h of MySQL distribution
19
This file defines the Innodb handler: the interface between MySQL and
23
#ifdef USE_PRAGMA_INTERFACE
24
#pragma interface /* gcc class implementation */
27
typedef struct st_innobase_share {
29
pthread_mutex_t mutex;
31
uint table_name_length,use_count;
35
struct dict_index_struct;
36
struct row_prebuilt_struct;
38
typedef struct dict_index_struct dict_index_t;
39
typedef struct row_prebuilt_struct row_prebuilt_t;
41
/* The class defining a handle to an Innodb table */
42
class ha_innobase: public handler
44
row_prebuilt_t* prebuilt; /* prebuilt struct in InnoDB, used
45
to save CPU time with prebuilt data
47
THD* user_thd; /* the thread handle of the user
48
currently using the handle; this is
49
set in external_lock function */
51
INNOBASE_SHARE *share;
53
uchar* upd_buff; /* buffer used in updates */
54
uchar* key_val_buff; /* buffer used in converting
55
search key values from MySQL format
57
ulong upd_and_key_val_buff_len;
58
/* the length of each of the previous
60
Table_flags int_table_flags;
62
ulong start_of_scan; /* this is set to 1 when we are
63
starting a table scan but have not
64
yet fetched any row, else 0 */
65
uint last_match_mode;/* match mode of the latest search:
66
ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
68
uint num_write_row; /* number of write_row() calls */
70
uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
72
int update_thd(THD* thd);
73
int change_active_index(uint keynr);
74
int general_fetch(uchar* buf, uint direction, uint match_mode);
75
int innobase_read_and_init_auto_inc(longlong* ret);
76
ulong innobase_autoinc_lock();
77
ulong innobase_set_max_autoinc(ulonglong auto_inc);
78
ulong innobase_reset_autoinc(ulonglong auto_inc);
79
ulong innobase_get_auto_increment(ulonglong* value);
80
dict_index_t* innobase_get_index(uint keynr);
82
/* Init values for the class: */
84
ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
87
Get the row type from the storage engine. If this method returns
88
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
90
enum row_type get_row_type() const;
92
const char* table_type() const { return("InnoDB");}
93
const char *index_type(uint key_number) { return "BTREE"; }
94
const char** bas_ext() const;
95
Table_flags table_flags() const;
96
ulong index_flags(uint idx, uint part, bool all_parts) const
98
return (HA_READ_NEXT |
103
((idx == primary_key)? 0 : HA_DO_INDEX_COND_PUSHDOWN));
105
uint max_supported_keys() const { return MAX_KEY; }
106
/* An InnoDB page must store >= 2 keys;
107
a secondary key record must also contain the
109
max key length is therefore set to slightly
110
less than 1 / 4 of page size which is 16 kB;
111
but currently MySQL does not work with keys
112
whose size is > MAX_KEY_LENGTH */
113
uint max_supported_key_length() const { return 3500; }
114
uint max_supported_key_part_length() const;
115
const key_map *keys_to_use_for_scanning() { return &key_map_full; }
117
int open(const char *name, int mode, uint test_if_locked);
120
double read_time(uint index, uint ranges, ha_rows rows);
122
int write_row(uchar * buf);
123
int update_row(const uchar * old_data, uchar * new_data);
124
int delete_row(const uchar * buf);
125
bool was_semi_consistent_read();
126
void try_semi_consistent_read(bool yes);
129
int index_init(uint index, bool sorted);
131
int index_read(uchar * buf, const uchar * key,
132
uint key_len, enum ha_rkey_function find_flag);
133
int index_read_idx(uchar * buf, uint index, const uchar * key,
134
uint key_len, enum ha_rkey_function find_flag);
135
int index_read_last(uchar * buf, const uchar * key, uint key_len);
136
int index_next(uchar * buf);
137
int index_next_same(uchar * buf, const uchar *key, uint keylen);
138
int index_prev(uchar * buf);
139
int index_first(uchar * buf);
140
int index_last(uchar * buf);
142
int rnd_init(bool scan);
144
int rnd_next(uchar *buf);
145
int rnd_pos(uchar * buf, uchar *pos);
147
void position(const uchar *record);
149
int analyze(THD* thd,HA_CHECK_OPT* check_opt);
150
int optimize(THD* thd,HA_CHECK_OPT* check_opt);
151
int discard_or_import_tablespace(my_bool discard);
152
int extra(enum ha_extra_function operation);
154
int lock_table(THD *thd, int lock_type, int lock_timeout)
157
Preliminarily call the pre-existing internal method for
158
transactional locking and ignore non-transactional locks.
162
/* Preliminarily show both possible errors for NOWAIT. */
163
if (lock_type == F_WRLCK)
164
return HA_ERR_UNSUPPORTED;
166
return HA_ERR_LOCK_WAIT_TIMEOUT;
168
return transactional_table_lock(thd, lock_type);
170
int external_lock(THD *thd, int lock_type);
171
int transactional_table_lock(THD *thd, int lock_type);
172
int start_stmt(THD *thd, thr_lock_type lock_type);
173
void position(uchar *record);
174
ha_rows records_in_range(uint inx, key_range *min_key, key_range
176
ha_rows estimate_rows_upper_bound();
178
void update_create_info(HA_CREATE_INFO* create_info);
179
int create(const char *name, register TABLE *form,
180
HA_CREATE_INFO *create_info);
181
int delete_all_rows();
182
int delete_table(const char *name);
183
int rename_table(const char* from, const char* to);
184
int check(THD* thd, HA_CHECK_OPT* check_opt);
185
char* update_table_comment(const char* comment);
186
char* get_foreign_key_create_info();
187
int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
188
bool can_switch_engines();
189
uint referenced_by_foreign_key();
190
void free_foreign_key_create_info(char* str);
191
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
192
enum thr_lock_type lock_type);
193
void init_table_handle_for_HANDLER();
194
virtual void get_auto_increment(ulonglong offset, ulonglong increment,
195
ulonglong nb_desired_values,
196
ulonglong *first_value,
197
ulonglong *nb_reserved_values);
198
int reset_auto_increment(ulonglong value);
200
virtual bool get_error_message(int error, String *buf);
202
uint8 table_cache_type() { return HA_CACHE_TBL_ASKTRANSACT; }
204
ask handler about permission to cache table during query registration
206
my_bool register_query_cache_table(THD *thd, char *table_key,
208
qc_engine_callback *call_back,
209
ulonglong *engine_data);
210
static char *get_mysql_bin_log_name();
211
static ulonglong get_mysql_bin_log_pos();
212
bool primary_key_is_clustered() { return true; }
213
int cmp_ref(const uchar *ref1, const uchar *ref2);
214
bool check_if_incompatible_data(HA_CREATE_INFO *info,
218
* Multi Range Read interface
220
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
221
uint n_ranges, uint mode, HANDLER_BUFFER *buf);
222
int multi_range_read_next(char **range_info);
223
ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
224
void *seq_init_param,
225
uint n_ranges, uint *bufsz,
226
uint *flags, COST_VECT *cost);
227
int multi_range_read_info(uint keyno, uint n_ranges, uint keys,
228
uint *bufsz, uint *flags, COST_VECT *cost);
231
int read_range_first(const key_range *start_key, const key_range *end_key,
232
bool eq_range_arg, bool sorted);
233
int read_range_next();
234
Item *idx_cond_push(uint keyno, Item* idx_cond);
237
/* Some accessor functions which the InnoDB plugin needs, but which
238
can not be added to mysql/plugin.h as part of the public interface;
239
the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */
241
#ifndef INNODB_COMPATIBILITY_HOOKS
242
#error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
246
struct charset_info_st *thd_charset(MYSQL_THD thd);
247
char **thd_query(MYSQL_THD thd);
249
/** Get the file name of the MySQL binlog.
250
* @return the name of the binlog file
252
const char* mysql_bin_log_file_name(void);
254
/** Get the current position of the MySQL binlog.
255
* @return byte offset from the beginning of the binlog
257
ulonglong mysql_bin_log_file_pos(void);
260
Check if a user thread is a replication slave thread
261
@param thd user thread
262
@retval 0 the user thread is not a replication slave thread
263
@retval 1 the user thread is a replication slave thread
265
int thd_slave_thread(const MYSQL_THD thd);
268
Check if a user thread is running a non-transactional update
269
@param thd user thread
270
@retval 0 the user thread is not running a non-transactional update
271
@retval 1 the user thread is running a non-transactional update
273
int thd_non_transactional_update(const MYSQL_THD thd);
276
Get the user thread's binary logging format
277
@param thd user thread
278
@return Value to be used as index into the binlog_format_names array
280
int thd_binlog_format(const MYSQL_THD thd);
283
Mark transaction to rollback and mark error as fatal to a sub-statement.
284
@param thd Thread handle
285
@param all TRUE <=> rollback main transaction.
287
void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);