~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Padraig O'Sullivan
  • Date: 2009-06-29 17:24:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1081.
  • Revision ID: osullivan.padraig@gmail.com-20090629172402-9c5n1kr7ry7xgau7
Removed the dependency on knowing the position of an I_S table in the
schema_tables array defined in show.cc. This issue crops up in
prepare_schema_table. An issue with my design is that it increases the time
complexity from O(1) to O(n) in numerous places to determine an I_S table to
work on since we don't have an explicit index into the array and instead
need to search by name. However, as n is the number of I_S tables and this
number is quite small (at the moment n is < 30), we don't see this causing
any issue. This design makes the code much more maintainable and easier to
understand. Previously, modifying anything to do with the I_S tables meant
having to tip-toe around the issue of hard-coded indexes into the
schema_tables array.

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 handler: 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/handler.h>
 
30
#include <mysys/thr_lock.h>
 
31
 
 
32
#ifdef USE_PRAGMA_INTERFACE
 
33
#pragma interface                       /* gcc class implementation */
 
34
#endif
 
35
 
 
36
typedef struct st_innobase_share {
 
37
  THR_LOCK lock;
 
38
  pthread_mutex_t mutex;
 
39
  const char* table_name;
 
40
  uint use_count;
 
41
  void* table_name_hash;
 
42
} INNOBASE_SHARE;
 
43
 
 
44
 
 
45
struct dict_index_struct;
 
46
struct row_prebuilt_struct;
 
47
 
 
48
typedef struct dict_index_struct dict_index_t;
 
49
typedef struct row_prebuilt_struct row_prebuilt_t;
 
50
 
 
51
/* The class defining a handle to an Innodb table */
 
52
class ha_innobase: public handler
 
53
{
 
54
        row_prebuilt_t* prebuilt;       /* prebuilt struct in InnoDB, used
 
55
                                        to save CPU time with prebuilt data
 
56
                                        structures*/
 
57
        Session*                user_session;   /* the thread handle of the user
 
58
                                        currently using the handle; this is
 
59
                                        set in external_lock function */
 
60
        THR_LOCK_DATA   lock;
 
61
        INNOBASE_SHARE  *share;
 
62
 
 
63
        unsigned char*          upd_buff;       /* buffer used in updates */
 
64
        unsigned char*          key_val_buff;   /* buffer used in converting
 
65
                                        search key values from MySQL format
 
66
                                        to Innodb format */
 
67
        ulong           upd_and_key_val_buff_len;
 
68
                                        /* the length of each of the previous
 
69
                                        two buffers */
 
70
        Table_flags     int_table_flags;
 
71
        uint            primary_key;
 
72
        ulong           start_of_scan;  /* this is set to 1 when we are
 
73
                                        starting a table scan but have not
 
74
                                        yet fetched any row, else 0 */
 
75
        uint            last_match_mode;/* match mode of the latest search:
 
76
                                        ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
 
77
                                        or undefined */
 
78
        uint            num_write_row;  /* number of write_row() calls */
 
79
 
 
80
        uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
 
81
                                   const unsigned char* record);
 
82
        void update_session(Session* session);
 
83
        void update_session();
 
84
        int change_active_index(uint32_t keynr);
 
85
        int general_fetch(unsigned char* buf, uint32_t direction, uint32_t match_mode);
 
86
        ulint innobase_lock_autoinc();
 
87
        uint64_t innobase_peek_autoinc();
 
88
        ulint innobase_set_max_autoinc(uint64_t auto_inc);
 
89
        ulint innobase_reset_autoinc(uint64_t auto_inc);
 
90
        ulint innobase_get_autoinc(uint64_t* value);
 
91
        ulint innobase_update_autoinc(uint64_t  auto_inc);
 
92
        ulint innobase_initialize_autoinc();
 
93
        dict_index_t* innobase_get_index(uint keynr);
 
94
        uint64_t innobase_get_int_col_max_value(const Field* field);
 
95
 
 
96
        /* Init values for the class: */
 
97
 public:
 
98
        ha_innobase(StorageEngine *engine, TableShare *table_arg);
 
99
        ~ha_innobase();
 
100
        /*
 
101
          Get the row type from the storage engine.  If this method returns
 
102
          ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
103
        */
 
104
        enum row_type get_row_type() const;
 
105
 
 
106
        const char* index_type(uint key_number);
 
107
        Table_flags table_flags() const;
 
108
        uint32_t index_flags(uint idx, uint part, bool all_parts) const;
 
109
        uint32_t max_supported_keys() const;
 
110
        uint32_t max_supported_key_length() const;
 
111
        uint32_t max_supported_key_part_length() const;
 
112
        const key_map* keys_to_use_for_scanning();
 
113
 
 
114
        int open(const char *name, int mode, uint test_if_locked);
 
115
        int close(void);
 
116
        double scan_time();
 
117
        double read_time(uint index, uint ranges, ha_rows rows);
 
118
 
 
119
        int write_row(unsigned char * buf);
 
120
        int update_row(const unsigned char * old_data, unsigned char * new_data);
 
121
        int delete_row(const unsigned char * buf);
 
122
        bool was_semi_consistent_read();
 
123
        void try_semi_consistent_read(bool yes);
 
124
        void unlock_row();
 
125
 
 
126
#ifdef ROW_MERGE_IS_INDEX_USABLE
 
127
        /** Check if an index can be used by this transaction.
 
128
        * @param keynr  key number to check
 
129
        * @return       true if available, false if the index
 
130
        *               does not contain old records that exist
 
131
        *               in the read view of this transaction */
 
132
        bool is_index_available(uint keynr);
 
133
#endif /* ROW_MERGE_IS_INDEX_USABLE */
 
134
        int index_init(uint index, bool sorted);
 
135
        int index_end();
 
136
        int index_read(unsigned char * buf, const unsigned char * key,
 
137
                uint key_len, enum ha_rkey_function find_flag);
 
138
        int index_read_idx(unsigned char * buf, uint index, const unsigned char * key,
 
139
                           uint key_len, enum ha_rkey_function find_flag);
 
140
        int index_read_last(unsigned char * buf, const unsigned char * key, uint key_len);
 
141
        int index_next(unsigned char * buf);
 
142
        int index_next_same(unsigned char * buf, const unsigned char *key, uint keylen);
 
143
        int index_prev(unsigned char * buf);
 
144
        int index_first(unsigned char * buf);
 
145
        int index_last(unsigned char * buf);
 
146
 
 
147
        int rnd_init(bool scan);
 
148
        int rnd_end();
 
149
        int rnd_next(unsigned char *buf);
 
150
        int rnd_pos(unsigned char * buf, unsigned char *pos);
 
151
 
 
152
        void position(const unsigned char *record);
 
153
        int info(uint);
 
154
        int analyze(Session* session,HA_CHECK_OPT* check_opt);
 
155
        int optimize(Session* session,HA_CHECK_OPT* check_opt);
 
156
        int discard_or_import_tablespace(bool discard);
 
157
        int extra(enum ha_extra_function operation);
 
158
        int reset();
 
159
        int external_lock(Session *session, int lock_type);
 
160
        int start_stmt(Session *session, thr_lock_type lock_type);
 
161
        void position(unsigned char *record);
 
162
        ha_rows records_in_range(uint inx, key_range *min_key, key_range
 
163
                                                                *max_key);
 
164
        ha_rows estimate_rows_upper_bound();
 
165
 
 
166
        void update_create_info(HA_CREATE_INFO* create_info);
 
167
        int delete_all_rows();
 
168
        int check(Session* session, HA_CHECK_OPT* check_opt);
 
169
        char* update_table_comment(const char* comment);
 
170
        char* get_foreign_key_create_info();
 
171
        int get_foreign_key_list(Session *session, List<FOREIGN_KEY_INFO> *f_key_list);
 
172
        bool can_switch_engines();
 
173
        uint referenced_by_foreign_key();
 
174
        void free_foreign_key_create_info(char* str);
 
175
        THR_LOCK_DATA **store_lock(Session *session, THR_LOCK_DATA **to,
 
176
                                        enum thr_lock_type lock_type);
 
177
        void init_table_handle_for_HANDLER();
 
178
        virtual void get_auto_increment(uint64_t offset, uint64_t increment,
 
179
                                        uint64_t nb_desired_values,
 
180
                                        uint64_t *first_value,
 
181
                                        uint64_t *nb_reserved_values);
 
182
        int reset_auto_increment(uint64_t value);
 
183
 
 
184
        virtual bool get_error_message(int error, String *buf);
 
185
 
 
186
        bool primary_key_is_clustered();
 
187
        int cmp_ref(const unsigned char *ref1, const unsigned char *ref2);
 
188
        /** Fast index creation (smart ALTER TABLE) @see handler0alter.cc @{ */
 
189
        int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
 
190
        int prepare_drop_index(TABLE *table_arg, uint *key_num,
 
191
                               uint num_of_keys);
 
192
        int final_drop_index(TABLE *table_arg);
 
193
        /** @} */
 
194
public:
 
195
  /**
 
196
   * Multi Range Read interface
 
197
   */
 
198
  int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
 
199
                            uint32_t n_ranges, uint32_t mode,
 
200
                            HANDLER_BUFFER *buf);
 
201
  int multi_range_read_next(char **range_info);
 
202
  ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
203
                                      void *seq_init_param,
 
204
                                      uint32_t n_ranges, uint32_t *bufsz,
 
205
                                      uint32_t *flags, COST_VECT *cost);
 
206
  int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
 
207
                            uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
 
208
  DsMrr_impl ds_mrr;
 
209
 
 
210
  int read_range_first(const key_range *start_key, const key_range *end_key,
 
211
                       bool eq_range_arg, bool sorted);
 
212
  int read_range_next();
 
213
  Item *idx_cond_push(uint32_t keyno, Item* idx_cond);
 
214
 
 
215
};
 
216
 
 
217
 
 
218
extern "C" {
 
219
struct charset_info_st *session_charset(Session *session);
 
220
char **session_query(Session *session);
 
221
 
 
222
/** Get the file name of the MySQL binlog.
 
223
 * @return the name of the binlog file
 
224
 */
 
225
const char* drizzle_bin_log_file_name(void);
 
226
 
 
227
/** Get the current position of the MySQL binlog.
 
228
 * @return byte offset from the beginning of the binlog
 
229
 */
 
230
uint64_t drizzle_bin_log_file_pos(void);
 
231
 
 
232
/**
 
233
  Check if a user thread is a replication slave thread
 
234
  @param session  user thread
 
235
  @retval 0 the user thread is not a replication slave thread
 
236
  @retval 1 the user thread is a replication slave thread
 
237
*/
 
238
int session_slave_thread(const Session *session);
 
239
 
 
240
/**
 
241
  Check if a user thread is running a non-transactional update
 
242
  @param session  user thread
 
243
  @retval 0 the user thread is not running a non-transactional update
 
244
  @retval 1 the user thread is running a non-transactional update
 
245
*/
 
246
int session_non_transactional_update(const Session *session);
 
247
 
 
248
/**
 
249
  Get the user thread's binary logging format
 
250
  @param session  user thread
 
251
  @return Value to be used as index into the binlog_format_names array
 
252
*/
 
253
int session_binlog_format(const Session *session);
 
254
 
 
255
/**
 
256
  Mark transaction to rollback and mark error as fatal to a sub-statement.
 
257
  @param  session   Thread handle
 
258
  @param  all   TRUE <=> rollback main transaction.
 
259
*/
 
260
void session_mark_transaction_to_rollback(Session *session, bool all);
 
261
}
 
262
 
 
263
typedef struct trx_struct trx_t;
 
264
/************************************************************************
 
265
Converts an InnoDB error code to a MySQL error code and also tells to MySQL
 
266
about a possible transaction rollback inside InnoDB caused by a lock wait
 
267
timeout or a deadlock. */
 
268
extern "C"
 
269
int
 
270
convert_error_code_to_mysql(
 
271
/*========================*/
 
272
                                        /* out: MySQL error code */
 
273
        int             error,          /* in: InnoDB error code */
 
274
        ulint           flags,          /* in: InnoDB table flags, or 0 */
 
275
        Session         *session);      /* in: user thread handle or NULL */
 
276
 
 
277
/*************************************************************************
 
278
Allocates an InnoDB transaction for a MySQL handler object. */
 
279
extern "C"
 
280
trx_t*
 
281
innobase_trx_allocate(
 
282
/*==================*/
 
283
                                        /* out: InnoDB transaction handle */
 
284
        Session         *session);      /* in: user thread handle */
 
285
#endif /* INNODB_HANDLER_HA_INNODB_H */