~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/handler/ha_innodb.h

  • Committer: Monty Taylor
  • Date: 2009-03-22 08:04:21 UTC
  • mto: (960.5.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: mordred@inaugust.com-20090322080421-xkfmhsstf51vvazm
Moved innodb handler code back to handler/ dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2005 MySQL AB && Innobase Oy
2
 
 
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.
6
 
 
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.
11
 
 
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 */
15
 
 
16
 
/*
17
 
  This file is based on ha_berkeley.h of MySQL distribution
18
 
 
19
 
  This file defines the Innodb handler: the interface between MySQL and
20
 
  Innodb
21
 
*/
22
 
 
23
 
#ifdef USE_PRAGMA_INTERFACE
24
 
#pragma interface                       /* gcc class implementation */
25
 
#endif
26
 
 
27
 
typedef struct st_innobase_share {
28
 
  THR_LOCK lock;
29
 
  pthread_mutex_t mutex;
30
 
  char *table_name;
31
 
  uint table_name_length,use_count;
32
 
} INNOBASE_SHARE;
33
 
 
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
 
class ha_innobase: public handler
43
 
{
44
 
        row_prebuilt_t* prebuilt;       /* prebuilt struct in InnoDB, used
45
 
                                        to save CPU time with prebuilt data
46
 
                                        structures*/
47
 
        THD*            user_thd;       /* the thread handle of the user
48
 
                                        currently using the handle; this is
49
 
                                        set in external_lock function */
50
 
        THR_LOCK_DATA   lock;
51
 
        INNOBASE_SHARE  *share;
52
 
 
53
 
        uchar*          upd_buff;       /* buffer used in updates */
54
 
        uchar*          key_val_buff;   /* buffer used in converting
55
 
                                        search key values from MySQL format
56
 
                                        to Innodb format */
57
 
        ulong           upd_and_key_val_buff_len;
58
 
                                        /* the length of each of the previous
59
 
                                        two buffers */
60
 
        Table_flags     int_table_flags;
61
 
        uint            primary_key;
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,
67
 
                                        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
 
        inline void update_thd(THD* thd);
73
 
        void update_thd();
74
 
        int change_active_index(uint keynr);
75
 
        int general_fetch(uchar* buf, uint direction, uint match_mode);
76
 
        ulint innobase_lock_autoinc();
77
 
        ulonglong innobase_peek_autoinc();
78
 
        ulint innobase_set_max_autoinc(ulonglong auto_inc);
79
 
        ulint innobase_reset_autoinc(ulonglong auto_inc);
80
 
        ulint innobase_get_autoinc(ulonglong* value);
81
 
        ulint innobase_update_autoinc(ulonglong auto_inc);
82
 
        ulint innobase_initialize_autoinc();
83
 
        dict_index_t* innobase_get_index(uint keynr);
84
 
        ulonglong innobase_get_int_col_max_value(const Field* field);
85
 
 
86
 
        /* Init values for the class: */
87
 
 public:
88
 
        ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
89
 
        ~ha_innobase();
90
 
        /*
91
 
          Get the row type from the storage engine.  If this method returns
92
 
          ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
93
 
        */
94
 
        enum row_type get_row_type() const;
95
 
 
96
 
        const char* table_type() const;
97
 
        const char* index_type(uint key_number);
98
 
        const char** bas_ext() const;
99
 
        Table_flags table_flags() const;
100
 
        ulong index_flags(uint idx, uint part, bool all_parts) const;
101
 
        uint max_supported_keys() const;
102
 
        uint max_supported_key_length() const;
103
 
        uint max_supported_key_part_length() const;
104
 
        const key_map* keys_to_use_for_scanning();
105
 
 
106
 
        int open(const char *name, int mode, uint test_if_locked);
107
 
        int close(void);
108
 
        double scan_time();
109
 
        double read_time(uint index, uint ranges, ha_rows rows);
110
 
 
111
 
        int write_row(uchar * buf);
112
 
        int update_row(const uchar * old_data, uchar * new_data);
113
 
        int delete_row(const uchar * buf);
114
 
        bool was_semi_consistent_read();
115
 
        void try_semi_consistent_read(bool yes);
116
 
        void unlock_row();
117
 
 
118
 
#ifdef ROW_MERGE_IS_INDEX_USABLE
119
 
        /** Check if an index can be used by this transaction.
120
 
        * @param keynr  key number to check
121
 
        * @return       true if available, false if the index
122
 
        *               does not contain old records that exist
123
 
        *               in the read view of this transaction */
124
 
        bool is_index_available(uint keynr);
125
 
#endif /* ROW_MERGE_IS_INDEX_USABLE */
126
 
        int index_init(uint index, bool sorted);
127
 
        int index_end();
128
 
        int index_read(uchar * buf, const uchar * key,
129
 
                uint key_len, enum ha_rkey_function find_flag);
130
 
        int index_read_idx(uchar * buf, uint index, const uchar * key,
131
 
                           uint key_len, enum ha_rkey_function find_flag);
132
 
        int index_read_last(uchar * buf, const uchar * key, uint key_len);
133
 
        int index_next(uchar * buf);
134
 
        int index_next_same(uchar * buf, const uchar *key, uint keylen);
135
 
        int index_prev(uchar * buf);
136
 
        int index_first(uchar * buf);
137
 
        int index_last(uchar * buf);
138
 
 
139
 
        int rnd_init(bool scan);
140
 
        int rnd_end();
141
 
        int rnd_next(uchar *buf);
142
 
        int rnd_pos(uchar * buf, uchar *pos);
143
 
 
144
 
        void position(const uchar *record);
145
 
        int info(uint);
146
 
        int analyze(THD* thd,HA_CHECK_OPT* check_opt);
147
 
        int optimize(THD* thd,HA_CHECK_OPT* check_opt);
148
 
        int discard_or_import_tablespace(my_bool discard);
149
 
        int extra(enum ha_extra_function operation);
150
 
        int reset();
151
 
        int external_lock(THD *thd, int lock_type);
152
 
        int transactional_table_lock(THD *thd, int lock_type);
153
 
        int start_stmt(THD *thd, thr_lock_type lock_type);
154
 
        void position(uchar *record);
155
 
        ha_rows records_in_range(uint inx, key_range *min_key, key_range
156
 
                                                                *max_key);
157
 
        ha_rows estimate_rows_upper_bound();
158
 
 
159
 
        void update_create_info(HA_CREATE_INFO* create_info);
160
 
        int create(const char *name, register TABLE *form,
161
 
                                        HA_CREATE_INFO *create_info);
162
 
        int delete_all_rows();
163
 
        int delete_table(const char *name);
164
 
        int rename_table(const char* from, const char* to);
165
 
        int check(THD* thd, HA_CHECK_OPT* check_opt);
166
 
        char* update_table_comment(const char* comment);
167
 
        char* get_foreign_key_create_info();
168
 
        int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
169
 
        bool can_switch_engines();
170
 
        uint referenced_by_foreign_key();
171
 
        void free_foreign_key_create_info(char* str);
172
 
        THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
173
 
                                        enum thr_lock_type lock_type);
174
 
        void init_table_handle_for_HANDLER();
175
 
        virtual void get_auto_increment(ulonglong offset, ulonglong increment,
176
 
                                        ulonglong nb_desired_values,
177
 
                                        ulonglong *first_value,
178
 
                                        ulonglong *nb_reserved_values);
179
 
        int reset_auto_increment(ulonglong value);
180
 
 
181
 
        virtual bool get_error_message(int error, String *buf);
182
 
 
183
 
        uint8 table_cache_type();
184
 
        /*
185
 
          ask handler about permission to cache table during query registration
186
 
        */
187
 
        my_bool register_query_cache_table(THD *thd, char *table_key,
188
 
                                           uint key_length,
189
 
                                           qc_engine_callback *call_back,
190
 
                                           ulonglong *engine_data);
191
 
        static char *get_mysql_bin_log_name();
192
 
        static ulonglong get_mysql_bin_log_pos();
193
 
        bool primary_key_is_clustered();
194
 
        int cmp_ref(const uchar *ref1, const uchar *ref2);
195
 
        /** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
196
 
        int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
197
 
        int prepare_drop_index(TABLE *table_arg, uint *key_num,
198
 
                               uint num_of_keys);
199
 
        int final_drop_index(TABLE *table_arg);
200
 
        /** @} */
201
 
        bool check_if_incompatible_data(HA_CREATE_INFO *info,
202
 
                                        uint table_changes);
203
 
};
204
 
 
205
 
/* Some accessor functions which the InnoDB plugin needs, but which
206
 
can not be added to mysql/plugin.h as part of the public interface;
207
 
the definitions are bracketed with #ifdef INNODB_COMPATIBILITY_HOOKS */
208
 
 
209
 
#ifndef INNODB_COMPATIBILITY_HOOKS
210
 
#error InnoDB needs MySQL to be built with #define INNODB_COMPATIBILITY_HOOKS
211
 
#endif
212
 
 
213
 
extern "C" {
214
 
struct charset_info_st *thd_charset(MYSQL_THD thd);
215
 
char **thd_query(MYSQL_THD thd);
216
 
 
217
 
/** Get the file name of the MySQL binlog.
218
 
 * @return the name of the binlog file
219
 
 */
220
 
const char* mysql_bin_log_file_name(void);
221
 
 
222
 
/** Get the current position of the MySQL binlog.
223
 
 * @return byte offset from the beginning of the binlog
224
 
 */
225
 
ulonglong mysql_bin_log_file_pos(void);
226
 
 
227
 
/**
228
 
  Check if a user thread is a replication slave thread
229
 
  @param thd  user thread
230
 
  @retval 0 the user thread is not a replication slave thread
231
 
  @retval 1 the user thread is a replication slave thread
232
 
*/
233
 
int thd_slave_thread(const MYSQL_THD thd);
234
 
 
235
 
/**
236
 
  Check if a user thread is running a non-transactional update
237
 
  @param thd  user thread
238
 
  @retval 0 the user thread is not running a non-transactional update
239
 
  @retval 1 the user thread is running a non-transactional update
240
 
*/
241
 
int thd_non_transactional_update(const MYSQL_THD thd);
242
 
 
243
 
/**
244
 
  Get the user thread's binary logging format
245
 
  @param thd  user thread
246
 
  @return Value to be used as index into the binlog_format_names array
247
 
*/
248
 
int thd_binlog_format(const MYSQL_THD thd);
249
 
 
250
 
/**
251
 
  Mark transaction to rollback and mark error as fatal to a sub-statement.
252
 
  @param  thd   Thread handle
253
 
  @param  all   TRUE <=> rollback main transaction.
254
 
*/
255
 
void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
256
 
}
257
 
 
258
 
typedef struct trx_struct trx_t;
259
 
/************************************************************************
260
 
Converts an InnoDB error code to a MySQL error code and also tells to MySQL
261
 
about a possible transaction rollback inside InnoDB caused by a lock wait
262
 
timeout or a deadlock. */
263
 
extern "C"
264
 
int
265
 
convert_error_code_to_mysql(
266
 
/*========================*/
267
 
                                /* out: MySQL error code */
268
 
        int             error,  /* in: InnoDB error code */
269
 
        ulint           flags,  /* in: InnoDB table flags, or 0 */
270
 
        MYSQL_THD       thd);   /* in: user thread handle or NULL */