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 |
75
void operator delete(void *) {}
76
void operator delete[] (void *) {}
78
/* override */ int close_connection(Session *);
79
/* override */ int commit(Session *, bool);
80
/* override */ int rollback(Session *, bool);
81
/* override */ Cursor *create(TableShare&, memory::Root *);
82
/* override */ void drop_database(char *);
83
/* override */ bool show_status(Session *, stat_print_fn *, enum ha_stat_type);
84
/* override */ const char **bas_ext() const;
85
/* override */ int doCreateTable(Session& session, Table &table_arg, TableIdentifier& ident, drizzled::message::Table &proto);
86
/* override */ int doRenameTable(Session& session, TableIdentifier& from, TableIdentifier& to);
87
/* override */ int doDropTable(Session &session, TableIdentifier& ident);
89
/* override */ int doStartTransaction(Session *session, start_transaction_option_t options);
90
/* override */ int doStartConsistentSnapshot(Session *) { /* obsolete */ return -1; }
92
/* override */ int doSetSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
93
/* override */ int doRollbackToSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
94
/* override */ int doReleaseSavepoint(drizzled::Session* thd, drizzled::NamedSavepoint&);
96
/* override */ int doCommit(drizzled::Session*, bool);
97
/* override */ int doRollback(drizzled::Session*, bool);
99
/* override */ uint32_t max_supported_keys(void) const { return -1; }
100
/* override */ uint32_t max_supported_key_part_length(void) const { return MAX_KEY_LENGTH; }
102
/* override */ void doGetTableIdentifiers(drizzled::CachedDirectory&,
103
drizzled::SchemaIdentifier&,
104
drizzled::TableIdentifiers&) {}
106
/* override */ void doGetTableNames(CachedDirectory&,
108
std::set<std::string>&) {}
110
/* override */ bool doDoesTableExist(Session&, TableIdentifier &identifier);
112
~PBXTStorageEngine();
115
typedef PBXTStorageEngine handlerton;
119
extern handlerton *pbxt_hton;
122
* XTShareRec is a structure that will be shared amoung all open handlers.
124
typedef struct XTShare {
125
XTPathStrPtr sh_table_path;
128
XTTableHPtr sh_table; /* This is a XTTableHPtr, a reference to the XT internal table handle. */
130
uint sh_dic_key_count;
131
XTIndexPtr *sh_dic_keys; /* A reference to the XT internal index list. */
132
xtBool sh_recalc_selectivity; /* This is set to TRUE if when have < 100 rows when the table is openned. */
134
/* We use a trick here to get an exclusive lock
135
* on a table. The trick avoids having to use a
136
* semaphore if a thread does not want
139
xt_mutex_type *sh_ex_mutex;
140
xt_cond_type *sh_ex_cond;
141
xtBool sh_table_lock; /* Set to TRUE if a lock on the table is held. */
142
ha_pbxt *sh_handlers; /* Double linked list of handlers for a particular table. */
143
xtWord8 sh_min_auto_inc; /* Used to proporgate the current auto-inc over a DELETE FROM
144
* (does not work if the server shuts down in between!).
147
THR_LOCK sh_lock; /* MySQL lock */
148
} XTShareRec, *XTSharePtr;
151
* Class definition for the storage engine
153
class ha_pbxt: public handler
156
XTSharePtr pb_share; /* Shared table info */
158
XTOpenTablePtr pb_open_tab; /* This is a XTOpenTablePtr (a reference to the XT internal table handle)! */
160
xtBool pb_key_read; /* No Need to retrieve the entire row, index values are sufficient. */
161
u_int pb_import_row_count;
162
int pb_ignore_dup_key;
163
u_int pb_ind_row_count;
165
THR_LOCK_DATA pb_lock; /* MySQL lock */
167
ha_pbxt *pb_ex_next; /* Double linked list of handlers for a particular table. */
170
xtBool pb_lock_table; /* The operation requires a table lock. */
171
int pb_table_locked; /* TRUE of this handler holds the table lock. */
172
int pb_ex_in_use; /* Set to 1 while when the handler is in use. */
174
THD *pb_mysql_thd; /* A pointer to the MySQL thread. */
175
xtBool pb_in_stat; /* TRUE of start_stmt() was issued */
178
ha_pbxt(handlerton *hton, TableShare& table_arg);
180
ha_pbxt(handlerton *hton, TABLE_SHARE *table_arg);
182
virtual ~ha_pbxt() { }
184
/* The name that will be used for display purposes */
185
const char *table_type() const { return "PBXT"; }
188
* The name of the index type that will be used for display
189
* don't implement this method unless you really have indexes.
191
const char *index_type(uint inx) { (void) inx; return "BTREE"; }
193
const char **bas_ext() const;
195
MX_UINT8_T table_cache_type();
198
* This is a list of flags that says what the storage engine
199
* implements. The current table flags are documented in
202
MX_TABLE_TYPES_T table_flags() const;
205
* part is the key part to check. First key part is 0
206
* If all_parts it's set, MySQL want to know the flags for the combined
207
* index up to and including 'part'.
209
MX_ULONG_T index_flags(uint inx, uint part, bool all_parts) const;
212
* unireg.cc will call the following to make sure that the storage engine can
213
* handle the data it is about to send.
215
* Return *real* limits of your storage engine here. MySQL will do
216
* min(your_limits, MySQL_limits) automatically
218
* Theoretically PBXT supports any number of key parts, etc.
219
* Practically this is not true of course.
221
uint max_supported_record_length() const { return UINT_MAX; }
222
uint max_supported_keys() const { return 512; }
223
uint max_supported_key_parts() const { return 128; }
224
uint max_supported_key_length() const;
225
uint max_supported_key_part_length() const;
229
double read_time(uint index, uint ranges, ha_rows rows);
231
bool has_transactions() { return 1; }
234
* Everything below are methods that we implement in ha_pbxt.cc.
236
void internal_close(THD *thd, struct XTThread *self);
237
int open(const char *name, int mode, uint test_if_locked); // required
239
int close(void); // required
241
void init_auto_increment(xtWord8 min_auto_inc);
242
void get_auto_increment(MX_ULONGLONG_T offset, MX_ULONGLONG_T increment,
243
MX_ULONGLONG_T nb_desired_values,
244
MX_ULONGLONG_T *first_value,
245
MX_ULONGLONG_T *nb_reserved_values);
246
void set_auto_increment(Field *nr);
248
int write_row(byte * buf);
249
int update_row(const byte * old_data, byte * new_data);
250
int delete_row(const byte * buf);
252
/* Index access functions: */
253
int xt_index_in_range(register XTOpenTablePtr ot, register XTIndexPtr ind, register XTIdxSearchKeyPtr search_key, byte *buf);
254
int xt_index_next_read(register XTOpenTablePtr ot, register XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
255
int xt_index_prev_read(XTOpenTablePtr ot, XTIndexPtr ind, xtBool key_only, register XTIdxSearchKeyPtr search_key, byte *buf);
256
int index_init(uint idx, bool sorted);
258
int index_read(byte * buf, const byte * key,
259
uint key_len, enum ha_rkey_function find_flag);
260
int index_read_idx(byte * buf, uint idx, const byte * key,
261
uint key_len, enum ha_rkey_function find_flag);
262
int index_read_xt(byte * buf, uint idx, const byte * key,
263
uint key_len, enum ha_rkey_function find_flag);
264
int index_next(byte * buf);
265
int index_next_same(byte * buf, const byte *key, uint length);
266
int index_prev(byte * buf);
267
int index_first(byte * buf);
268
int index_last(byte * buf);
269
int index_read_last(byte * buf, const byte * key, uint key_len);
271
/* Sequential scan functions: */
272
int rnd_init(bool scan); //required
274
int rnd_next(byte *buf); //required
275
int rnd_pos(byte * buf, byte *pos); //required
276
void position(const byte *record); //required
277
#if MYSQL_VERSION_ID < 50114
283
int extra(enum ha_extra_function operation);
285
int external_lock(THD *thd, int lock_type); //required
286
int start_stmt(THD *thd, thr_lock_type lock_type);
288
int delete_all_rows(void);
289
int repair(THD* thd, HA_CHECK_OPT* check_opt);
290
int analyze(THD* thd, HA_CHECK_OPT* check_opt);
291
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
292
int check(THD* thd, HA_CHECK_OPT* check_opt);
293
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
295
int delete_system_table(const char *table_path);
296
int delete_table(const char *from);
297
int rename_system_table(const char * from, const char * to);
298
int rename_table(const char * from, const char * to);
299
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); //required
301
void update_create_info(HA_CREATE_INFO *create_info);
303
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); //required
305
/* Foreign key support: */
306
//bool is_fk_defined_on_table_or_index(uint index);
307
char* get_foreign_key_create_info();
309
int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
310
//bool can_switch_engines();
311
uint referenced_by_foreign_key();
313
void free_foreign_key_create_info(char* str);
315
virtual bool get_error_message(int error, String *buf);
318
/* From ha_pbxt.cc: */
319
#define XT_TAB_NAME_WITH_EXT_SIZE XT_TABLE_NAME_SIZE+4
325
void xt_ha_unlock_table(struct XTThread *self, void *share);
326
void xt_ha_close_global_database(XTThreadPtr self);
327
void xt_ha_open_database_of_table(struct XTThread *self, XTPathStrPtr table_path);
328
struct XTThread *xt_ha_set_current_thread(THD *thd, XTExceptionPtr e);
329
void xt_ha_close_connection(THD* thd);
330
struct XTThread *xt_ha_thd_to_self(THD* thd);
331
int xt_ha_pbxt_to_mysql_error(int xt_err);
332
int xt_ha_pbxt_thread_error_for_mysql(THD *thd, const XTThreadPtr self, int ignore_dup_key);
333
void xt_ha_all_threads_close_database(XTThreadPtr self, XTDatabase *db);
334
void ha_set_auto_increment(XTOpenTablePtr ot, Field *nr);
337
* These hooks are suppossed to only be used by InnoDB:
340
#ifdef INNODB_COMPATIBILITY_HOOKS
341
extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd);
342
extern "C" char **thd_query(MYSQL_THD thd);
343
extern "C" int thd_slave_thread(const MYSQL_THD thd);
344
extern "C" int thd_non_transactional_update(const MYSQL_THD thd);
345
extern "C" int thd_binlog_format(const MYSQL_THD thd);
346
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
348
#define thd_charset(t) (t)->charset()
349
#define thd_query(t) &(t)->query
350
#define thd_slave_thread(t) (t)->slave_thread
351
#define thd_non_transactional_update(t) (t)->transaction.all.modified_non_trans_table
352
#define thd_binlog_format(t) (t)->variables.binlog_format
353
#define thd_mark_transaction_to_rollback(t) mark_transaction_to_rollback(t, all)
354
#endif // INNODB_COMPATIBILITY_HOOKS */
355
#endif /* !DRIZZLED */
357
/* How to lock MySQL mutexes! */
360
#if MYSQL_VERSION_ID < 60000
361
#if MYSQL_VERSION_ID < 50123
362
#define myxt_mutex_lock(x) safe_mutex_lock(x,__FILE__,__LINE__)
364
#define myxt_mutex_lock(x) safe_mutex_lock(x,0,__FILE__,__LINE__)
367
#if MYSQL_VERSION_ID < 60004
368
#define myxt_mutex_lock(x) safe_mutex_lock(x,__FILE__,__LINE__)
370
#define myxt_mutex_lock(x) safe_mutex_lock(x,0,__FILE__,__LINE__)
374
#define myxt_mutex_t safe_mutex_t
375
#define myxt_mutex_unlock(x) safe_mutex_unlock(x,__FILE__,__LINE__)
379
#ifdef MY_PTHREAD_FASTMUTEX
380
#define myxt_mutex_lock(x) my_pthread_fastmutex_lock(x)
381
#define myxt_mutex_t my_pthread_fastmutex_t
382
#define myxt_mutex_unlock(x) pthread_mutex_unlock(&(x)->mutex)
384
#define myxt_mutex_lock(x) pthread_mutex_lock(x)
385
#define myxt_mutex_t pthread_mutex_t
386
#define myxt_mutex_unlock(x) pthread_mutex_unlock(x)