~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Monty Taylor
  • Date: 2009-08-17 18:46:08 UTC
  • mto: (1182.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090817184608-0b2emowpjr9m6le7
"Fixed" the deadlock test. I'd still like someone to look at what's going on here.

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 <mysys/thr_lock.h>
 
29
#include <mysys/hash.h>
30
30
#include <drizzled/sql_string.h>
31
31
#include <drizzled/sql_list.h>
32
32
#include <drizzled/plugin/storage_engine.h>
39
39
/* Bits to show what an alter table will do */
40
40
#include <drizzled/sql_bitmap.h>
41
41
 
 
42
#include <drizzled/handler.h>
 
43
 
42
44
#include <bitset>
43
45
#include <algorithm>
44
46
 
45
 
namespace drizzled
46
 
{
47
 
 
48
47
#define HA_MAX_ALTER_FLAGS 40
49
 
 
50
 
 
51
48
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
52
49
 
53
 
extern uint64_t refresh_version;  /* Increments on each reload */
 
50
extern drizzled::atomic<uint32_t> refresh_version;  /* Increments on each reload */
54
51
 
55
52
 
56
53
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
58
55
                                      uint64_t *engine_data);
59
56
 
60
57
 
61
 
/* The Cursor for a table type.  Will be included in the Table structure */
 
58
/* The handler for a table type.  Will be included in the Table structure */
62
59
 
63
60
class Table;
64
61
class TableList;
73
70
 
74
71
class LEX;
75
72
class Select_Lex;
76
 
class AlterInfo;
 
73
class Alter_info;
77
74
class select_result;
78
75
class CreateField;
79
76
class sys_var_str;
81
78
typedef struct st_sort_field SORT_FIELD;
82
79
 
83
80
typedef List<Item> List_item;
 
81
 
 
82
typedef struct st_savepoint SAVEPOINT;
 
83
extern uint32_t savepoint_alloc_size;
84
84
extern KEY_CREATE_INFO default_key_create_info;
85
85
 
86
86
/* Forward declaration for condition pushdown to storage engine */
87
87
typedef class Item COND;
88
88
 
89
 
typedef struct system_status_var system_status_var;
 
89
typedef struct system_status_var SSV;
90
90
 
91
 
namespace optimizer
92
 
{
93
 
  class CostVector;
94
 
}
 
91
class COST_VECT;
95
92
 
96
93
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
97
94
/*
115
112
}
116
113
 
117
114
/**
118
 
  The Cursor class is the interface for dynamically loadable
 
115
  The handler class is the interface for dynamically loadable
119
116
  storage engines. Do not add ifdefs and take care when adding or
120
117
  changing virtual functions to avoid vtable confusion
121
118
 
125
122
     storage engine
126
123
 
127
124
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
128
 
     storage engine. See optimizer/range.cc for description of this format.
 
125
     storage engine. See opt_range.cc for description of this format.
129
126
 
130
127
  TableRecordFormat
131
128
  =================
162
159
  must be set to 0.
163
160
*/
164
161
 
165
 
class Cursor :public memory::SqlAlloc
 
162
class handler :public Sql_alloc
166
163
{
 
164
public:
 
165
  typedef uint64_t Table_flags;
 
166
 
167
167
protected:
168
168
  TableShare *table_share;   /* The table definition */
169
169
  Table *table;               /* The current open table */
 
170
  Table_flags cached_table_flags;       /* Set on init() and open() */
170
171
 
171
172
  ha_rows estimation_rows_to_insert;
172
173
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 */
 
174
  StorageEngine *engine;      /* storage engine of this handler */
 
175
  unsigned char *ref;                           /* Pointer to current row */
179
176
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
180
177
 
181
178
  ha_statistics stats;
224
221
    get_auto_increment().
225
222
  */
226
223
  uint64_t next_insert_id;
227
 
  uint64_t getNextInsertId()
228
 
  {
229
 
    return next_insert_id;
230
 
  }
231
 
 
232
224
  /**
233
225
    insert id for the current row (*autogenerated*; if not
234
226
    autogenerated, it's 0).
242
234
  */
243
235
  Discrete_interval auto_inc_interval_for_cur_row;
244
236
 
245
 
  Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
246
 
  virtual ~Cursor(void);
247
 
  virtual Cursor *clone(memory::Root *mem_root);
 
237
  handler(StorageEngine *engine_arg, TableShare *share_arg)
 
238
    :table_share(share_arg), table(0),
 
239
    estimation_rows_to_insert(0), engine(engine_arg),
 
240
    ref(0), in_range_check_pushed_down(false),
 
241
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
 
242
    ref_length(sizeof(my_off_t)),
 
243
    inited(NONE),
 
244
    locked(false), implicit_emptied(0),
 
245
    next_insert_id(0), insert_id_for_cur_row(0)
 
246
    {}
 
247
  virtual ~handler(void);
 
248
  virtual handler *clone(MEM_ROOT *mem_root);
 
249
  /** This is called after create to allow us to set up cached variables */
 
250
  void init()
 
251
  {
 
252
    cached_table_flags= table_flags();
 
253
  }
248
254
 
249
255
  /* ha_ methods: pubilc wrappers for private virtual API */
250
256
 
257
263
 
258
264
  /* this is necessary in many places, e.g. in HANDLER command */
259
265
  int ha_index_or_rnd_end();
 
266
  Table_flags ha_table_flags() const;
260
267
 
261
268
  /**
262
269
    These functions represent the public interface to *users* of the
263
 
    Cursor class, hence they are *not* virtual. For the inheritance
 
270
    handler class, hence they are *not* virtual. For the inheritance
264
271
    interface, see the (private) functions write_row(), update_row(),
265
272
    and delete_row() below.
266
273
  */
275
282
 
276
283
  void ha_start_bulk_insert(ha_rows rows);
277
284
  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);
278
287
  int ha_delete_all_rows();
279
288
  int ha_reset_auto_increment(uint64_t value);
 
289
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
280
290
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
281
291
 
282
292
  int ha_disable_indexes(uint32_t mode);
283
293
  int ha_enable_indexes(uint32_t mode);
284
294
  int ha_discard_or_import_tablespace(bool discard);
285
 
  void closeMarkForDelete(const char *name);
 
295
  void ha_prepare_for_alter();
 
296
  void ha_drop_table(const char *name);
286
297
 
287
298
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
288
299
  int update_auto_increment();
 
300
  void print_keydup_error(uint32_t key_nr, const char *msg);
 
301
  virtual void print_error(int error, myf errflag);
 
302
  virtual bool get_error_message(int error, String *buf);
 
303
  uint32_t get_dup_key(int error);
289
304
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
290
305
 
291
306
  /* Estimates calculation */
299
314
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
300
315
                                              void *seq_init_param,
301
316
                                              uint32_t n_ranges, uint32_t *bufsz,
302
 
                                              uint32_t *flags, optimizer::CostVector *cost);
 
317
                                              uint32_t *flags, COST_VECT *cost);
303
318
  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);
 
319
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
305
320
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
306
321
                                    uint32_t n_ranges, uint32_t mode,
307
322
                                    HANDLER_BUFFER *buf);
314
329
  /**
315
330
    This method is used to analyse the error to see whether the error
316
331
    is ignorable or not, certain handlers can have more error that are
317
 
    ignorable than others. E.g. the partition Cursor can get inserts
 
332
    ignorable than others. E.g. the partition handler can get inserts
318
333
    into a range where there is no partition and this is an ignorable
319
334
    error.
320
335
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
328
343
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
329
344
  */
330
345
  virtual ha_rows records();
331
 
  virtual uint64_t tableSize();
332
 
  virtual uint64_t rowSize();
333
346
  /**
334
347
    Return upper bound of current number of records in the table
335
348
    (max. of how many records one will retrieve when doing a full table scan)
353
366
  virtual int close(void)=0;
354
367
 
355
368
  /**
 
369
    @retval  0   Bulk update used by handler
 
370
    @retval  1   Bulk update not used, normal operation used
 
371
  */
 
372
  virtual bool start_bulk_update() { return 1; }
 
373
  /**
 
374
    @retval  0   Bulk delete used by handler
 
375
    @retval  1   Bulk delete not used, normal operation used
 
376
  */
 
377
  virtual bool start_bulk_delete() { return 1; }
 
378
  /**
 
379
    After this call all outstanding updates must be performed. The number
 
380
    of duplicate key errors are reported in the duplicate key parameter.
 
381
    It is allowed to continue to the batched update after this call, the
 
382
    handler has to wait until end_bulk_update with changing state.
 
383
 
 
384
    @param    dup_key_found       Number of duplicate keys found
 
385
 
 
386
    @retval  0           Success
 
387
    @retval  >0          Error code
 
388
  */
 
389
  virtual int exec_bulk_update(uint32_t *)
 
390
  {
 
391
    assert(false);
 
392
    return HA_ERR_WRONG_COMMAND;
 
393
  }
 
394
  /**
 
395
    Perform any needed clean-up, no outstanding updates are there at the
 
396
    moment.
 
397
  */
 
398
  virtual void end_bulk_update() { return; }
 
399
  /**
 
400
    Execute all outstanding deletes and close down the bulk delete.
 
401
 
 
402
    @retval 0             Success
 
403
    @retval >0            Error code
 
404
  */
 
405
  virtual int end_bulk_delete()
 
406
  {
 
407
    assert(false);
 
408
    return HA_ERR_WRONG_COMMAND;
 
409
  }
 
410
  /**
356
411
     @brief
357
412
     Positions an index cursor to the index specified in the handle. Fetches the
358
413
     row if available. If the key value is null, begin at the first key of the
451
506
  */
452
507
  virtual void try_semi_consistent_read(bool) {}
453
508
  virtual void unlock_row(void) {}
 
509
  virtual int start_stmt(Session *, thr_lock_type)
 
510
  {return 0;}
454
511
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
455
512
                                  uint64_t nb_desired_values,
456
513
                                  uint64_t *first_value,
457
 
                                  uint64_t *nb_reserved_values)= 0;
458
 
 
 
514
                                  uint64_t *nb_reserved_values);
459
515
  void set_next_insert_id(uint64_t id)
460
516
  {
461
517
    next_insert_id= id;
478
534
 
479
535
  virtual void update_create_info(HA_CREATE_INFO *) {}
480
536
  int check_old_types(void);
 
537
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
 
538
  { return HA_ADMIN_NOT_IMPLEMENTED; }
481
539
  /* end of the list of admin commands */
482
540
 
483
541
  virtual int indexes_are_disabled(void) {return 0;}
 
542
  virtual char *update_table_comment(const char * comment)
 
543
  { return (char*) comment;}
484
544
  virtual void append_create_info(String *)
485
545
  {}
486
546
  /**
493
553
    @retval   true            Foreign key defined on table or index
494
554
    @retval   false           No foreign key defined
495
555
  */
 
556
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
 
557
  { return false; }
496
558
  virtual char* get_foreign_key_create_info(void)
497
559
  { return NULL;}  /* gets foreign key create string from InnoDB */
498
560
  /** used in ALTER Table; if changing storage engine is allowed.
503
565
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
504
566
  { return 0; }
505
567
  virtual uint32_t referenced_by_foreign_key() { return 0;}
 
568
  virtual void init_table_handle_for_HANDLER()
 
569
  { return; }       /* prepare InnoDB for HANDLER */
506
570
  virtual void free_foreign_key_create_info(char *) {}
507
 
  /** The following can be called without an open Cursor */
 
571
  /** The following can be called without an open handler */
 
572
 
 
573
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
508
574
 
509
575
  virtual int add_index(Table *, KEY *, uint32_t)
510
576
  { return (HA_ERR_WRONG_COMMAND); }
513
579
  virtual int final_drop_index(Table *)
514
580
  { return (HA_ERR_WRONG_COMMAND); }
515
581
 
 
582
  uint32_t max_record_length() const
 
583
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
584
  uint32_t max_keys() const
 
585
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
 
586
  uint32_t max_key_parts() const
 
587
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
588
  uint32_t max_key_length() const
 
589
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
590
  uint32_t max_key_part_length(void) const
 
591
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
592
 
 
593
  virtual uint32_t max_supported_record_length(void) const
 
594
  { return HA_MAX_REC_LENGTH; }
 
595
  virtual uint32_t max_supported_keys(void) const { return 0; }
 
596
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
597
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
598
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
 
599
 
 
600
  virtual bool low_byte_first(void) const { return 1; }
516
601
  virtual uint32_t checksum(void) const { return 0; }
 
602
  virtual bool is_crashed(void) const  { return 0; }
 
603
  virtual bool auto_repair(void) const { return 0; }
517
604
 
518
605
  /**
519
606
    Is not invoked for non-transactional temporary tables.
528
615
    than lock_count() claimed. This can happen when the MERGE children
529
616
    are not attached when this is called from another thread.
530
617
  */
531
 
  virtual THR_LOCK_DATA **store_lock(Session *,
 
618
  virtual THR_LOCK_DATA **store_lock(Session *session,
532
619
                                     THR_LOCK_DATA **to,
533
 
                                     enum thr_lock_type)
534
 
  {
535
 
    assert(0); // Impossible programming situation
536
 
 
537
 
    return(to);
538
 
  }
 
620
                                     enum thr_lock_type lock_type)=0;
539
621
 
540
622
 /*
541
623
   @retval true   Primary key (if there is one) is clustered
548
630
   return memcmp(ref1, ref2, ref_length);
549
631
 }
550
632
 
551
 
  virtual bool isOrdered(void)
 
633
  /**
 
634
    Lock table.
 
635
 
 
636
    @param    session                     Thread handle
 
637
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
 
638
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
 
639
    @param    lock_timeout            -1 default timeout
 
640
                                      0  no wait
 
641
                                      >0 wait timeout in milliseconds.
 
642
 
 
643
   @note
 
644
      lock_timeout >0 is not used by MySQL currently. If the storage
 
645
      engine does not support NOWAIT (lock_timeout == 0) it should
 
646
      return an error. But if it does not support WAIT X (lock_timeout
 
647
      >0) it should treat it as lock_timeout == -1 and wait a default
 
648
      (or even hard-coded) timeout.
 
649
 
 
650
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
 
651
                                      lock_table()
 
652
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
 
653
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
 
654
                                      lock conflict with NOWAIT option
 
655
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
 
656
  */
 
657
  virtual int lock_table(Session *, int, int)
552
658
  {
553
 
    return false;
 
659
    return HA_ERR_WRONG_COMMAND;
554
660
  }
555
661
 
556
 
 
557
662
protected:
558
663
  /* Service methods for use by storage engines. */
559
 
  void ha_statistic_increment(ulong system_status_var::*offset) const;
 
664
  void ha_statistic_increment(ulong SSV::*offset) const;
560
665
  void **ha_data(Session *) const;
561
666
  Session *ha_session(void) const;
562
667
 
563
668
private:
564
669
  /* Private helpers */
565
 
  inline void setTransactionReadWrite();
 
670
  inline void mark_trx_read_write();
566
671
private:
567
672
  /*
568
673
    Low-level primitives for storage engines.  These should be
603
708
    by that statement.
604
709
  */
605
710
  virtual int reset() { return 0; }
 
711
  virtual Table_flags table_flags(void) const= 0;
606
712
 
607
713
  /**
608
714
    Is not invoked for non-transactional temporary tables.
609
715
 
610
716
    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.
 
717
    from the table. This call is prefixed with a call to handler::store_lock()
 
718
    and is invoked only for those handler instances that stored the lock.
613
719
 
614
720
    Calls to rnd_init/index_init are prefixed with this call. When table
615
721
    IO is complete, we call external_lock(F_UNLCK).
632
738
  }
633
739
  virtual void release_auto_increment(void) { return; };
634
740
  /** admin commands - called from mysql_admin_table */
635
 
  virtual int check(Session *)
 
741
  virtual int check_for_upgrade(HA_CHECK_OPT *)
 
742
  { return 0; }
 
743
  virtual int check(Session *, HA_CHECK_OPT *)
636
744
  { return HA_ADMIN_NOT_IMPLEMENTED; }
637
745
 
638
746
  virtual void start_bulk_insert(ha_rows)
642
750
                         uint32_t, enum ha_rkey_function)
643
751
   { return  HA_ERR_WRONG_COMMAND; }
644
752
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
645
 
   { return (errno= HA_ERR_WRONG_COMMAND); }
 
753
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
 
754
  /**
 
755
    This method is similar to update_row, however the handler doesn't need
 
756
    to execute the updates at this point in time. The handler can be certain
 
757
    that another call to bulk_update_row will occur OR a call to
 
758
    exec_bulk_update before the set of updates in this query is concluded.
 
759
 
 
760
    @param    old_data       Old record
 
761
    @param    new_data       New record
 
762
    @param    dup_key_found  Number of duplicate keys found
 
763
 
 
764
    @retval  0   Bulk delete used by handler
 
765
    @retval  1   Bulk delete not used, normal operation used
 
766
  */
 
767
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
 
768
  {
 
769
    assert(false);
 
770
    return HA_ERR_WRONG_COMMAND;
 
771
  }
646
772
  /**
647
773
    This is called to delete all rows in a table
648
 
    If the Cursor don't support this, then this function will
 
774
    If the handler don't support this, then this function will
649
775
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
650
776
    by one.
651
777
  */
652
778
  virtual int delete_all_rows(void)
653
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
 
779
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
654
780
  /**
655
781
    Reset the auto-increment counter to the given value, i.e. the next row
656
782
    inserted will get the given value. This is called e.g. after TRUNCATE
659
785
  */
660
786
  virtual int reset_auto_increment(uint64_t)
661
787
  { return HA_ERR_WRONG_COMMAND; }
662
 
 
663
 
  virtual int analyze(Session *)
 
788
  virtual int optimize(Session *, HA_CHECK_OPT *)
 
789
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
790
  virtual int analyze(Session *, HA_CHECK_OPT *)
664
791
  { return HA_ADMIN_NOT_IMPLEMENTED; }
665
792
 
666
793
  virtual int disable_indexes(uint32_t)
667
794
  { return HA_ERR_WRONG_COMMAND; }
668
 
 
669
795
  virtual int enable_indexes(uint32_t)
670
796
  { return HA_ERR_WRONG_COMMAND; }
671
 
 
672
797
  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
 
  */
 
798
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
799
  virtual void prepare_for_alter(void) { return; }
681
800
  virtual void drop_table(const char *name);
682
801
};
683
802
 
684
803
extern const char *ha_row_type[];
 
804
extern const char *tx_isolation_names[];
 
805
extern const char *binlog_format_names[];
 
806
extern TYPELIB tx_isolation_typelib;
 
807
extern TYPELIB myisam_stats_method_typelib;
 
808
extern uint32_t total_ha, total_ha_2pc;
 
809
 
 
810
       /* Wrapper functions */
 
811
#define ha_commit(session) (ha_commit_trans((session), true))
 
812
#define ha_rollback(session) (ha_rollback_trans((session), true))
685
813
 
686
814
/* basic stuff */
687
 
void ha_init_errors(void);
 
815
int ha_init_errors(void);
 
816
int ha_init(void);
 
817
int ha_end(void);
 
818
 
 
819
void add_storage_engine(StorageEngine *engine);
 
820
void remove_storage_engine(StorageEngine *engine);
 
821
 
 
822
void ha_close_connection(Session* session);
 
823
bool ha_flush_logs(StorageEngine *db_type);
 
824
void ha_drop_database(char* path);
 
825
int ha_create_table(Session *session, const char *path,
 
826
                    const char *db, const char *table_name,
 
827
                    HA_CREATE_INFO *create_info,
 
828
                    bool update_create_info,
 
829
                    drizzled::message::Table *table_proto);
 
830
int ha_delete_table(Session *session, const char *path,
 
831
                    const char *db, const char *alias, bool generate_warning);
 
832
 
 
833
/* statistics and info */
 
834
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
 
835
 
 
836
int ha_find_files(Session *session,const char *db,const char *path,
 
837
                  const char *wild, bool dir, List<LEX_STRING>* files);
 
838
 
 
839
/* report to InnoDB that control passes to the client */
 
840
int ha_release_temporary_latches(Session *session);
 
841
 
 
842
/* transactions: interface to StorageEngine functions */
 
843
int ha_start_consistent_snapshot(Session *session);
 
844
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
 
845
int ha_commit_one_phase(Session *session, bool all);
 
846
int ha_rollback_trans(Session *session, bool all);
 
847
int ha_recover(HASH *commit_list);
 
848
 
 
849
/* transactions: these functions never call StorageEngine functions directly */
 
850
int ha_commit_trans(Session *session, bool all);
 
851
int ha_autocommit_or_rollback(Session *session, int error);
 
852
int ha_enable_transaction(Session *session, bool on);
 
853
 
 
854
/* savepoints */
 
855
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
 
856
int ha_savepoint(Session *session, SAVEPOINT *sv);
 
857
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
 
858
 
 
859
/* these are called by storage engines */
 
860
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
 
861
 
 
862
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
 
863
bool tablename_to_filename(const char *from, char *to, size_t to_length);
 
864
 
 
865
 
 
866
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
 
867
bool mysql_ha_close(Session *session, TableList *tables);
 
868
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
 
869
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
 
870
void mysql_ha_flush(Session *session);
 
871
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
 
872
void mysql_ha_cleanup(Session *session);
 
873
 
 
874
/*
 
875
  Storage engine has to assume the transaction will end up with 2pc if
 
876
   - there is more than one 2pc-capable storage engine available
 
877
   - in the current transaction 2pc was not disabled yet
 
878
*/
 
879
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
 
880
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
 
881
 
 
882
 
 
883
bool mysql_xa_recover(Session *session);
688
884
 
689
885
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
690
886
                                   SORT_FIELD *sortorder);
698
894
 
699
895
bool handle_select(Session *session, LEX *lex, select_result *result,
700
896
                   uint64_t setup_tables_done_option);
 
897
bool mysql_select(Session *session, Item ***rref_pointer_array,
 
898
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
 
899
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
 
900
                  Item *having, uint64_t select_type,
 
901
                  select_result *result, Select_Lex_Unit *unit,
 
902
                  Select_Lex *select_lex);
701
903
void free_underlaid_joins(Session *session, Select_Lex *select);
 
904
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
 
905
                         select_result *result);
 
906
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
 
907
                         select_result *result);
702
908
 
703
909
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
704
910
                                                      LEX *lex,
705
911
                                                      TableList *table));
706
912
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
707
913
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
 
914
void sp_prepare_create_field(Session *session, CreateField *sql_field);
708
915
int prepare_create_field(CreateField *sql_field,
709
916
                         uint32_t *blob_columns,
710
 
                         int *timestamps, int *timestamps_with_niladic);
711
 
 
712
 
bool mysql_create_table(Session *session,
713
 
                        TableIdentifier &identifier,
 
917
                         int *timestamps, int *timestamps_with_niladic,
 
918
                         int64_t table_flags);
 
919
bool mysql_create_table(Session *session,const char *db, const char *table_name,
714
920
                        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,
 
921
                        drizzled::message::Table *table_proto,
 
922
                        Alter_info *alter_info,
 
923
                        bool tmp_table, uint32_t select_field_count);
 
924
bool mysql_create_table_no_lock(Session *session, const char *db,
 
925
                                const char *table_name,
722
926
                                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
 
 
 
927
                                drizzled::message::Table *table_proto,
 
928
                                Alter_info *alter_info,
 
929
                                bool tmp_table, uint32_t select_field_count);
 
930
 
 
931
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
 
932
                       HA_CREATE_INFO *create_info,
 
933
                       TableList *table_list,
 
934
                       Alter_info *alter_info,
 
935
                       uint32_t order_num, order_st *order, bool ignore);
 
936
bool mysql_recreate_table(Session *session, TableList *table_list);
 
937
bool mysql_create_like_table(Session *session, TableList *table,
 
938
                             TableList *src_table,
 
939
                             HA_CREATE_INFO *create_info);
 
940
bool mysql_rename_table(StorageEngine *base, const char *old_db,
 
941
                        const char * old_name, const char *new_db,
 
942
                        const char * new_name, uint32_t flags);
740
943
bool mysql_prepare_update(Session *session, TableList *table_list,
741
944
                          Item **conds, uint32_t order_num, order_st *order);
742
945
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
759
962
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
760
963
                  SQL_LIST *order, ha_rows rows, uint64_t options,
761
964
                  bool reset_auto_increment);
762
 
bool mysql_truncate(Session& session, TableList *table_list);
 
965
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
763
966
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
764
967
                             uint32_t key_length, uint32_t db_flags, int *error);
765
968
TableShare *get_cached_table_share(const char *db, const char *table_name);
796
999
Field *
797
1000
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
798
1001
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
799
 
 
800
 
} /* namespace drizzled */
801
 
 
802
 
#endif /* DRIZZLED_CURSOR_H */
 
1002
Field *
 
1003
find_field_in_table_sef(Table *table, const char *name);
 
1004
 
 
1005
 
 
1006
#endif /* DRIZZLED_HANDLER_H */