~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Monty Taylor
  • Date: 2009-09-30 07:01:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090930070132-b1ol1xu1rpajdddy
Small namespace cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#define DRIZZLED_HANDLER_H
22
22
 
23
23
#include <drizzled/xid.h>
 
24
#include <drizzled/discrete_interval.h>
24
25
 
25
26
/* Definitions for parameters to do with handler-routines */
26
27
 
27
 
#include <storage/myisam/keycache.h>
28
28
#include <mysys/thr_lock.h>
29
29
#include <mysys/hash.h>
30
30
#include <drizzled/sql_string.h>
31
31
#include <drizzled/sql_list.h>
32
 
#include <drizzled/handlerton.h>
 
32
#include <drizzled/plugin/storage_engine.h>
33
33
#include <drizzled/handler_structs.h>
34
34
#include <drizzled/ha_statistics.h>
 
35
#include <drizzled/atomics.h>
 
36
 
 
37
#include <drizzled/message/table.pb.h>
35
38
 
36
39
/* Bits to show what an alter table will do */
37
40
#include <drizzled/sql_bitmap.h>
38
41
 
 
42
#include <drizzled/handler.h>
 
43
 
 
44
#include <bitset>
 
45
#include <algorithm>
 
46
 
39
47
#define HA_MAX_ALTER_FLAGS 40
40
 
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
48
 
 
49
 
 
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
51
 
 
52
extern drizzled::atomic<uint32_t> refresh_version;  /* Increments on each reload */
41
53
 
42
54
 
43
55
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
49
61
 
50
62
class Table;
51
63
class TableList;
52
 
typedef struct st_table_share TABLE_SHARE;
 
64
class TableShare;
 
65
class Select_Lex_Unit;
53
66
struct st_foreign_key_info;
54
67
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
 
68
struct order_st;
55
69
 
56
70
class Item;
57
71
struct st_table_log_memory_entry;
58
72
 
 
73
class LEX;
 
74
class Select_Lex;
 
75
class AlterInfo;
 
76
class select_result;
 
77
class CreateField;
 
78
class sys_var_str;
 
79
class Item_ident;
 
80
typedef struct st_sort_field SORT_FIELD;
 
81
 
 
82
typedef List<Item> List_item;
 
83
 
59
84
typedef struct st_savepoint SAVEPOINT;
60
85
extern uint32_t savepoint_alloc_size;
61
86
extern KEY_CREATE_INFO default_key_create_info;
67
92
 
68
93
class COST_VECT;
69
94
 
70
 
 
71
 
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
72
 
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
73
 
 
74
95
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
75
96
/*
76
97
  bitmap with first N+1 bits set
109
130
  =================
110
131
  [Warning: this description is work in progress and may be incomplete]
111
132
  The table record is stored in a fixed-size buffer:
112
 
   
 
133
 
113
134
    record: null_bytes, column1_data, column2_data, ...
114
 
  
115
 
  The offsets of the parts of the buffer are also fixed: every column has 
 
135
 
 
136
  The offsets of the parts of the buffer are also fixed: every column has
116
137
  an offset to its column{i}_data, and if it is nullable it also has its own
117
 
  bit in null_bytes. 
 
138
  bit in null_bytes.
118
139
 
119
140
  The record buffer only includes data about columns that are marked in the
120
141
  relevant column set (table->read_set and/or table->write_set, depending on
121
 
  the situation). 
 
142
  the situation).
122
143
  <not-sure>It could be that it is required that null bits of non-present
123
144
  columns are set to 1</not-sure>
124
145
 
125
146
  VARIOUS EXCEPTIONS AND SPECIAL CASES
126
147
 
127
 
  f the table has no nullable columns, then null_bytes is still 
128
 
  present, its length is one byte <not-sure> which must be set to 0xFF 
 
148
  f the table has no nullable columns, then null_bytes is still
 
149
  present, its length is one byte <not-sure> which must be set to 0xFF
129
150
  at all times. </not-sure>
130
 
  
 
151
 
131
152
  If the table has columns of type BIT, then certain bits from those columns
132
153
  may be stored in null_bytes as well. Grep around for Field_bit for
133
154
  details.
134
155
 
135
 
  For blob columns (see Field_blob), the record buffer stores length of the 
136
 
  data, following by memory pointer to the blob data. The pointer is owned 
 
156
  For blob columns (see Field_blob), the record buffer stores length of the
 
157
  data, following by memory pointer to the blob data. The pointer is owned
137
158
  by the storage engine and is valid until the next operation.
138
159
 
139
160
  If a blob column has NULL value, then its length and blob data pointer
144
165
{
145
166
public:
146
167
  typedef uint64_t Table_flags;
 
168
 
147
169
protected:
148
 
  struct st_table_share *table_share;   /* The table definition */
 
170
  TableShare *table_share;   /* The table definition */
149
171
  Table *table;               /* The current open table */
150
172
  Table_flags cached_table_flags;       /* Set on init() and open() */
151
173
 
152
174
  ha_rows estimation_rows_to_insert;
153
175
public:
154
 
  handlerton *ht;                 /* storage engine of this handler */
155
 
  unsigned char *ref;                           /* Pointer to current row */
 
176
  drizzled::plugin::StorageEngine *engine;      /* storage engine of this handler */
 
177
  unsigned char *ref;                           /* Pointer to current row */
156
178
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
157
179
 
158
180
  ha_statistics stats;
166
188
 
167
189
  /** true <=> we're currently traversing a range in mrr_cur_range. */
168
190
  bool mrr_have_range;
 
191
 
 
192
  bool eq_range;
 
193
  /*
 
194
    true <=> the engine guarantees that returned records are within the range
 
195
    being scanned.
 
196
  */
 
197
  bool in_range_check_pushed_down;
 
198
 
169
199
  /** Current range (the one we're now returning rows from) */
170
200
  KEY_MULTI_RANGE mrr_cur_range;
171
201
 
173
203
  key_range save_end_range, *end_range;
174
204
  KEY_PART_INFO *range_key_part;
175
205
  int key_compare_result_on_equal;
176
 
  bool eq_range;
177
 
  /* 
178
 
    true <=> the engine guarantees that returned records are within the range
179
 
    being scanned.
180
 
  */
181
 
  bool in_range_check_pushed_down;
182
206
 
183
207
  uint32_t errkey;                              /* Last dup key */
184
208
  uint32_t key_used_on_scan;
188
212
  enum {NONE=0, INDEX, RND} inited;
189
213
  bool locked;
190
214
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
191
 
  const Item *pushed_cond;
192
 
 
193
 
  Item *pushed_idx_cond;
194
 
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
195
215
 
196
216
  /**
197
217
    next_insert_id is the next value which should be inserted into the
216
236
  */
217
237
  Discrete_interval auto_inc_interval_for_cur_row;
218
238
 
219
 
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
 
239
  handler(drizzled::plugin::StorageEngine *engine_arg, TableShare *share_arg)
220
240
    :table_share(share_arg), table(0),
221
 
    estimation_rows_to_insert(0), ht(ht_arg),
 
241
    estimation_rows_to_insert(0), engine(engine_arg),
222
242
    ref(0), in_range_check_pushed_down(false),
223
243
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
224
244
    ref_length(sizeof(my_off_t)),
225
245
    inited(NONE),
226
246
    locked(false), implicit_emptied(0),
227
 
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
228
247
    next_insert_id(0), insert_id_for_cur_row(0)
229
248
    {}
230
 
  virtual ~handler(void)
231
 
  {
232
 
    assert(locked == false);
233
 
    /* TODO: assert(inited == NONE); */
234
 
  }
 
249
  virtual ~handler(void);
235
250
  virtual handler *clone(MEM_ROOT *mem_root);
236
251
  /** This is called after create to allow us to set up cached variables */
237
252
  void init()
264
279
  int ha_delete_row(const unsigned char * buf);
265
280
  void ha_release_auto_increment();
266
281
 
267
 
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
268
282
  /** to be actually called to get 'check()' functionality*/
269
283
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
270
 
  int ha_repair(Session* session, HA_CHECK_OPT* check_opt);
 
284
 
271
285
  void ha_start_bulk_insert(ha_rows rows);
272
286
  int ha_end_bulk_insert();
273
287
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
276
290
  int ha_reset_auto_increment(uint64_t value);
277
291
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
278
292
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
279
 
  bool ha_check_and_repair(Session *session);
 
293
 
280
294
  int ha_disable_indexes(uint32_t mode);
281
295
  int ha_enable_indexes(uint32_t mode);
282
296
  int ha_discard_or_import_tablespace(bool discard);
283
 
  void ha_prepare_for_alter();
284
 
  int ha_rename_table(const char *from, const char *to);
285
 
  int ha_delete_table(const char *name);
286
297
  void ha_drop_table(const char *name);
287
298
 
288
 
  int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
289
 
 
290
 
  int ha_create_handler_files(const char *name, const char *old_name,
291
 
                              int action_flag, HA_CREATE_INFO *info);
292
 
 
293
299
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
294
300
  int update_auto_increment();
295
301
  void print_keydup_error(uint32_t key_nr, const char *msg);
296
302
  virtual void print_error(int error, myf errflag);
297
303
  virtual bool get_error_message(int error, String *buf);
298
304
  uint32_t get_dup_key(int error);
299
 
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share);
 
305
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
300
306
 
301
307
  /* Estimates calculation */
302
308
  virtual double scan_time(void)
303
309
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
304
 
  virtual double read_time(uint32_t index __attribute__((unused)),
305
 
                           uint32_t ranges, ha_rows rows)
 
310
  virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
306
311
  { return rows2double(ranges+rows); }
307
312
 
308
313
  virtual double index_only_read_time(uint32_t keynr, double records);
309
 
  
 
314
 
310
315
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
311
 
                                              void *seq_init_param, 
 
316
                                              void *seq_init_param,
312
317
                                              uint32_t n_ranges, uint32_t *bufsz,
313
318
                                              uint32_t *flags, COST_VECT *cost);
314
319
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
321
326
 
322
327
  virtual const key_map *keys_to_use_for_scanning();
323
328
  bool has_transactions();
324
 
  virtual uint32_t extra_rec_buf_length() const { return 0; }
325
329
 
326
330
  /**
327
331
    This method is used to analyse the error to see whether the error
355
359
  */
356
360
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
357
361
 
358
 
  virtual const char *index_type(uint32_t key_number __attribute__((unused)))
 
362
  virtual const char *index_type(uint32_t)
359
363
  { assert(0); return "";}
360
364
 
361
365
 
362
 
  /**
363
 
    Signal that the table->read_set and table->write_set table maps changed
364
 
    The handler is allowed to set additional bits in the above map in this
365
 
    call. Normally the handler should ignore all calls until we have done
366
 
    a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
367
 
    as there may be several calls to this routine.
368
 
  */
369
 
  virtual void column_bitmaps_signal();
370
366
  uint32_t get_index(void) const { return active_index; }
371
367
  virtual int close(void)=0;
372
368
 
391
387
    @retval  0           Success
392
388
    @retval  >0          Error code
393
389
  */
394
 
  virtual int exec_bulk_update(uint32_t *dup_key_found __attribute__((unused)))
 
390
  virtual int exec_bulk_update(uint32_t *)
395
391
  {
396
392
    assert(false);
397
393
    return HA_ERR_WRONG_COMMAND;
431
427
     row if available. If the key value is null, begin at the first key of the
432
428
     index.
433
429
  */
434
 
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
 
430
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index,
 
431
                                 const unsigned char * key,
435
432
                                 key_part_map keypart_map,
436
433
                                 enum ha_rkey_function find_flag);
437
 
  virtual int index_next(unsigned char * buf __attribute__((unused)))
438
 
   { return  HA_ERR_WRONG_COMMAND; }
439
 
  virtual int index_prev(unsigned char * buf __attribute__((unused)))
440
 
   { return  HA_ERR_WRONG_COMMAND; }
441
 
  virtual int index_first(unsigned char * buf __attribute__((unused)))
442
 
   { return  HA_ERR_WRONG_COMMAND; }
443
 
  virtual int index_last(unsigned char * buf __attribute__((unused)))
444
 
   { return  HA_ERR_WRONG_COMMAND; }
445
 
  virtual int index_next_same(unsigned char *buf __attribute__((unused)),
446
 
                              const unsigned char *key __attribute__((unused)),
447
 
                              uint32_t keylen __attribute__((unused)));
 
434
  virtual int index_next(unsigned char *)
 
435
   { return  HA_ERR_WRONG_COMMAND; }
 
436
  virtual int index_prev(unsigned char *)
 
437
   { return  HA_ERR_WRONG_COMMAND; }
 
438
  virtual int index_first(unsigned char *)
 
439
   { return  HA_ERR_WRONG_COMMAND; }
 
440
  virtual int index_last(unsigned char *)
 
441
   { return  HA_ERR_WRONG_COMMAND; }
 
442
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
448
443
  /**
449
444
     @brief
450
445
     The following functions works like index_read, but it find the last
462
457
  virtual int read_range_next();
463
458
  int compare_key(key_range *range);
464
459
  int compare_key2(key_range *range);
465
 
  virtual int rnd_next(unsigned char *buf __attribute__((unused)))=0;
466
 
  virtual int rnd_pos(unsigned char * buf __attribute__((unused)),
467
 
                      unsigned char *pos __attribute__((unused)))=0;
 
460
  virtual int rnd_next(unsigned char *)=0;
 
461
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
468
462
  /**
469
463
    One has to use this method when to find
470
464
    random position by record as the plain
477
471
    The following function is only needed for tables that may be temporary
478
472
    tables during joins.
479
473
  */
480
 
  virtual int restart_rnd_next(unsigned char *buf __attribute__((unused)),
481
 
                               unsigned char *pos __attribute__((unused)))
482
 
    { return HA_ERR_WRONG_COMMAND; }
483
 
  virtual int rnd_same(unsigned char *buf __attribute__((unused)),
484
 
                       uint32_t inx __attribute__((unused)))
485
 
    { return HA_ERR_WRONG_COMMAND; }
486
 
  virtual ha_rows records_in_range(uint32_t inx __attribute__((unused)),
487
 
                                   key_range *min_key __attribute__((unused)),
488
 
                                   key_range *max_key __attribute__((unused)))
 
474
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
 
475
    { return HA_ERR_WRONG_COMMAND; }
 
476
  virtual int rnd_same(unsigned char *, uint32_t)
 
477
    { return HA_ERR_WRONG_COMMAND; }
 
478
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
489
479
    { return (ha_rows) 10; }
490
480
  virtual void position(const unsigned char *record)=0;
491
 
  virtual int info(uint)=0; // see my_base.h for full description
492
 
  virtual uint32_t calculate_key_hash_value(Field **field_array __attribute__((unused)))
 
481
  virtual int info(uint32_t)=0; // see my_base.h for full description
 
482
  virtual uint32_t calculate_key_hash_value(Field **)
493
483
  { assert(0); return 0; }
494
 
  virtual int extra(enum ha_extra_function operation __attribute__((unused)))
 
484
  virtual int extra(enum ha_extra_function)
495
485
  { return 0; }
496
 
  virtual int extra_opt(enum ha_extra_function operation,
497
 
                        uint32_t cache_size __attribute__((unused)))
 
486
  virtual int extra_opt(enum ha_extra_function operation, uint32_t)
498
487
  { return extra(operation); }
499
488
 
500
489
  /**
518
507
  */
519
508
  virtual void try_semi_consistent_read(bool) {}
520
509
  virtual void unlock_row(void) {}
521
 
  virtual int start_stmt(Session *session __attribute__((unused)),
522
 
                         thr_lock_type lock_type __attribute__((unused)))
 
510
  virtual int start_stmt(Session *, thr_lock_type)
523
511
  {return 0;}
524
512
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
525
513
                                  uint64_t nb_desired_values,
545
533
      insert_id_for_cur_row;
546
534
  }
547
535
 
548
 
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((unused))) {}
 
536
  virtual void update_create_info(HA_CREATE_INFO *) {}
549
537
  int check_old_types(void);
550
 
  virtual int assign_to_keycache(Session* session __attribute__((unused)),
551
 
                                 HA_CHECK_OPT* check_opt __attribute__((unused)))
552
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
553
538
  /* end of the list of admin commands */
554
539
 
555
540
  virtual int indexes_are_disabled(void) {return 0;}
556
 
  virtual char *update_table_comment(const char * comment)
557
 
  { return (char*) comment;}
558
 
  virtual void append_create_info(String *packet __attribute__((unused)))
 
541
  virtual void append_create_info(String *)
559
542
  {}
560
543
  /**
561
544
      If index == MAX_KEY then a check for table is made and if index <
567
550
    @retval   true            Foreign key defined on table or index
568
551
    @retval   false           No foreign key defined
569
552
  */
570
 
  virtual bool is_fk_defined_on_table_or_index(uint32_t index __attribute__((unused)))
571
 
  { return false; }
572
553
  virtual char* get_foreign_key_create_info(void)
573
 
  { return(NULL);}  /* gets foreign key create string from InnoDB */
574
 
  /** used in ALTER Table; 1 if changing storage engine is allowed */
575
 
  virtual bool can_switch_engines(void) { return 1; }
 
554
  { return NULL;}  /* gets foreign key create string from InnoDB */
 
555
  /** used in ALTER Table; if changing storage engine is allowed.
 
556
      e.g. not be allowed if table has foreign key constraints in engine.
 
557
   */
 
558
  virtual bool can_switch_engines(void) { return true; }
576
559
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
577
 
  virtual int get_foreign_key_list(Session *session __attribute__((unused)),
578
 
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((unused)))
 
560
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
579
561
  { return 0; }
580
562
  virtual uint32_t referenced_by_foreign_key() { return 0;}
581
 
  virtual void init_table_handle_for_HANDLER()
582
 
  { return; }       /* prepare InnoDB for HANDLER */
583
 
  virtual void free_foreign_key_create_info(char* str __attribute__((unused))) {}
 
563
  virtual void free_foreign_key_create_info(char *) {}
584
564
  /** The following can be called without an open handler */
585
 
  virtual const char *table_type() const =0;
586
 
  /**
587
 
    If frm_error() is called then we will use this to find out what file
588
 
    extentions exist for the storage engine. This is also used by the default
589
 
    rename_table and delete_table method in handler.cc.
590
 
 
591
 
    For engines that have two file name extentions (separate meta/index file
592
 
    and data file), the order of elements is relevant. First element of engine
593
 
    file name extentions array should be meta/index file extention. Second
594
 
    element - data file extention. This order is assumed by
595
 
    prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
596
 
  */
597
 
  virtual const char **bas_ext() const =0;
598
 
 
599
 
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((unused))) { return 1;}
600
 
  virtual bool get_no_parts(const char *name __attribute__((unused)),
601
 
                            uint32_t *no_parts)
602
 
  {
603
 
    *no_parts= 0;
604
 
    return 0;
605
 
  }
606
565
 
607
566
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
608
567
 
609
 
  virtual int add_index(Table *table_arg __attribute__((unused)),
610
 
                        KEY *key_info __attribute__((unused)),
611
 
                        uint32_t num_of_keys __attribute__((unused)))
612
 
  { return (HA_ERR_WRONG_COMMAND); }
613
 
  virtual int prepare_drop_index(Table *table_arg __attribute__((unused)),
614
 
                                 uint32_t *key_num __attribute__((unused)),
615
 
                                 uint32_t num_of_keys __attribute__((unused)))
616
 
  { return (HA_ERR_WRONG_COMMAND); }
617
 
  virtual int final_drop_index(Table *table_arg __attribute__((unused)))
 
568
  virtual int add_index(Table *, KEY *, uint32_t)
 
569
  { return (HA_ERR_WRONG_COMMAND); }
 
570
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
 
571
  { return (HA_ERR_WRONG_COMMAND); }
 
572
  virtual int final_drop_index(Table *)
618
573
  { return (HA_ERR_WRONG_COMMAND); }
619
574
 
620
575
  uint32_t max_record_length() const
621
 
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
576
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
622
577
  uint32_t max_keys() const
623
 
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
 
578
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
624
579
  uint32_t max_key_parts() const
625
 
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
580
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
626
581
  uint32_t max_key_length() const
627
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
582
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
628
583
  uint32_t max_key_part_length(void) const
629
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
584
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
630
585
 
631
586
  virtual uint32_t max_supported_record_length(void) const
632
587
  { return HA_MAX_REC_LENGTH; }
634
589
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
635
590
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
636
591
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
637
 
  virtual uint32_t min_record_length(uint32_t options __attribute__((unused))) const
638
 
  { return 1; }
639
592
 
640
593
  virtual bool low_byte_first(void) const { return 1; }
641
594
  virtual uint32_t checksum(void) const { return 0; }
642
595
  virtual bool is_crashed(void) const  { return 0; }
643
596
  virtual bool auto_repair(void) const { return 0; }
644
597
 
645
 
 
646
 
#define CHF_CREATE_FLAG 0
647
 
#define CHF_DELETE_FLAG 1
648
 
#define CHF_RENAME_FLAG 2
649
 
 
650
 
 
651
 
  /**
652
 
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
653
 
  */
654
 
  virtual uint32_t lock_count(void) const { return 1; }
655
598
  /**
656
599
    Is not invoked for non-transactional temporary tables.
657
600
 
669
612
                                     THR_LOCK_DATA **to,
670
613
                                     enum thr_lock_type lock_type)=0;
671
614
 
672
 
  /** Type of table for caching query */
673
 
  virtual uint8_t table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
674
 
 
675
 
 
676
 
  /**
677
 
    @brief Register a named table with a call back function to the query cache.
678
 
 
679
 
    @param session The thread handle
680
 
    @param table_key A pointer to the table name in the table cache
681
 
    @param key_length The length of the table name
682
 
    @param[out] engine_callback The pointer to the storage engine call back
683
 
      function
684
 
    @param[out] engine_data Storage engine specific data which could be
685
 
      anything
686
 
 
687
 
    This method offers the storage engine, the possibility to store a reference
688
 
    to a table name which is going to be used with query cache. 
689
 
    The method is called each time a statement is written to the cache and can
690
 
    be used to verify if a specific statement is cachable. It also offers
691
 
    the possibility to register a generic (but static) call back function which
692
 
    is called each time a statement is matched against the query cache.
693
 
 
694
 
    @note If engine_data supplied with this function is different from
695
 
      engine_data supplied with the callback function, and the callback returns
696
 
      false, a table invalidation on the current table will occur.
697
 
 
698
 
    @return Upon success the engine_callback will point to the storage engine
699
 
      call back function, if any, and engine_data will point to any storage
700
 
      engine data used in the specific implementation.
701
 
      @retval true Success
702
 
      @retval false The specified table or current statement should not be
703
 
        cached
704
 
  */
705
 
 
706
 
  virtual bool
707
 
    register_query_cache_table(Session *session __attribute__((unused)),
708
 
                               char *table_key __attribute__((unused)),
709
 
                               uint32_t key_length __attribute__((unused)),
710
 
                               qc_engine_callback *engine_callback,
711
 
                               uint64_t *engine_data __attribute__((unused)))
712
 
  {
713
 
    *engine_callback= 0;
714
 
    return true;
715
 
  }
716
 
 
717
 
 
718
615
 /*
719
616
   @retval true   Primary key (if there is one) is clustered
720
617
                  key covering all fields
726
623
   return memcmp(ref1, ref2, ref_length);
727
624
 }
728
625
 
729
 
 /*
730
 
   Condition pushdown to storage engines
731
 
 */
732
 
 
733
 
 /**
734
 
   Push condition down to the table handler.
735
 
 
736
 
   @param  cond   Condition to be pushed. The condition tree must not be
737
 
                  modified by the by the caller.
738
 
 
739
 
   @return
740
 
     The 'remainder' condition that caller must use to filter out records.
741
 
     NULL means the handler will not return rows that do not match the
742
 
     passed condition.
743
 
 
744
 
   @note
745
 
   The pushed conditions form a stack (from which one can remove the
746
 
   last pushed condition using cond_pop).
747
 
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2 
748
 
   AND ... AND pushed_condN)
749
 
   or less restrictive condition, depending on handler's capabilities.
750
 
 
751
 
   handler->ha_reset() call empties the condition stack.
752
 
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
753
 
   condition stack.
754
 
 */ 
755
 
 virtual const COND *cond_push(const COND *cond) { return cond; }
756
 
 
757
 
 /**
758
 
   Pop the top condition from the condition stack of the handler instance.
759
 
 
760
 
   Pops the top if condition stack, if stack is not empty.
761
 
 */
762
 
 virtual void cond_pop(void) { return; }
763
 
 
764
 
 virtual Item
765
 
   *idx_cond_push(uint32_t keyno __attribute__((unused)),
766
 
                  Item* idx_cond __attribute__((unused)))
767
 
 { return idx_cond; }
768
 
 
769
 
 /*
770
 
    Part of old fast alter table, to be depricated
771
 
  */
772
 
 virtual bool
773
 
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((unused)),
774
 
                              uint32_t table_changes __attribute__((unused)))
775
 
 { return COMPATIBLE_DATA_NO; }
776
 
 
777
 
 /* On-line ALTER Table interface */
778
 
 
779
 
 /**
780
 
    Check if a storage engine supports a particular alter table on-line
781
 
 
782
 
    @param    altered_table     A temporary table show what table is to
783
 
                                change to
784
 
    @param    create_info       Information from the parsing phase about new
785
 
                                table properties.
786
 
    @param    alter_flags       Bitmask that shows what will be changed
787
 
    @param    table_changes     Shows if table layout has changed (for
788
 
                                backwards compatibility with
789
 
                                check_if_incompatible_data
790
 
 
791
 
    @retval   HA_ALTER_ERROR                Unexpected error
792
 
    @retval   HA_ALTER_SUPPORTED_WAIT_LOCK  Supported, but requires DDL lock
793
 
    @retval   HA_ALTER_SUPPORTED_NO_LOCK    Supported
794
 
    @retval   HA_ALTER_NOT_SUPPORTED        Not supported
795
 
 
796
 
    @note
797
 
      The default implementation is implemented to support fast
798
 
      alter table (storage engines that support some changes by
799
 
      just changing the frm file) without any change in the handler
800
 
      implementation.
801
 
 */
802
 
 virtual int
803
 
   check_if_supported_alter(Table *altered_table __attribute__((unused)),
804
 
                            HA_CREATE_INFO *create_info,
805
 
                            HA_ALTER_FLAGS *alter_flags __attribute__((unused)),
806
 
                            uint32_t table_changes)
807
 
 {
808
 
   if (this->check_if_incompatible_data(create_info, table_changes)
809
 
       == COMPATIBLE_DATA_NO)
810
 
     return(HA_ALTER_NOT_SUPPORTED);
811
 
   else if ((*alter_flags & HA_ALTER_STORED_VCOL).is_set())
812
 
     return(HA_ALTER_NOT_SUPPORTED);
813
 
   else
814
 
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
815
 
 }
816
 
 /**
817
 
   Tell storage engine to prepare for the on-line alter table (pre-alter)
818
 
 
819
 
   @param     session               The thread handle
820
 
   @param     altered_table     A temporary table show what table is to
821
 
                                change to
822
 
   @param     alter_info        Storage place for data used during phase1
823
 
                                and phase2
824
 
   @param     alter_flags       Bitmask that shows what will be changed
825
 
 
826
 
   @retval   0      OK
827
 
   @retval   error  error code passed from storage engine
828
 
 */
829
 
 virtual int alter_table_phase1(Session *session __attribute__((unused)),
830
 
                                Table *altered_table __attribute__((unused)),
831
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
832
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
833
 
                                HA_ALTER_FLAGS *alter_flags  __attribute__((unused)))
834
 
 {
835
 
   return HA_ERR_UNSUPPORTED;
836
 
 }
837
 
 /**
838
 
    Tell storage engine to perform the on-line alter table (alter)
839
 
 
840
 
    @param    session               The thread handle
841
 
    @param    altered_table     A temporary table show what table is to
842
 
                                change to
843
 
    @param    alter_info        Storage place for data used during phase1
844
 
                                and phase2
845
 
    @param    alter_flags       Bitmask that shows what will be changed
846
 
 
847
 
    @retval  0      OK
848
 
    @retval  error  error code passed from storage engine
849
 
 
850
 
    @note
851
 
      If check_if_supported_alter returns HA_ALTER_SUPPORTED_WAIT_LOCK
852
 
      this call is to be wrapped with a DDL lock. This is currently NOT
853
 
      supported.
854
 
 */
855
 
 virtual int alter_table_phase2(Session *session  __attribute__((unused)),
856
 
                                Table *altered_table  __attribute__((unused)),
857
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
858
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
859
 
                                HA_ALTER_FLAGS *alter_flags __attribute__((unused)))
860
 
 {
861
 
   return HA_ERR_UNSUPPORTED;
862
 
 }
863
 
 /**
864
 
    Tell storage engine that changed frm file is now on disk and table
865
 
    has been re-opened (post-alter)
866
 
 
867
 
    @param    session               The thread handle
868
 
    @param    table             The altered table, re-opened
869
 
 */
870
 
 virtual int alter_table_phase3(Session *session __attribute__((unused)),
871
 
                                Table *table __attribute__((unused)))
872
 
 {
873
 
   return HA_ERR_UNSUPPORTED;
874
 
 }
875
 
 
876
 
  /**
877
 
    use_hidden_primary_key() is called in case of an update/delete when
878
 
    (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
879
 
    but we don't have a primary key
880
 
  */
881
 
  virtual void use_hidden_primary_key();
882
 
 
883
626
  /**
884
627
    Lock table.
885
628
 
904
647
                                      lock conflict with NOWAIT option
905
648
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
906
649
  */
907
 
  virtual int lock_table(Session *session         __attribute__((unused)),
908
 
                         int lock_type    __attribute__((unused)),
909
 
                         int lock_timeout __attribute__((unused)))
 
650
  virtual int lock_table(Session *, int, int)
910
651
  {
911
652
    return HA_ERR_WRONG_COMMAND;
912
653
  }
913
 
  /*
914
 
    This procedure defines if the storage engine supports virtual columns.
915
 
    Default false means "not supported".
916
 
  */
917
 
  virtual bool check_if_supported_virtual_columns(void) 
918
 
  { return false; }
919
654
 
920
655
protected:
921
656
  /* Service methods for use by storage engines. */
923
658
  void **ha_data(Session *) const;
924
659
  Session *ha_session(void) const;
925
660
 
926
 
  /**
927
 
    Default rename_table() and delete_table() rename/delete files with a
928
 
    given name and extensions from bas_ext().
929
 
 
930
 
    These methods can be overridden, but their default implementation
931
 
    provide useful functionality.
932
 
  */
933
 
  virtual int rename_table(const char *from, const char *to);
934
 
  /**
935
 
    Delete a table in the engine. Called for base as well as temporary
936
 
    tables.
937
 
  */
938
 
  virtual int delete_table(const char *name);
939
 
 
940
661
private:
941
662
  /* Private helpers */
942
663
  inline void mark_trx_read_write();
948
669
  */
949
670
 
950
671
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
951
 
  virtual int index_init(uint32_t idx,
952
 
                         bool sorted __attribute__((unused)))
 
672
  virtual int index_init(uint32_t idx, bool)
953
673
  { active_index= idx; return 0; }
954
674
  virtual int index_end() { active_index= MAX_KEY; return 0; }
955
675
  /**
961
681
  */
962
682
  virtual int rnd_init(bool scan)= 0;
963
683
  virtual int rnd_end() { return 0; }
964
 
  virtual int write_row(unsigned char *buf __attribute__((unused)))
965
 
  {
966
 
    return HA_ERR_WRONG_COMMAND;
967
 
  }
968
 
 
969
 
  virtual int update_row(const unsigned char *old_data __attribute__((unused)),
970
 
                         unsigned char *new_data __attribute__((unused)))
971
 
  {
972
 
    return HA_ERR_WRONG_COMMAND;
973
 
  }
974
 
 
975
 
  virtual int delete_row(const unsigned char *buf __attribute__((unused)))
 
684
  virtual int write_row(unsigned char *)
 
685
  {
 
686
    return HA_ERR_WRONG_COMMAND;
 
687
  }
 
688
 
 
689
  virtual int update_row(const unsigned char *, unsigned char *)
 
690
  {
 
691
    return HA_ERR_WRONG_COMMAND;
 
692
  }
 
693
 
 
694
  virtual int delete_row(const unsigned char *)
976
695
  {
977
696
    return HA_ERR_WRONG_COMMAND;
978
697
  }
1006
725
    @return  non-0 in case of failure, 0 in case of success.
1007
726
    When lock_type is F_UNLCK, the return value is ignored.
1008
727
  */
1009
 
  virtual int external_lock(Session *session __attribute__((unused)),
1010
 
                            int lock_type __attribute__((unused)))
 
728
  virtual int external_lock(Session *, int)
1011
729
  {
1012
730
    return 0;
1013
731
  }
1014
732
  virtual void release_auto_increment(void) { return; };
1015
733
  /** admin commands - called from mysql_admin_table */
1016
 
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
1017
 
  { return 0; }
1018
 
  virtual int check(Session* session __attribute__((unused)),
1019
 
                    HA_CHECK_OPT* check_opt __attribute__((unused)))
 
734
  virtual int check(Session *, HA_CHECK_OPT *)
1020
735
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1021
736
 
1022
 
  /**
1023
 
     In this method check_opt can be modified
1024
 
     to specify CHECK option to use to call check()
1025
 
     upon the table.
1026
 
  */
1027
 
  virtual int repair(Session* session __attribute__((unused)),
1028
 
                     HA_CHECK_OPT* check_opt __attribute__((unused)))
1029
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1030
 
  virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
 
737
  virtual void start_bulk_insert(ha_rows)
1031
738
  {}
1032
739
  virtual int end_bulk_insert(void) { return 0; }
1033
 
  virtual int index_read(unsigned char * buf __attribute__((unused)),
1034
 
                         const unsigned char * key __attribute__((unused)),
1035
 
                         uint32_t key_len __attribute__((unused)),
1036
 
                         enum ha_rkey_function find_flag __attribute__((unused)))
 
740
  virtual int index_read(unsigned char *, const unsigned char *,
 
741
                         uint32_t, enum ha_rkey_function)
1037
742
   { return  HA_ERR_WRONG_COMMAND; }
1038
 
  virtual int index_read_last(unsigned char * buf __attribute__((unused)),
1039
 
                              const unsigned char * key __attribute__((unused)),
1040
 
                              uint32_t key_len __attribute__((unused)))
 
743
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
1041
744
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
1042
745
  /**
1043
746
    This method is similar to update_row, however the handler doesn't need
1052
755
    @retval  0   Bulk delete used by handler
1053
756
    @retval  1   Bulk delete not used, normal operation used
1054
757
  */
1055
 
  virtual int bulk_update_row(const unsigned char *old_data __attribute__((unused)),
1056
 
                              unsigned char *new_data __attribute__((unused)),
1057
 
                              uint32_t *dup_key_found __attribute__((unused)))
 
758
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
1058
759
  {
1059
760
    assert(false);
1060
761
    return HA_ERR_WRONG_COMMAND;
1073
774
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
1074
775
    returned by storage engines that don't support this operation.
1075
776
  */
1076
 
  virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
1077
 
  { return HA_ERR_WRONG_COMMAND; }
1078
 
  virtual int optimize(Session* session __attribute__((unused)),
1079
 
                       HA_CHECK_OPT* check_opt __attribute__((unused)))
1080
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1081
 
  virtual int analyze(Session* session __attribute__((unused)),
1082
 
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
1083
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1084
 
  virtual bool check_and_repair(Session *session __attribute__((unused)))
1085
 
  { return true; }
1086
 
  virtual int disable_indexes(uint32_t mode __attribute__((unused)))
1087
 
  { return HA_ERR_WRONG_COMMAND; }
1088
 
  virtual int enable_indexes(uint32_t mode __attribute__((unused)))
1089
 
  { return HA_ERR_WRONG_COMMAND; }
1090
 
  virtual int discard_or_import_tablespace(bool discard __attribute__((unused)))
 
777
  virtual int reset_auto_increment(uint64_t)
 
778
  { return HA_ERR_WRONG_COMMAND; }
 
779
  virtual int optimize(Session *, HA_CHECK_OPT *)
 
780
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
781
  virtual int analyze(Session *, HA_CHECK_OPT *)
 
782
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
783
 
 
784
  virtual int disable_indexes(uint32_t)
 
785
  { return HA_ERR_WRONG_COMMAND; }
 
786
  virtual int enable_indexes(uint32_t)
 
787
  { return HA_ERR_WRONG_COMMAND; }
 
788
  virtual int discard_or_import_tablespace(bool)
1091
789
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
1092
 
  virtual void prepare_for_alter(void) { return; }
1093
790
  virtual void drop_table(const char *name);
1094
 
  virtual int create(const char *name __attribute__((unused)),
1095
 
                     Table *form __attribute__((unused)),
1096
 
                     HA_CREATE_INFO *info __attribute__((unused)))=0;
1097
 
 
1098
 
  virtual int create_handler_files(const char *name __attribute__((unused)),
1099
 
                                   const char *old_name __attribute__((unused)),
1100
 
                                   int action_flag __attribute__((unused)),
1101
 
                                   HA_CREATE_INFO *info __attribute__((unused)))
1102
 
  { return false; }
1103
 
};
1104
 
 
1105
 
 
1106
 
 
1107
 
/**
1108
 
  A Disk-Sweep MRR interface implementation
1109
 
 
1110
 
  This implementation makes range (and, in the future, 'ref') scans to read
1111
 
  table rows in disk sweeps. 
1112
 
  
1113
 
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
1114
 
  any table handler that has non-clustered indexes and on-disk rows.
1115
 
*/
1116
 
 
1117
 
class DsMrr_impl
1118
 
{
1119
 
public:
1120
 
  typedef void (handler::*range_check_toggle_func_t)(bool on);
1121
 
 
1122
 
  DsMrr_impl()
1123
 
    : h2(NULL) {};
1124
 
 
1125
 
  handler *h; /* The "owner" handler object. It is used for scanning the index */
1126
 
  Table *table; /* Always equal to h->table */
1127
 
private:
1128
 
  /*
1129
 
    Secondary handler object. It is used to retrieve full table rows by
1130
 
    calling rnd_pos().
1131
 
  */
1132
 
  handler *h2;
1133
 
 
1134
 
  /* Buffer to store rowids, or (rowid, range_id) pairs */
1135
 
  unsigned char *rowids_buf;
1136
 
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
1137
 
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
1138
 
  unsigned char *rowids_buf_end;   /* End of the buffer */
1139
 
 
1140
 
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
1141
 
 
1142
 
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
1143
 
  bool is_mrr_assoc;
1144
 
 
1145
 
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
1146
 
public:
1147
 
  void init(handler *h_arg, Table *table_arg)
1148
 
  {
1149
 
    h= h_arg; 
1150
 
    table= table_arg;
1151
 
  }
1152
 
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
1153
 
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode, 
1154
 
                 HANDLER_BUFFER *buf);
1155
 
  void dsmrr_close();
1156
 
  int dsmrr_fill_buffer(handler *h);
1157
 
  int dsmrr_next(handler *h, char **range_info);
1158
 
 
1159
 
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
1160
 
                 uint32_t *flags, COST_VECT *cost);
1161
 
 
1162
 
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq, 
1163
 
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
1164
 
                            uint32_t *flags, COST_VECT *cost);
1165
 
private:
1166
 
  bool key_uses_partial_cols(uint32_t keyno);
1167
 
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz, 
1168
 
                       COST_VECT *cost);
1169
 
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags, 
1170
 
                               uint32_t *buffer_size, COST_VECT *cost);
1171
791
};
1172
792
 
1173
793
extern const char *ha_row_type[];
1174
794
extern const char *tx_isolation_names[];
1175
795
extern const char *binlog_format_names[];
1176
796
extern TYPELIB tx_isolation_typelib;
1177
 
extern TYPELIB myisam_stats_method_typelib;
1178
797
extern uint32_t total_ha, total_ha_2pc;
1179
798
 
1180
799
       /* Wrapper functions */
1185
804
int ha_init_errors(void);
1186
805
int ha_init(void);
1187
806
int ha_end(void);
1188
 
int ha_initialize_handlerton(st_plugin_int *plugin);
1189
 
int ha_finalize_handlerton(st_plugin_int *plugin);
1190
 
 
1191
 
TYPELIB *ha_known_exts(void);
1192
 
void ha_close_connection(Session* session);
1193
 
bool ha_flush_logs(handlerton *db_type);
1194
 
void ha_drop_database(char* path);
1195
 
int ha_create_table(Session *session, const char *path,
1196
 
                    const char *db, const char *table_name,
1197
 
                    HA_CREATE_INFO *create_info,
1198
 
                    bool update_create_info);
1199
 
int ha_delete_table(Session *session, handlerton *db_type, const char *path,
1200
 
                    const char *db, const char *alias, bool generate_warning);
1201
807
 
1202
808
/* statistics and info */
1203
 
bool ha_show_status(Session *session, handlerton *db_type, enum ha_stat_type stat);
 
809
bool ha_show_status(Session *session, drizzled::plugin::StorageEngine *db_type, enum ha_stat_type stat);
1204
810
 
1205
 
/* discovery */
1206
 
int ha_create_table_from_engine(Session* session, const char *db, const char *name);
1207
 
int ha_discover(Session* session, const char* dbname, const char* name,
1208
 
                unsigned char** frmblob, size_t* frmlen);
1209
811
int ha_find_files(Session *session,const char *db,const char *path,
1210
812
                  const char *wild, bool dir, List<LEX_STRING>* files);
1211
 
int ha_table_exists_in_engine(Session* session, const char* db, const char* name);
1212
 
 
1213
 
/* key cache */
1214
 
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
1215
 
int ha_resize_key_cache(KEY_CACHE *key_cache);
1216
 
int ha_change_key_cache_param(KEY_CACHE *key_cache);
1217
 
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
1218
 
int ha_end_key_cache(KEY_CACHE *key_cache);
1219
 
 
1220
 
/* report to InnoDB that control passes to the client */
1221
 
int ha_release_temporary_latches(Session *session);
1222
 
 
1223
 
/* transactions: interface to handlerton functions */
1224
 
int ha_start_consistent_snapshot(Session *session);
1225
 
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
 
813
 
 
814
/* transactions: interface to plugin::StorageEngine functions */
1226
815
int ha_commit_one_phase(Session *session, bool all);
1227
816
int ha_rollback_trans(Session *session, bool all);
1228
 
int ha_prepare(Session *session);
1229
 
int ha_recover(HASH *commit_list);
1230
817
 
1231
 
/* transactions: these functions never call handlerton functions directly */
 
818
/* transactions: these functions never call plugin::StorageEngine functions directly */
1232
819
int ha_commit_trans(Session *session, bool all);
1233
820
int ha_autocommit_or_rollback(Session *session, int error);
1234
821
int ha_enable_transaction(Session *session, bool on);
1239
826
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
1240
827
 
1241
828
/* these are called by storage engines */
1242
 
void trans_register_ha(Session *session, bool all, handlerton *ht);
1243
 
 
1244
 
void table_case_convert(char * name, uint32_t length);
1245
 
const char *table_case_name(HA_CREATE_INFO *info, const char *name);
1246
 
 
1247
 
extern char reg_ext[FN_EXTLEN];
1248
 
extern uint32_t reg_ext_length;
1249
 
extern ulong specialflag;
1250
 
extern uint32_t lower_case_table_names;
 
829
void trans_register_ha(Session *session, bool all, drizzled::plugin::StorageEngine *engine);
 
830
 
1251
831
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
1252
 
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
1253
 
 
1254
 
 
1255
 
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
1256
 
bool mysql_ha_close(Session *session, TableList *tables);
1257
 
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
1258
 
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1259
 
void mysql_ha_flush(Session *session);
1260
 
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
1261
 
void mysql_ha_cleanup(Session *session);
 
832
bool tablename_to_filename(const char *from, char *to, size_t to_length);
 
833
 
1262
834
 
1263
835
/*
1264
836
  Storage engine has to assume the transaction will end up with 2pc if
1268
840
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
1269
841
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
1270
842
 
 
843
 
 
844
bool mysql_xa_recover(Session *session);
 
845
 
 
846
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
847
                                   SORT_FIELD *sortorder);
 
848
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
 
849
                List<Item> &fields, List <Item> &all_fields, order_st *order);
 
850
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
 
851
                List<Item> &fields, List<Item> &all_fields, order_st *order,
 
852
                bool *hidden_group_fields);
 
853
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
 
854
                    Item **ref_pointer_array);
 
855
 
 
856
bool handle_select(Session *session, LEX *lex, select_result *result,
 
857
                   uint64_t setup_tables_done_option);
 
858
bool mysql_select(Session *session, Item ***rref_pointer_array,
 
859
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
 
860
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
 
861
                  Item *having, uint64_t select_type,
 
862
                  select_result *result, Select_Lex_Unit *unit,
 
863
                  Select_Lex *select_lex);
 
864
void free_underlaid_joins(Session *session, Select_Lex *select);
 
865
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
 
866
                         select_result *result);
 
867
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
 
868
                         select_result *result);
 
869
 
 
870
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
 
871
                                                      LEX *lex,
 
872
                                                      TableList *table));
 
873
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
 
874
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
 
875
void sp_prepare_create_field(Session *session, CreateField *sql_field);
 
876
int prepare_create_field(CreateField *sql_field,
 
877
                         uint32_t *blob_columns,
 
878
                         int *timestamps, int *timestamps_with_niladic,
 
879
                         int64_t table_flags);
 
880
bool mysql_create_table(Session *session,const char *db, const char *table_name,
 
881
                        HA_CREATE_INFO *create_info,
 
882
                        drizzled::message::Table *table_proto,
 
883
                        AlterInfo *alter_info,
 
884
                        bool tmp_table, uint32_t select_field_count);
 
885
bool mysql_create_table_no_lock(Session *session, const char *db,
 
886
                                const char *table_name,
 
887
                                HA_CREATE_INFO *create_info,
 
888
                                drizzled::message::Table *table_proto,
 
889
                                AlterInfo *alter_info,
 
890
                                bool tmp_table, uint32_t select_field_count);
 
891
 
 
892
bool mysql_recreate_table(Session *session, TableList *table_list);
 
893
bool mysql_create_like_table(Session *session, TableList *table,
 
894
                             TableList *src_table,
 
895
                             HA_CREATE_INFO *create_info);
 
896
bool mysql_rename_table(drizzled::plugin::StorageEngine *base, const char *old_db,
 
897
                        const char * old_name, const char *new_db,
 
898
                        const char * new_name, uint32_t flags);
 
899
bool mysql_prepare_update(Session *session, TableList *table_list,
 
900
                          Item **conds, uint32_t order_num, order_st *order);
 
901
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
 
902
                 List<Item> &values,COND *conds,
 
903
                 uint32_t order_num, order_st *order, ha_rows limit,
 
904
                 enum enum_duplicates handle_duplicates, bool ignore);
 
905
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
 
906
                          List<Item> &fields, List_item *values,
 
907
                          List<Item> &update_fields,
 
908
                          List<Item> &update_values, enum_duplicates duplic,
 
909
                          COND **where, bool select_insert,
 
910
                          bool check_fields, bool abort_on_warning);
 
911
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
 
912
                  List<List_item> &values, List<Item> &update_fields,
 
913
                  List<Item> &update_values, enum_duplicates flag,
 
914
                  bool ignore);
 
915
int check_that_all_fields_are_given_values(Session *session, Table *entry,
 
916
                                           TableList *table_list);
 
917
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
 
918
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
 
919
                  SQL_LIST *order, ha_rows rows, uint64_t options,
 
920
                  bool reset_auto_increment);
 
921
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
 
922
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
 
923
                             uint32_t key_length, uint32_t db_flags, int *error);
 
924
TableShare *get_cached_table_share(const char *db, const char *table_name);
 
925
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
 
926
Table *table_cache_insert_placeholder(Session *session, const char *key,
 
927
                                      uint32_t key_length);
 
928
bool lock_table_name_if_not_cached(Session *session, const char *db,
 
929
                                   const char *table_name, Table **table);
 
930
bool reopen_table(Table *table);
 
931
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
 
932
void close_data_files_and_morph_locks(Session *session, const char *db,
 
933
                                      const char *table_name);
 
934
void close_handle_and_leave_table_as_lock(Table *table);
 
935
bool wait_for_tables(Session *session);
 
936
bool table_is_used(Table *table, bool wait_for_name_lock);
 
937
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
 
938
void abort_locked_tables(Session *session,const char *db, const char *table_name);
 
939
extern Field *not_found_field;
 
940
extern Field *view_ref_found;
 
941
 
 
942
Field *
 
943
find_field_in_tables(Session *session, Item_ident *item,
 
944
                     TableList *first_table, TableList *last_table,
 
945
                     Item **ref, find_item_error_report_type report_error,
 
946
                     bool register_tree_change);
 
947
Field *
 
948
find_field_in_table_ref(Session *session, TableList *table_list,
 
949
                        const char *name, uint32_t length,
 
950
                        const char *item_name, const char *db_name,
 
951
                        const char *table_name, Item **ref,
 
952
                        bool allow_rowid,
 
953
                        uint32_t *cached_field_index_ptr,
 
954
                        bool register_tree_change, TableList **actual_table);
 
955
Field *
 
956
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
 
957
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
 
958
Field *
 
959
find_field_in_table_sef(Table *table, const char *name);
 
960
 
 
961
 
1271
962
#endif /* DRIZZLED_HANDLER_H */