ha_innodb.h 8.99 KB
Newer Older
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
1
/* Copyright (C) 2000-2005 MySQL AB && Innobase Oy
2 3 4

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6

7 8
   This program is distributed in the hope that it will be useful,
   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.
11

12 13
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA */
15

16 17 18 19 20 21 22
/*
  This file is based on ha_berkeley.h of MySQL distribution

  This file defines the Innodb handler: the interface between MySQL and
  Innodb
*/

23
#ifdef USE_PRAGMA_INTERFACE
24 25 26 27 28 29 30 31 32 33
#pragma interface			/* gcc class implementation */
#endif

typedef struct st_innobase_share {
  THR_LOCK lock;
  pthread_mutex_t mutex;
  char *table_name;
  uint table_name_length,use_count;
} INNOBASE_SHARE;

heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
34

35
struct dict_index_struct;
36
struct row_prebuilt_struct;
37 38

typedef struct dict_index_struct dict_index_t;
39
typedef struct row_prebuilt_struct row_prebuilt_t;
40

41
/* The class defining a handle to an Innodb table */
42 43
class ha_innobase: public handler
{
44 45
	row_prebuilt_t*	prebuilt;	/* prebuilt struct in InnoDB, used
					to save CPU time with prebuilt data
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
46
					structures*/
47 48 49
	THD*		user_thd;	/* the thread handle of the user
					currently using the handle; this is
					set in external_lock function */
50 51 52
	THR_LOCK_DATA	lock;
	INNOBASE_SHARE	*share;

53 54
	uchar*		upd_buff;	/* buffer used in updates */
	uchar*		key_val_buff;	/* buffer used in converting
55 56
					search key values from MySQL format
					to Innodb format */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
57 58 59
	ulong		upd_and_key_val_buff_len;
					/* the length of each of the previous
					two buffers */
60
	Table_flags	int_table_flags;
61
	uint		primary_key;
62 63 64
	ulong		start_of_scan;	/* this is set to 1 when we are
					starting a table scan but have not
					yet fetched any row, else 0 */
65
	uint		last_match_mode;/* match mode of the latest search:
66 67
					ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
					or undefined */
68
	uint		num_write_row;	/* number of write_row() calls */
69

70
	uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
71
                                   const uchar* record);
72 73
	int update_thd(THD* thd);
	int change_active_index(uint keynr);
74
	int general_fetch(uchar* buf, uint direction, uint match_mode);
75 76
	ulong innobase_lock_autoinc();
	ulonglong innobase_peek_autoinc();
77 78
	ulong innobase_set_max_autoinc(ulonglong auto_inc);
	ulong innobase_reset_autoinc(ulonglong auto_inc);
79 80
	ulong innobase_get_autoinc(ulonglong* value);
	ulong innobase_update_autoinc(ulonglong	auto_inc);
81
	void innobase_initialize_autoinc();
82
	dict_index_t* innobase_get_index(uint keynr);
83 84 85

	/* Init values for the class: */
 public:
86
	ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
87
	~ha_innobase() {}
88 89 90 91 92
	/*
	  Get the row type from the storage engine.  If this method returns
	  ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
	*/
	enum row_type get_row_type() const;
93

94
	const char* table_type() const { return("InnoDB");}
95
	const char *index_type(uint key_number) { return "BTREE"; }
96
	const char** bas_ext() const;
97
	Table_flags table_flags() const;
98
	ulong index_flags(uint idx, uint part, bool all_parts) const
99
	{
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
100 101 102 103
	  return (HA_READ_NEXT |
		  HA_READ_PREV |
		  HA_READ_ORDER |
		  HA_READ_RANGE |
104
		  HA_KEYREAD_ONLY);
105
	}
106
	uint max_supported_keys()	   const { return MAX_KEY; }
heikki@donna.mysql.fi's avatar
heikki@donna.mysql.fi committed
107 108 109 110
				/* An InnoDB page must store >= 2 keys;
				a secondary key record must also contain the
				primary key value:
				max key length is therefore set to slightly
heikki@donna.mysql.fi's avatar
heikki@donna.mysql.fi committed
111 112 113
				less than 1 / 4 of page size which is 16 kB;
				but currently MySQL does not work with keys
				whose size is > MAX_KEY_LENGTH */
114 115
	uint max_supported_key_length() const { return 3500; }
	uint max_supported_key_part_length() const;
serg@serg.mylan's avatar
serg@serg.mylan committed
116
	const key_map *keys_to_use_for_scanning() { return &key_map_full; }
117

118 119 120
	int open(const char *name, int mode, uint test_if_locked);
	int close(void);
	double scan_time();
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
121
	double read_time(uint index, uint ranges, ha_rows rows);
122

123 124 125
	int write_row(uchar * buf);
	int update_row(const uchar * old_data, uchar * new_data);
	int delete_row(const uchar * buf);
126 127
	bool was_semi_consistent_read();
	void try_semi_consistent_read(bool yes);
128
	void unlock_row();
129

130 131
	int index_init(uint index, bool sorted);
	int index_end();
132
	int index_read(uchar * buf, const uchar * key,
133
		uint key_len, enum ha_rkey_function find_flag);
134
	int index_read_idx(uchar * buf, uint index, const uchar * key,
135
			   uint key_len, enum ha_rkey_function find_flag);
136 137 138 139 140 141
	int index_read_last(uchar * buf, const uchar * key, uint key_len);
	int index_next(uchar * buf);
	int index_next_same(uchar * buf, const uchar *key, uint keylen);
	int index_prev(uchar * buf);
	int index_first(uchar * buf);
	int index_last(uchar * buf);
142 143 144

	int rnd_init(bool scan);
	int rnd_end();
145 146
	int rnd_next(uchar *buf);
	int rnd_pos(uchar * buf, uchar *pos);
147

148
	void position(const uchar *record);
149
	int info(uint);
150 151
	int analyze(THD* thd,HA_CHECK_OPT* check_opt);
	int optimize(THD* thd,HA_CHECK_OPT* check_opt);
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
152
	int discard_or_import_tablespace(my_bool discard);
153
	int extra(enum ha_extra_function operation);
154
        int reset();
155
	int external_lock(THD *thd, int lock_type);
156
	int transactional_table_lock(THD *thd, int lock_type);
157
	int start_stmt(THD *thd, thr_lock_type lock_type);
158
	void position(uchar *record);
159
	ha_rows records_in_range(uint inx, key_range *min_key, key_range
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
160
								*max_key);
sergefp@mysql.com's avatar
sergefp@mysql.com committed
161
	ha_rows estimate_rows_upper_bound();
162

163
	void update_create_info(HA_CREATE_INFO* create_info);
164
	int create(const char *name, register TABLE *form,
165
					HA_CREATE_INFO *create_info);
166
	int delete_all_rows();
167
	int delete_table(const char *name);
168
	int rename_table(const char* from, const char* to);
169
	int check(THD* thd, HA_CHECK_OPT* check_opt);
170
	char* update_table_comment(const char* comment);
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
171
	char* get_foreign_key_create_info();
172
	int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
173
	bool can_switch_engines();
174 175 176 177 178
	uint referenced_by_foreign_key();
	void free_foreign_key_create_info(char* str);
	THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
					enum thr_lock_type lock_type);
	void init_table_handle_for_HANDLER();
179 180 181 182
        virtual void get_auto_increment(ulonglong offset, ulonglong increment,
                                        ulonglong nb_desired_values,
                                        ulonglong *first_value,
                                        ulonglong *nb_reserved_values);
osku@127.(none)'s avatar
osku@127.(none) committed
183
	int reset_auto_increment(ulonglong value);
184 185

	virtual bool get_error_message(int error, String *buf);
186 187 188 189 190 191

	uint8 table_cache_type() { return HA_CACHE_TBL_ASKTRANSACT; }
	/*
	  ask handler about permission to cache table during query registration
	*/
	my_bool register_query_cache_table(THD *thd, char *table_key,
192 193
					   uint key_length,
					   qc_engine_callback *call_back,
194
					   ulonglong *engine_data);
195 196 197
	static char *get_mysql_bin_log_name();
	static ulonglong get_mysql_bin_log_pos();
	bool primary_key_is_clustered() { return true; }
198
	int cmp_ref(const uchar *ref1, const uchar *ref2);
199 200
	bool check_if_incompatible_data(HA_CREATE_INFO *info,
					uint table_changes);
201 202
};

203 204 205 206 207 208 209 210
/* Some accessor functions which the InnoDB plugin needs, but which
can not be added to mysql/plugin.h as part of the public interface;
the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */

#ifndef INNODB_COMPATIBILITY_HOOKS
#error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
#endif

211
extern "C" {
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
struct charset_info_st *thd_charset(MYSQL_THD thd);
char **thd_query(MYSQL_THD thd);

/** Get the file name of the MySQL binlog.
 * @return the name of the binlog file
 */
const char* mysql_bin_log_file_name(void);

/** Get the current position of the MySQL binlog.
 * @return byte offset from the beginning of the binlog
 */
ulonglong mysql_bin_log_file_pos(void);

/**
  Check if a user thread is a replication slave thread
  @param thd  user thread
  @retval 0 the user thread is not a replication slave thread
  @retval 1 the user thread is a replication slave thread
*/
int thd_slave_thread(const MYSQL_THD thd);

/**
  Check if a user thread is running a non-transactional update
  @param thd  user thread
  @retval 0 the user thread is not running a non-transactional update
  @retval 1 the user thread is running a non-transactional update
*/
int thd_non_transactional_update(const MYSQL_THD thd);

/**
  Get the user thread's binary logging format
  @param thd  user thread
  @return Value to be used as index into the binlog_format_names array
*/
int thd_binlog_format(const MYSQL_THD thd);
247 248 249 250 251 252 253

/**
  Mark transaction to rollback and mark error as fatal to a sub-statement.
  @param  thd   Thread handle
  @param  all   TRUE <=> rollback main transaction.
*/
void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
254 255 256 257 258 259 260

/**
  Check if binary logging is filtered for thread's current db.
  @param  thd   Thread handle
  @retval 1 the query is not filtered, 0 otherwise.
*/
bool thd_binlog_filter_ok(const MYSQL_THD thd);
261
}