~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
4
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.
8
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.
12
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
16
17
*****************************************************************************/
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
18
19
/*
20
  This file is based on ha_berkeley.h of MySQL distribution
21
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
22
  This file defines the Innodb Cursor: the interface between MySQL and
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
23
  Innodb
24
*/
25
641.1.4 by Monty Taylor
Merged in InnoDB changes.
26
#ifndef INNODB_HANDLER_HA_INNODB_H
27
#define INNODB_HANDLER_HA_INNODB_H
28
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
29
#include <drizzled/cursor.h>
641.1.4 by Monty Taylor
Merged in InnoDB changes.
30
#include <mysys/thr_lock.h>
31
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
32
/** InnoDB table share */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
33
typedef struct st_innobase_share {
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
34
	THR_LOCK	lock;		/*!< MySQL lock protecting
35
					this structure */
36
	const char*	table_name;	/*!< InnoDB table name */
37
	uint		use_count;	/*!< reference count,
38
					incremented in get_share()
39
					and decremented in free_share() */
40
	void*		table_name_hash;/*!< hash table chain node */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
41
} INNOBASE_SHARE;
42
43
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
44
/** InnoDB B-tree index */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
45
struct dict_index_struct;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
46
/** Prebuilt structures in an Innobase table handle used within MySQL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
47
struct row_prebuilt_struct;
48
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
49
/** InnoDB B-tree index */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
50
typedef struct dict_index_struct dict_index_t;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
51
/** Prebuilt structures in an Innobase table handle used within MySQL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
52
typedef struct row_prebuilt_struct row_prebuilt_t;
53
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
54
/** The class defining a handle to an Innodb table */
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
55
class ha_innobase: public Cursor
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
56
{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
57
	row_prebuilt_t*	prebuilt;	/*!< prebuilt struct in InnoDB, used
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
58
					to save CPU time with prebuilt data
59
					structures*/
1114.1.1 by Monty Taylor
Merged InnoDB Plugin 1.0.4
60
	Session*	user_session;	/*!< the thread handle of the user
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
61
					currently using the handle; this is
62
					set in external_lock function */
63
	THR_LOCK_DATA	lock;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
64
	INNOBASE_SHARE*	share;		/*!< information for MySQL
65
					table locking */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
66
1114.1.1 by Monty Taylor
Merged InnoDB Plugin 1.0.4
67
	unsigned char*	upd_buff;	/*!< buffer used in updates */
68
	unsigned char*	key_val_buff;	/*!< buffer used in converting
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
69
					search key values from MySQL format
70
					to Innodb format */
71
	ulong		upd_and_key_val_buff_len;
72
					/* the length of each of the previous
73
					two buffers */
74
	uint		primary_key;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
75
	ulong		start_of_scan;	/*!< this is set to 1 when we are
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
76
					starting a table scan but have not
77
					yet fetched any row, else 0 */
78
	uint		last_match_mode;/* match mode of the latest search:
79
					ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
80
					or undefined */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
81
	uint		num_write_row;	/*!< number of write_row() calls */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
82
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
83
	UNIV_INTERN uint store_key_val_for_row(uint keynr, char* buff, 
84
                                   uint buff_len, const unsigned char* record);
85
	UNIV_INTERN void update_session(Session* session);
86
	UNIV_INTERN void update_session();
87
	UNIV_INTERN int change_active_index(uint32_t keynr);
88
	UNIV_INTERN int general_fetch(unsigned char* buf, uint32_t direction, uint32_t match_mode);
89
	UNIV_INTERN ulint innobase_lock_autoinc();
90
	UNIV_INTERN uint64_t innobase_peek_autoinc();
1192.3.17 by Monty Taylor
Fixed a couple of visibility attributes.
91
	UNIV_INTERN ulint innobase_set_max_autoinc(uint64_t auto_inc);
92
	UNIV_INTERN ulint innobase_reset_autoinc(uint64_t auto_inc);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
93
	UNIV_INTERN ulint innobase_get_autoinc(uint64_t* value);
641.1.5 by Monty Taylor
Merged in innodb plugin 1.0.2
94
	ulint innobase_update_autoinc(uint64_t	auto_inc);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
95
	UNIV_INTERN ulint innobase_initialize_autoinc();
96
	UNIV_INTERN dict_index_t* innobase_get_index(uint keynr);
97
 	UNIV_INTERN uint64_t innobase_get_int_col_max_value(const Field* field);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
98
99
	/* Init values for the class: */
100
 public:
1208.3.2 by brian
Update for Cursor renaming.
101
	UNIV_INTERN ha_innobase(drizzled::plugin::StorageEngine &engine,
102
                                TableShare &table_arg);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
103
	UNIV_INTERN ~ha_innobase();
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
104
	/*
105
	  Get the row type from the storage engine.  If this method returns
106
	  ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
107
	*/
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
108
	UNIV_INTERN enum row_type get_row_type() const;
109
110
	UNIV_INTERN const char* index_type(uint key_number);
111
	UNIV_INTERN const key_map* keys_to_use_for_scanning();
112
113
	UNIV_INTERN int open(const char *name, int mode, uint test_if_locked);
114
	UNIV_INTERN int close(void);
115
	UNIV_INTERN double scan_time();
116
	UNIV_INTERN double read_time(uint index, uint ranges, ha_rows rows);
117
118
	UNIV_INTERN int write_row(unsigned char * buf);
119
	UNIV_INTERN int update_row(const unsigned char * old_data, unsigned char * new_data);
120
	UNIV_INTERN int delete_row(const unsigned char * buf);
121
	UNIV_INTERN bool was_semi_consistent_read();
122
	UNIV_INTERN void try_semi_consistent_read(bool yes);
123
	UNIV_INTERN void unlock_row();
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
124
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
125
	UNIV_INTERN int index_init(uint index, bool sorted);
126
	UNIV_INTERN int index_end();
1114.1.1 by Monty Taylor
Merged InnoDB Plugin 1.0.4
127
	UNIV_INTERN int index_read(unsigned char * buf, const unsigned char * key,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
128
		uint key_len, enum ha_rkey_function find_flag);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
129
	UNIV_INTERN int index_read_idx(unsigned char * buf, uint index, const unsigned char * key,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
130
			   uint key_len, enum ha_rkey_function find_flag);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
131
	UNIV_INTERN int index_read_last(unsigned char * buf, const unsigned char * key, uint key_len);
132
	UNIV_INTERN int index_next(unsigned char * buf);
133
	UNIV_INTERN int index_next_same(unsigned char * buf, const unsigned char *key, uint keylen);
134
	UNIV_INTERN int index_prev(unsigned char * buf);
135
	UNIV_INTERN int index_first(unsigned char * buf);
136
	UNIV_INTERN int index_last(unsigned char * buf);
137
138
	UNIV_INTERN int rnd_init(bool scan);
139
	UNIV_INTERN int rnd_end();
140
	UNIV_INTERN int rnd_next(unsigned char *buf);
141
	UNIV_INTERN int rnd_pos(unsigned char * buf, unsigned char *pos);
142
143
	UNIV_INTERN void position(const unsigned char *record);
144
	UNIV_INTERN int info(uint);
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
145
	UNIV_INTERN int analyze(Session* session);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
146
	UNIV_INTERN int discard_or_import_tablespace(bool discard);
147
	UNIV_INTERN int extra(enum ha_extra_function operation);
148
        UNIV_INTERN int reset();
149
	UNIV_INTERN int external_lock(Session *session, int lock_type);
150
	UNIV_INTERN int start_stmt(Session *session, thr_lock_type lock_type);
641.1.4 by Monty Taylor
Merged in InnoDB changes.
151
	void position(unsigned char *record);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
152
	UNIV_INTERN ha_rows records_in_range(uint inx, key_range *min_key, key_range
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
153
								*max_key);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
154
	UNIV_INTERN ha_rows estimate_rows_upper_bound();
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
155
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
156
	UNIV_INTERN int delete_all_rows();
1222.1.10 by Brian Aker
Removes options from DDL left in Cursor for admin operations (they were
157
	UNIV_INTERN int check(Session* session);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
158
	UNIV_INTERN char* update_table_comment(const char* comment);
159
	UNIV_INTERN char* get_foreign_key_create_info();
160
	UNIV_INTERN int get_foreign_key_list(Session *session, List<FOREIGN_KEY_INFO> *f_key_list);
161
	UNIV_INTERN bool can_switch_engines();
162
	UNIV_INTERN uint referenced_by_foreign_key();
163
	UNIV_INTERN void free_foreign_key_create_info(char* str);
164
	UNIV_INTERN THR_LOCK_DATA **store_lock(Session *session, THR_LOCK_DATA **to,
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
165
					enum thr_lock_type lock_type);
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
166
	UNIV_INTERN void init_table_handle_for_HANDLER();
167
        UNIV_INTERN virtual void get_auto_increment(uint64_t offset, 
168
                                                    uint64_t increment,
169
                                                    uint64_t nb_desired_values,
170
                                                    uint64_t *first_value,
171
                                                    uint64_t *nb_reserved_values);
172
        UNIV_INTERN int reset_auto_increment(uint64_t value);
173
174
	UNIV_INTERN bool primary_key_is_clustered();
175
	UNIV_INTERN int cmp_ref(const unsigned char *ref1, const unsigned char *ref2);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
176
	/** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
177
	UNIV_INTERN int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
178
	UNIV_INTERN int prepare_drop_index(TABLE *table_arg, uint *key_num,
179
                                           uint num_of_keys);
180
        UNIV_INTERN int final_drop_index(TABLE *table_arg);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
181
	/** @} */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
182
public:
183
  int read_range_first(const key_range *start_key, const key_range *end_key,
184
		       bool eq_range_arg, bool sorted);
185
  int read_range_next();
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
186
};
187
188
189
extern "C" {
641.1.4 by Monty Taylor
Merged in InnoDB changes.
190
char **session_query(Session *session);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
191
192
/** Get the file name of the MySQL binlog.
193
 * @return the name of the binlog file
194
 */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
195
const char* drizzle_bin_log_file_name(void);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
196
197
/** Get the current position of the MySQL binlog.
198
 * @return byte offset from the beginning of the binlog
199
 */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
200
uint64_t drizzle_bin_log_file_pos(void);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
201
202
/**
203
  Check if a user thread is a replication slave thread
641.1.4 by Monty Taylor
Merged in InnoDB changes.
204
  @param session  user thread
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
205
  @retval 0 the user thread is not a replication slave thread
206
  @retval 1 the user thread is a replication slave thread
207
*/
641.1.4 by Monty Taylor
Merged in InnoDB changes.
208
int session_slave_thread(const Session *session);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
209
210
/**
211
  Check if a user thread is running a non-transactional update
641.1.4 by Monty Taylor
Merged in InnoDB changes.
212
  @param session  user thread
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
213
  @retval 0 the user thread is not running a non-transactional update
214
  @retval 1 the user thread is running a non-transactional update
215
*/
641.1.4 by Monty Taylor
Merged in InnoDB changes.
216
int session_non_transactional_update(const Session *session);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
217
218
/**
219
  Get the user thread's binary logging format
641.1.4 by Monty Taylor
Merged in InnoDB changes.
220
  @param session  user thread
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
221
  @return Value to be used as index into the binlog_format_names array
222
*/
641.1.4 by Monty Taylor
Merged in InnoDB changes.
223
int session_binlog_format(const Session *session);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
224
225
/**
226
  Mark transaction to rollback and mark error as fatal to a sub-statement.
641.1.4 by Monty Taylor
Merged in InnoDB changes.
227
  @param  session   Thread handle
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
228
  @param  all   TRUE <=> rollback main transaction.
229
*/
641.1.4 by Monty Taylor
Merged in InnoDB changes.
230
void session_mark_transaction_to_rollback(Session *session, bool all);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
231
}
232
233
typedef struct trx_struct trx_t;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
234
/********************************************************************//**
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
235
@file Cursor/ha_innodb.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
236
Converts an InnoDB error code to a MySQL error code and also tells to MySQL
237
about a possible transaction rollback inside InnoDB caused by a lock wait
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
238
timeout or a deadlock.
239
@return	MySQL error code */
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
240
extern "C" UNIV_INTERN
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
241
int
242
convert_error_code_to_mysql(
243
/*========================*/
1114.1.1 by Monty Taylor
Merged InnoDB Plugin 1.0.4
244
	int		error,		/*!< in: InnoDB error code */
245
	ulint		flags,		/*!< in: InnoDB table flags, or 0 */
246
	Session		*session);	/*!< in: user thread handle or NULL */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
247
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
248
/*********************************************************************//**
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
249
Allocates an InnoDB transaction for a MySQL Cursor object.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
250
@return	InnoDB transaction handle */
1099.2.1 by rm
get things compiling on FreeBSD (7.1)
251
extern "C" UNIV_INTERN
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
252
trx_t*
253
innobase_trx_allocate(
254
/*==================*/
1114.1.1 by Monty Taylor
Merged InnoDB Plugin 1.0.4
255
	Session		*session);	/*!< in: user thread handle */
641.1.4 by Monty Taylor
Merged in InnoDB changes.
256
#endif /* INNODB_HANDLER_HA_INNODB_H */