~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Brian Aker
  • Date: 2010-11-08 18:54:26 UTC
  • mto: (1921.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1916.
  • Revision ID: brian@tangent.org-20101108185426-fymkf2xnelupf11x
Rename lock methods to be style + well make sense.

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