~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Stewart Smith
  • Date: 2010-06-16 14:17:58 UTC
  • mto: (1626.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1633.
  • Revision ID: stewart@flamingspork.com-20100616141758-odpf36m0wo09ok4c
add handler_write status variable test for when statement was rolled back

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
22
22
 
23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
 
#include <drizzled/identifier.h>
26
 
#include <drizzled/definitions.h>
27
 
#include <drizzled/key_map.h>
28
 
#include <drizzled/error_t.h>
 
25
#include <drizzled/table_identifier.h>
29
26
 
30
27
/* Definitions for parameters to do with Cursor-routines */
31
28
 
32
29
#include <drizzled/thr_lock.h>
 
30
#include <drizzled/sql_string.h>
33
31
#include <drizzled/sql_list.h>
 
32
#include <drizzled/plugin/storage_engine.h>
34
33
#include <drizzled/handler_structs.h>
35
34
#include <drizzled/ha_statistics.h>
36
35
#include <drizzled/atomics.h>
37
36
 
38
 
#include <drizzled/message/table.h>
 
37
#include <drizzled/message/table.pb.h>
 
38
 
 
39
/* Bits to show what an alter table will do */
 
40
#include <drizzled/sql_bitmap.h>
39
41
 
40
42
#include <bitset>
41
43
#include <algorithm>
42
44
 
43
 
#include "drizzled/visibility.h"
44
 
 
45
45
namespace drizzled
46
46
{
47
47
 
49
49
 
50
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
51
51
 
52
 
class AlterInfo;
53
 
class CreateField;
 
52
extern uint64_t refresh_version;  /* Increments on each reload */
 
53
 
 
54
class Table;
 
55
class TableList;
 
56
class TableShare;
 
57
class Select_Lex_Unit;
54
58
class ForeignKeyInfo;
 
59
struct order_st;
 
60
 
55
61
class Item;
56
 
class Item_ident;
 
62
 
57
63
class LEX;
58
64
class Select_Lex;
59
 
class Select_Lex_Unit;
60
 
class String;
61
 
class Table;
62
 
class TableList;
63
 
class TableShare;
 
65
class AlterInfo;
64
66
class select_result;
 
67
class CreateField;
65
68
class sys_var_str;
66
 
struct Order;
 
69
class Item_ident;
 
70
typedef struct st_sort_field SORT_FIELD;
67
71
 
68
72
typedef List<Item> List_item;
69
73
extern KEY_CREATE_INFO default_key_create_info;
73
77
 
74
78
typedef struct system_status_var system_status_var;
75
79
 
76
 
namespace optimizer { class CostVector; }
77
 
namespace plugin { class StorageEngine; }
 
80
namespace optimizer
 
81
{
 
82
  class CostVector;
 
83
}
78
84
 
79
85
/*
80
86
  bitmap with first N+1 bits set
139
145
  If a blob column has NULL value, then its length and blob data pointer
140
146
  must be set to 0.
141
147
*/
142
 
class DRIZZLED_API Cursor
 
148
class Cursor :public memory::SqlAlloc
143
149
{
144
 
  friend class SEAPITesterCursor;
145
 
  Table &table;               /* The current open table */
146
 
  plugin::StorageEngine &engine;      /* storage engine of this Cursor */
 
150
protected:
 
151
  TableShare *table_share;   /* The table definition */
 
152
  Table *table;               /* The current open table */
147
153
 
148
 
protected:
149
154
  ha_rows estimation_rows_to_insert;
150
 
 
 
155
  plugin::StorageEngine *engine;      /* storage engine of this Cursor */
151
156
public:
152
157
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
153
158
  {
154
 
    return &engine;
 
159
    return engine;
155
160
  }
156
161
  unsigned char *ref;                           /* Pointer to current row */
157
162
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
158
163
 
159
 
  TableShare *getShare();
160
 
 
161
 
  Table *getTable() const
 
164
  TableShare *getShare() const
162
165
  {
163
 
    return &table;
 
166
    return table_share;
164
167
  }
165
168
 
166
169
  ha_statistics stats;
167
170
  /** MultiRangeRead-related members: */
168
171
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
169
172
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
170
 
 
 
173
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
171
174
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
172
175
  /* true <=> source MRR ranges and the output are ordered */
173
176
  bool mrr_is_output_sorted;
209
212
  }
210
213
 
211
214
  /**
212
 
    Used by SHOW TABLE STATUS to get the current auto_inc from the engine
213
 
  */
214
 
  uint64_t getAutoIncrement()
215
 
  {
216
 
    return stats.auto_increment_value;
217
 
  }
218
 
 
219
 
  /**
220
215
    insert id for the current row (*autogenerated*; if not
221
216
    autogenerated, it's 0).
222
217
    At first successful insertion, this variable is stored into
229
224
  */
230
225
  Discrete_interval auto_inc_interval_for_cur_row;
231
226
 
232
 
  Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
 
227
  Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
233
228
  virtual ~Cursor(void);
234
229
  virtual Cursor *clone(memory::Root *mem_root);
235
230
 
236
231
  /* ha_ methods: pubilc wrappers for private virtual API */
237
232
 
238
 
  int ha_open(const identifier::Table &identifier, int mode, int test_if_locked);
239
 
  int startIndexScan(uint32_t idx, bool sorted) __attribute__ ((warn_unused_result));
 
233
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
 
234
  int startIndexScan(uint32_t idx, bool sorted);
240
235
  int endIndexScan();
241
 
  int startTableScan(bool scan) __attribute__ ((warn_unused_result));
 
236
  int startTableScan(bool scan);
242
237
  int endTableScan();
243
238
  int ha_reset();
244
239
 
252
247
    and doDeleteRecord() below.
253
248
  */
254
249
  int ha_external_lock(Session *session, int lock_type);
255
 
  int insertRecord(unsigned char * buf) __attribute__ ((warn_unused_result));
256
 
  int updateRecord(const unsigned char * old_data, unsigned char * new_data) __attribute__ ((warn_unused_result));
257
 
  int deleteRecord(const unsigned char * buf) __attribute__ ((warn_unused_result));
 
250
  int insertRecord(unsigned char * buf);
 
251
  int updateRecord(const unsigned char * old_data, unsigned char * new_data);
 
252
  int deleteRecord(const unsigned char * buf);
258
253
  void ha_release_auto_increment();
259
254
 
260
255
  /** to be actually called to get 'check()' functionality*/
273
268
 
274
269
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
275
270
  int update_auto_increment();
 
271
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
276
272
 
277
273
  /* Estimates calculation */
278
274
  virtual double scan_time(void)
324
320
  virtual ha_rows estimate_rows_upper_bound()
325
321
  { return stats.records+EXTRA_RECORDS; }
326
322
 
 
323
  /**
 
324
    Get the row type from the storage engine.  If this method returns
 
325
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
326
  */
 
327
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
 
328
 
327
329
  virtual const char *index_type(uint32_t)
328
330
  { assert(0); return "";}
329
331
 
354
356
                                 const unsigned char * key,
355
357
                                 key_part_map keypart_map,
356
358
                                 enum ha_rkey_function find_flag);
357
 
  virtual int index_next(unsigned char *) __attribute__ ((warn_unused_result))
 
359
  virtual int index_next(unsigned char *)
358
360
   { return  HA_ERR_WRONG_COMMAND; }
359
361
  virtual int index_prev(unsigned char *)
360
362
   { return  HA_ERR_WRONG_COMMAND; }
446
448
      insert_id_for_cur_row;
447
449
  }
448
450
 
 
451
  virtual void update_create_info(HA_CREATE_INFO *) {}
 
452
  int check_old_types(void);
449
453
  /* end of the list of admin commands */
450
454
 
451
455
  virtual int indexes_are_disabled(void) {return 0;}
480
484
    or partitioned.
481
485
 
482
486
    @note that one can NOT rely on table->in_use in store_lock().  It may
483
 
    refer to a different thread if called from abortLockForThread().
 
487
    refer to a different thread if called from mysql_lock_abort_for_thread().
484
488
 
485
489
    @note If the table is MERGE, store_lock() can return less locks
486
490
    than lock_count() claimed. This can happen when the MERGE children
527
531
    the corresponding 'ha_*' method above.
528
532
  */
529
533
 
530
 
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; }
531
 
  virtual int doOpen(const identifier::Table &identifier, int mode, uint32_t test_if_locked);
 
534
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
532
535
  virtual int doStartIndexScan(uint32_t idx, bool)
533
536
  { active_index= idx; return 0; }
534
537
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
539
542
    if rnd_init allocates the cursor, second call should position it
540
543
    to the start of the table, no need to deallocate and allocate it again
541
544
  */
542
 
  virtual int doStartTableScan(bool scan) __attribute__ ((warn_unused_result)) = 0;
 
545
  virtual int doStartTableScan(bool scan)= 0;
543
546
  virtual int doEndTableScan() { return 0; }
544
547
  virtual int doInsertRecord(unsigned char *)
545
548
  {
588
591
  {
589
592
    return 0;
590
593
  }
591
 
  virtual void release_auto_increment(void) { return; }
 
594
  virtual void release_auto_increment(void) { return; };
592
595
  /** admin commands - called from mysql_admin_table */
593
596
  virtual int check(Session *)
594
597
  { return HA_ADMIN_NOT_IMPLEMENTED; }
644
647
/* basic stuff */
645
648
void ha_init_errors(void);
646
649
 
647
 
class SortField;
648
 
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
649
 
                                 SortField *sortorder);
 
650
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
651
                                   SORT_FIELD *sortorder);
650
652
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
651
 
                List<Item> &fields, List <Item> &all_fields, Order *order);
 
653
                List<Item> &fields, List <Item> &all_fields, order_st *order);
652
654
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
653
 
                List<Item> &fields, List<Item> &all_fields, Order *order,
 
655
                List<Item> &fields, List<Item> &all_fields, order_st *order,
654
656
                bool *hidden_group_fields);
655
657
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
656
658
                    Item **ref_pointer_array);
659
661
                   uint64_t setup_tables_done_option);
660
662
void free_underlaid_joins(Session *session, Select_Lex *select);
661
663
 
662
 
bool handle_derived(LEX *lex, bool (*processor)(Session *session,
 
664
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
663
665
                                                      LEX *lex,
664
666
                                                      TableList *table));
665
 
bool derived_prepare(Session *session, LEX *lex, TableList *t);
666
 
bool derived_filling(Session *session, LEX *lex, TableList *t);
 
667
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
 
668
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
667
669
int prepare_create_field(CreateField *sql_field,
668
670
                         uint32_t *blob_columns,
669
671
                         int *timestamps, int *timestamps_with_niladic);
670
672
 
671
 
bool create_table(Session *session,
672
 
                  const identifier::Table &identifier,
673
 
                  HA_CREATE_INFO *create_info,
674
 
                  message::Table &table_proto,
675
 
                  AlterInfo *alter_info,
676
 
                  bool tmp_table, uint32_t select_field_count,
677
 
                  bool is_if_not_exists);
678
 
 
679
 
bool create_table_no_lock(Session *session,
680
 
                          const identifier::Table &identifier,
681
 
                          HA_CREATE_INFO *create_info,
682
 
                          message::Table &table_proto,
683
 
                          AlterInfo *alter_info,
684
 
                          bool tmp_table, uint32_t select_field_count,
685
 
                          bool is_if_not_exists);
686
 
 
687
 
bool create_like_table(Session* session,
688
 
                       identifier::Table::const_reference destination_identifier,
689
 
                       identifier::Table::const_reference source_identifier,
690
 
                       message::Table &create_table_proto,
691
 
                       bool is_if_not_exists,
692
 
                       bool is_engine_set);
693
 
 
694
 
bool rename_table(Session &session,
 
673
bool mysql_create_table(Session *session,
 
674
                        TableIdentifier &identifier,
 
675
                        HA_CREATE_INFO *create_info,
 
676
                        message::Table &table_proto,
 
677
                        AlterInfo *alter_info,
 
678
                        bool tmp_table, uint32_t select_field_count,
 
679
                        bool is_if_not_exists);
 
680
 
 
681
bool mysql_create_table_no_lock(Session *session,
 
682
                                TableIdentifier &identifier,
 
683
                                HA_CREATE_INFO *create_info,
 
684
                                message::Table &table_proto,
 
685
                                AlterInfo *alter_info,
 
686
                                bool tmp_table, uint32_t select_field_count,
 
687
                                bool is_if_not_exists);
 
688
 
 
689
bool mysql_create_like_table(Session* session,
 
690
                             TableIdentifier &destination_identifier,
 
691
                             TableList* table, TableList* src_table,
 
692
                             message::Table &create_table_proto,
 
693
                             bool is_if_not_exists,
 
694
                             bool is_engine_set);
 
695
 
 
696
bool mysql_rename_table(Session &session,
695
697
                        plugin::StorageEngine *base,
696
 
                        const identifier::Table &old_identifier,
697
 
                        const identifier::Table &new_identifier);
 
698
                        TableIdentifier &old_identifier,
 
699
                        TableIdentifier &new_identifier);
698
700
 
699
 
bool prepare_update(Session *session, TableList *table_list,
700
 
                          Item **conds, uint32_t order_num, Order *order);
701
 
int update_query(Session *session,TableList *tables,List<Item> &fields,
 
701
bool mysql_prepare_update(Session *session, TableList *table_list,
 
702
                          Item **conds, uint32_t order_num, order_st *order);
 
703
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
702
704
                 List<Item> &values,COND *conds,
703
 
                 uint32_t order_num, Order *order, ha_rows limit,
 
705
                 uint32_t order_num, order_st *order, ha_rows limit,
704
706
                 enum enum_duplicates handle_duplicates, bool ignore);
705
 
bool prepare_insert(Session *session, TableList *table_list, Table *table,
 
707
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
706
708
                          List<Item> &fields, List_item *values,
707
709
                          List<Item> &update_fields,
708
710
                          List<Item> &update_values, enum_duplicates duplic,
709
711
                          COND **where, bool select_insert,
710
712
                          bool check_fields, bool abort_on_warning);
711
 
bool insert_query(Session *session,TableList *table,List<Item> &fields,
 
713
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
712
714
                  List<List_item> &values, List<Item> &update_fields,
713
715
                  List<Item> &update_values, enum_duplicates flag,
714
716
                  bool ignore);
715
717
int check_that_all_fields_are_given_values(Session *session, Table *entry,
716
718
                                           TableList *table_list);
717
 
int prepare_delete(Session *session, TableList *table_list, Item **conds);
718
 
bool delete_query(Session *session, TableList *table_list, COND *conds,
 
719
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
 
720
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
719
721
                  SQL_LIST *order, ha_rows rows, uint64_t options,
720
722
                  bool reset_auto_increment);
721
 
bool truncate(Session& session, TableList *table_list);
 
723
bool mysql_truncate(Session& session, TableList *table_list);
722
724
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
723
725
                             uint32_t key_length, uint32_t db_flags, int *error);
724
726
TableShare *get_cached_table_share(const char *db, const char *table_name);
727
729
void close_handle_and_leave_table_as_lock(Table *table);
728
730
bool wait_for_tables(Session *session);
729
731
bool table_is_used(Table *table, bool wait_for_name_lock);
730
 
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
731
 
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
 
732
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
 
733
void abort_locked_tables(Session *session,const char *db, const char *table_name);
732
734
extern Field *not_found_field;
733
735
extern Field *view_ref_found;
734
736