~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

Separated BlitzCursor code out to it's own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
 
25
#include <drizzled/table_identifier.h>
28
26
 
29
27
/* Definitions for parameters to do with Cursor-routines */
30
28
 
38
36
 
39
37
#include <drizzled/message/table.pb.h>
40
38
 
 
39
/* Bits to show what an alter table will do */
 
40
#include <drizzled/sql_bitmap.h>
 
41
 
41
42
#include <bitset>
42
43
#include <algorithm>
43
44
 
55
56
class TableShare;
56
57
class Select_Lex_Unit;
57
58
class ForeignKeyInfo;
58
 
struct Order;
 
59
struct order_st;
59
60
 
60
61
class Item;
61
62
 
66
67
class CreateField;
67
68
class sys_var_str;
68
69
class Item_ident;
 
70
typedef struct st_sort_field SORT_FIELD;
69
71
 
70
72
typedef List<Item> List_item;
71
73
extern KEY_CREATE_INFO default_key_create_info;
143
145
  If a blob column has NULL value, then its length and blob data pointer
144
146
  must be set to 0.
145
147
*/
146
 
class Cursor
 
148
class Cursor :public memory::SqlAlloc
147
149
{
148
 
  Table &table;               /* The current open table */
149
 
  plugin::StorageEngine &engine;      /* storage engine of this Cursor */
 
150
protected:
 
151
  TableShare *table_share;   /* The table definition */
 
152
  Table *table;               /* The current open table */
150
153
 
151
 
protected:
152
154
  ha_rows estimation_rows_to_insert;
153
 
 
 
155
  plugin::StorageEngine *engine;      /* storage engine of this Cursor */
154
156
public:
155
157
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
156
158
  {
157
 
    return &engine;
 
159
    return engine;
158
160
  }
159
161
  unsigned char *ref;                           /* Pointer to current row */
160
162
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
161
163
 
162
 
  TableShare *getShare();
163
 
 
164
 
  Table *getTable() const
165
 
  {
166
 
    return &table;
167
 
  }
168
 
 
169
164
  ha_statistics stats;
170
165
  /** MultiRangeRead-related members: */
171
166
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
172
167
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
173
 
 
 
168
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
174
169
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
175
170
  /* true <=> source MRR ranges and the output are ordered */
176
171
  bool mrr_is_output_sorted;
185
180
 
186
181
  /** The following are for read_range() */
187
182
  key_range save_end_range, *end_range;
188
 
  KeyPartInfo *range_key_part;
 
183
  KEY_PART_INFO *range_key_part;
189
184
  int key_compare_result_on_equal;
190
185
 
191
186
  uint32_t errkey;                              /* Last dup key */
224
219
  */
225
220
  Discrete_interval auto_inc_interval_for_cur_row;
226
221
 
227
 
  Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
 
222
  Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
228
223
  virtual ~Cursor(void);
229
224
  virtual Cursor *clone(memory::Root *mem_root);
230
225
 
231
226
  /* ha_ methods: pubilc wrappers for private virtual API */
232
227
 
233
 
  int ha_open(const TableIdentifier &identifier, int mode, int test_if_locked);
 
228
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
234
229
  int startIndexScan(uint32_t idx, bool sorted);
235
230
  int endIndexScan();
236
231
  int startTableScan(bool scan);
268
263
 
269
264
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
270
265
  int update_auto_increment();
 
266
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
271
267
 
272
268
  /* Estimates calculation */
273
269
  virtual double scan_time(void)
319
315
  virtual ha_rows estimate_rows_upper_bound()
320
316
  { return stats.records+EXTRA_RECORDS; }
321
317
 
 
318
  /**
 
319
    Get the row type from the storage engine.  If this method returns
 
320
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
321
  */
 
322
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
 
323
 
322
324
  virtual const char *index_type(uint32_t)
323
325
  { assert(0); return "";}
324
326
 
381
383
  int compare_key(key_range *range);
382
384
  virtual int rnd_next(unsigned char *)=0;
383
385
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
 
386
  /**
 
387
    One has to use this method when to find
 
388
    random position by record as the plain
 
389
    position() call doesn't work for some
 
390
    handlers for random position.
 
391
  */
 
392
  virtual int rnd_pos_by_record(unsigned char *record);
384
393
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
385
394
  virtual int rnd_same(unsigned char *, uint32_t)
386
395
    { return HA_ERR_WRONG_COMMAND; }
441
450
      insert_id_for_cur_row;
442
451
  }
443
452
 
 
453
  virtual void update_create_info(HA_CREATE_INFO *) {}
 
454
  int check_old_types(void);
444
455
  /* end of the list of admin commands */
445
456
 
446
457
  virtual int indexes_are_disabled(void) {return 0;}
475
486
    or partitioned.
476
487
 
477
488
    @note that one can NOT rely on table->in_use in store_lock().  It may
478
 
    refer to a different thread if called from abortLockForThread().
 
489
    refer to a different thread if called from mysql_lock_abort_for_thread().
479
490
 
480
491
    @note If the table is MERGE, store_lock() can return less locks
481
492
    than lock_count() claimed. This can happen when the MERGE children
509
520
 
510
521
protected:
511
522
  /* Service methods for use by storage engines. */
512
 
  void ha_statistic_increment(uint64_t system_status_var::*offset) const;
 
523
  void ha_statistic_increment(ulong system_status_var::*offset) const;
513
524
  void **ha_data(Session *) const;
 
525
  Session *ha_session(void) const;
514
526
 
515
527
private:
516
528
  /* Private helpers */
522
534
    the corresponding 'ha_*' method above.
523
535
  */
524
536
 
525
 
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; }
526
 
  virtual int doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked);
 
537
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
527
538
  virtual int doStartIndexScan(uint32_t idx, bool)
528
539
  { active_index= idx; return 0; }
529
540
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
583
594
  {
584
595
    return 0;
585
596
  }
586
 
  virtual void release_auto_increment(void) { return; }
 
597
  virtual void release_auto_increment(void) { return; };
587
598
  /** admin commands - called from mysql_admin_table */
588
599
  virtual int check(Session *)
589
600
  { return HA_ADMIN_NOT_IMPLEMENTED; }
639
650
/* basic stuff */
640
651
void ha_init_errors(void);
641
652
 
642
 
class SortField;
643
 
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
644
 
                                 SortField *sortorder);
 
653
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
654
                                   SORT_FIELD *sortorder);
645
655
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
646
 
                List<Item> &fields, List <Item> &all_fields, Order *order);
 
656
                List<Item> &fields, List <Item> &all_fields, order_st *order);
647
657
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
648
 
                List<Item> &fields, List<Item> &all_fields, Order *order,
 
658
                List<Item> &fields, List<Item> &all_fields, order_st *order,
649
659
                bool *hidden_group_fields);
650
660
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
651
661
                    Item **ref_pointer_array);
664
674
                         int *timestamps, int *timestamps_with_niladic);
665
675
 
666
676
bool mysql_create_table(Session *session,
667
 
                        const TableIdentifier &identifier,
 
677
                        TableIdentifier &identifier,
668
678
                        HA_CREATE_INFO *create_info,
669
679
                        message::Table &table_proto,
670
680
                        AlterInfo *alter_info,
672
682
                        bool is_if_not_exists);
673
683
 
674
684
bool mysql_create_table_no_lock(Session *session,
675
 
                                const TableIdentifier &identifier,
 
685
                                TableIdentifier &identifier,
676
686
                                HA_CREATE_INFO *create_info,
677
687
                                message::Table &table_proto,
678
688
                                AlterInfo *alter_info,
680
690
                                bool is_if_not_exists);
681
691
 
682
692
bool mysql_create_like_table(Session* session,
683
 
                             const TableIdentifier &destination_identifier,
 
693
                             TableIdentifier &destination_identifier,
684
694
                             TableList* table, TableList* src_table,
685
695
                             message::Table &create_table_proto,
686
696
                             bool is_if_not_exists,
687
697
                             bool is_engine_set);
688
698
 
689
 
bool mysql_rename_table(Session &session,
690
 
                        plugin::StorageEngine *base,
691
 
                        const TableIdentifier &old_identifier,
692
 
                        const TableIdentifier &new_identifier);
 
699
bool mysql_rename_table(plugin::StorageEngine *base,
 
700
                        TableIdentifier &old_identifier,
 
701
                        TableIdentifier &new_identifier);
693
702
 
694
703
bool mysql_prepare_update(Session *session, TableList *table_list,
695
 
                          Item **conds, uint32_t order_num, Order *order);
 
704
                          Item **conds, uint32_t order_num, order_st *order);
696
705
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
697
706
                 List<Item> &values,COND *conds,
698
 
                 uint32_t order_num, Order *order, ha_rows limit,
 
707
                 uint32_t order_num, order_st *order, ha_rows limit,
699
708
                 enum enum_duplicates handle_duplicates, bool ignore);
700
709
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
701
710
                          List<Item> &fields, List_item *values,
722
731
void close_handle_and_leave_table_as_lock(Table *table);
723
732
bool wait_for_tables(Session *session);
724
733
bool table_is_used(Table *table, bool wait_for_name_lock);
725
 
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
726
 
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
 
734
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
 
735
void abort_locked_tables(Session *session,const char *db, const char *table_name);
727
736
extern Field *not_found_field;
728
737
extern Field *view_ref_found;
729
738