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