~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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