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
inline void update_thd(THD* thd);
74
int change_active_index(uint keynr);
75
int general_fetch(uchar* buf, uint direction, uint match_mode);
76
int innobase_read_and_init_auto_inc(ulonglong* ret);
77
ulong innobase_autoinc_lock();
78
ulong innobase_set_max_autoinc(ulonglong auto_inc);
79
ulong innobase_reset_autoinc(ulonglong auto_inc);
80
ulong innobase_get_auto_increment(ulonglong* value);
81
dict_index_t* innobase_get_index(uint keynr);
83
/* Init values for the class: */
85
ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
88
Get the row type from the storage engine. If this method returns
89
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
91
enum row_type get_row_type() const;
93
const char* table_type() const;
94
const char* index_type(uint key_number);
95
const char** bas_ext() const;
96
Table_flags table_flags() const;
97
ulong index_flags(uint idx, uint part, bool all_parts) const;
98
uint max_supported_keys() const;
99
uint max_supported_key_length() const;
100
uint max_supported_key_part_length() const;
101
const key_map* keys_to_use_for_scanning();
103
int open(const char *name, int mode, uint test_if_locked);
106
double read_time(uint index, uint ranges, ha_rows rows);
108
int write_row(uchar * buf);
109
int update_row(const uchar * old_data, uchar * new_data);
110
int delete_row(const uchar * buf);
111
bool was_semi_consistent_read();
112
void try_semi_consistent_read(bool yes);
115
#ifdef ROW_MERGE_IS_INDEX_USABLE
116
/** Check if an index can be used by this transaction.
117
* @param keynr key number to check
118
* @return true if available, false if the index
119
* does not contain old records that exist
120
* in the read view of this transaction */
121
bool is_index_available(uint keynr);
122
#endif /* ROW_MERGE_IS_INDEX_USABLE */
123
int index_init(uint index, bool sorted);
125
int index_read(uchar * buf, const uchar * key,
126
uint key_len, enum ha_rkey_function find_flag);
127
int index_read_idx(uchar * buf, uint index, const uchar * key,
128
uint key_len, enum ha_rkey_function find_flag);
129
int index_read_last(uchar * buf, const uchar * key, uint key_len);
130
int index_next(uchar * buf);
131
int index_next_same(uchar * buf, const uchar *key, uint keylen);
132
int index_prev(uchar * buf);
133
int index_first(uchar * buf);
134
int index_last(uchar * buf);
136
int rnd_init(bool scan);
138
int rnd_next(uchar *buf);
139
int rnd_pos(uchar * buf, uchar *pos);
141
void position(const uchar *record);
143
int analyze(THD* thd,HA_CHECK_OPT* check_opt);
144
int optimize(THD* thd,HA_CHECK_OPT* check_opt);
145
int discard_or_import_tablespace(my_bool discard);
146
int extra(enum ha_extra_function operation);
148
int external_lock(THD *thd, int lock_type);
149
int transactional_table_lock(THD *thd, int lock_type);
150
int start_stmt(THD *thd, thr_lock_type lock_type);
151
void position(uchar *record);
152
ha_rows records_in_range(uint inx, key_range *min_key, key_range
154
ha_rows estimate_rows_upper_bound();
156
void update_create_info(HA_CREATE_INFO* create_info);
157
int create(const char *name, register TABLE *form,
158
HA_CREATE_INFO *create_info);
159
int delete_all_rows();
160
int delete_table(const char *name);
161
int rename_table(const char* from, const char* to);
162
int check(THD* thd, HA_CHECK_OPT* check_opt);
163
char* update_table_comment(const char* comment);
164
char* get_foreign_key_create_info();
165
int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
166
bool can_switch_engines();
167
uint referenced_by_foreign_key();
168
void free_foreign_key_create_info(char* str);
169
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
170
enum thr_lock_type lock_type);
171
void init_table_handle_for_HANDLER();
172
virtual void get_auto_increment(ulonglong offset, ulonglong increment,
173
ulonglong nb_desired_values,
174
ulonglong *first_value,
175
ulonglong *nb_reserved_values);
176
int reset_auto_increment(ulonglong value);
178
virtual bool get_error_message(int error, String *buf);
180
uint8 table_cache_type();
182
ask handler about permission to cache table during query registration
184
my_bool register_query_cache_table(THD *thd, char *table_key,
186
qc_engine_callback *call_back,
187
ulonglong *engine_data);
188
static char *get_mysql_bin_log_name();
189
static ulonglong get_mysql_bin_log_pos();
190
bool primary_key_is_clustered();
191
int cmp_ref(const uchar *ref1, const uchar *ref2);
192
/** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
193
int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
194
int prepare_drop_index(TABLE *table_arg, uint *key_num,
196
int final_drop_index(TABLE *table_arg);
198
bool check_if_incompatible_data(HA_CREATE_INFO *info,
202
/* Some accessor functions which the InnoDB plugin needs, but which
203
can not be added to mysql/plugin.h as part of the public interface;
204
the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */
206
#ifndef INNODB_COMPATIBILITY_HOOKS
207
#error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
211
struct charset_info_st *thd_charset(MYSQL_THD thd);
212
char **thd_query(MYSQL_THD thd);
214
/** Get the file name of the MySQL binlog.
215
* @return the name of the binlog file
217
const char* mysql_bin_log_file_name(void);
219
/** Get the current position of the MySQL binlog.
220
* @return byte offset from the beginning of the binlog
222
ulonglong mysql_bin_log_file_pos(void);
225
Check if a user thread is a replication slave thread
226
@param thd user thread
227
@retval 0 the user thread is not a replication slave thread
228
@retval 1 the user thread is a replication slave thread
230
int thd_slave_thread(const MYSQL_THD thd);
233
Check if a user thread is running a non-transactional update
234
@param thd user thread
235
@retval 0 the user thread is not running a non-transactional update
236
@retval 1 the user thread is running a non-transactional update
238
int thd_non_transactional_update(const MYSQL_THD thd);
241
Get the user thread's binary logging format
242
@param thd user thread
243
@return Value to be used as index into the binlog_format_names array
245
int thd_binlog_format(const MYSQL_THD thd);
248
Mark transaction to rollback and mark error as fatal to a sub-statement.
249
@param thd Thread handle
250
@param all TRUE <=> rollback main transaction.
252
void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
255
typedef struct trx_struct trx_t;
256
/************************************************************************
257
Converts an InnoDB error code to a MySQL error code and also tells to MySQL
258
about a possible transaction rollback inside InnoDB caused by a lock wait
259
timeout or a deadlock. */
262
convert_error_code_to_mysql(
263
/*========================*/
264
/* out: MySQL error code */
265
int error, /* in: InnoDB error code */
266
ulint flags, /* in: InnoDB table flags, or 0 */
267
MYSQL_THD thd); /* in: user thread handle or NULL */