1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
3
* Derived from ha_example.h
4
* Copyright (C) 2003 MySQL AB
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
* 2005-11-10 Paul McCullagh
30
#include <drizzled/common.h>
31
#include <drizzled/thr_lock.h>
32
#include <drizzled/cursor.h>
33
#include <drizzled/plugin/transactional_storage_engine.h>
34
using namespace drizzled;
35
using namespace drizzled::plugin;
37
#include "mysql_priv.h"
43
#ifdef USE_PRAGMA_INTERFACE
44
#pragma interface /* gcc class implementation */
47
#if MYSQL_VERSION_ID <= 50120
48
#define thd_killed(t) (t)->killed
51
#if MYSQL_VERSION_ID >= 50120
59
class PBXTStorageEngine : public drizzled::plugin::TransactionalStorageEngine
62
int delete_system_table(const char *table_path);
63
int rename_system_table(const char * from, const char * to);
66
PBXTStorageEngine(std::string name_arg)
67
: drizzled::plugin::TransactionalStorageEngine(name_arg,
70
HTON_CAN_INDEX_BLOBS |
74
void operator delete(void *) {}
75
void operator delete[] (void *) {}
77
/* override */ int close_connection(Session *);
78
/* override */ int commit(Session *, bool);
79
/* override */ int rollback(Session *, bool);
80
/* override */ Cursor *create(TableShare&, memory::Root *);
81
/* override */ void drop_database(char *);
82
/* override */ bool show_status(Session *, stat_print_fn *, enum ha_stat_type);
83
/* override */ const char **bas_ext() const;
84
/* override */ int doCreateTable(Session& session, Table &table_arg, TableIdentifier& ident, drizzled::message::Table &proto);
85
/* override */ int doRenameTable(Session& session, TableIdentifier& from, TableIdentifier& to);
86
/* override */ int doDropTable(Session &session, TableIdentifier& ident);
88
/* override */ int doStartTransaction(Session *session, start_transaction_option_t options);
89
/* override */ int doStartConsistentSnapshot(Session *) { /* obsolete */ return -1; }
91
/* override */ int doSetSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
92
/* override */ int doRollbackToSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
93
/* override */ int doReleaseSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
95
/* override */ int doCommit(drizzled::Session*, bool);
96
/* override */ int doRollback(drizzled::Session*, bool);
98
/* override */ uint32_t max_supported_keys(void) const { return -1; }
99
/* override */ uint32_t max_supported_key_part_length(void) const { return MAX_KEY_LENGTH; }
101
/* override */ void doGetTableIdentifiers(drizzled::CachedDirectory&,
102
drizzled::SchemaIdentifier&,
103
drizzled::TableIdentifiers&) {}
105
/* override */ void doGetTableNames(CachedDirectory&,
107
std::set<std::string>&) {}
109
/* override */ bool doDoesTableExist(Session&, TableIdentifier &identifier);
111
~PBXTStorageEngine();
114
typedef PBXTStorageEngine handlerton;
118
extern handlerton *pbxt_hton;
121
* XTShareRec is a structure that will be shared amoung all open handlers.
123
typedef struct XTShare {
124
XTPathStrPtr sh_table_path;
127
XTTableHPtr sh_table; /* This is a XTTableHPtr, a reference to the XT internal table handle. */
129
uint sh_dic_key_count;
130
XTIndexPtr *sh_dic_keys; /* A reference to the XT internal index list. */
131
xtBool sh_recalc_selectivity; /* This is set to TRUE if when have < 100 rows when the table is openned. */
133
/* We use a trick here to get an exclusive lock
134
* on a table. The trick avoids having to use a
135
* semaphore if a thread does not want
138
xt_mutex_type *sh_ex_mutex;
139
xt_cond_type *sh_ex_cond;
140
xtBool sh_table_lock; /* Set to TRUE if a lock on the table is held. */
141
ha_pbxt *sh_handlers; /* Double linked list of handlers for a particular table. */
142
xtWord8 sh_min_auto_inc; /* Used to proporgate the current auto-inc over a DELETE FROM
143
* (does not work if the server shuts down in between!).
146
THR_LOCK sh_lock; /* MySQL lock */
147
} XTShareRec, *XTSharePtr;
150
* Class definition for the storage engine
152
class ha_pbxt: public handler
155
XTSharePtr pb_share; /* Shared table info */
157
XTOpenTablePtr pb_open_tab; /* This is a XTOpenTablePtr (a reference to the XT internal table handle)! */
159
xtBool pb_key_read; /* No Need to retrieve the entire row, index values are sufficient. */
160
u_int pb_import_row_count;
161
int pb_ignore_dup_key;
162
u_int pb_ind_row_count;
164
THR_LOCK_DATA pb_lock; /* MySQL lock */
166
ha_pbxt *pb_ex_next; /* Double linked list of handlers for a particular table. */
169
xtBool pb_lock_table; /* The operation requires a table lock. */
170
int pb_table_locked; /* TRUE of this handler holds the table lock. */
171
int pb_ex_in_use; /* Set to 1 while when the handler is in use. */
173
THD *pb_mysql_thd; /* A pointer to the MySQL thread. */
174
xtBool pb_in_stat; /* TRUE of start_stmt() was issued */
177
ha_pbxt(handlerton *hton, TableShare& table_arg);
179
ha_pbxt(handlerton *hton, TABLE_SHARE *table_arg);
181
virtual ~ha_pbxt() { }
183
/* The name that will be used for display purposes */
184
const char *table_type() const { return "PBXT"; }
187
* The name of the index type that will be used for display
188
* don't implement this method unless you really have indexes.
190
const char *index_type(uint inx) { (void) inx; return "BTREE"; }
192
const char **bas_ext() const;
194
MX_UINT8_T table_cache_type();
197
* This is a list of flags that says what the storage engine
198
* implements. The current table flags are documented in
201
MX_TABLE_TYPES_T table_flags() const;
204
* part is the key part to check. First key part is 0
205
* If all_parts it's set, MySQL want to know the flags for the combined
206
* index up to and including 'part'.
208
MX_ULONG_T index_flags(uint inx, uint part, bool all_parts) const;
211
* unireg.cc will call the following to make sure that the storage engine can
212
* handle the data it is about to send.
214
* Return *real* limits of your storage engine here. MySQL will do
215
* min(your_limits, MySQL_limits) automatically
217
* Theoretically PBXT supports any number of key parts, etc.
218
* Practically this is not true of course.
220
uint max_supported_record_length() const { return UINT_MAX; }
221
uint max_supported_keys() const { return 512; }
222
uint max_supported_key_parts() const { return 128; }
223
uint max_supported_key_length() const;
224
uint max_supported_key_part_length() const;
228
double read_time(uint index, uint ranges, ha_rows rows);
230
bool has_transactions() { return 1; }
233
* Everything below are methods that we implement in ha_pbxt.cc.
235
void internal_close(THD *thd, struct XTThread *self);
236
int open(const char *name, int mode, uint test_if_locked); // required
238
int close(void); // required
240
void init_auto_increment(xtWord8 min_auto_inc);
241
void get_auto_increment(MX_ULONGLONG_T offset, MX_ULONGLONG_T increment,
242
MX_ULONGLONG_T nb_desired_values,
243
MX_ULONGLONG_T *first_value,
244
MX_ULONGLONG_T *nb_reserved_values);
245
void set_auto_increment(Field *nr);
247
int write_row(byte * buf);
248
int update_row(const byte * old_data, byte * new_data);
249
int delete_row(const byte * buf);
251
/* Index access functions: */
252
int xt_index_in_range(register XTOpenTablePtr ot, register XTIndexPtr ind, register XTIdxSearchKeyPtr search_key, byte *buf);
253
int xt_index_next_read(register XTOpenTablePtr ot, register XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
254
int xt_index_prev_read(XTOpenTablePtr ot, XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
255
int index_init(uint idx, bool sorted);
257
int index_read(byte * buf, const byte * key,
258
uint key_len, enum ha_rkey_function find_flag);
259
int index_read_idx(byte * buf, uint idx, const byte * key,
260
uint key_len, enum ha_rkey_function find_flag);
261
int index_read_xt(byte * buf, uint idx, const byte * key,
262
uint key_len, enum ha_rkey_function find_flag);
263
int index_next(byte * buf);
264
int index_next_same(byte * buf, const byte *key, uint length);
265
int index_prev(byte * buf);
266
int index_first(byte * buf);
267
int index_last(byte * buf);
268
int index_read_last(byte * buf, const byte * key, uint key_len);
270
/* Sequential scan functions: */
271
int rnd_init(bool scan); //required
273
int rnd_next(byte *buf); //required
274
int rnd_pos(byte * buf, byte *pos); //required
275
void position(const byte *record); //required
276
#if MYSQL_VERSION_ID < 50114
282
int extra(enum ha_extra_function operation);
284
int external_lock(THD *thd, int lock_type); //required
285
int start_stmt(THD *thd, thr_lock_type lock_type);
287
int delete_all_rows(void);
288
int repair(THD* thd, HA_CHECK_OPT* check_opt);
290
int analyze(THD* thd);
291
int optimize(THD* thd);
294
int analyze(THD* thd, HA_CHECK_OPT* check_opt);
295
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
296
int check(THD* thd, HA_CHECK_OPT* check_opt);
298
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
300
int delete_system_table(const char *table_path);
301
int delete_table(const char *from);
302
int rename_system_table(const char * from, const char * to);
303
int rename_table(const char * from, const char * to);
304
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); //required
306
void update_create_info(HA_CREATE_INFO *create_info);
308
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); //required
310
/* Foreign key support: */
311
//bool is_fk_defined_on_table_or_index(uint index);
312
char* get_foreign_key_create_info();
314
int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
315
//bool can_switch_engines();
316
uint referenced_by_foreign_key();
318
void free_foreign_key_create_info(char* str);
320
virtual bool get_error_message(int error, String *buf);
323
/* From ha_pbxt.cc: */
324
#define XT_TAB_NAME_WITH_EXT_SIZE XT_TABLE_NAME_SIZE+4
330
void xt_ha_unlock_table(struct XTThread *self, void *share);
331
void xt_ha_close_global_database(XTThreadPtr self);
332
void xt_ha_open_database_of_table(struct XTThread *self, XTPathStrPtr table_path);
333
struct XTThread *xt_ha_set_current_thread(THD *thd, XTExceptionPtr e);
334
void xt_ha_close_connection(THD* thd);
335
struct XTThread *xt_ha_thd_to_self(THD* thd);
336
int xt_ha_pbxt_to_mysql_error(int xt_err);
337
int xt_ha_pbxt_thread_error_for_mysql(THD *thd, const XTThreadPtr self, int ignore_dup_key);
338
void xt_ha_all_threads_close_database(XTThreadPtr self, XTDatabase *db);
339
void ha_set_auto_increment(XTOpenTablePtr ot, Field *nr);
342
* These hooks are suppossed to only be used by InnoDB:
345
#ifdef INNODB_COMPATIBILITY_HOOKS
346
extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd);
347
extern "C" char **thd_query(MYSQL_THD thd);
348
extern "C" int thd_slave_thread(const MYSQL_THD thd);
349
extern "C" int thd_binlog_format(const MYSQL_THD thd);
350
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
352
#define thd_charset(t) (t)->charset()
353
#define thd_query(t) &(t)->query
354
#define thd_slave_thread(t) (t)->slave_thread
355
#define thd_binlog_format(t) (t)->variables.binlog_format
356
#define thd_mark_transaction_to_rollback(t) mark_transaction_to_rollback(t, all)
357
#endif // INNODB_COMPATIBILITY_HOOKS */
358
#endif /* !DRIZZLED */
360
/* How to lock MySQL mutexes! */
363
#if MYSQL_VERSION_ID < 60000
364
#if MYSQL_VERSION_ID < 50123
365
#define myxt_mutex_lock(x) safe_mutex_lock(x,__FILE__,__LINE__)
367
#define myxt_mutex_lock(x) safe_mutex_lock(x,0,__FILE__,__LINE__)
370
#if MYSQL_VERSION_ID < 60004
371
#define myxt_mutex_lock(x) safe_mutex_lock(x,__FILE__,__LINE__)
373
#define myxt_mutex_lock(x) safe_mutex_lock(x,0,__FILE__,__LINE__)
377
#define myxt_mutex_t safe_mutex_t
378
#define myxt_mutex_unlock(x) safe_mutex_unlock(x,__FILE__,__LINE__)
382
#ifdef MY_PTHREAD_FASTMUTEX
383
#define myxt_mutex_lock(x) my_pthread_fastmutex_lock(x)
384
#define myxt_mutex_t my_pthread_fastmutex_t
385
#define myxt_mutex_unlock(x) pthread_mutex_unlock(&(x)->mutex)
387
#define myxt_mutex_lock(x) pthread_mutex_lock(x)
388
#define myxt_mutex_t pthread_mutex_t
389
#define myxt_mutex_unlock(x) pthread_mutex_unlock(x)