~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Brian Aker
  • Date: 2010-03-31 23:39:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1434.
  • Revision ID: brian@gaz-20100331233912-q2zi8n0sg35kvwsm
Shift show commands to their own dictionary.

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_HANDLER_H
21
 
#define DRIZZLED_HANDLER_H
 
20
#ifndef DRIZZLED_CURSOR_H
 
21
#define DRIZZLED_CURSOR_H
22
22
 
23
23
#include <drizzled/xid.h>
24
 
 
25
 
/* Definitions for parameters to do with handler-routines */
26
 
 
27
 
#include <storage/myisam/keycache.h>
28
 
#include <mysys/thr_lock.h>
29
 
#include <mysys/hash.h>
 
24
#include <drizzled/discrete_interval.h>
 
25
#include <drizzled/table_identifier.h>
 
26
 
 
27
/* Definitions for parameters to do with Cursor-routines */
 
28
 
 
29
#include <drizzled/thr_lock.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 <bitset>
 
43
#include <algorithm>
 
44
 
 
45
namespace drizzled
 
46
{
 
47
 
39
48
#define HA_MAX_ALTER_FLAGS 40
40
 
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
49
 
 
50
 
 
51
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
52
 
 
53
extern uint64_t refresh_version;  /* Increments on each reload */
41
54
 
42
55
 
43
56
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
45
58
                                      uint64_t *engine_data);
46
59
 
47
60
 
48
 
/* The handler for a table type.  Will be included in the Table structure */
 
61
/* The Cursor for a table type.  Will be included in the Table structure */
49
62
 
50
63
class Table;
51
64
class TableList;
52
 
typedef struct st_table_share TABLE_SHARE;
 
65
class TableShare;
 
66
class Select_Lex_Unit;
53
67
struct st_foreign_key_info;
54
68
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
55
69
struct order_st;
58
72
struct st_table_log_memory_entry;
59
73
 
60
74
class LEX;
61
 
typedef class st_select_lex SELECT_LEX;
62
 
typedef class st_select_lex_unit SELECT_LEX_UNIT;
63
 
class Alter_info;
 
75
class Select_Lex;
 
76
class AlterInfo;
64
77
class select_result;
65
 
class Create_field;
 
78
class CreateField;
66
79
class sys_var_str;
67
80
class Item_ident;
68
81
typedef struct st_sort_field SORT_FIELD;
69
82
 
70
83
typedef List<Item> List_item;
71
 
 
72
 
typedef struct st_savepoint SAVEPOINT;
73
 
extern uint32_t savepoint_alloc_size;
74
84
extern KEY_CREATE_INFO default_key_create_info;
75
85
 
76
86
/* Forward declaration for condition pushdown to storage engine */
77
87
typedef class Item COND;
78
88
 
79
 
typedef struct system_status_var SSV;
80
 
 
81
 
class COST_VECT;
82
 
 
83
 
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
84
 
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
 
89
typedef struct system_status_var system_status_var;
 
90
 
 
91
namespace optimizer
 
92
{
 
93
  class CostVector;
 
94
}
85
95
 
86
96
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
87
97
/*
105
115
}
106
116
 
107
117
/**
108
 
  The handler class is the interface for dynamically loadable
 
118
  The Cursor class is the interface for dynamically loadable
109
119
  storage engines. Do not add ifdefs and take care when adding or
110
120
  changing virtual functions to avoid vtable confusion
111
121
 
115
125
     storage engine
116
126
 
117
127
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
118
 
     storage engine. See opt_range.cc for description of this format.
 
128
     storage engine. See optimizer/range.cc for description of this format.
119
129
 
120
130
  TableRecordFormat
121
131
  =================
152
162
  must be set to 0.
153
163
*/
154
164
 
155
 
class handler :public Sql_alloc
 
165
class Cursor :public memory::SqlAlloc
156
166
{
157
 
public:
158
 
  typedef uint64_t Table_flags;
159
167
protected:
160
 
  struct st_table_share *table_share;   /* The table definition */
 
168
  TableShare *table_share;   /* The table definition */
161
169
  Table *table;               /* The current open table */
162
 
  Table_flags cached_table_flags;       /* Set on init() and open() */
163
170
 
164
171
  ha_rows estimation_rows_to_insert;
165
172
public:
166
 
  handlerton *ht;                 /* storage engine of this handler */
 
173
  plugin::StorageEngine *engine;      /* storage engine of this Cursor */
 
174
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
 
175
  {
 
176
    return engine;
 
177
  }
167
178
  unsigned char *ref;                           /* Pointer to current row */
168
179
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
169
180
 
178
189
 
179
190
  /** true <=> we're currently traversing a range in mrr_cur_range. */
180
191
  bool mrr_have_range;
 
192
 
 
193
  bool eq_range;
 
194
  /*
 
195
    true <=> the engine guarantees that returned records are within the range
 
196
    being scanned.
 
197
  */
 
198
  bool in_range_check_pushed_down;
 
199
 
181
200
  /** Current range (the one we're now returning rows from) */
182
201
  KEY_MULTI_RANGE mrr_cur_range;
183
202
 
185
204
  key_range save_end_range, *end_range;
186
205
  KEY_PART_INFO *range_key_part;
187
206
  int key_compare_result_on_equal;
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;
194
207
 
195
208
  uint32_t errkey;                              /* Last dup key */
196
209
  uint32_t key_used_on_scan;
200
213
  enum {NONE=0, INDEX, RND} inited;
201
214
  bool locked;
202
215
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
203
 
  const Item *pushed_cond;
204
 
 
205
 
  Item *pushed_idx_cond;
206
 
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
207
216
 
208
217
  /**
209
218
    next_insert_id is the next value which should be inserted into the
215
224
    get_auto_increment().
216
225
  */
217
226
  uint64_t next_insert_id;
 
227
  uint64_t getNextInsertId()
 
228
  {
 
229
    return next_insert_id;
 
230
  }
 
231
 
218
232
  /**
219
233
    insert id for the current row (*autogenerated*; if not
220
234
    autogenerated, it's 0).
228
242
  */
229
243
  Discrete_interval auto_inc_interval_for_cur_row;
230
244
 
231
 
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
232
 
    :table_share(share_arg), table(0),
233
 
    estimation_rows_to_insert(0), ht(ht_arg),
234
 
    ref(0), in_range_check_pushed_down(false),
235
 
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
236
 
    ref_length(sizeof(my_off_t)),
237
 
    inited(NONE),
238
 
    locked(false), implicit_emptied(0),
239
 
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
240
 
    next_insert_id(0), insert_id_for_cur_row(0)
241
 
    {}
242
 
  virtual ~handler(void)
243
 
  {
244
 
    assert(locked == false);
245
 
    /* TODO: assert(inited == NONE); */
246
 
  }
247
 
  virtual handler *clone(MEM_ROOT *mem_root);
248
 
  /** This is called after create to allow us to set up cached variables */
249
 
  void init()
250
 
  {
251
 
    cached_table_flags= table_flags();
252
 
  }
 
245
  Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
 
246
  virtual ~Cursor(void);
 
247
  virtual Cursor *clone(memory::Root *mem_root);
253
248
 
254
249
  /* ha_ methods: pubilc wrappers for private virtual API */
255
250
 
262
257
 
263
258
  /* this is necessary in many places, e.g. in HANDLER command */
264
259
  int ha_index_or_rnd_end();
265
 
  Table_flags ha_table_flags() const;
266
260
 
267
261
  /**
268
262
    These functions represent the public interface to *users* of the
269
 
    handler class, hence they are *not* virtual. For the inheritance
 
263
    Cursor class, hence they are *not* virtual. For the inheritance
270
264
    interface, see the (private) functions write_row(), update_row(),
271
265
    and delete_row() below.
272
266
  */
276
270
  int ha_delete_row(const unsigned char * buf);
277
271
  void ha_release_auto_increment();
278
272
 
279
 
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
280
273
  /** to be actually called to get 'check()' functionality*/
281
274
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
282
 
  int ha_repair(Session* session, HA_CHECK_OPT* check_opt);
 
275
 
283
276
  void ha_start_bulk_insert(ha_rows rows);
284
277
  int ha_end_bulk_insert();
285
 
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
286
 
                         uint32_t *dup_key_found);
287
278
  int ha_delete_all_rows();
288
279
  int ha_reset_auto_increment(uint64_t value);
289
 
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
290
280
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
291
 
  bool ha_check_and_repair(Session *session);
 
281
 
292
282
  int ha_disable_indexes(uint32_t mode);
293
283
  int ha_enable_indexes(uint32_t mode);
294
284
  int ha_discard_or_import_tablespace(bool discard);
295
 
  void ha_prepare_for_alter();
296
 
  int ha_rename_table(const char *from, const char *to);
297
 
  int ha_delete_table(const char *name);
298
 
  void ha_drop_table(const char *name);
299
 
 
300
 
  int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
301
 
 
302
 
  int ha_create_handler_files(const char *name, const char *old_name,
303
 
                              int action_flag, HA_CREATE_INFO *info);
 
285
  void closeMarkForDelete(const char *name);
304
286
 
305
287
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
306
288
  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, TABLE_SHARE *share);
 
289
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
312
290
 
313
291
  /* Estimates calculation */
314
292
  virtual double scan_time(void)
321
299
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
322
300
                                              void *seq_init_param,
323
301
                                              uint32_t n_ranges, uint32_t *bufsz,
324
 
                                              uint32_t *flags, COST_VECT *cost);
 
302
                                              uint32_t *flags, optimizer::CostVector *cost);
325
303
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
326
 
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
 
304
                                    uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
327
305
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
328
306
                                    uint32_t n_ranges, uint32_t mode,
329
307
                                    HANDLER_BUFFER *buf);
332
310
 
333
311
  virtual const key_map *keys_to_use_for_scanning();
334
312
  bool has_transactions();
335
 
  virtual uint32_t extra_rec_buf_length() const { return 0; }
336
313
 
337
314
  /**
338
315
    This method is used to analyse the error to see whether the error
339
316
    is ignorable or not, certain handlers can have more error that are
340
 
    ignorable than others. E.g. the partition handler can get inserts
 
317
    ignorable than others. E.g. the partition Cursor can get inserts
341
318
    into a range where there is no partition and this is an ignorable
342
319
    error.
343
320
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
351
328
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
352
329
  */
353
330
  virtual ha_rows records();
 
331
  virtual uint64_t tableSize();
 
332
  virtual uint64_t rowSize();
354
333
  /**
355
334
    Return upper bound of current number of records in the table
356
335
    (max. of how many records one will retrieve when doing a full table scan)
370
349
  { assert(0); return "";}
371
350
 
372
351
 
373
 
  /**
374
 
    Signal that the table->read_set and table->write_set table maps changed
375
 
    The handler is allowed to set additional bits in the above map in this
376
 
    call. Normally the handler should ignore all calls until we have done
377
 
    a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
378
 
    as there may be several calls to this routine.
379
 
  */
380
 
  virtual void column_bitmaps_signal();
381
352
  uint32_t get_index(void) const { return active_index; }
382
353
  virtual int close(void)=0;
383
354
 
384
355
  /**
385
 
    @retval  0   Bulk update used by handler
386
 
    @retval  1   Bulk update not used, normal operation used
387
 
  */
388
 
  virtual bool start_bulk_update() { return 1; }
389
 
  /**
390
 
    @retval  0   Bulk delete used by handler
391
 
    @retval  1   Bulk delete not used, normal operation used
392
 
  */
393
 
  virtual bool start_bulk_delete() { return 1; }
394
 
  /**
395
 
    After this call all outstanding updates must be performed. The number
396
 
    of duplicate key errors are reported in the duplicate key parameter.
397
 
    It is allowed to continue to the batched update after this call, the
398
 
    handler has to wait until end_bulk_update with changing state.
399
 
 
400
 
    @param    dup_key_found       Number of duplicate keys found
401
 
 
402
 
    @retval  0           Success
403
 
    @retval  >0          Error code
404
 
  */
405
 
  virtual int exec_bulk_update(uint32_t *)
406
 
  {
407
 
    assert(false);
408
 
    return HA_ERR_WRONG_COMMAND;
409
 
  }
410
 
  /**
411
 
    Perform any needed clean-up, no outstanding updates are there at the
412
 
    moment.
413
 
  */
414
 
  virtual void end_bulk_update() { return; }
415
 
  /**
416
 
    Execute all outstanding deletes and close down the bulk delete.
417
 
 
418
 
    @retval 0             Success
419
 
    @retval >0            Error code
420
 
  */
421
 
  virtual int end_bulk_delete()
422
 
  {
423
 
    assert(false);
424
 
    return HA_ERR_WRONG_COMMAND;
425
 
  }
426
 
  /**
427
356
     @brief
428
357
     Positions an index cursor to the index specified in the handle. Fetches the
429
358
     row if available. If the key value is null, begin at the first key of the
493
422
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
494
423
    { return (ha_rows) 10; }
495
424
  virtual void position(const unsigned char *record)=0;
496
 
  virtual int info(uint)=0; // see my_base.h for full description
 
425
  virtual int info(uint32_t)=0; // see my_base.h for full description
497
426
  virtual uint32_t calculate_key_hash_value(Field **)
498
427
  { assert(0); return 0; }
499
428
  virtual int extra(enum ha_extra_function)
522
451
  */
523
452
  virtual void try_semi_consistent_read(bool) {}
524
453
  virtual void unlock_row(void) {}
525
 
  virtual int start_stmt(Session *, thr_lock_type)
526
 
  {return 0;}
527
454
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
528
455
                                  uint64_t nb_desired_values,
529
456
                                  uint64_t *first_value,
550
477
 
551
478
  virtual void update_create_info(HA_CREATE_INFO *) {}
552
479
  int check_old_types(void);
553
 
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
554
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
555
480
  /* end of the list of admin commands */
556
481
 
557
482
  virtual int indexes_are_disabled(void) {return 0;}
558
 
  virtual char *update_table_comment(const char * comment)
559
 
  { return (char*) comment;}
560
483
  virtual void append_create_info(String *)
561
484
  {}
562
485
  /**
569
492
    @retval   true            Foreign key defined on table or index
570
493
    @retval   false           No foreign key defined
571
494
  */
572
 
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
573
 
  { return false; }
574
495
  virtual char* get_foreign_key_create_info(void)
575
 
  { return(NULL);}  /* gets foreign key create string from InnoDB */
576
 
  /** used in ALTER Table; 1 if changing storage engine is allowed */
577
 
  virtual bool can_switch_engines(void) { return 1; }
 
496
  { return NULL;}  /* gets foreign key create string from InnoDB */
 
497
  /** used in ALTER Table; if changing storage engine is allowed.
 
498
      e.g. not be allowed if table has foreign key constraints in engine.
 
499
   */
 
500
  virtual bool can_switch_engines(void) { return true; }
578
501
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
579
502
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
580
503
  { return 0; }
581
504
  virtual uint32_t referenced_by_foreign_key() { return 0;}
582
 
  virtual void init_table_handle_for_HANDLER()
583
 
  { return; }       /* prepare InnoDB for HANDLER */
584
505
  virtual void free_foreign_key_create_info(char *) {}
585
 
  /** The following can be called without an open handler */
586
 
  virtual const char *table_type() const =0;
587
 
  /**
588
 
    If frm_error() is called then we will use this to find out what file
589
 
    extentions exist for the storage engine. This is also used by the default
590
 
    rename_table and delete_table method in handler.cc.
591
 
 
592
 
    For engines that have two file name extentions (separate meta/index file
593
 
    and data file), the order of elements is relevant. First element of engine
594
 
    file name extentions array should be meta/index file extention. Second
595
 
    element - data file extention. This order is assumed by
596
 
    prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
597
 
  */
598
 
  virtual const char **bas_ext() const =0;
599
 
 
600
 
  virtual int get_default_no_partitions(HA_CREATE_INFO *) { return 1;}
601
 
  virtual bool get_no_parts(const char *, uint32_t *no_parts)
602
 
  {
603
 
    *no_parts= 0;
604
 
    return 0;
605
 
  }
606
 
 
607
 
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
 
506
  /** The following can be called without an open Cursor */
608
507
 
609
508
  virtual int add_index(Table *, KEY *, uint32_t)
610
509
  { return (HA_ERR_WRONG_COMMAND); }
613
512
  virtual int final_drop_index(Table *)
614
513
  { return (HA_ERR_WRONG_COMMAND); }
615
514
 
616
 
  uint32_t max_record_length() const
617
 
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
618
 
  uint32_t max_keys() const
619
 
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
620
 
  uint32_t max_key_parts() const
621
 
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
622
 
  uint32_t max_key_length() const
623
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
624
 
  uint32_t max_key_part_length(void) const
625
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
626
 
 
627
 
  virtual uint32_t max_supported_record_length(void) const
628
 
  { return HA_MAX_REC_LENGTH; }
629
 
  virtual uint32_t max_supported_keys(void) const { return 0; }
630
 
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
631
 
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
632
 
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
633
 
  virtual uint32_t min_record_length(uint32_t) const
634
 
  { return 1; }
635
 
 
636
 
  virtual bool low_byte_first(void) const { return 1; }
637
515
  virtual uint32_t checksum(void) const { return 0; }
638
 
  virtual bool is_crashed(void) const  { return 0; }
639
 
  virtual bool auto_repair(void) const { return 0; }
640
 
 
641
 
 
642
 
#define CHF_CREATE_FLAG 0
643
 
#define CHF_DELETE_FLAG 1
644
 
#define CHF_RENAME_FLAG 2
645
 
 
646
 
 
647
 
  /**
648
 
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
649
 
  */
650
 
  virtual uint32_t lock_count(void) const { return 1; }
 
516
 
651
517
  /**
652
518
    Is not invoked for non-transactional temporary tables.
653
519
 
661
527
    than lock_count() claimed. This can happen when the MERGE children
662
528
    are not attached when this is called from another thread.
663
529
  */
664
 
  virtual THR_LOCK_DATA **store_lock(Session *session,
 
530
  virtual THR_LOCK_DATA **store_lock(Session *,
665
531
                                     THR_LOCK_DATA **to,
666
 
                                     enum thr_lock_type lock_type)=0;
667
 
 
668
 
  /** Type of table for caching query */
669
 
  virtual uint8_t table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
670
 
 
671
 
 
672
 
  /**
673
 
    @brief Register a named table with a call back function to the query cache.
674
 
 
675
 
    @param session The thread handle
676
 
    @param table_key A pointer to the table name in the table cache
677
 
    @param key_length The length of the table name
678
 
    @param[out] engine_callback The pointer to the storage engine call back
679
 
      function
680
 
    @param[out] engine_data Storage engine specific data which could be
681
 
      anything
682
 
 
683
 
    This method offers the storage engine, the possibility to store a reference
684
 
    to a table name which is going to be used with query cache.
685
 
    The method is called each time a statement is written to the cache and can
686
 
    be used to verify if a specific statement is cachable. It also offers
687
 
    the possibility to register a generic (but static) call back function which
688
 
    is called each time a statement is matched against the query cache.
689
 
 
690
 
    @note If engine_data supplied with this function is different from
691
 
      engine_data supplied with the callback function, and the callback returns
692
 
      false, a table invalidation on the current table will occur.
693
 
 
694
 
    @return Upon success the engine_callback will point to the storage engine
695
 
      call back function, if any, and engine_data will point to any storage
696
 
      engine data used in the specific implementation.
697
 
      @retval true Success
698
 
      @retval false The specified table or current statement should not be
699
 
        cached
700
 
  */
701
 
 
702
 
  virtual bool
703
 
    register_query_cache_table(Session *, char *, uint32_t,
704
 
                               qc_engine_callback *engine_callback,
705
 
                               uint64_t *)
 
532
                                     enum thr_lock_type)
706
533
  {
707
 
    *engine_callback= 0;
708
 
    return true;
 
534
    assert(0); // Impossible programming situation
 
535
 
 
536
    return(to);
709
537
  }
710
538
 
711
 
 
712
539
 /*
713
540
   @retval true   Primary key (if there is one) is clustered
714
541
                  key covering all fields
720
547
   return memcmp(ref1, ref2, ref_length);
721
548
 }
722
549
 
723
 
 /*
724
 
   Condition pushdown to storage engines
725
 
 */
726
 
 
727
 
 /**
728
 
   Push condition down to the table handler.
729
 
 
730
 
   @param  cond   Condition to be pushed. The condition tree must not be
731
 
                  modified by the by the caller.
732
 
 
733
 
   @return
734
 
     The 'remainder' condition that caller must use to filter out records.
735
 
     NULL means the handler will not return rows that do not match the
736
 
     passed condition.
737
 
 
738
 
   @note
739
 
   The pushed conditions form a stack (from which one can remove the
740
 
   last pushed condition using cond_pop).
741
 
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2
742
 
   AND ... AND pushed_condN)
743
 
   or less restrictive condition, depending on handler's capabilities.
744
 
 
745
 
   handler->ha_reset() call empties the condition stack.
746
 
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
747
 
   condition stack.
748
 
 */
749
 
 virtual const COND *cond_push(const COND *cond) { return cond; }
750
 
 
751
 
 /**
752
 
   Pop the top condition from the condition stack of the handler instance.
753
 
 
754
 
   Pops the top if condition stack, if stack is not empty.
755
 
 */
756
 
 virtual void cond_pop(void) { return; }
757
 
 
758
 
 virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
759
 
 { return idx_cond; }
760
 
 
761
 
 /*
762
 
    Part of old fast alter table, to be depricated
763
 
  */
764
 
 virtual bool
765
 
   check_if_incompatible_data(HA_CREATE_INFO *, uint32_t)
766
 
 { return COMPATIBLE_DATA_NO; }
767
 
 
768
 
 /* On-line ALTER Table interface */
769
 
 
770
 
 /**
771
 
    Check if a storage engine supports a particular alter table on-line
772
 
 
773
 
    @param    altered_table     A temporary table show what table is to
774
 
                                change to
775
 
    @param    create_info       Information from the parsing phase about new
776
 
                                table properties.
777
 
    @param    alter_flags       Bitmask that shows what will be changed
778
 
    @param    table_changes     Shows if table layout has changed (for
779
 
                                backwards compatibility with
780
 
                                check_if_incompatible_data
781
 
 
782
 
    @retval   HA_ALTER_ERROR                Unexpected error
783
 
    @retval   HA_ALTER_SUPPORTED_WAIT_LOCK  Supported, but requires DDL lock
784
 
    @retval   HA_ALTER_SUPPORTED_NO_LOCK    Supported
785
 
    @retval   HA_ALTER_NOT_SUPPORTED        Not supported
786
 
 
787
 
    @note
788
 
      The default implementation is implemented to support fast
789
 
      alter table (storage engines that support some changes by
790
 
      just changing the frm file) without any change in the handler
791
 
      implementation.
792
 
 */
793
 
 virtual int check_if_supported_alter(Table *, HA_CREATE_INFO *create_info,
794
 
                                      HA_ALTER_FLAGS * alter_flags, uint32_t table_changes)
795
 
 {
796
 
   if (this->check_if_incompatible_data(create_info, table_changes)
797
 
       == COMPATIBLE_DATA_NO)
798
 
     return(HA_ALTER_NOT_SUPPORTED);
799
 
   else if ((*alter_flags & HA_ALTER_STORED_VCOL).is_set())
800
 
     return(HA_ALTER_NOT_SUPPORTED);
801
 
   else
802
 
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
803
 
 }
804
 
 /**
805
 
   Tell storage engine to prepare for the on-line alter table (pre-alter)
806
 
 
807
 
   @param     session               The thread handle
808
 
   @param     altered_table     A temporary table show what table is to
809
 
                                change to
810
 
   @param     alter_info        Storage place for data used during phase1
811
 
                                and phase2
812
 
   @param     alter_flags       Bitmask that shows what will be changed
813
 
 
814
 
   @retval   0      OK
815
 
   @retval   error  error code passed from storage engine
816
 
 */
817
 
 virtual int alter_table_phase1(Session *, Table *, HA_CREATE_INFO *, HA_ALTER_INFO *,
818
 
                                HA_ALTER_FLAGS *)
819
 
 {
820
 
   return HA_ERR_UNSUPPORTED;
821
 
 }
822
 
 /**
823
 
    Tell storage engine to perform the on-line alter table (alter)
824
 
 
825
 
    @param    session               The thread handle
826
 
    @param    altered_table     A temporary table show what table is to
827
 
                                change to
828
 
    @param    alter_info        Storage place for data used during phase1
829
 
                                and phase2
830
 
    @param    alter_flags       Bitmask that shows what will be changed
831
 
 
832
 
    @retval  0      OK
833
 
    @retval  error  error code passed from storage engine
834
 
 
835
 
    @note
836
 
      If check_if_supported_alter returns HA_ALTER_SUPPORTED_WAIT_LOCK
837
 
      this call is to be wrapped with a DDL lock. This is currently NOT
838
 
      supported.
839
 
 */
840
 
 virtual int alter_table_phase2(Session *, Table *, HA_CREATE_INFO *, HA_ALTER_INFO *,
841
 
                                HA_ALTER_FLAGS *)
842
 
 {
843
 
   return HA_ERR_UNSUPPORTED;
844
 
 }
845
 
 /**
846
 
    Tell storage engine that changed frm file is now on disk and table
847
 
    has been re-opened (post-alter)
848
 
 
849
 
    @param    session               The thread handle
850
 
    @param    table             The altered table, re-opened
851
 
 */
852
 
 virtual int alter_table_phase3(Session *, Table *)
853
 
 {
854
 
   return HA_ERR_UNSUPPORTED;
855
 
 }
856
 
 
857
 
  /**
858
 
    use_hidden_primary_key() is called in case of an update/delete when
859
 
    (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
860
 
    but we don't have a primary key
861
 
  */
862
 
  virtual void use_hidden_primary_key();
863
 
 
864
 
  /**
865
 
    Lock table.
866
 
 
867
 
    @param    session                     Thread handle
868
 
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
869
 
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
870
 
    @param    lock_timeout            -1 default timeout
871
 
                                      0  no wait
872
 
                                      >0 wait timeout in milliseconds.
873
 
 
874
 
   @note
875
 
      lock_timeout >0 is not used by MySQL currently. If the storage
876
 
      engine does not support NOWAIT (lock_timeout == 0) it should
877
 
      return an error. But if it does not support WAIT X (lock_timeout
878
 
      >0) it should treat it as lock_timeout == -1 and wait a default
879
 
      (or even hard-coded) timeout.
880
 
 
881
 
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
882
 
                                      lock_table()
883
 
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
884
 
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
885
 
                                      lock conflict with NOWAIT option
886
 
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
887
 
  */
888
 
  virtual int lock_table(Session *, int, int)
 
550
  virtual bool isOrdered(void)
889
551
  {
890
 
    return HA_ERR_WRONG_COMMAND;
 
552
    return false;
891
553
  }
892
 
  /*
893
 
    This procedure defines if the storage engine supports virtual columns.
894
 
    Default false means "not supported".
895
 
  */
896
 
  virtual bool check_if_supported_virtual_columns(void)
897
 
  { return false; }
 
554
 
898
555
 
899
556
protected:
900
557
  /* Service methods for use by storage engines. */
901
 
  void ha_statistic_increment(ulong SSV::*offset) const;
 
558
  void ha_statistic_increment(ulong system_status_var::*offset) const;
902
559
  void **ha_data(Session *) const;
903
560
  Session *ha_session(void) const;
904
561
 
905
 
  /**
906
 
    Default rename_table() and delete_table() rename/delete files with a
907
 
    given name and extensions from bas_ext().
908
 
 
909
 
    These methods can be overridden, but their default implementation
910
 
    provide useful functionality.
911
 
  */
912
 
  virtual int rename_table(const char *from, const char *to);
913
 
  /**
914
 
    Delete a table in the engine. Called for base as well as temporary
915
 
    tables.
916
 
  */
917
 
  virtual int delete_table(const char *name);
918
 
 
919
562
private:
920
563
  /* Private helpers */
921
 
  inline void mark_trx_read_write();
 
564
  inline void setTransactionReadWrite();
922
565
private:
923
566
  /*
924
567
    Low-level primitives for storage engines.  These should be
959
602
    by that statement.
960
603
  */
961
604
  virtual int reset() { return 0; }
962
 
  virtual Table_flags table_flags(void) const= 0;
963
605
 
964
606
  /**
965
607
    Is not invoked for non-transactional temporary tables.
966
608
 
967
609
    Tells the storage engine that we intend to read or write data
968
 
    from the table. This call is prefixed with a call to handler::store_lock()
969
 
    and is invoked only for those handler instances that stored the lock.
 
610
    from the table. This call is prefixed with a call to Cursor::store_lock()
 
611
    and is invoked only for those Cursor instances that stored the lock.
970
612
 
971
613
    Calls to rnd_init/index_init are prefixed with this call. When table
972
614
    IO is complete, we call external_lock(F_UNLCK).
989
631
  }
990
632
  virtual void release_auto_increment(void) { return; };
991
633
  /** admin commands - called from mysql_admin_table */
992
 
  virtual int check_for_upgrade(HA_CHECK_OPT *)
993
 
  { return 0; }
994
 
  virtual int check(Session *, HA_CHECK_OPT *)
 
634
  virtual int check(Session *)
995
635
  { return HA_ADMIN_NOT_IMPLEMENTED; }
996
636
 
997
 
  /**
998
 
     In this method check_opt can be modified
999
 
     to specify CHECK option to use to call check()
1000
 
     upon the table.
1001
 
  */
1002
 
  virtual int repair(Session *, HA_CHECK_OPT *)
1003
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1004
637
  virtual void start_bulk_insert(ha_rows)
1005
638
  {}
1006
639
  virtual int end_bulk_insert(void) { return 0; }
1008
641
                         uint32_t, enum ha_rkey_function)
1009
642
   { return  HA_ERR_WRONG_COMMAND; }
1010
643
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
1011
 
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
1012
 
  /**
1013
 
    This method is similar to update_row, however the handler doesn't need
1014
 
    to execute the updates at this point in time. The handler can be certain
1015
 
    that another call to bulk_update_row will occur OR a call to
1016
 
    exec_bulk_update before the set of updates in this query is concluded.
1017
 
 
1018
 
    @param    old_data       Old record
1019
 
    @param    new_data       New record
1020
 
    @param    dup_key_found  Number of duplicate keys found
1021
 
 
1022
 
    @retval  0   Bulk delete used by handler
1023
 
    @retval  1   Bulk delete not used, normal operation used
1024
 
  */
1025
 
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
1026
 
  {
1027
 
    assert(false);
1028
 
    return HA_ERR_WRONG_COMMAND;
1029
 
  }
 
644
   { return (errno= HA_ERR_WRONG_COMMAND); }
1030
645
  /**
1031
646
    This is called to delete all rows in a table
1032
 
    If the handler don't support this, then this function will
 
647
    If the Cursor don't support this, then this function will
1033
648
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
1034
649
    by one.
1035
650
  */
1036
651
  virtual int delete_all_rows(void)
1037
 
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
652
  { return (errno=HA_ERR_WRONG_COMMAND); }
1038
653
  /**
1039
654
    Reset the auto-increment counter to the given value, i.e. the next row
1040
655
    inserted will get the given value. This is called e.g. after TRUNCATE
1043
658
  */
1044
659
  virtual int reset_auto_increment(uint64_t)
1045
660
  { return HA_ERR_WRONG_COMMAND; }
1046
 
  virtual int optimize(Session *, HA_CHECK_OPT *)
1047
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1048
 
  virtual int analyze(Session *, HA_CHECK_OPT *)
1049
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1050
 
  virtual bool check_and_repair(Session *)
1051
 
  { return true; }
 
661
 
 
662
  virtual int analyze(Session *)
 
663
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
664
 
1052
665
  virtual int disable_indexes(uint32_t)
1053
666
  { return HA_ERR_WRONG_COMMAND; }
 
667
 
1054
668
  virtual int enable_indexes(uint32_t)
1055
669
  { return HA_ERR_WRONG_COMMAND; }
 
670
 
1056
671
  virtual int discard_or_import_tablespace(bool)
1057
 
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
1058
 
  virtual void prepare_for_alter(void) { return; }
 
672
  { return (errno=HA_ERR_WRONG_COMMAND); }
 
673
 
 
674
  /* 
 
675
    @todo this is just for the HEAP engine, it should
 
676
    be removed at some point in the future (and
 
677
    no new engine should ever use it). Right
 
678
    now HEAP does rely on it, so we cannot remove it.
 
679
  */
1059
680
  virtual void drop_table(const char *name);
1060
 
  virtual int create(const char *, Table *, HA_CREATE_INFO *)=0;
1061
 
 
1062
 
  virtual int create_handler_files(const char *, const char *, int, HA_CREATE_INFO *)
1063
 
  { return false; }
1064
 
};
1065
 
 
1066
 
 
1067
 
 
1068
 
/**
1069
 
  A Disk-Sweep MRR interface implementation
1070
 
 
1071
 
  This implementation makes range (and, in the future, 'ref') scans to read
1072
 
  table rows in disk sweeps.
1073
 
 
1074
 
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
1075
 
  any table handler that has non-clustered indexes and on-disk rows.
1076
 
*/
1077
 
 
1078
 
class DsMrr_impl
1079
 
{
1080
 
public:
1081
 
  typedef void (handler::*range_check_toggle_func_t)(bool on);
1082
 
 
1083
 
  DsMrr_impl()
1084
 
    : h2(NULL) {};
1085
 
 
1086
 
  handler *h; /* The "owner" handler object. It is used for scanning the index */
1087
 
  Table *table; /* Always equal to h->table */
1088
 
private:
1089
 
  /*
1090
 
    Secondary handler object. It is used to retrieve full table rows by
1091
 
    calling rnd_pos().
1092
 
  */
1093
 
  handler *h2;
1094
 
 
1095
 
  /* Buffer to store rowids, or (rowid, range_id) pairs */
1096
 
  unsigned char *rowids_buf;
1097
 
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
1098
 
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
1099
 
  unsigned char *rowids_buf_end;   /* End of the buffer */
1100
 
 
1101
 
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
1102
 
 
1103
 
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
1104
 
  bool is_mrr_assoc;
1105
 
 
1106
 
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
1107
 
public:
1108
 
  void init(handler *h_arg, Table *table_arg)
1109
 
  {
1110
 
    h= h_arg;
1111
 
    table= table_arg;
1112
 
  }
1113
 
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
1114
 
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode,
1115
 
                 HANDLER_BUFFER *buf);
1116
 
  void dsmrr_close();
1117
 
  int dsmrr_fill_buffer(handler *h);
1118
 
  int dsmrr_next(handler *h, char **range_info);
1119
 
 
1120
 
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
1121
 
                 uint32_t *flags, COST_VECT *cost);
1122
 
 
1123
 
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
1124
 
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
1125
 
                            uint32_t *flags, COST_VECT *cost);
1126
 
private:
1127
 
  bool key_uses_partial_cols(uint32_t keyno);
1128
 
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz,
1129
 
                       COST_VECT *cost);
1130
 
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
1131
 
                               uint32_t *buffer_size, COST_VECT *cost);
1132
681
};
1133
682
 
1134
683
extern const char *ha_row_type[];
1135
 
extern const char *tx_isolation_names[];
1136
 
extern const char *binlog_format_names[];
1137
 
extern TYPELIB tx_isolation_typelib;
1138
 
extern TYPELIB myisam_stats_method_typelib;
1139
 
extern uint32_t total_ha, total_ha_2pc;
1140
 
 
1141
 
       /* Wrapper functions */
1142
 
#define ha_commit(session) (ha_commit_trans((session), true))
1143
 
#define ha_rollback(session) (ha_rollback_trans((session), true))
1144
684
 
1145
685
/* basic stuff */
1146
 
int ha_init_errors(void);
1147
 
int ha_init(void);
1148
 
int ha_end(void);
1149
 
int ha_initialize_handlerton(st_plugin_int *plugin);
1150
 
int ha_finalize_handlerton(st_plugin_int *plugin);
1151
 
 
1152
 
TYPELIB *ha_known_exts(void);
1153
 
void ha_close_connection(Session* session);
1154
 
bool ha_flush_logs(handlerton *db_type);
1155
 
void ha_drop_database(char* path);
1156
 
int ha_create_table(Session *session, const char *path,
1157
 
                    const char *db, const char *table_name,
1158
 
                    HA_CREATE_INFO *create_info,
1159
 
                    bool update_create_info);
1160
 
int ha_delete_table(Session *session, const char *path,
1161
 
                    const char *db, const char *alias, bool generate_warning);
1162
 
 
1163
 
/* statistics and info */
1164
 
bool ha_show_status(Session *session, handlerton *db_type, enum ha_stat_type stat);
1165
 
 
1166
 
int ha_find_files(Session *session,const char *db,const char *path,
1167
 
                  const char *wild, bool dir, List<LEX_STRING>* files);
1168
 
int ha_table_exists_in_engine(Session* session, const char* db, const char* name);
1169
 
 
1170
 
/* key cache */
1171
 
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
1172
 
int ha_resize_key_cache(KEY_CACHE *key_cache);
1173
 
int ha_change_key_cache_param(KEY_CACHE *key_cache);
1174
 
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
1175
 
int ha_end_key_cache(KEY_CACHE *key_cache);
1176
 
 
1177
 
/* report to InnoDB that control passes to the client */
1178
 
int ha_release_temporary_latches(Session *session);
1179
 
 
1180
 
/* transactions: interface to handlerton functions */
1181
 
int ha_start_consistent_snapshot(Session *session);
1182
 
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
1183
 
int ha_commit_one_phase(Session *session, bool all);
1184
 
int ha_rollback_trans(Session *session, bool all);
1185
 
int ha_prepare(Session *session);
1186
 
int ha_recover(HASH *commit_list);
1187
 
 
1188
 
/* transactions: these functions never call handlerton functions directly */
1189
 
int ha_commit_trans(Session *session, bool all);
1190
 
int ha_autocommit_or_rollback(Session *session, int error);
1191
 
int ha_enable_transaction(Session *session, bool on);
1192
 
 
1193
 
/* savepoints */
1194
 
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
1195
 
int ha_savepoint(Session *session, SAVEPOINT *sv);
1196
 
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
1197
 
 
1198
 
/* these are called by storage engines */
1199
 
void trans_register_ha(Session *session, bool all, handlerton *ht);
1200
 
 
1201
 
void table_case_convert(char * name, uint32_t length);
1202
 
const char *table_case_name(HA_CREATE_INFO *info, const char *name);
1203
 
 
1204
 
extern char reg_ext[FN_EXTLEN];
1205
 
extern uint32_t reg_ext_length;
1206
 
extern ulong specialflag;
1207
 
extern uint32_t lower_case_table_names;
1208
 
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
1209
 
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
1210
 
 
1211
 
 
1212
 
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
1213
 
bool mysql_ha_close(Session *session, TableList *tables);
1214
 
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
1215
 
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1216
 
void mysql_ha_flush(Session *session);
1217
 
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
1218
 
void mysql_ha_cleanup(Session *session);
1219
 
 
1220
 
/*
1221
 
  Storage engine has to assume the transaction will end up with 2pc if
1222
 
   - there is more than one 2pc-capable storage engine available
1223
 
   - in the current transaction 2pc was not disabled yet
1224
 
*/
1225
 
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
1226
 
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
1227
 
 
1228
 
 
1229
 
bool mysql_xa_recover(Session *session);
 
686
void ha_init_errors(void);
1230
687
 
1231
688
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
1232
689
                                   SORT_FIELD *sortorder);
1235
692
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
1236
693
                List<Item> &fields, List<Item> &all_fields, order_st *order,
1237
694
                bool *hidden_group_fields);
1238
 
bool fix_inner_refs(Session *session, List<Item> &all_fields, SELECT_LEX *select,
 
695
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
1239
696
                    Item **ref_pointer_array);
1240
697
 
1241
698
bool handle_select(Session *session, LEX *lex, select_result *result,
1242
 
                   ulong setup_tables_done_option);
1243
 
bool mysql_select(Session *session, Item ***rref_pointer_array,
1244
 
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
1245
 
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
1246
 
                  Item *having, order_st *proc_param, uint64_t select_type,
1247
 
                  select_result *result, SELECT_LEX_UNIT *unit,
1248
 
                  SELECT_LEX *select_lex);
1249
 
void free_underlaid_joins(Session *session, SELECT_LEX *select);
1250
 
bool mysql_explain_union(Session *session, SELECT_LEX_UNIT *unit,
1251
 
                         select_result *result);
1252
 
int mysql_explain_select(Session *session, SELECT_LEX *sl, char const *type,
1253
 
                         select_result *result);
1254
 
bool mysql_union(Session *session, LEX *lex, select_result *result,
1255
 
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
 
699
                   uint64_t setup_tables_done_option);
 
700
void free_underlaid_joins(Session *session, Select_Lex *select);
 
701
 
1256
702
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
1257
703
                                                      LEX *lex,
1258
704
                                                      TableList *table));
1259
705
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
1260
706
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
1261
 
void sp_prepare_create_field(Session *session, Create_field *sql_field);
1262
 
int prepare_create_field(Create_field *sql_field,
 
707
int prepare_create_field(CreateField *sql_field,
1263
708
                         uint32_t *blob_columns,
1264
 
                         int *timestamps, int *timestamps_with_niladic,
1265
 
                         int64_t table_flags);
1266
 
bool mysql_create_table(Session *session,const char *db, const char *table_name,
 
709
                         int *timestamps, int *timestamps_with_niladic);
 
710
 
 
711
bool mysql_create_table(Session *session,
 
712
                        TableIdentifier &identifier,
1267
713
                        HA_CREATE_INFO *create_info,
1268
 
                        Alter_info *alter_info,
1269
 
                        bool tmp_table, uint32_t select_field_count);
1270
 
bool mysql_create_table_no_lock(Session *session, const char *db,
1271
 
                                const char *table_name,
 
714
                        message::Table &table_proto,
 
715
                        AlterInfo *alter_info,
 
716
                        bool tmp_table, uint32_t select_field_count,
 
717
                        bool is_if_not_exists);
 
718
 
 
719
bool mysql_create_table_no_lock(Session *session,
 
720
                                TableIdentifier &identifier,
1272
721
                                HA_CREATE_INFO *create_info,
1273
 
                                Alter_info *alter_info,
 
722
                                message::Table &table_proto,
 
723
                                AlterInfo *alter_info,
1274
724
                                bool tmp_table, uint32_t select_field_count,
1275
 
                                bool lock_open_lock);
1276
 
 
1277
 
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
1278
 
                       HA_CREATE_INFO *create_info,
1279
 
                       TableList *table_list,
1280
 
                       Alter_info *alter_info,
1281
 
                       uint32_t order_num, order_st *order, bool ignore);
1282
 
bool mysql_recreate_table(Session *session, TableList *table_list);
1283
 
bool mysql_create_like_table(Session *session, TableList *table,
1284
 
                             TableList *src_table,
1285
 
                             HA_CREATE_INFO *create_info);
1286
 
bool mysql_rename_table(handlerton *base, const char *old_db,
1287
 
                        const char * old_name, const char *new_db,
1288
 
                        const char * new_name, uint32_t flags);
 
725
                                bool is_if_not_exists);
 
726
 
 
727
bool mysql_create_like_table(Session* session,
 
728
                             TableIdentifier &destination_identifier,
 
729
                             TableList* table, TableList* src_table,
 
730
                             message::Table &create_table_proto,
 
731
                             bool is_if_not_exists,
 
732
                             bool is_engine_set);
 
733
 
 
734
bool mysql_rename_table(plugin::StorageEngine *base,
 
735
                        TableIdentifier &old_identifier,
 
736
                        TableIdentifier &new_identifier,
 
737
                        uint32_t flags);
 
738
 
1289
739
bool mysql_prepare_update(Session *session, TableList *table_list,
1290
740
                          Item **conds, uint32_t order_num, order_st *order);
1291
741
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
1292
742
                 List<Item> &values,COND *conds,
1293
743
                 uint32_t order_num, order_st *order, ha_rows limit,
1294
744
                 enum enum_duplicates handle_duplicates, bool ignore);
1295
 
bool mysql_multi_update(Session *session, TableList *table_list,
1296
 
                        List<Item> *fields, List<Item> *values,
1297
 
                        COND *conds, uint64_t options,
1298
 
                        enum enum_duplicates handle_duplicates, bool ignore,
1299
 
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
1300
745
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
1301
746
                          List<Item> &fields, List_item *values,
1302
747
                          List<Item> &update_fields,
1309
754
                  bool ignore);
1310
755
int check_that_all_fields_are_given_values(Session *session, Table *entry,
1311
756
                                           TableList *table_list);
1312
 
void prepare_triggers_for_insert_stmt(Table *table);
1313
757
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
1314
758
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
1315
759
                  SQL_LIST *order, ha_rows rows, uint64_t options,
1316
760
                  bool reset_auto_increment);
1317
 
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
1318
 
uint32_t create_table_def_key(Session *session, char *key, TableList *table_list,
1319
 
                              bool tmp_table);
1320
 
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
 
761
bool mysql_truncate(Session& session, TableList *table_list);
 
762
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
1321
763
                             uint32_t key_length, uint32_t db_flags, int *error);
1322
 
void release_table_share(TABLE_SHARE *share, enum release_type type);
1323
 
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
1324
 
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update,
1325
 
                   uint32_t lock_flags);
1326
 
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
1327
 
bool name_lock_locked_table(Session *session, TableList *tables);
 
764
TableShare *get_cached_table_share(const char *db, const char *table_name);
1328
765
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
1329
766
Table *table_cache_insert_placeholder(Session *session, const char *key,
1330
767
                                      uint32_t key_length);
1331
768
bool lock_table_name_if_not_cached(Session *session, const char *db,
1332
769
                                   const char *table_name, Table **table);
1333
 
Table *find_locked_table(Session *session, const char *db,const char *table_name);
1334
 
void detach_merge_children(Table *table, bool clear_refs);
1335
 
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
1336
 
                          TableList *new_child_list, TableList **new_last);
1337
770
bool reopen_table(Table *table);
1338
771
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
1339
772
void close_data_files_and_morph_locks(Session *session, const char *db,
1340
773
                                      const char *table_name);
1341
774
void close_handle_and_leave_table_as_lock(Table *table);
1342
 
bool open_new_frm(Session *session, TABLE_SHARE *share, const char *alias,
1343
 
                  uint32_t db_stat, uint32_t prgflag,
1344
 
                  uint32_t ha_open_flags, Table *outparam,
1345
 
                  TableList *table_desc, MEM_ROOT *mem_root);
1346
775
bool wait_for_tables(Session *session);
1347
776
bool table_is_used(Table *table, bool wait_for_name_lock);
1348
777
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
1349
778
void abort_locked_tables(Session *session,const char *db, const char *table_name);
1350
 
void execute_init_command(Session *session, sys_var_str *init_command_var,
1351
 
                          pthread_rwlock_t *var_mutex);
1352
779
extern Field *not_found_field;
1353
780
extern Field *view_ref_found;
1354
781
 
1356
783
find_field_in_tables(Session *session, Item_ident *item,
1357
784
                     TableList *first_table, TableList *last_table,
1358
785
                     Item **ref, find_item_error_report_type report_error,
1359
 
                     bool check_privileges, bool register_tree_change);
 
786
                     bool register_tree_change);
1360
787
Field *
1361
788
find_field_in_table_ref(Session *session, TableList *table_list,
1362
789
                        const char *name, uint32_t length,
1363
790
                        const char *item_name, const char *db_name,
1364
791
                        const char *table_name, Item **ref,
1365
 
                        bool check_privileges, bool allow_rowid,
 
792
                        bool allow_rowid,
1366
793
                        uint32_t *cached_field_index_ptr,
1367
794
                        bool register_tree_change, TableList **actual_table);
1368
795
Field *
1369
796
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
1370
797
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
1371
 
Field *
1372
 
find_field_in_table_sef(Table *table, const char *name);
1373
 
int update_virtual_fields_marked_for_write(Table *table,
1374
 
                                           bool ignore_stored=true);
1375
 
 
1376
 
 
1377
 
#endif /* DRIZZLED_HANDLER_H */
 
798
 
 
799
} /* namespace drizzled */
 
800
 
 
801
#endif /* DRIZZLED_CURSOR_H */