~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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/table_identifier.h>
 
25
#include <drizzled/identifier.h>
26
26
 
27
27
/* Definitions for parameters to do with Cursor-routines */
28
28
 
39
39
/* Bits to show what an alter table will do */
40
40
#include <drizzled/sql_bitmap.h>
41
41
 
42
 
#include <drizzled/cursor.h>
43
 
 
44
42
#include <bitset>
45
43
#include <algorithm>
46
44
 
49
47
 
50
48
#define HA_MAX_ALTER_FLAGS 40
51
49
 
52
 
 
53
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
54
51
 
55
52
extern uint64_t refresh_version;  /* Increments on each reload */
56
53
 
57
 
 
58
 
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
59
 
                                      uint32_t key_length,
60
 
                                      uint64_t *engine_data);
61
 
 
62
 
 
63
 
/* The Cursor for a table type.  Will be included in the Table structure */
64
 
 
65
54
class Table;
66
55
class TableList;
67
56
class TableShare;
68
57
class Select_Lex_Unit;
69
 
struct st_foreign_key_info;
70
 
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
 
58
class ForeignKeyInfo;
71
59
struct order_st;
72
60
 
73
61
class Item;
74
 
struct st_table_log_memory_entry;
75
62
 
76
63
class LEX;
77
64
class Select_Lex;
80
67
class CreateField;
81
68
class sys_var_str;
82
69
class Item_ident;
83
 
typedef struct st_sort_field SORT_FIELD;
84
70
 
85
71
typedef List<Item> List_item;
86
72
extern KEY_CREATE_INFO default_key_create_info;
90
76
 
91
77
typedef struct system_status_var system_status_var;
92
78
 
93
 
class COST_VECT;
 
79
namespace optimizer
 
80
{
 
81
  class CostVector;
 
82
}
94
83
 
95
 
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
96
84
/*
97
85
  bitmap with first N+1 bits set
98
86
  (keypart_map for a key prefix of [0..N] keyparts)
149
137
  present, its length is one byte <not-sure> which must be set to 0xFF
150
138
  at all times. </not-sure>
151
139
 
152
 
  If the table has columns of type BIT, then certain bits from those columns
153
 
  may be stored in null_bytes as well. Grep around for Field_bit for
154
 
  details.
155
 
 
156
140
  For blob columns (see Field_blob), the record buffer stores length of the
157
141
  data, following by memory pointer to the blob data. The pointer is owned
158
142
  by the storage engine and is valid until the next operation.
160
144
  If a blob column has NULL value, then its length and blob data pointer
161
145
  must be set to 0.
162
146
*/
163
 
 
164
 
class Cursor :public memory::SqlAlloc
 
147
class Cursor
165
148
{
166
149
protected:
167
150
  TableShare *table_share;   /* The table definition */
168
151
  Table *table;               /* The current open table */
169
152
 
170
153
  ha_rows estimation_rows_to_insert;
171
 
public:
172
154
  plugin::StorageEngine *engine;      /* storage engine of this Cursor */
 
155
public:
173
156
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
174
157
  {
175
158
    return engine;
177
160
  unsigned char *ref;                           /* Pointer to current row */
178
161
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
179
162
 
 
163
  TableShare *getShare() const
 
164
  {
 
165
    return table_share;
 
166
  }
 
167
 
180
168
  ha_statistics stats;
181
169
  /** MultiRangeRead-related members: */
182
170
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
183
171
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
184
 
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
 
172
 
185
173
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
186
174
  /* true <=> source MRR ranges and the output are ordered */
187
175
  bool mrr_is_output_sorted;
190
178
  bool mrr_have_range;
191
179
 
192
180
  bool eq_range;
193
 
  /*
194
 
    true <=> the engine guarantees that returned records are within the range
195
 
    being scanned.
196
 
  */
197
 
  bool in_range_check_pushed_down;
198
181
 
199
182
  /** Current range (the one we're now returning rows from) */
200
183
  KEY_MULTI_RANGE mrr_cur_range;
201
184
 
202
185
  /** The following are for read_range() */
203
186
  key_range save_end_range, *end_range;
204
 
  KEY_PART_INFO *range_key_part;
 
187
  KeyPartInfo *range_key_part;
205
188
  int key_compare_result_on_equal;
206
189
 
207
190
  uint32_t errkey;                              /* Last dup key */
211
194
  uint32_t ref_length;
212
195
  enum {NONE=0, INDEX, RND} inited;
213
196
  bool locked;
214
 
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
215
197
 
216
198
  /**
217
199
    next_insert_id is the next value which should be inserted into the
247
229
 
248
230
  /* ha_ methods: pubilc wrappers for private virtual API */
249
231
 
250
 
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
251
 
  int ha_index_init(uint32_t idx, bool sorted);
252
 
  int ha_index_end();
253
 
  int ha_rnd_init(bool scan);
254
 
  int ha_rnd_end();
 
232
  int ha_open(const TableIdentifier &identifier, Table *table, int mode, int test_if_locked);
 
233
  int startIndexScan(uint32_t idx, bool sorted);
 
234
  int endIndexScan();
 
235
  int startTableScan(bool scan);
 
236
  int endTableScan();
255
237
  int ha_reset();
256
238
 
257
239
  /* this is necessary in many places, e.g. in HANDLER command */
260
242
  /**
261
243
    These functions represent the public interface to *users* of the
262
244
    Cursor class, hence they are *not* virtual. For the inheritance
263
 
    interface, see the (private) functions write_row(), update_row(),
264
 
    and delete_row() below.
 
245
    interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
 
246
    and doDeleteRecord() below.
265
247
  */
266
248
  int ha_external_lock(Session *session, int lock_type);
267
 
  int ha_write_row(unsigned char * buf);
268
 
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
269
 
  int ha_delete_row(const unsigned char * buf);
 
249
  int insertRecord(unsigned char * buf);
 
250
  int updateRecord(const unsigned char * old_data, unsigned char * new_data);
 
251
  int deleteRecord(const unsigned char * buf);
270
252
  void ha_release_auto_increment();
271
253
 
272
254
  /** to be actually called to get 'check()' functionality*/
298
280
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
299
281
                                              void *seq_init_param,
300
282
                                              uint32_t n_ranges, uint32_t *bufsz,
301
 
                                              uint32_t *flags, COST_VECT *cost);
 
283
                                              uint32_t *flags, optimizer::CostVector *cost);
302
284
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
303
 
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
 
285
                                    uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
304
286
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
305
 
                                    uint32_t n_ranges, uint32_t mode,
306
 
                                    HANDLER_BUFFER *buf);
 
287
                                    uint32_t n_ranges, uint32_t mode);
307
288
  virtual int multi_range_read_next(char **range_info);
308
289
 
309
290
 
338
319
  virtual ha_rows estimate_rows_upper_bound()
339
320
  { return stats.records+EXTRA_RECORDS; }
340
321
 
341
 
  /**
342
 
    Get the row type from the storage engine.  If this method returns
343
 
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
344
 
  */
345
 
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
346
 
 
347
322
  virtual const char *index_type(uint32_t)
348
323
  { assert(0); return "";}
349
324
 
357
332
     row if available. If the key value is null, begin at the first key of the
358
333
     index.
359
334
  */
360
 
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
 
335
  virtual int index_read_map(unsigned char * buf, const unsigned char *key,
361
336
                             key_part_map keypart_map,
362
337
                             enum ha_rkey_function find_flag)
363
338
  {
364
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
339
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
365
340
    return  index_read(buf, key, key_len, find_flag);
366
341
  }
367
342
  /**
383
358
  virtual int index_last(unsigned char *)
384
359
   { return  HA_ERR_WRONG_COMMAND; }
385
360
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
 
361
 
 
362
private:
 
363
  uint32_t calculate_key_len(uint32_t key_position, key_part_map keypart_map_arg);
 
364
public:
 
365
 
386
366
  /**
387
367
     @brief
388
368
     The following functions works like index_read, but it find the last
391
371
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
392
372
                                  key_part_map keypart_map)
393
373
  {
394
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
374
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
395
375
    return index_read_last(buf, key, key_len);
396
376
  }
397
377
  virtual int read_range_first(const key_range *start_key,
399
379
                               bool eq_range, bool sorted);
400
380
  virtual int read_range_next();
401
381
  int compare_key(key_range *range);
402
 
  int compare_key2(key_range *range);
403
382
  virtual int rnd_next(unsigned char *)=0;
404
383
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
405
 
  /**
406
 
    One has to use this method when to find
407
 
    random position by record as the plain
408
 
    position() call doesn't work for some
409
 
    handlers for random position.
410
 
  */
411
 
  virtual int rnd_pos_by_record(unsigned char *record);
412
384
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
413
 
  /**
414
 
    The following function is only needed for tables that may be temporary
415
 
    tables during joins.
416
 
  */
417
 
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
418
 
    { return HA_ERR_WRONG_COMMAND; }
419
385
  virtual int rnd_same(unsigned char *, uint32_t)
420
386
    { return HA_ERR_WRONG_COMMAND; }
421
387
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
453
419
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
454
420
                                  uint64_t nb_desired_values,
455
421
                                  uint64_t *first_value,
456
 
                                  uint64_t *nb_reserved_values);
 
422
                                  uint64_t *nb_reserved_values)= 0;
 
423
 
457
424
  void set_next_insert_id(uint64_t id)
458
425
  {
459
426
    next_insert_id= id;
474
441
      insert_id_for_cur_row;
475
442
  }
476
443
 
477
 
  virtual void update_create_info(HA_CREATE_INFO *) {}
478
 
  int check_old_types(void);
479
444
  /* end of the list of admin commands */
480
445
 
481
446
  virtual int indexes_are_disabled(void) {return 0;}
498
463
   */
499
464
  virtual bool can_switch_engines(void) { return true; }
500
465
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
501
 
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
 
466
  virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
502
467
  { return 0; }
503
468
  virtual uint32_t referenced_by_foreign_key() { return 0;}
504
469
  virtual void free_foreign_key_create_info(char *) {}
505
 
  /** The following can be called without an open Cursor */
506
 
 
507
 
  virtual int add_index(Table *, KEY *, uint32_t)
508
 
  { return (HA_ERR_WRONG_COMMAND); }
509
 
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
510
 
  { return (HA_ERR_WRONG_COMMAND); }
511
 
  virtual int final_drop_index(Table *)
512
 
  { return (HA_ERR_WRONG_COMMAND); }
513
 
 
514
 
  virtual uint32_t checksum(void) const { return 0; }
515
470
 
516
471
  /**
517
472
    Is not invoked for non-transactional temporary tables.
554
509
 
555
510
protected:
556
511
  /* Service methods for use by storage engines. */
557
 
  void ha_statistic_increment(ulong system_status_var::*offset) const;
 
512
  void ha_statistic_increment(uint64_t system_status_var::*offset) const;
558
513
  void **ha_data(Session *) const;
559
 
  Session *ha_session(void) const;
560
514
 
561
515
private:
562
516
  /* Private helpers */
568
522
    the corresponding 'ha_*' method above.
569
523
  */
570
524
 
571
 
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
572
 
  virtual int index_init(uint32_t idx, bool)
 
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);
 
527
  virtual int doStartIndexScan(uint32_t idx, bool)
573
528
  { active_index= idx; return 0; }
574
 
  virtual int index_end() { active_index= MAX_KEY; return 0; }
 
529
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
575
530
  /**
576
 
    rnd_init() can be called two times without rnd_end() in between
 
531
    doStartTableScan() can be called two times without doEndTableScan() in between
577
532
    (it only makes sense if scan=1).
578
533
    then the second call should prepare for the new table scan (e.g
579
534
    if rnd_init allocates the cursor, second call should position it
580
535
    to the start of the table, no need to deallocate and allocate it again
581
536
  */
582
 
  virtual int rnd_init(bool scan)= 0;
583
 
  virtual int rnd_end() { return 0; }
584
 
  virtual int write_row(unsigned char *)
585
 
  {
586
 
    return HA_ERR_WRONG_COMMAND;
587
 
  }
588
 
 
589
 
  virtual int update_row(const unsigned char *, unsigned char *)
590
 
  {
591
 
    return HA_ERR_WRONG_COMMAND;
592
 
  }
593
 
 
594
 
  virtual int delete_row(const unsigned char *)
 
537
  virtual int doStartTableScan(bool scan)= 0;
 
538
  virtual int doEndTableScan() { return 0; }
 
539
  virtual int doInsertRecord(unsigned char *)
 
540
  {
 
541
    return HA_ERR_WRONG_COMMAND;
 
542
  }
 
543
 
 
544
  virtual int doUpdateRecord(const unsigned char *, unsigned char *)
 
545
  {
 
546
    return HA_ERR_WRONG_COMMAND;
 
547
  }
 
548
 
 
549
  virtual int doDeleteRecord(const unsigned char *)
595
550
  {
596
551
    return HA_ERR_WRONG_COMMAND;
597
552
  }
682
637
extern const char *ha_row_type[];
683
638
 
684
639
/* basic stuff */
685
 
int ha_init_errors(void);
686
 
int ha_end(void);
 
640
void ha_init_errors(void);
687
641
 
688
 
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
689
 
                                   SORT_FIELD *sortorder);
 
642
class SortField;
 
643
SortField *make_unireg_sortorder(order_st *order, uint32_t *length,
 
644
                                 SortField *sortorder);
690
645
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
691
646
                List<Item> &fields, List <Item> &all_fields, order_st *order);
692
647
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
721
676
                                HA_CREATE_INFO *create_info,
722
677
                                message::Table &table_proto,
723
678
                                AlterInfo *alter_info,
724
 
                                bool tmp_table,
725
 
                                uint32_t select_field_count,
 
679
                                bool tmp_table, uint32_t select_field_count,
726
680
                                bool is_if_not_exists);
727
681
 
728
682
bool mysql_create_like_table(Session* session,
732
686
                             bool is_if_not_exists,
733
687
                             bool is_engine_set);
734
688
 
735
 
bool mysql_rename_table(plugin::StorageEngine *base, const char *old_db,
736
 
                        const char * old_name, const char *new_db,
737
 
                        const char * new_name, uint32_t flags);
 
689
bool mysql_rename_table(Session &session,
 
690
                        plugin::StorageEngine *base,
 
691
                        TableIdentifier &old_identifier,
 
692
                        TableIdentifier &new_identifier);
738
693
 
739
694
bool mysql_prepare_update(Session *session, TableList *table_list,
740
695
                          Item **conds, uint32_t order_num, order_st *order);
763
718
                             uint32_t key_length, uint32_t db_flags, int *error);
764
719
TableShare *get_cached_table_share(const char *db, const char *table_name);
765
720
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
766
 
Table *table_cache_insert_placeholder(Session *session, const char *key,
767
 
                                      uint32_t key_length);
768
 
bool lock_table_name_if_not_cached(Session *session, const char *db,
769
 
                                   const char *table_name, Table **table);
770
 
bool reopen_table(Table *table);
771
721
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
772
 
void close_data_files_and_morph_locks(Session *session, const char *db,
773
 
                                      const char *table_name);
774
722
void close_handle_and_leave_table_as_lock(Table *table);
775
723
bool wait_for_tables(Session *session);
776
724
bool table_is_used(Table *table, bool wait_for_name_lock);
777
 
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
778
 
void abort_locked_tables(Session *session,const char *db, const char *table_name);
 
725
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
 
726
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
779
727
extern Field *not_found_field;
780
728
extern Field *view_ref_found;
781
729