~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
*****************************************************************************/
 
18
 
 
19
/*
 
20
  This file is based on ha_berkeley.h of MySQL distribution
 
21
 
 
22
  This file defines the Innodb Cursor: the interface between MySQL and
 
23
  Innodb
 
24
*/
 
25
 
 
26
#ifndef INNODB_HANDLER_HA_INNODB_H
 
27
#define INNODB_HANDLER_HA_INNODB_H
 
28
 
 
29
#include <drizzled/cursor.h>
 
30
#include <drizzled/thr_lock.h>
 
31
 
 
32
/** InnoDB table share */
 
33
typedef struct st_innobase_share {
 
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 */
 
41
} INNOBASE_SHARE;
 
42
 
 
43
 
 
44
/** InnoDB B-tree index */
 
45
struct dict_index_struct;
 
46
/** Prebuilt structures in an Innobase table handle used within MySQL */
 
47
struct row_prebuilt_struct;
 
48
 
 
49
/** InnoDB B-tree index */
 
50
typedef struct dict_index_struct dict_index_t;
 
51
/** Prebuilt structures in an Innobase table handle used within MySQL */
 
52
typedef struct row_prebuilt_struct row_prebuilt_t;
 
53
 
 
54
/** The class defining a handle to an Innodb table */
 
55
class ha_innobase: public Cursor
 
56
{
 
57
        row_prebuilt_t* prebuilt;       /*!< prebuilt struct in InnoDB, used
 
58
                                        to save CPU time with prebuilt data
 
59
                                        structures*/
 
60
        Session*        user_session;   /*!< the thread handle of the user
 
61
                                        currently using the handle; this is
 
62
                                        set in external_lock function */
 
63
        THR_LOCK_DATA   lock;
 
64
        INNOBASE_SHARE* share;          /*!< information for MySQL
 
65
                                        table locking */
 
66
 
 
67
        unsigned char*  upd_buff;       /*!< buffer used in updates */
 
68
        unsigned char*  key_val_buff;   /*!< buffer used in converting
 
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;
 
75
        ulong           start_of_scan;  /*!< this is set to 1 when we are
 
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 */
 
81
        uint            num_write_row;  /*!< number of write_row() calls */
 
82
 
 
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();
 
91
        UNIV_INTERN ulint innobase_set_max_autoinc(uint64_t auto_inc);
 
92
        UNIV_INTERN ulint innobase_reset_autoinc(uint64_t auto_inc);
 
93
        UNIV_INTERN ulint innobase_get_autoinc(uint64_t* value);
 
94
        ulint innobase_update_autoinc(uint64_t  auto_inc);
 
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);
 
98
 
 
99
        /* Init values for the class: */
 
100
 public:
 
101
        UNIV_INTERN ha_innobase(drizzled::plugin::StorageEngine &engine,
 
102
                                TableShare &table_arg);
 
103
        UNIV_INTERN ~ha_innobase();
 
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
        */
 
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();
 
124
 
 
125
        UNIV_INTERN int index_init(uint index, bool sorted);
 
126
        UNIV_INTERN int index_end();
 
127
        UNIV_INTERN int index_read(unsigned char * buf, const unsigned char * key,
 
128
                uint key_len, enum ha_rkey_function find_flag);
 
129
        UNIV_INTERN int index_read_idx(unsigned char * buf, uint index, const unsigned char * key,
 
130
                           uint key_len, enum ha_rkey_function find_flag);
 
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);
 
145
        UNIV_INTERN int analyze(Session* session);
 
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);
 
151
        void position(unsigned char *record);
 
152
        UNIV_INTERN ha_rows records_in_range(uint inx, key_range *min_key, key_range
 
153
                                                                *max_key);
 
154
        UNIV_INTERN ha_rows estimate_rows_upper_bound();
 
155
 
 
156
        UNIV_INTERN int delete_all_rows();
 
157
        UNIV_INTERN int check(Session* session);
 
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,
 
165
                                        enum thr_lock_type lock_type);
 
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);
 
176
        /** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
 
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);
 
181
        /** @} */
 
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();
 
186
};
 
187
 
 
188
 
 
189
extern "C" {
 
190
char **session_query(Session *session);
 
191
 
 
192
/** Get the file name of the MySQL binlog.
 
193
 * @return the name of the binlog file
 
194
 */
 
195
const char* drizzle_bin_log_file_name(void);
 
196
 
 
197
/** Get the current position of the MySQL binlog.
 
198
 * @return byte offset from the beginning of the binlog
 
199
 */
 
200
uint64_t drizzle_bin_log_file_pos(void);
 
201
 
 
202
/**
 
203
  Check if a user thread is a replication slave thread
 
204
  @param session  user thread
 
205
  @retval 0 the user thread is not a replication slave thread
 
206
  @retval 1 the user thread is a replication slave thread
 
207
*/
 
208
int session_slave_thread(const Session *session);
 
209
 
 
210
/**
 
211
  Check if a user thread is running a non-transactional update
 
212
  @param session  user thread
 
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
*/
 
216
int session_non_transactional_update(const Session *session);
 
217
 
 
218
/**
 
219
  Get the user thread's binary logging format
 
220
  @param session  user thread
 
221
  @return Value to be used as index into the binlog_format_names array
 
222
*/
 
223
int session_binlog_format(const Session *session);
 
224
 
 
225
/**
 
226
  Mark transaction to rollback and mark error as fatal to a sub-statement.
 
227
  @param  session   Thread handle
 
228
  @param  all   TRUE <=> rollback main transaction.
 
229
*/
 
230
void session_mark_transaction_to_rollback(Session *session, bool all);
 
231
}
 
232
 
 
233
typedef struct trx_struct trx_t;
 
234
/********************************************************************//**
 
235
@file Cursor/ha_innodb.h
 
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
 
238
timeout or a deadlock.
 
239
@return MySQL error code */
 
240
extern "C" UNIV_INTERN
 
241
int
 
242
convert_error_code_to_mysql(
 
243
/*========================*/
 
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 */
 
247
 
 
248
/*********************************************************************//**
 
249
Allocates an InnoDB transaction for a MySQL Cursor object.
 
250
@return InnoDB transaction handle */
 
251
extern "C" UNIV_INTERN
 
252
trx_t*
 
253
innobase_trx_allocate(
 
254
/*==================*/
 
255
        Session         *session);      /*!< in: user thread handle */
 
256
#endif /* INNODB_HANDLER_HA_INNODB_H */