~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Brian Aker
  • Date: 2009-05-30 22:30:05 UTC
  • mto: This revision was merged to the branch mainline in revision 1045.
  • Revision ID: brian@gaz-20090530223005-hmylm6iywddfentm
A lot of little cleanups (most based off lcov)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_CURSOR_H
21
 
#define DRIZZLED_CURSOR_H
 
20
#ifndef DRIZZLED_HANDLER_H
 
21
#define DRIZZLED_HANDLER_H
22
22
 
23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
 
#include <drizzled/identifier.h>
26
 
#include <drizzled/definitions.h>
27
 
#include <drizzled/key_map.h>
28
 
 
29
 
/* Definitions for parameters to do with Cursor-routines */
30
 
 
31
 
#include <drizzled/thr_lock.h>
 
25
 
 
26
/* Definitions for parameters to do with handler-routines */
 
27
 
 
28
#include <plugin/myisam/keycache.h>
 
29
#include <mysys/thr_lock.h>
 
30
#include <mysys/hash.h>
32
31
#include <drizzled/sql_string.h>
33
32
#include <drizzled/sql_list.h>
34
33
#include <drizzled/plugin/storage_engine.h>
35
34
#include <drizzled/handler_structs.h>
36
35
#include <drizzled/ha_statistics.h>
37
 
#include <drizzled/atomics.h>
38
36
 
39
37
#include <drizzled/message/table.pb.h>
40
38
 
41
 
#include <bitset>
42
 
#include <algorithm>
 
39
/* Bits to show what an alter table will do */
 
40
#include <drizzled/sql_bitmap.h>
43
41
 
44
 
namespace drizzled
45
 
{
 
42
#include<bitset>
46
43
 
47
44
#define HA_MAX_ALTER_FLAGS 40
48
 
 
49
45
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
50
46
 
51
 
extern uint64_t refresh_version;  /* Increments on each reload */
 
47
 
 
48
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
 
49
                                      uint32_t key_length,
 
50
                                      uint64_t *engine_data);
 
51
 
 
52
 
 
53
/* The handler for a table type.  Will be included in the Table structure */
52
54
 
53
55
class Table;
54
56
class TableList;
55
57
class TableShare;
56
58
class Select_Lex_Unit;
57
 
class ForeignKeyInfo;
58
 
struct Order;
 
59
struct st_foreign_key_info;
 
60
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
 
61
struct order_st;
59
62
 
60
63
class Item;
 
64
struct st_table_log_memory_entry;
61
65
 
62
66
class LEX;
63
67
class Select_Lex;
64
 
class AlterInfo;
 
68
class Alter_info;
65
69
class select_result;
66
 
class CreateField;
 
70
class Create_field;
67
71
class sys_var_str;
68
72
class Item_ident;
 
73
typedef struct st_sort_field SORT_FIELD;
69
74
 
70
75
typedef List<Item> List_item;
 
76
 
 
77
typedef struct st_savepoint SAVEPOINT;
 
78
extern uint32_t savepoint_alloc_size;
71
79
extern KEY_CREATE_INFO default_key_create_info;
72
80
 
73
81
/* Forward declaration for condition pushdown to storage engine */
74
82
typedef class Item COND;
75
83
 
76
 
typedef struct system_status_var system_status_var;
77
 
 
78
 
namespace optimizer
79
 
{
80
 
  class CostVector;
81
 
}
82
 
 
 
84
typedef struct system_status_var SSV;
 
85
 
 
86
class COST_VECT;
 
87
 
 
88
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
 
89
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
 
90
 
 
91
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
83
92
/*
84
93
  bitmap with first N+1 bits set
85
94
  (keypart_map for a key prefix of [0..N] keyparts)
101
110
}
102
111
 
103
112
/**
104
 
  The Cursor class is the interface for dynamically loadable
 
113
  The handler class is the interface for dynamically loadable
105
114
  storage engines. Do not add ifdefs and take care when adding or
106
115
  changing virtual functions to avoid vtable confusion
107
116
 
111
120
     storage engine
112
121
 
113
122
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
114
 
     storage engine. See optimizer/range.cc for description of this format.
 
123
     storage engine. See opt_range.cc for description of this format.
115
124
 
116
125
  TableRecordFormat
117
126
  =================
136
145
  present, its length is one byte <not-sure> which must be set to 0xFF
137
146
  at all times. </not-sure>
138
147
 
 
148
  If the table has columns of type BIT, then certain bits from those columns
 
149
  may be stored in null_bytes as well. Grep around for Field_bit for
 
150
  details.
 
151
 
139
152
  For blob columns (see Field_blob), the record buffer stores length of the
140
153
  data, following by memory pointer to the blob data. The pointer is owned
141
154
  by the storage engine and is valid until the next operation.
143
156
  If a blob column has NULL value, then its length and blob data pointer
144
157
  must be set to 0.
145
158
*/
146
 
class Cursor
 
159
 
 
160
class handler :public Sql_alloc
147
161
{
148
 
  Table &table;               /* The current open table */
149
 
  plugin::StorageEngine &engine;      /* storage engine of this Cursor */
 
162
public:
 
163
  typedef uint64_t Table_flags;
150
164
 
151
165
protected:
 
166
  TableShare *table_share;   /* The table definition */
 
167
  Table *table;               /* The current open table */
 
168
  Table_flags cached_table_flags;       /* Set on init() and open() */
 
169
 
152
170
  ha_rows estimation_rows_to_insert;
153
 
 
154
171
public:
155
 
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
156
 
  {
157
 
    return &engine;
158
 
  }
159
 
  unsigned char *ref;                           /* Pointer to current row */
 
172
  StorageEngine *engine;      /* storage engine of this handler */
 
173
  unsigned char *ref;                           /* Pointer to current row */
160
174
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
161
175
 
162
 
  TableShare *getShare();
163
 
 
164
 
  Table *getTable() const
165
 
  {
166
 
    return &table;
167
 
  }
168
 
 
169
176
  ha_statistics stats;
170
177
  /** MultiRangeRead-related members: */
171
178
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
172
179
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
173
 
 
 
180
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
174
181
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
175
182
  /* true <=> source MRR ranges and the output are ordered */
176
183
  bool mrr_is_output_sorted;
179
186
  bool mrr_have_range;
180
187
 
181
188
  bool eq_range;
 
189
  /*
 
190
    true <=> the engine guarantees that returned records are within the range
 
191
    being scanned.
 
192
  */
 
193
  bool in_range_check_pushed_down;
182
194
 
183
195
  /** Current range (the one we're now returning rows from) */
184
196
  KEY_MULTI_RANGE mrr_cur_range;
185
197
 
186
198
  /** The following are for read_range() */
187
199
  key_range save_end_range, *end_range;
188
 
  KeyPartInfo *range_key_part;
 
200
  KEY_PART_INFO *range_key_part;
189
201
  int key_compare_result_on_equal;
190
202
 
191
203
  uint32_t errkey;                              /* Last dup key */
195
207
  uint32_t ref_length;
196
208
  enum {NONE=0, INDEX, RND} inited;
197
209
  bool locked;
 
210
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
 
211
  const Item *pushed_cond;
 
212
 
 
213
  Item *pushed_idx_cond;
 
214
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
198
215
 
199
216
  /**
200
217
    next_insert_id is the next value which should be inserted into the
206
223
    get_auto_increment().
207
224
  */
208
225
  uint64_t next_insert_id;
209
 
  uint64_t getNextInsertId()
210
 
  {
211
 
    return next_insert_id;
212
 
  }
213
 
 
214
226
  /**
215
227
    insert id for the current row (*autogenerated*; if not
216
228
    autogenerated, it's 0).
224
236
  */
225
237
  Discrete_interval auto_inc_interval_for_cur_row;
226
238
 
227
 
  Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
228
 
  virtual ~Cursor(void);
229
 
  virtual Cursor *clone(memory::Root *mem_root);
 
239
  handler(StorageEngine *engine_arg, TableShare *share_arg)
 
240
    :table_share(share_arg), table(0),
 
241
    estimation_rows_to_insert(0), engine(engine_arg),
 
242
    ref(0), in_range_check_pushed_down(false),
 
243
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
 
244
    ref_length(sizeof(my_off_t)),
 
245
    inited(NONE),
 
246
    locked(false), implicit_emptied(0),
 
247
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
 
248
    next_insert_id(0), insert_id_for_cur_row(0)
 
249
    {}
 
250
  virtual ~handler(void);
 
251
  virtual handler *clone(MEM_ROOT *mem_root);
 
252
  /** This is called after create to allow us to set up cached variables */
 
253
  void init()
 
254
  {
 
255
    cached_table_flags= table_flags();
 
256
  }
230
257
 
231
258
  /* ha_ methods: pubilc wrappers for private virtual API */
232
259
 
233
 
  int ha_open(const TableIdentifier &identifier, int mode, int test_if_locked);
234
 
  int startIndexScan(uint32_t idx, bool sorted);
235
 
  int endIndexScan();
236
 
  int startTableScan(bool scan);
237
 
  int endTableScan();
 
260
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
 
261
  int ha_index_init(uint32_t idx, bool sorted);
 
262
  int ha_index_end();
 
263
  int ha_rnd_init(bool scan);
 
264
  int ha_rnd_end();
238
265
  int ha_reset();
239
266
 
240
267
  /* this is necessary in many places, e.g. in HANDLER command */
241
268
  int ha_index_or_rnd_end();
 
269
  Table_flags ha_table_flags() const;
242
270
 
243
271
  /**
244
272
    These functions represent the public interface to *users* of the
245
 
    Cursor class, hence they are *not* virtual. For the inheritance
246
 
    interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
247
 
    and doDeleteRecord() below.
 
273
    handler class, hence they are *not* virtual. For the inheritance
 
274
    interface, see the (private) functions write_row(), update_row(),
 
275
    and delete_row() below.
248
276
  */
249
277
  int ha_external_lock(Session *session, int lock_type);
250
 
  int insertRecord(unsigned char * buf);
251
 
  int updateRecord(const unsigned char * old_data, unsigned char * new_data);
252
 
  int deleteRecord(const unsigned char * buf);
 
278
  int ha_write_row(unsigned char * buf);
 
279
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
 
280
  int ha_delete_row(const unsigned char * buf);
253
281
  void ha_release_auto_increment();
254
282
 
255
283
  /** to be actually called to get 'check()' functionality*/
256
284
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
257
 
 
 
285
  int ha_repair(Session* session, HA_CHECK_OPT* check_opt);
258
286
  void ha_start_bulk_insert(ha_rows rows);
259
287
  int ha_end_bulk_insert();
 
288
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
 
289
                         uint32_t *dup_key_found);
260
290
  int ha_delete_all_rows();
261
291
  int ha_reset_auto_increment(uint64_t value);
 
292
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
262
293
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
263
 
 
 
294
  bool ha_check_and_repair(Session *session);
264
295
  int ha_disable_indexes(uint32_t mode);
265
296
  int ha_enable_indexes(uint32_t mode);
266
297
  int ha_discard_or_import_tablespace(bool discard);
267
 
  void closeMarkForDelete(const char *name);
 
298
  void ha_prepare_for_alter();
 
299
  int ha_rename_table(const char *from, const char *to);
 
300
  int ha_delete_table(const char *name);
 
301
  void ha_drop_table(const char *name);
 
302
 
 
303
  int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
268
304
 
269
305
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
270
306
  int update_auto_increment();
 
307
  void print_keydup_error(uint32_t key_nr, const char *msg);
 
308
  virtual void print_error(int error, myf errflag);
 
309
  virtual bool get_error_message(int error, String *buf);
 
310
  uint32_t get_dup_key(int error);
 
311
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
271
312
 
272
313
  /* Estimates calculation */
273
314
  virtual double scan_time(void)
280
321
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
281
322
                                              void *seq_init_param,
282
323
                                              uint32_t n_ranges, uint32_t *bufsz,
283
 
                                              uint32_t *flags, optimizer::CostVector *cost);
 
324
                                              uint32_t *flags, COST_VECT *cost);
284
325
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
285
 
                                    uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
 
326
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
286
327
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
287
 
                                    uint32_t n_ranges, uint32_t mode);
 
328
                                    uint32_t n_ranges, uint32_t mode,
 
329
                                    HANDLER_BUFFER *buf);
288
330
  virtual int multi_range_read_next(char **range_info);
289
331
 
290
332
 
294
336
  /**
295
337
    This method is used to analyse the error to see whether the error
296
338
    is ignorable or not, certain handlers can have more error that are
297
 
    ignorable than others. E.g. the partition Cursor can get inserts
 
339
    ignorable than others. E.g. the partition handler can get inserts
298
340
    into a range where there is no partition and this is an ignorable
299
341
    error.
300
342
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
308
350
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
309
351
  */
310
352
  virtual ha_rows records();
311
 
  virtual uint64_t tableSize();
312
 
  virtual uint64_t rowSize();
313
353
  /**
314
354
    Return upper bound of current number of records in the table
315
355
    (max. of how many records one will retrieve when doing a full table scan)
319
359
  virtual ha_rows estimate_rows_upper_bound()
320
360
  { return stats.records+EXTRA_RECORDS; }
321
361
 
 
362
  /**
 
363
    Get the row type from the storage engine.  If this method returns
 
364
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
365
  */
 
366
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
 
367
 
322
368
  virtual const char *index_type(uint32_t)
323
369
  { assert(0); return "";}
324
370
 
327
373
  virtual int close(void)=0;
328
374
 
329
375
  /**
 
376
    @retval  0   Bulk update used by handler
 
377
    @retval  1   Bulk update not used, normal operation used
 
378
  */
 
379
  virtual bool start_bulk_update() { return 1; }
 
380
  /**
 
381
    @retval  0   Bulk delete used by handler
 
382
    @retval  1   Bulk delete not used, normal operation used
 
383
  */
 
384
  virtual bool start_bulk_delete() { return 1; }
 
385
  /**
 
386
    After this call all outstanding updates must be performed. The number
 
387
    of duplicate key errors are reported in the duplicate key parameter.
 
388
    It is allowed to continue to the batched update after this call, the
 
389
    handler has to wait until end_bulk_update with changing state.
 
390
 
 
391
    @param    dup_key_found       Number of duplicate keys found
 
392
 
 
393
    @retval  0           Success
 
394
    @retval  >0          Error code
 
395
  */
 
396
  virtual int exec_bulk_update(uint32_t *)
 
397
  {
 
398
    assert(false);
 
399
    return HA_ERR_WRONG_COMMAND;
 
400
  }
 
401
  /**
 
402
    Perform any needed clean-up, no outstanding updates are there at the
 
403
    moment.
 
404
  */
 
405
  virtual void end_bulk_update() { return; }
 
406
  /**
 
407
    Execute all outstanding deletes and close down the bulk delete.
 
408
 
 
409
    @retval 0             Success
 
410
    @retval >0            Error code
 
411
  */
 
412
  virtual int end_bulk_delete()
 
413
  {
 
414
    assert(false);
 
415
    return HA_ERR_WRONG_COMMAND;
 
416
  }
 
417
  /**
330
418
     @brief
331
419
     Positions an index cursor to the index specified in the handle. Fetches the
332
420
     row if available. If the key value is null, begin at the first key of the
333
421
     index.
334
422
  */
335
 
  virtual int index_read_map(unsigned char * buf, const unsigned char *key,
 
423
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
336
424
                             key_part_map keypart_map,
337
425
                             enum ha_rkey_function find_flag)
338
426
  {
339
 
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
 
427
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
340
428
    return  index_read(buf, key, key_len, find_flag);
341
429
  }
342
430
  /**
358
446
  virtual int index_last(unsigned char *)
359
447
   { return  HA_ERR_WRONG_COMMAND; }
360
448
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
361
 
 
362
 
private:
363
 
  uint32_t calculate_key_len(uint32_t key_position, key_part_map keypart_map_arg);
364
 
public:
365
 
 
366
449
  /**
367
450
     @brief
368
451
     The following functions works like index_read, but it find the last
371
454
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
372
455
                                  key_part_map keypart_map)
373
456
  {
374
 
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
 
457
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
375
458
    return index_read_last(buf, key, key_len);
376
459
  }
377
460
  virtual int read_range_first(const key_range *start_key,
379
462
                               bool eq_range, bool sorted);
380
463
  virtual int read_range_next();
381
464
  int compare_key(key_range *range);
 
465
  int compare_key2(key_range *range);
382
466
  virtual int rnd_next(unsigned char *)=0;
383
467
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
 
468
  /**
 
469
    One has to use this method when to find
 
470
    random position by record as the plain
 
471
    position() call doesn't work for some
 
472
    handlers for random position.
 
473
  */
 
474
  virtual int rnd_pos_by_record(unsigned char *record);
384
475
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
 
476
  /**
 
477
    The following function is only needed for tables that may be temporary
 
478
    tables during joins.
 
479
  */
 
480
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
 
481
    { return HA_ERR_WRONG_COMMAND; }
385
482
  virtual int rnd_same(unsigned char *, uint32_t)
386
483
    { return HA_ERR_WRONG_COMMAND; }
387
484
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
416
513
  */
417
514
  virtual void try_semi_consistent_read(bool) {}
418
515
  virtual void unlock_row(void) {}
 
516
  virtual int start_stmt(Session *, thr_lock_type)
 
517
  {return 0;}
419
518
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
420
519
                                  uint64_t nb_desired_values,
421
520
                                  uint64_t *first_value,
422
 
                                  uint64_t *nb_reserved_values)= 0;
423
 
 
 
521
                                  uint64_t *nb_reserved_values);
424
522
  void set_next_insert_id(uint64_t id)
425
523
  {
426
524
    next_insert_id= id;
441
539
      insert_id_for_cur_row;
442
540
  }
443
541
 
 
542
  virtual void update_create_info(HA_CREATE_INFO *) {}
 
543
  int check_old_types(void);
 
544
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
 
545
  { return HA_ADMIN_NOT_IMPLEMENTED; }
444
546
  /* end of the list of admin commands */
445
547
 
446
548
  virtual int indexes_are_disabled(void) {return 0;}
 
549
  virtual char *update_table_comment(const char * comment)
 
550
  { return (char*) comment;}
447
551
  virtual void append_create_info(String *)
448
552
  {}
449
553
  /**
456
560
    @retval   true            Foreign key defined on table or index
457
561
    @retval   false           No foreign key defined
458
562
  */
 
563
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
 
564
  { return false; }
459
565
  virtual char* get_foreign_key_create_info(void)
460
566
  { return NULL;}  /* gets foreign key create string from InnoDB */
461
567
  /** used in ALTER Table; if changing storage engine is allowed.
463
569
   */
464
570
  virtual bool can_switch_engines(void) { return true; }
465
571
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
466
 
  virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
 
572
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
467
573
  { return 0; }
468
574
  virtual uint32_t referenced_by_foreign_key() { return 0;}
 
575
  virtual void init_table_handle_for_HANDLER()
 
576
  { return; }       /* prepare InnoDB for HANDLER */
469
577
  virtual void free_foreign_key_create_info(char *) {}
470
 
 
 
578
  /** The following can be called without an open handler */
 
579
 
 
580
  /**
 
581
    If frm_error() is called then we will use this to find out what file
 
582
    extentions exist for the storage engine. This is also used by the default
 
583
    rename_table and delete_table method in handler.cc.
 
584
 
 
585
    For engines that have two file name extentions (separate meta/index file
 
586
    and data file), the order of elements is relevant. First element of engine
 
587
    file name extentions array should be meta/index file extention. Second
 
588
    element - data file extention. This order is assumed by
 
589
    prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
 
590
  */
 
591
  virtual const char **bas_ext() const =0;
 
592
 
 
593
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
 
594
 
 
595
  virtual int add_index(Table *, KEY *, uint32_t)
 
596
  { return (HA_ERR_WRONG_COMMAND); }
 
597
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
 
598
  { return (HA_ERR_WRONG_COMMAND); }
 
599
  virtual int final_drop_index(Table *)
 
600
  { return (HA_ERR_WRONG_COMMAND); }
 
601
 
 
602
  uint32_t max_record_length() const
 
603
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
604
  uint32_t max_keys() const
 
605
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
 
606
  uint32_t max_key_parts() const
 
607
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
608
  uint32_t max_key_length() const
 
609
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
610
  uint32_t max_key_part_length(void) const
 
611
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
612
 
 
613
  virtual uint32_t max_supported_record_length(void) const
 
614
  { return HA_MAX_REC_LENGTH; }
 
615
  virtual uint32_t max_supported_keys(void) const { return 0; }
 
616
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
617
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
618
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
 
619
 
 
620
  virtual bool low_byte_first(void) const { return 1; }
 
621
  virtual uint32_t checksum(void) const { return 0; }
 
622
  virtual bool is_crashed(void) const  { return 0; }
 
623
  virtual bool auto_repair(void) const { return 0; }
 
624
 
 
625
  /**
 
626
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
 
627
  */
 
628
  virtual uint32_t lock_count(void) const { return 1; }
471
629
  /**
472
630
    Is not invoked for non-transactional temporary tables.
473
631
 
475
633
    or partitioned.
476
634
 
477
635
    @note that one can NOT rely on table->in_use in store_lock().  It may
478
 
    refer to a different thread if called from abortLockForThread().
 
636
    refer to a different thread if called from mysql_lock_abort_for_thread().
479
637
 
480
638
    @note If the table is MERGE, store_lock() can return less locks
481
639
    than lock_count() claimed. This can happen when the MERGE children
482
640
    are not attached when this is called from another thread.
483
641
  */
484
 
  virtual THR_LOCK_DATA **store_lock(Session *,
 
642
  virtual THR_LOCK_DATA **store_lock(Session *session,
485
643
                                     THR_LOCK_DATA **to,
486
 
                                     enum thr_lock_type)
487
 
  {
488
 
    assert(0); // Impossible programming situation
489
 
 
490
 
    return(to);
491
 
  }
 
644
                                     enum thr_lock_type lock_type)=0;
492
645
 
493
646
 /*
494
647
   @retval true   Primary key (if there is one) is clustered
501
654
   return memcmp(ref1, ref2, ref_length);
502
655
 }
503
656
 
504
 
  virtual bool isOrdered(void)
 
657
 /*
 
658
   Condition pushdown to storage engines
 
659
 */
 
660
 
 
661
 /**
 
662
   Push condition down to the table handler.
 
663
 
 
664
   @param  cond   Condition to be pushed. The condition tree must not be
 
665
                  modified by the by the caller.
 
666
 
 
667
   @return
 
668
     The 'remainder' condition that caller must use to filter out records.
 
669
     NULL means the handler will not return rows that do not match the
 
670
     passed condition.
 
671
 
 
672
   @note
 
673
   The pushed conditions form a stack (from which one can remove the
 
674
   last pushed condition using cond_pop).
 
675
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2
 
676
   AND ... AND pushed_condN)
 
677
   or less restrictive condition, depending on handler's capabilities.
 
678
 
 
679
   handler->ha_reset() call empties the condition stack.
 
680
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
 
681
   condition stack.
 
682
 */
 
683
 virtual const COND *cond_push(const COND *cond) { return cond; }
 
684
 
 
685
 /**
 
686
   Pop the top condition from the condition stack of the handler instance.
 
687
 
 
688
   Pops the top if condition stack, if stack is not empty.
 
689
 */
 
690
 virtual void cond_pop(void) { return; }
 
691
 
 
692
 virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
 
693
 { return idx_cond; }
 
694
 
 
695
  /**
 
696
    Lock table.
 
697
 
 
698
    @param    session                     Thread handle
 
699
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
 
700
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
 
701
    @param    lock_timeout            -1 default timeout
 
702
                                      0  no wait
 
703
                                      >0 wait timeout in milliseconds.
 
704
 
 
705
   @note
 
706
      lock_timeout >0 is not used by MySQL currently. If the storage
 
707
      engine does not support NOWAIT (lock_timeout == 0) it should
 
708
      return an error. But if it does not support WAIT X (lock_timeout
 
709
      >0) it should treat it as lock_timeout == -1 and wait a default
 
710
      (or even hard-coded) timeout.
 
711
 
 
712
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
 
713
                                      lock_table()
 
714
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
 
715
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
 
716
                                      lock conflict with NOWAIT option
 
717
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
 
718
  */
 
719
  virtual int lock_table(Session *, int, int)
505
720
  {
506
 
    return false;
 
721
    return HA_ERR_WRONG_COMMAND;
507
722
  }
508
723
 
509
 
 
510
724
protected:
511
725
  /* Service methods for use by storage engines. */
512
 
  void ha_statistic_increment(uint64_t system_status_var::*offset) const;
 
726
  void ha_statistic_increment(ulong SSV::*offset) const;
513
727
  void **ha_data(Session *) const;
 
728
  Session *ha_session(void) const;
 
729
 
 
730
  /**
 
731
    Default rename_table() and delete_table() rename/delete files with a
 
732
    given name and extensions from bas_ext().
 
733
 
 
734
    These methods can be overridden, but their default implementation
 
735
    provide useful functionality.
 
736
  */
 
737
  virtual int rename_table(const char *from, const char *to);
 
738
  /**
 
739
    Delete a table in the engine. Called for base as well as temporary
 
740
    tables.
 
741
  */
 
742
  virtual int delete_table(const char *name);
514
743
 
515
744
private:
516
745
  /* Private helpers */
517
 
  inline void setTransactionReadWrite();
 
746
  inline void mark_trx_read_write();
518
747
private:
519
748
  /*
520
749
    Low-level primitives for storage engines.  These should be
522
751
    the corresponding 'ha_*' method above.
523
752
  */
524
753
 
525
 
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; }
526
 
  virtual int doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked);
527
 
  virtual int doStartIndexScan(uint32_t idx, bool)
 
754
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
 
755
  virtual int index_init(uint32_t idx, bool)
528
756
  { active_index= idx; return 0; }
529
 
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
 
757
  virtual int index_end() { active_index= MAX_KEY; return 0; }
530
758
  /**
531
 
    doStartTableScan() can be called two times without doEndTableScan() in between
 
759
    rnd_init() can be called two times without rnd_end() in between
532
760
    (it only makes sense if scan=1).
533
761
    then the second call should prepare for the new table scan (e.g
534
762
    if rnd_init allocates the cursor, second call should position it
535
763
    to the start of the table, no need to deallocate and allocate it again
536
764
  */
537
 
  virtual int doStartTableScan(bool scan)= 0;
538
 
  virtual int doEndTableScan() { return 0; }
539
 
  virtual int doInsertRecord(unsigned char *)
540
 
  {
541
 
    return HA_ERR_WRONG_COMMAND;
542
 
  }
543
 
 
544
 
  virtual int doUpdateRecord(const unsigned char *, unsigned char *)
545
 
  {
546
 
    return HA_ERR_WRONG_COMMAND;
547
 
  }
548
 
 
549
 
  virtual int doDeleteRecord(const unsigned char *)
 
765
  virtual int rnd_init(bool scan)= 0;
 
766
  virtual int rnd_end() { return 0; }
 
767
  virtual int write_row(unsigned char *)
 
768
  {
 
769
    return HA_ERR_WRONG_COMMAND;
 
770
  }
 
771
 
 
772
  virtual int update_row(const unsigned char *, unsigned char *)
 
773
  {
 
774
    return HA_ERR_WRONG_COMMAND;
 
775
  }
 
776
 
 
777
  virtual int delete_row(const unsigned char *)
550
778
  {
551
779
    return HA_ERR_WRONG_COMMAND;
552
780
  }
556
784
    by that statement.
557
785
  */
558
786
  virtual int reset() { return 0; }
 
787
  virtual Table_flags table_flags(void) const= 0;
559
788
 
560
789
  /**
561
790
    Is not invoked for non-transactional temporary tables.
562
791
 
563
792
    Tells the storage engine that we intend to read or write data
564
 
    from the table. This call is prefixed with a call to Cursor::store_lock()
565
 
    and is invoked only for those Cursor instances that stored the lock.
 
793
    from the table. This call is prefixed with a call to handler::store_lock()
 
794
    and is invoked only for those handler instances that stored the lock.
566
795
 
567
796
    Calls to rnd_init/index_init are prefixed with this call. When table
568
797
    IO is complete, we call external_lock(F_UNLCK).
583
812
  {
584
813
    return 0;
585
814
  }
586
 
  virtual void release_auto_increment(void) { return; }
 
815
  virtual void release_auto_increment(void) { return; };
587
816
  /** admin commands - called from mysql_admin_table */
588
 
  virtual int check(Session *)
 
817
  virtual int check_for_upgrade(HA_CHECK_OPT *)
 
818
  { return 0; }
 
819
  virtual int check(Session *, HA_CHECK_OPT *)
589
820
  { return HA_ADMIN_NOT_IMPLEMENTED; }
590
821
 
 
822
  /**
 
823
     In this method check_opt can be modified
 
824
     to specify CHECK option to use to call check()
 
825
     upon the table.
 
826
  */
 
827
  virtual int repair(Session *, HA_CHECK_OPT *)
 
828
  { return HA_ADMIN_NOT_IMPLEMENTED; }
591
829
  virtual void start_bulk_insert(ha_rows)
592
830
  {}
593
831
  virtual int end_bulk_insert(void) { return 0; }
595
833
                         uint32_t, enum ha_rkey_function)
596
834
   { return  HA_ERR_WRONG_COMMAND; }
597
835
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
598
 
   { return (errno= HA_ERR_WRONG_COMMAND); }
 
836
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
 
837
  /**
 
838
    This method is similar to update_row, however the handler doesn't need
 
839
    to execute the updates at this point in time. The handler can be certain
 
840
    that another call to bulk_update_row will occur OR a call to
 
841
    exec_bulk_update before the set of updates in this query is concluded.
 
842
 
 
843
    @param    old_data       Old record
 
844
    @param    new_data       New record
 
845
    @param    dup_key_found  Number of duplicate keys found
 
846
 
 
847
    @retval  0   Bulk delete used by handler
 
848
    @retval  1   Bulk delete not used, normal operation used
 
849
  */
 
850
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
 
851
  {
 
852
    assert(false);
 
853
    return HA_ERR_WRONG_COMMAND;
 
854
  }
599
855
  /**
600
856
    This is called to delete all rows in a table
601
 
    If the Cursor don't support this, then this function will
 
857
    If the handler don't support this, then this function will
602
858
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
603
859
    by one.
604
860
  */
605
861
  virtual int delete_all_rows(void)
606
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
 
862
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
607
863
  /**
608
864
    Reset the auto-increment counter to the given value, i.e. the next row
609
865
    inserted will get the given value. This is called e.g. after TRUNCATE
612
868
  */
613
869
  virtual int reset_auto_increment(uint64_t)
614
870
  { return HA_ERR_WRONG_COMMAND; }
615
 
 
616
 
  virtual int analyze(Session *)
617
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
618
 
 
 
871
  virtual int optimize(Session *, HA_CHECK_OPT *)
 
872
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
873
  virtual int analyze(Session *, HA_CHECK_OPT *)
 
874
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
875
  virtual bool check_and_repair(Session *)
 
876
  { return true; }
619
877
  virtual int disable_indexes(uint32_t)
620
878
  { return HA_ERR_WRONG_COMMAND; }
621
 
 
622
879
  virtual int enable_indexes(uint32_t)
623
880
  { return HA_ERR_WRONG_COMMAND; }
624
 
 
625
881
  virtual int discard_or_import_tablespace(bool)
626
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
627
 
 
628
 
  /* 
629
 
    @todo this is just for the HEAP engine, it should
630
 
    be removed at some point in the future (and
631
 
    no new engine should ever use it). Right
632
 
    now HEAP does rely on it, so we cannot remove it.
633
 
  */
 
882
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
883
  virtual void prepare_for_alter(void) { return; }
634
884
  virtual void drop_table(const char *name);
 
885
  virtual int create(const char *, Table *, HA_CREATE_INFO *)=0;
 
886
};
 
887
 
 
888
 
 
889
 
 
890
/**
 
891
  A Disk-Sweep MRR interface implementation
 
892
 
 
893
  This implementation makes range (and, in the future, 'ref') scans to read
 
894
  table rows in disk sweeps.
 
895
 
 
896
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
 
897
  any table handler that has non-clustered indexes and on-disk rows.
 
898
*/
 
899
 
 
900
class DsMrr_impl
 
901
{
 
902
public:
 
903
  typedef void (handler::*range_check_toggle_func_t)(bool on);
 
904
 
 
905
  DsMrr_impl()
 
906
    : h2(NULL) {};
 
907
 
 
908
  handler *h; /* The "owner" handler object. It is used for scanning the index */
 
909
  Table *table; /* Always equal to h->table */
 
910
private:
 
911
  /*
 
912
    Secondary handler object. It is used to retrieve full table rows by
 
913
    calling rnd_pos().
 
914
  */
 
915
  handler *h2;
 
916
 
 
917
  /* Buffer to store rowids, or (rowid, range_id) pairs */
 
918
  unsigned char *rowids_buf;
 
919
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
 
920
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
 
921
  unsigned char *rowids_buf_end;   /* End of the buffer */
 
922
 
 
923
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
 
924
 
 
925
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
 
926
  bool is_mrr_assoc;
 
927
 
 
928
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
 
929
public:
 
930
  void init(handler *h_arg, Table *table_arg)
 
931
  {
 
932
    h= h_arg;
 
933
    table= table_arg;
 
934
  }
 
935
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
 
936
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode,
 
937
                 HANDLER_BUFFER *buf);
 
938
  void dsmrr_close();
 
939
  int dsmrr_fill_buffer(handler *h);
 
940
  int dsmrr_next(handler *h, char **range_info);
 
941
 
 
942
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
 
943
                 uint32_t *flags, COST_VECT *cost);
 
944
 
 
945
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
946
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
 
947
                            uint32_t *flags, COST_VECT *cost);
 
948
private:
 
949
  bool key_uses_partial_cols(uint32_t keyno);
 
950
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz,
 
951
                       COST_VECT *cost);
 
952
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
 
953
                               uint32_t *buffer_size, COST_VECT *cost);
635
954
};
636
955
 
637
956
extern const char *ha_row_type[];
 
957
extern const char *tx_isolation_names[];
 
958
extern const char *binlog_format_names[];
 
959
extern TYPELIB tx_isolation_typelib;
 
960
extern TYPELIB myisam_stats_method_typelib;
 
961
extern uint32_t total_ha, total_ha_2pc;
 
962
 
 
963
       /* Wrapper functions */
 
964
#define ha_commit(session) (ha_commit_trans((session), true))
 
965
#define ha_rollback(session) (ha_rollback_trans((session), true))
638
966
 
639
967
/* basic stuff */
640
 
void ha_init_errors(void);
641
 
 
642
 
class SortField;
643
 
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
644
 
                                 SortField *sortorder);
 
968
int ha_init_errors(void);
 
969
int ha_init(void);
 
970
int ha_end(void);
 
971
 
 
972
void add_storage_engine(StorageEngine *engine);
 
973
void remove_storage_engine(StorageEngine *engine);
 
974
 
 
975
void ha_close_connection(Session* session);
 
976
bool ha_flush_logs(StorageEngine *db_type);
 
977
void ha_drop_database(char* path);
 
978
int ha_create_table(Session *session, const char *path,
 
979
                    const char *db, const char *table_name,
 
980
                    HA_CREATE_INFO *create_info,
 
981
                    bool update_create_info);
 
982
int ha_delete_table(Session *session, const char *path,
 
983
                    const char *db, const char *alias, bool generate_warning);
 
984
 
 
985
/* statistics and info */
 
986
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
 
987
 
 
988
int ha_find_files(Session *session,const char *db,const char *path,
 
989
                  const char *wild, bool dir, List<LEX_STRING>* files);
 
990
int ha_table_exists_in_engine(Session* session, const char* db, const char* name, StorageEngine **engine= NULL);
 
991
 
 
992
/* key cache */
 
993
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
 
994
int ha_resize_key_cache(KEY_CACHE *key_cache);
 
995
int ha_change_key_cache_param(KEY_CACHE *key_cache);
 
996
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
 
997
int ha_end_key_cache(KEY_CACHE *key_cache);
 
998
 
 
999
/* report to InnoDB that control passes to the client */
 
1000
int ha_release_temporary_latches(Session *session);
 
1001
 
 
1002
/* transactions: interface to StorageEngine functions */
 
1003
int ha_start_consistent_snapshot(Session *session);
 
1004
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
 
1005
int ha_commit_one_phase(Session *session, bool all);
 
1006
int ha_rollback_trans(Session *session, bool all);
 
1007
int ha_prepare(Session *session);
 
1008
int ha_recover(HASH *commit_list);
 
1009
 
 
1010
/* transactions: these functions never call StorageEngine functions directly */
 
1011
int ha_commit_trans(Session *session, bool all);
 
1012
int ha_autocommit_or_rollback(Session *session, int error);
 
1013
int ha_enable_transaction(Session *session, bool on);
 
1014
 
 
1015
/* savepoints */
 
1016
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
 
1017
int ha_savepoint(Session *session, SAVEPOINT *sv);
 
1018
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
 
1019
 
 
1020
/* these are called by storage engines */
 
1021
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
 
1022
 
 
1023
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
 
1024
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
 
1025
 
 
1026
 
 
1027
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
 
1028
bool mysql_ha_close(Session *session, TableList *tables);
 
1029
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
 
1030
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
 
1031
void mysql_ha_flush(Session *session);
 
1032
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
 
1033
void mysql_ha_cleanup(Session *session);
 
1034
 
 
1035
/*
 
1036
  Storage engine has to assume the transaction will end up with 2pc if
 
1037
   - there is more than one 2pc-capable storage engine available
 
1038
   - in the current transaction 2pc was not disabled yet
 
1039
*/
 
1040
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
 
1041
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
 
1042
 
 
1043
 
 
1044
bool mysql_xa_recover(Session *session);
 
1045
 
 
1046
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
1047
                                   SORT_FIELD *sortorder);
645
1048
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
646
 
                List<Item> &fields, List <Item> &all_fields, Order *order);
 
1049
                List<Item> &fields, List <Item> &all_fields, order_st *order);
647
1050
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
648
 
                List<Item> &fields, List<Item> &all_fields, Order *order,
 
1051
                List<Item> &fields, List<Item> &all_fields, order_st *order,
649
1052
                bool *hidden_group_fields);
650
1053
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
651
1054
                    Item **ref_pointer_array);
652
1055
 
653
1056
bool handle_select(Session *session, LEX *lex, select_result *result,
654
1057
                   uint64_t setup_tables_done_option);
 
1058
bool mysql_select(Session *session, Item ***rref_pointer_array,
 
1059
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
 
1060
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
 
1061
                  Item *having, uint64_t select_type,
 
1062
                  select_result *result, Select_Lex_Unit *unit,
 
1063
                  Select_Lex *select_lex);
655
1064
void free_underlaid_joins(Session *session, Select_Lex *select);
 
1065
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
 
1066
                         select_result *result);
 
1067
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
 
1068
                         select_result *result);
656
1069
 
657
1070
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
658
1071
                                                      LEX *lex,
659
1072
                                                      TableList *table));
660
1073
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
661
1074
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
662
 
int prepare_create_field(CreateField *sql_field,
 
1075
void sp_prepare_create_field(Session *session, Create_field *sql_field);
 
1076
int prepare_create_field(Create_field *sql_field,
663
1077
                         uint32_t *blob_columns,
664
 
                         int *timestamps, int *timestamps_with_niladic);
665
 
 
666
 
bool mysql_create_table(Session *session,
667
 
                        const TableIdentifier &identifier,
 
1078
                         int *timestamps, int *timestamps_with_niladic,
 
1079
                         int64_t table_flags);
 
1080
bool mysql_create_table(Session *session,const char *db, const char *table_name,
668
1081
                        HA_CREATE_INFO *create_info,
669
 
                        message::Table &table_proto,
670
 
                        AlterInfo *alter_info,
671
 
                        bool tmp_table, uint32_t select_field_count,
672
 
                        bool is_if_not_exists);
673
 
 
674
 
bool mysql_create_table_no_lock(Session *session,
675
 
                                const TableIdentifier &identifier,
 
1082
                        drizzled::message::Table *table_proto,
 
1083
                        Alter_info *alter_info,
 
1084
                        bool tmp_table, uint32_t select_field_count);
 
1085
bool mysql_create_table_no_lock(Session *session, const char *db,
 
1086
                                const char *table_name,
676
1087
                                HA_CREATE_INFO *create_info,
677
 
                                message::Table &table_proto,
678
 
                                AlterInfo *alter_info,
679
 
                                bool tmp_table, uint32_t select_field_count,
680
 
                                bool is_if_not_exists);
681
 
 
682
 
bool mysql_create_like_table(Session* session,
683
 
                             const TableIdentifier &destination_identifier,
684
 
                             TableList* table, TableList* src_table,
685
 
                             message::Table &create_table_proto,
686
 
                             bool is_if_not_exists,
687
 
                             bool is_engine_set);
688
 
 
689
 
bool mysql_rename_table(Session &session,
690
 
                        plugin::StorageEngine *base,
691
 
                        const TableIdentifier &old_identifier,
692
 
                        const TableIdentifier &new_identifier);
693
 
 
 
1088
                                drizzled::message::Table *table_proto,
 
1089
                                Alter_info *alter_info,
 
1090
                                bool tmp_table, uint32_t select_field_count);
 
1091
 
 
1092
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
 
1093
                       HA_CREATE_INFO *create_info,
 
1094
                       TableList *table_list,
 
1095
                       Alter_info *alter_info,
 
1096
                       uint32_t order_num, order_st *order, bool ignore);
 
1097
bool mysql_recreate_table(Session *session, TableList *table_list);
 
1098
bool mysql_create_like_table(Session *session, TableList *table,
 
1099
                             TableList *src_table,
 
1100
                             HA_CREATE_INFO *create_info);
 
1101
bool mysql_rename_table(StorageEngine *base, const char *old_db,
 
1102
                        const char * old_name, const char *new_db,
 
1103
                        const char * new_name, uint32_t flags);
694
1104
bool mysql_prepare_update(Session *session, TableList *table_list,
695
 
                          Item **conds, uint32_t order_num, Order *order);
 
1105
                          Item **conds, uint32_t order_num, order_st *order);
696
1106
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
697
1107
                 List<Item> &values,COND *conds,
698
 
                 uint32_t order_num, Order *order, ha_rows limit,
 
1108
                 uint32_t order_num, order_st *order, ha_rows limit,
699
1109
                 enum enum_duplicates handle_duplicates, bool ignore);
 
1110
bool mysql_multi_update(Session *session, TableList *table_list,
 
1111
                        List<Item> *fields, List<Item> *values,
 
1112
                        COND *conds, uint64_t options,
 
1113
                        enum enum_duplicates handle_duplicates, bool ignore,
 
1114
                        Select_Lex_Unit *unit, Select_Lex *select_lex);
700
1115
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
701
1116
                          List<Item> &fields, List_item *values,
702
1117
                          List<Item> &update_fields,
713
1128
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
714
1129
                  SQL_LIST *order, ha_rows rows, uint64_t options,
715
1130
                  bool reset_auto_increment);
716
 
bool mysql_truncate(Session& session, TableList *table_list);
 
1131
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
 
1132
uint32_t create_table_def_key(char *key, TableList *table_list);
717
1133
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
718
1134
                             uint32_t key_length, uint32_t db_flags, int *error);
 
1135
void release_table_share(TableShare *share, enum release_type type);
719
1136
TableShare *get_cached_table_share(const char *db, const char *table_name);
 
1137
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update,
 
1138
                   uint32_t lock_flags);
 
1139
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
 
1140
bool name_lock_locked_table(Session *session, TableList *tables);
720
1141
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
 
1142
Table *table_cache_insert_placeholder(Session *session, const char *key,
 
1143
                                      uint32_t key_length);
 
1144
bool lock_table_name_if_not_cached(Session *session, const char *db,
 
1145
                                   const char *table_name, Table **table);
 
1146
Table *find_locked_table(Session *session, const char *db,const char *table_name);
 
1147
void detach_merge_children(Table *table, bool clear_refs);
 
1148
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
 
1149
                          TableList *new_child_list, TableList **new_last);
 
1150
bool reopen_table(Table *table);
721
1151
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
 
1152
void close_data_files_and_morph_locks(Session *session, const char *db,
 
1153
                                      const char *table_name);
722
1154
void close_handle_and_leave_table_as_lock(Table *table);
 
1155
bool open_new_frm(Session *session, TableShare *share, const char *alias,
 
1156
                  uint32_t db_stat, uint32_t prgflag,
 
1157
                  uint32_t ha_open_flags, Table *outparam,
 
1158
                  TableList *table_desc, MEM_ROOT *mem_root);
723
1159
bool wait_for_tables(Session *session);
724
1160
bool table_is_used(Table *table, bool wait_for_name_lock);
725
 
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
726
 
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
 
1161
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
 
1162
void abort_locked_tables(Session *session,const char *db, const char *table_name);
727
1163
extern Field *not_found_field;
728
1164
extern Field *view_ref_found;
729
1165
 
731
1167
find_field_in_tables(Session *session, Item_ident *item,
732
1168
                     TableList *first_table, TableList *last_table,
733
1169
                     Item **ref, find_item_error_report_type report_error,
734
 
                     bool register_tree_change);
 
1170
                     bool check_privileges, bool register_tree_change);
735
1171
Field *
736
1172
find_field_in_table_ref(Session *session, TableList *table_list,
737
1173
                        const char *name, uint32_t length,
738
1174
                        const char *item_name, const char *db_name,
739
1175
                        const char *table_name, Item **ref,
740
 
                        bool allow_rowid,
 
1176
                        bool check_privileges, bool allow_rowid,
741
1177
                        uint32_t *cached_field_index_ptr,
742
1178
                        bool register_tree_change, TableList **actual_table);
743
1179
Field *
744
1180
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
745
1181
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
746
 
 
747
 
} /* namespace drizzled */
748
 
 
749
 
#endif /* DRIZZLED_CURSOR_H */
 
1182
Field *
 
1183
find_field_in_table_sef(Table *table, const char *name);
 
1184
int update_virtual_fields_marked_for_write(Table *table,
 
1185
                                           bool ignore_stored=true);
 
1186
 
 
1187
 
 
1188
#endif /* DRIZZLED_HANDLER_H */