~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Brian Aker
  • Date: 2009-07-16 22:37:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: brian@gaz-20090716223701-vbbbo8dmgd2ljqqo
Refactor TableShare has to be behind class.

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/table_identifier.h>
26
 
 
27
 
/* Definitions for parameters to do with Cursor-routines */
28
 
 
29
 
#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>
30
31
#include <drizzled/sql_string.h>
31
32
#include <drizzled/sql_list.h>
32
33
#include <drizzled/plugin/storage_engine.h>
42
43
#include <bitset>
43
44
#include <algorithm>
44
45
 
45
 
namespace drizzled
46
 
{
47
 
 
48
46
#define HA_MAX_ALTER_FLAGS 40
49
 
 
50
 
 
51
47
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
52
48
 
53
 
extern uint64_t refresh_version;  /* Increments on each reload */
 
49
extern drizzled::atomic<uint32_t> refresh_version;  /* Increments on each reload */
54
50
 
55
51
 
56
52
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
58
54
                                      uint64_t *engine_data);
59
55
 
60
56
 
61
 
/* The Cursor for a table type.  Will be included in the Table structure */
 
57
/* The handler for a table type.  Will be included in the Table structure */
62
58
 
63
59
class Table;
64
60
class TableList;
73
69
 
74
70
class LEX;
75
71
class Select_Lex;
76
 
class AlterInfo;
 
72
class Alter_info;
77
73
class select_result;
78
74
class CreateField;
79
75
class sys_var_str;
81
77
typedef struct st_sort_field SORT_FIELD;
82
78
 
83
79
typedef List<Item> List_item;
 
80
 
 
81
typedef struct st_savepoint SAVEPOINT;
 
82
extern uint32_t savepoint_alloc_size;
84
83
extern KEY_CREATE_INFO default_key_create_info;
85
84
 
86
85
/* Forward declaration for condition pushdown to storage engine */
87
86
typedef class Item COND;
88
87
 
89
 
typedef struct system_status_var system_status_var;
90
 
 
91
 
namespace optimizer
92
 
{
93
 
  class CostVector;
94
 
}
 
88
typedef struct system_status_var SSV;
 
89
 
 
90
class COST_VECT;
 
91
 
 
92
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
 
93
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
95
94
 
96
95
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
97
96
/*
115
114
}
116
115
 
117
116
/**
118
 
  The Cursor class is the interface for dynamically loadable
 
117
  The handler class is the interface for dynamically loadable
119
118
  storage engines. Do not add ifdefs and take care when adding or
120
119
  changing virtual functions to avoid vtable confusion
121
120
 
125
124
     storage engine
126
125
 
127
126
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
128
 
     storage engine. See optimizer/range.cc for description of this format.
 
127
     storage engine. See opt_range.cc for description of this format.
129
128
 
130
129
  TableRecordFormat
131
130
  =================
162
161
  must be set to 0.
163
162
*/
164
163
 
165
 
class Cursor :public memory::SqlAlloc
 
164
class handler :public Sql_alloc
166
165
{
 
166
public:
 
167
  typedef uint64_t Table_flags;
 
168
 
167
169
protected:
168
170
  TableShare *table_share;   /* The table definition */
169
171
  Table *table;               /* The current open table */
 
172
  Table_flags cached_table_flags;       /* Set on init() and open() */
170
173
 
171
174
  ha_rows estimation_rows_to_insert;
172
175
public:
173
 
  plugin::StorageEngine *engine;      /* storage engine of this Cursor */
174
 
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
175
 
  {
176
 
    return engine;
177
 
  }
178
 
  unsigned char *ref;                           /* Pointer to current row */
 
176
  StorageEngine *engine;      /* storage engine of this handler */
 
177
  unsigned char *ref;                           /* Pointer to current row */
179
178
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
180
179
 
181
180
  ha_statistics stats;
213
212
  enum {NONE=0, INDEX, RND} inited;
214
213
  bool locked;
215
214
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
 
215
  const Item *pushed_cond;
 
216
 
 
217
  Item *pushed_idx_cond;
 
218
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
216
219
 
217
220
  /**
218
221
    next_insert_id is the next value which should be inserted into the
224
227
    get_auto_increment().
225
228
  */
226
229
  uint64_t next_insert_id;
227
 
  uint64_t getNextInsertId()
228
 
  {
229
 
    return next_insert_id;
230
 
  }
231
 
 
232
230
  /**
233
231
    insert id for the current row (*autogenerated*; if not
234
232
    autogenerated, it's 0).
242
240
  */
243
241
  Discrete_interval auto_inc_interval_for_cur_row;
244
242
 
245
 
  Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
246
 
  virtual ~Cursor(void);
247
 
  virtual Cursor *clone(memory::Root *mem_root);
 
243
  handler(StorageEngine *engine_arg, TableShare *share_arg)
 
244
    :table_share(share_arg), table(0),
 
245
    estimation_rows_to_insert(0), engine(engine_arg),
 
246
    ref(0), in_range_check_pushed_down(false),
 
247
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
 
248
    ref_length(sizeof(my_off_t)),
 
249
    inited(NONE),
 
250
    locked(false), implicit_emptied(0),
 
251
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
 
252
    next_insert_id(0), insert_id_for_cur_row(0)
 
253
    {}
 
254
  virtual ~handler(void);
 
255
  virtual handler *clone(MEM_ROOT *mem_root);
 
256
  /** This is called after create to allow us to set up cached variables */
 
257
  void init()
 
258
  {
 
259
    cached_table_flags= table_flags();
 
260
  }
248
261
 
249
262
  /* ha_ methods: pubilc wrappers for private virtual API */
250
263
 
257
270
 
258
271
  /* this is necessary in many places, e.g. in HANDLER command */
259
272
  int ha_index_or_rnd_end();
 
273
  Table_flags ha_table_flags() const;
260
274
 
261
275
  /**
262
276
    These functions represent the public interface to *users* of the
263
 
    Cursor class, hence they are *not* virtual. For the inheritance
 
277
    handler class, hence they are *not* virtual. For the inheritance
264
278
    interface, see the (private) functions write_row(), update_row(),
265
279
    and delete_row() below.
266
280
  */
275
289
 
276
290
  void ha_start_bulk_insert(ha_rows rows);
277
291
  int ha_end_bulk_insert();
 
292
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
 
293
                         uint32_t *dup_key_found);
278
294
  int ha_delete_all_rows();
279
295
  int ha_reset_auto_increment(uint64_t value);
 
296
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
280
297
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
281
298
 
282
299
  int ha_disable_indexes(uint32_t mode);
283
300
  int ha_enable_indexes(uint32_t mode);
284
301
  int ha_discard_or_import_tablespace(bool discard);
285
 
  void closeMarkForDelete(const char *name);
 
302
  void ha_prepare_for_alter();
 
303
  void ha_drop_table(const char *name);
286
304
 
287
305
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
288
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);
289
311
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
290
312
 
291
313
  /* Estimates calculation */
299
321
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
300
322
                                              void *seq_init_param,
301
323
                                              uint32_t n_ranges, uint32_t *bufsz,
302
 
                                              uint32_t *flags, optimizer::CostVector *cost);
 
324
                                              uint32_t *flags, COST_VECT *cost);
303
325
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
304
 
                                    uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
 
326
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
305
327
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
306
328
                                    uint32_t n_ranges, uint32_t mode,
307
329
                                    HANDLER_BUFFER *buf);
314
336
  /**
315
337
    This method is used to analyse the error to see whether the error
316
338
    is ignorable or not, certain handlers can have more error that are
317
 
    ignorable than others. E.g. the partition Cursor can get inserts
 
339
    ignorable than others. E.g. the partition handler can get inserts
318
340
    into a range where there is no partition and this is an ignorable
319
341
    error.
320
342
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
328
350
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
329
351
  */
330
352
  virtual ha_rows records();
331
 
  virtual uint64_t tableSize();
332
 
  virtual uint64_t rowSize();
333
353
  /**
334
354
    Return upper bound of current number of records in the table
335
355
    (max. of how many records one will retrieve when doing a full table scan)
353
373
  virtual int close(void)=0;
354
374
 
355
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
  /**
356
418
     @brief
357
419
     Positions an index cursor to the index specified in the handle. Fetches the
358
420
     row if available. If the key value is null, begin at the first key of the
451
513
  */
452
514
  virtual void try_semi_consistent_read(bool) {}
453
515
  virtual void unlock_row(void) {}
 
516
  virtual int start_stmt(Session *, thr_lock_type)
 
517
  {return 0;}
454
518
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
455
519
                                  uint64_t nb_desired_values,
456
520
                                  uint64_t *first_value,
457
 
                                  uint64_t *nb_reserved_values)= 0;
458
 
 
 
521
                                  uint64_t *nb_reserved_values);
459
522
  void set_next_insert_id(uint64_t id)
460
523
  {
461
524
    next_insert_id= id;
478
541
 
479
542
  virtual void update_create_info(HA_CREATE_INFO *) {}
480
543
  int check_old_types(void);
 
544
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
 
545
  { return HA_ADMIN_NOT_IMPLEMENTED; }
481
546
  /* end of the list of admin commands */
482
547
 
483
548
  virtual int indexes_are_disabled(void) {return 0;}
 
549
  virtual char *update_table_comment(const char * comment)
 
550
  { return (char*) comment;}
484
551
  virtual void append_create_info(String *)
485
552
  {}
486
553
  /**
493
560
    @retval   true            Foreign key defined on table or index
494
561
    @retval   false           No foreign key defined
495
562
  */
 
563
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
 
564
  { return false; }
496
565
  virtual char* get_foreign_key_create_info(void)
497
566
  { return NULL;}  /* gets foreign key create string from InnoDB */
498
567
  /** used in ALTER Table; if changing storage engine is allowed.
503
572
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
504
573
  { return 0; }
505
574
  virtual uint32_t referenced_by_foreign_key() { return 0;}
 
575
  virtual void init_table_handle_for_HANDLER()
 
576
  { return; }       /* prepare InnoDB for HANDLER */
506
577
  virtual void free_foreign_key_create_info(char *) {}
507
 
  /** The following can be called without an open Cursor */
 
578
  /** The following can be called without an open handler */
 
579
 
 
580
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
508
581
 
509
582
  virtual int add_index(Table *, KEY *, uint32_t)
510
583
  { return (HA_ERR_WRONG_COMMAND); }
513
586
  virtual int final_drop_index(Table *)
514
587
  { return (HA_ERR_WRONG_COMMAND); }
515
588
 
 
589
  uint32_t max_record_length() const
 
590
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
591
  uint32_t max_keys() const
 
592
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
 
593
  uint32_t max_key_parts() const
 
594
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
595
  uint32_t max_key_length() const
 
596
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
597
  uint32_t max_key_part_length(void) const
 
598
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
599
 
 
600
  virtual uint32_t max_supported_record_length(void) const
 
601
  { return HA_MAX_REC_LENGTH; }
 
602
  virtual uint32_t max_supported_keys(void) const { return 0; }
 
603
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
604
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
605
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
 
606
 
 
607
  virtual bool low_byte_first(void) const { return 1; }
516
608
  virtual uint32_t checksum(void) const { return 0; }
 
609
  virtual bool is_crashed(void) const  { return 0; }
 
610
  virtual bool auto_repair(void) const { return 0; }
517
611
 
518
612
  /**
519
613
    Is not invoked for non-transactional temporary tables.
528
622
    than lock_count() claimed. This can happen when the MERGE children
529
623
    are not attached when this is called from another thread.
530
624
  */
531
 
  virtual THR_LOCK_DATA **store_lock(Session *,
 
625
  virtual THR_LOCK_DATA **store_lock(Session *session,
532
626
                                     THR_LOCK_DATA **to,
533
 
                                     enum thr_lock_type)
534
 
  {
535
 
    assert(0); // Impossible programming situation
536
 
 
537
 
    return(to);
538
 
  }
 
627
                                     enum thr_lock_type lock_type)=0;
539
628
 
540
629
 /*
541
630
   @retval true   Primary key (if there is one) is clustered
548
637
   return memcmp(ref1, ref2, ref_length);
549
638
 }
550
639
 
551
 
  virtual bool isOrdered(void)
 
640
 /*
 
641
   Condition pushdown to storage engines
 
642
 */
 
643
 
 
644
 /**
 
645
   Push condition down to the table handler.
 
646
 
 
647
   @param  cond   Condition to be pushed. The condition tree must not be
 
648
                  modified by the by the caller.
 
649
 
 
650
   @return
 
651
     The 'remainder' condition that caller must use to filter out records.
 
652
     NULL means the handler will not return rows that do not match the
 
653
     passed condition.
 
654
 
 
655
   @note
 
656
   The pushed conditions form a stack (from which one can remove the
 
657
   last pushed condition using cond_pop).
 
658
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2
 
659
   AND ... AND pushed_condN)
 
660
   or less restrictive condition, depending on handler's capabilities.
 
661
 
 
662
   handler->ha_reset() call empties the condition stack.
 
663
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
 
664
   condition stack.
 
665
 */
 
666
 virtual const COND *cond_push(const COND *cond) { return cond; }
 
667
 
 
668
 /**
 
669
   Pop the top condition from the condition stack of the handler instance.
 
670
 
 
671
   Pops the top if condition stack, if stack is not empty.
 
672
 */
 
673
 virtual void cond_pop(void) { return; }
 
674
 
 
675
 virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
 
676
 { return idx_cond; }
 
677
 
 
678
  /**
 
679
    Lock table.
 
680
 
 
681
    @param    session                     Thread handle
 
682
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
 
683
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
 
684
    @param    lock_timeout            -1 default timeout
 
685
                                      0  no wait
 
686
                                      >0 wait timeout in milliseconds.
 
687
 
 
688
   @note
 
689
      lock_timeout >0 is not used by MySQL currently. If the storage
 
690
      engine does not support NOWAIT (lock_timeout == 0) it should
 
691
      return an error. But if it does not support WAIT X (lock_timeout
 
692
      >0) it should treat it as lock_timeout == -1 and wait a default
 
693
      (or even hard-coded) timeout.
 
694
 
 
695
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
 
696
                                      lock_table()
 
697
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
 
698
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
 
699
                                      lock conflict with NOWAIT option
 
700
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
 
701
  */
 
702
  virtual int lock_table(Session *, int, int)
552
703
  {
553
 
    return false;
 
704
    return HA_ERR_WRONG_COMMAND;
554
705
  }
555
706
 
556
 
 
557
707
protected:
558
708
  /* Service methods for use by storage engines. */
559
 
  void ha_statistic_increment(ulong system_status_var::*offset) const;
 
709
  void ha_statistic_increment(ulong SSV::*offset) const;
560
710
  void **ha_data(Session *) const;
561
711
  Session *ha_session(void) const;
562
712
 
563
713
private:
564
714
  /* Private helpers */
565
 
  inline void setTransactionReadWrite();
 
715
  inline void mark_trx_read_write();
566
716
private:
567
717
  /*
568
718
    Low-level primitives for storage engines.  These should be
603
753
    by that statement.
604
754
  */
605
755
  virtual int reset() { return 0; }
 
756
  virtual Table_flags table_flags(void) const= 0;
606
757
 
607
758
  /**
608
759
    Is not invoked for non-transactional temporary tables.
609
760
 
610
761
    Tells the storage engine that we intend to read or write data
611
 
    from the table. This call is prefixed with a call to Cursor::store_lock()
612
 
    and is invoked only for those Cursor instances that stored the lock.
 
762
    from the table. This call is prefixed with a call to handler::store_lock()
 
763
    and is invoked only for those handler instances that stored the lock.
613
764
 
614
765
    Calls to rnd_init/index_init are prefixed with this call. When table
615
766
    IO is complete, we call external_lock(F_UNLCK).
632
783
  }
633
784
  virtual void release_auto_increment(void) { return; };
634
785
  /** admin commands - called from mysql_admin_table */
635
 
  virtual int check(Session *)
 
786
  virtual int check_for_upgrade(HA_CHECK_OPT *)
 
787
  { return 0; }
 
788
  virtual int check(Session *, HA_CHECK_OPT *)
636
789
  { return HA_ADMIN_NOT_IMPLEMENTED; }
637
790
 
638
791
  virtual void start_bulk_insert(ha_rows)
642
795
                         uint32_t, enum ha_rkey_function)
643
796
   { return  HA_ERR_WRONG_COMMAND; }
644
797
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
645
 
   { return (errno= HA_ERR_WRONG_COMMAND); }
 
798
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
 
799
  /**
 
800
    This method is similar to update_row, however the handler doesn't need
 
801
    to execute the updates at this point in time. The handler can be certain
 
802
    that another call to bulk_update_row will occur OR a call to
 
803
    exec_bulk_update before the set of updates in this query is concluded.
 
804
 
 
805
    @param    old_data       Old record
 
806
    @param    new_data       New record
 
807
    @param    dup_key_found  Number of duplicate keys found
 
808
 
 
809
    @retval  0   Bulk delete used by handler
 
810
    @retval  1   Bulk delete not used, normal operation used
 
811
  */
 
812
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
 
813
  {
 
814
    assert(false);
 
815
    return HA_ERR_WRONG_COMMAND;
 
816
  }
646
817
  /**
647
818
    This is called to delete all rows in a table
648
 
    If the Cursor don't support this, then this function will
 
819
    If the handler don't support this, then this function will
649
820
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
650
821
    by one.
651
822
  */
652
823
  virtual int delete_all_rows(void)
653
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
 
824
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
654
825
  /**
655
826
    Reset the auto-increment counter to the given value, i.e. the next row
656
827
    inserted will get the given value. This is called e.g. after TRUNCATE
659
830
  */
660
831
  virtual int reset_auto_increment(uint64_t)
661
832
  { return HA_ERR_WRONG_COMMAND; }
662
 
 
663
 
  virtual int analyze(Session *)
 
833
  virtual int optimize(Session *, HA_CHECK_OPT *)
 
834
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
835
  virtual int analyze(Session *, HA_CHECK_OPT *)
664
836
  { return HA_ADMIN_NOT_IMPLEMENTED; }
665
837
 
666
838
  virtual int disable_indexes(uint32_t)
667
839
  { return HA_ERR_WRONG_COMMAND; }
668
 
 
669
840
  virtual int enable_indexes(uint32_t)
670
841
  { return HA_ERR_WRONG_COMMAND; }
671
 
 
672
842
  virtual int discard_or_import_tablespace(bool)
673
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
674
 
 
675
 
  /* 
676
 
    @todo this is just for the HEAP engine, it should
677
 
    be removed at some point in the future (and
678
 
    no new engine should ever use it). Right
679
 
    now HEAP does rely on it, so we cannot remove it.
680
 
  */
 
843
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
844
  virtual void prepare_for_alter(void) { return; }
681
845
  virtual void drop_table(const char *name);
682
846
};
683
847
 
 
848
 
 
849
 
 
850
/**
 
851
  A Disk-Sweep MRR interface implementation
 
852
 
 
853
  This implementation makes range (and, in the future, 'ref') scans to read
 
854
  table rows in disk sweeps.
 
855
 
 
856
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
 
857
  any table handler that has non-clustered indexes and on-disk rows.
 
858
*/
 
859
 
 
860
class DsMrr_impl
 
861
{
 
862
public:
 
863
  typedef void (handler::*range_check_toggle_func_t)(bool on);
 
864
 
 
865
  DsMrr_impl()
 
866
    : h2(NULL) {};
 
867
 
 
868
  handler *h; /* The "owner" handler object. It is used for scanning the index */
 
869
  Table *table; /* Always equal to h->table */
 
870
private:
 
871
  /*
 
872
    Secondary handler object. It is used to retrieve full table rows by
 
873
    calling rnd_pos().
 
874
  */
 
875
  handler *h2;
 
876
 
 
877
  /* Buffer to store rowids, or (rowid, range_id) pairs */
 
878
  unsigned char *rowids_buf;
 
879
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
 
880
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
 
881
  unsigned char *rowids_buf_end;   /* End of the buffer */
 
882
 
 
883
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
 
884
 
 
885
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
 
886
  bool is_mrr_assoc;
 
887
 
 
888
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
 
889
public:
 
890
  void init(handler *h_arg, Table *table_arg)
 
891
  {
 
892
    h= h_arg;
 
893
    table= table_arg;
 
894
  }
 
895
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
 
896
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode,
 
897
                 HANDLER_BUFFER *buf);
 
898
  void dsmrr_close();
 
899
  int dsmrr_fill_buffer(handler *h);
 
900
  int dsmrr_next(handler *h, char **range_info);
 
901
 
 
902
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
 
903
                 uint32_t *flags, COST_VECT *cost);
 
904
 
 
905
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
906
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
 
907
                            uint32_t *flags, COST_VECT *cost);
 
908
private:
 
909
  bool key_uses_partial_cols(uint32_t keyno);
 
910
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz,
 
911
                       COST_VECT *cost);
 
912
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
 
913
                               uint32_t *buffer_size, COST_VECT *cost);
 
914
};
 
915
 
684
916
extern const char *ha_row_type[];
 
917
extern const char *tx_isolation_names[];
 
918
extern const char *binlog_format_names[];
 
919
extern TYPELIB tx_isolation_typelib;
 
920
extern TYPELIB myisam_stats_method_typelib;
 
921
extern uint32_t total_ha, total_ha_2pc;
 
922
 
 
923
       /* Wrapper functions */
 
924
#define ha_commit(session) (ha_commit_trans((session), true))
 
925
#define ha_rollback(session) (ha_rollback_trans((session), true))
685
926
 
686
927
/* basic stuff */
687
 
void ha_init_errors(void);
 
928
int ha_init_errors(void);
 
929
int ha_init(void);
 
930
int ha_end(void);
 
931
 
 
932
void add_storage_engine(StorageEngine *engine);
 
933
void remove_storage_engine(StorageEngine *engine);
 
934
 
 
935
void ha_close_connection(Session* session);
 
936
bool ha_flush_logs(StorageEngine *db_type);
 
937
void ha_drop_database(char* path);
 
938
int ha_create_table(Session *session, const char *path,
 
939
                    const char *db, const char *table_name,
 
940
                    HA_CREATE_INFO *create_info,
 
941
                    bool update_create_info);
 
942
int ha_delete_table(Session *session, const char *path,
 
943
                    const char *db, const char *alias, bool generate_warning);
 
944
 
 
945
/* statistics and info */
 
946
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
 
947
 
 
948
int ha_find_files(Session *session,const char *db,const char *path,
 
949
                  const char *wild, bool dir, List<LEX_STRING>* files);
 
950
int ha_table_exists_in_engine(Session* session, const char* db, const char* name, StorageEngine **engine= NULL);
 
951
 
 
952
/* key cache */
 
953
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
 
954
int ha_resize_key_cache(KEY_CACHE *key_cache);
 
955
int ha_change_key_cache_param(KEY_CACHE *key_cache);
 
956
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
 
957
int ha_end_key_cache(KEY_CACHE *key_cache);
 
958
 
 
959
/* report to InnoDB that control passes to the client */
 
960
int ha_release_temporary_latches(Session *session);
 
961
 
 
962
/* transactions: interface to StorageEngine functions */
 
963
int ha_start_consistent_snapshot(Session *session);
 
964
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
 
965
int ha_commit_one_phase(Session *session, bool all);
 
966
int ha_rollback_trans(Session *session, bool all);
 
967
int ha_recover(HASH *commit_list);
 
968
 
 
969
/* transactions: these functions never call StorageEngine functions directly */
 
970
int ha_commit_trans(Session *session, bool all);
 
971
int ha_autocommit_or_rollback(Session *session, int error);
 
972
int ha_enable_transaction(Session *session, bool on);
 
973
 
 
974
/* savepoints */
 
975
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
 
976
int ha_savepoint(Session *session, SAVEPOINT *sv);
 
977
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
 
978
 
 
979
/* these are called by storage engines */
 
980
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
 
981
 
 
982
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
 
983
bool tablename_to_filename(const char *from, char *to, size_t to_length);
 
984
 
 
985
 
 
986
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
 
987
bool mysql_ha_close(Session *session, TableList *tables);
 
988
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
 
989
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
 
990
void mysql_ha_flush(Session *session);
 
991
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
 
992
void mysql_ha_cleanup(Session *session);
 
993
 
 
994
/*
 
995
  Storage engine has to assume the transaction will end up with 2pc if
 
996
   - there is more than one 2pc-capable storage engine available
 
997
   - in the current transaction 2pc was not disabled yet
 
998
*/
 
999
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
 
1000
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
 
1001
 
 
1002
 
 
1003
bool mysql_xa_recover(Session *session);
688
1004
 
689
1005
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
690
1006
                                   SORT_FIELD *sortorder);
698
1014
 
699
1015
bool handle_select(Session *session, LEX *lex, select_result *result,
700
1016
                   uint64_t setup_tables_done_option);
 
1017
bool mysql_select(Session *session, Item ***rref_pointer_array,
 
1018
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
 
1019
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
 
1020
                  Item *having, uint64_t select_type,
 
1021
                  select_result *result, Select_Lex_Unit *unit,
 
1022
                  Select_Lex *select_lex);
701
1023
void free_underlaid_joins(Session *session, Select_Lex *select);
 
1024
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
 
1025
                         select_result *result);
 
1026
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
 
1027
                         select_result *result);
702
1028
 
703
1029
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
704
1030
                                                      LEX *lex,
705
1031
                                                      TableList *table));
706
1032
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
707
1033
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
 
1034
void sp_prepare_create_field(Session *session, CreateField *sql_field);
708
1035
int prepare_create_field(CreateField *sql_field,
709
1036
                         uint32_t *blob_columns,
710
 
                         int *timestamps, int *timestamps_with_niladic);
711
 
 
712
 
bool mysql_create_table(Session *session,
713
 
                        TableIdentifier &identifier,
 
1037
                         int *timestamps, int *timestamps_with_niladic,
 
1038
                         int64_t table_flags);
 
1039
bool mysql_create_table(Session *session,const char *db, const char *table_name,
714
1040
                        HA_CREATE_INFO *create_info,
715
 
                        message::Table &table_proto,
716
 
                        AlterInfo *alter_info,
717
 
                        bool tmp_table, uint32_t select_field_count,
718
 
                        bool is_if_not_exists);
719
 
 
720
 
bool mysql_create_table_no_lock(Session *session,
721
 
                                TableIdentifier &identifier,
 
1041
                        drizzled::message::Table *table_proto,
 
1042
                        Alter_info *alter_info,
 
1043
                        bool tmp_table, uint32_t select_field_count);
 
1044
bool mysql_create_table_no_lock(Session *session, const char *db,
 
1045
                                const char *table_name,
722
1046
                                HA_CREATE_INFO *create_info,
723
 
                                message::Table &table_proto,
724
 
                                AlterInfo *alter_info,
725
 
                                bool tmp_table, uint32_t select_field_count,
726
 
                                bool is_if_not_exists);
727
 
 
728
 
bool mysql_create_like_table(Session* session,
729
 
                             TableIdentifier &destination_identifier,
730
 
                             TableList* table, TableList* src_table,
731
 
                             message::Table &create_table_proto,
732
 
                             bool is_if_not_exists,
733
 
                             bool is_engine_set);
734
 
 
735
 
bool mysql_rename_table(plugin::StorageEngine *base,
736
 
                        TableIdentifier &old_identifier,
737
 
                        TableIdentifier &new_identifier,
738
 
                        uint32_t flags);
739
 
 
 
1047
                                drizzled::message::Table *table_proto,
 
1048
                                Alter_info *alter_info,
 
1049
                                bool tmp_table, uint32_t select_field_count);
 
1050
 
 
1051
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
 
1052
                       HA_CREATE_INFO *create_info,
 
1053
                       TableList *table_list,
 
1054
                       Alter_info *alter_info,
 
1055
                       uint32_t order_num, order_st *order, bool ignore);
 
1056
bool mysql_recreate_table(Session *session, TableList *table_list);
 
1057
bool mysql_create_like_table(Session *session, TableList *table,
 
1058
                             TableList *src_table,
 
1059
                             HA_CREATE_INFO *create_info);
 
1060
bool mysql_rename_table(StorageEngine *base, const char *old_db,
 
1061
                        const char * old_name, const char *new_db,
 
1062
                        const char * new_name, uint32_t flags);
740
1063
bool mysql_prepare_update(Session *session, TableList *table_list,
741
1064
                          Item **conds, uint32_t order_num, order_st *order);
742
1065
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
743
1066
                 List<Item> &values,COND *conds,
744
1067
                 uint32_t order_num, order_st *order, ha_rows limit,
745
1068
                 enum enum_duplicates handle_duplicates, bool ignore);
 
1069
bool mysql_multi_update(Session *session, TableList *table_list,
 
1070
                        List<Item> *fields, List<Item> *values,
 
1071
                        COND *conds, uint64_t options,
 
1072
                        enum enum_duplicates handle_duplicates, bool ignore,
 
1073
                        Select_Lex_Unit *unit, Select_Lex *select_lex);
746
1074
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
747
1075
                          List<Item> &fields, List_item *values,
748
1076
                          List<Item> &update_fields,
759
1087
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
760
1088
                  SQL_LIST *order, ha_rows rows, uint64_t options,
761
1089
                  bool reset_auto_increment);
762
 
bool mysql_truncate(Session& session, TableList *table_list);
 
1090
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
763
1091
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
764
1092
                             uint32_t key_length, uint32_t db_flags, int *error);
765
1093
TableShare *get_cached_table_share(const char *db, const char *table_name);
 
1094
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update);
 
1095
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
 
1096
bool name_lock_locked_table(Session *session, TableList *tables);
766
1097
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
767
1098
Table *table_cache_insert_placeholder(Session *session, const char *key,
768
1099
                                      uint32_t key_length);
769
1100
bool lock_table_name_if_not_cached(Session *session, const char *db,
770
1101
                                   const char *table_name, Table **table);
 
1102
Table *find_locked_table(Session *session, const char *db,const char *table_name);
 
1103
void detach_merge_children(Table *table, bool clear_refs);
 
1104
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
 
1105
                          TableList *new_child_list, TableList **new_last);
771
1106
bool reopen_table(Table *table);
772
1107
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
773
1108
void close_data_files_and_morph_locks(Session *session, const char *db,
774
1109
                                      const char *table_name);
775
1110
void close_handle_and_leave_table_as_lock(Table *table);
 
1111
bool open_new_frm(Session *session, TableShare *share, const char *alias,
 
1112
                  uint32_t db_stat, uint32_t prgflag,
 
1113
                  uint32_t ha_open_flags, Table *outparam,
 
1114
                  TableList *table_desc, MEM_ROOT *mem_root);
776
1115
bool wait_for_tables(Session *session);
777
1116
bool table_is_used(Table *table, bool wait_for_name_lock);
778
1117
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
784
1123
find_field_in_tables(Session *session, Item_ident *item,
785
1124
                     TableList *first_table, TableList *last_table,
786
1125
                     Item **ref, find_item_error_report_type report_error,
787
 
                     bool register_tree_change);
 
1126
                     bool check_privileges, bool register_tree_change);
788
1127
Field *
789
1128
find_field_in_table_ref(Session *session, TableList *table_list,
790
1129
                        const char *name, uint32_t length,
791
1130
                        const char *item_name, const char *db_name,
792
1131
                        const char *table_name, Item **ref,
793
 
                        bool allow_rowid,
 
1132
                        bool check_privileges, bool allow_rowid,
794
1133
                        uint32_t *cached_field_index_ptr,
795
1134
                        bool register_tree_change, TableList **actual_table);
796
1135
Field *
797
1136
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
798
1137
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
799
 
 
800
 
} /* namespace drizzled */
801
 
 
802
 
#endif /* DRIZZLED_CURSOR_H */
 
1138
Field *
 
1139
find_field_in_table_sef(Table *table, const char *name);
 
1140
int update_virtual_fields_marked_for_write(Table *table,
 
1141
                                           bool ignore_stored=true);
 
1142
 
 
1143
 
 
1144
#endif /* DRIZZLED_HANDLER_H */