~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Paul McCullagh
  • Date: 2010-05-26 10:17:56 UTC
  • mto: (1567.1.3 new-staging)
  • mto: This revision was merged to the branch mainline in revision 1568.
  • Revision ID: paul.mccullagh@primebase.org-20100526101756-3qdwb9id3qhog0z1
Adjust for namespace changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#define DRIZZLED_TABLE_H
25
25
 
26
26
#include <string>
27
 
#include <boost/dynamic_bitset.hpp>
28
27
 
29
28
#include "drizzled/order.h"
30
29
#include "drizzled/filesort_info.h"
33
32
#include "drizzled/cursor.h"
34
33
#include "drizzled/lex_string.h"
35
34
#include "drizzled/table_list.h"
36
 
#include "drizzled/definition/table.h"
 
35
#include "drizzled/table_share.h"
37
36
#include "drizzled/atomics.h"
38
37
#include "drizzled/query_id.h"
39
38
 
61
60
 */
62
61
class Table 
63
62
{
 
63
 
 
64
public:
 
65
  TableShare *s; /**< Pointer to the shared metadata about the table */
 
66
 
64
67
  Field **field; /**< Pointer to fields collection */
65
 
public:
66
 
 
67
 
  Field **getFields() const
68
 
  {
69
 
    return field;
70
 
  }
71
 
 
72
 
  Field *getField(uint32_t arg) const
73
 
  {
74
 
    return field[arg];
75
 
  }
76
 
 
77
 
  void setFields(Field **arg)
78
 
  {
79
 
    field= arg;
80
 
  }
81
 
 
82
 
  void setFieldAt(Field *arg, uint32_t arg_pos)
83
 
  {
84
 
    field[arg_pos]= arg;
85
 
  }
86
68
 
87
69
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
88
 
private:
89
70
  Table *next;
90
 
public:
91
 
  Table *getNext() const
92
 
  {
93
 
    return next;
94
 
  }
95
 
 
96
 
  Table **getNextPtr()
97
 
  {
98
 
    return &next;
99
 
  }
100
 
 
101
 
  void setNext(Table *arg)
102
 
  {
103
 
    next= arg;
104
 
  }
105
 
 
106
 
  void unlink()
107
 
  {
108
 
    getNext()->setPrev(getPrev());              /* remove from used chain */
109
 
    getPrev()->setNext(getNext());
110
 
  }
111
 
 
112
 
private:
113
71
  Table *prev;
114
 
public:
115
 
  Table *getPrev() const
116
 
  {
117
 
    return prev;
118
 
  }
119
 
 
120
 
  Table **getPrevPtr()
121
 
  {
122
 
    return &prev;
123
 
  }
124
 
 
125
 
  void setPrev(Table *arg)
126
 
  {
127
 
    prev= arg;
128
 
  }
129
 
 
130
 
  boost::dynamic_bitset<> *read_set; /* Active column sets */
131
 
  boost::dynamic_bitset<> *write_set; /* Active column sets */
 
72
 
 
73
  MyBitmap *read_set; /* Active column sets */
 
74
  MyBitmap *write_set; /* Active column sets */
132
75
 
133
76
  uint32_t tablenr;
134
77
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
135
78
 
136
 
  boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
137
 
  boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
138
 
  boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
 
79
  MyBitmap def_read_set; /**< Default read set of columns */
 
80
  MyBitmap def_write_set; /**< Default write set of columns */
 
81
  MyBitmap tmp_set; /* Not sure about this... */
139
82
 
140
83
  Session *in_use; /**< Pointer to the current session using this object */
141
84
  Session *getSession()
143
86
    return in_use;
144
87
  }
145
88
 
146
 
  unsigned char *getInsertRecord()
147
 
  {
148
 
    return record[0];
149
 
  }
150
 
 
151
 
  unsigned char *getUpdateRecord()
152
 
  {
153
 
    return record[1];
154
 
  }
155
 
 
156
89
  unsigned char *record[2]; /**< Pointer to "records" */
157
 
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
 
90
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
158
91
  KeyInfo  *key_info; /**< data of keys in database */
159
92
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
160
93
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
161
94
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
162
95
 
163
96
  TableList *pos_in_table_list; /* Element referring to this table */
164
 
  Order *group;
165
 
  
166
 
  const char *getAlias() const
167
 
  {
168
 
    return _alias.c_str();
169
 
  }
170
 
 
171
 
  void clearAlias()
172
 
  {
173
 
    _alias.clear();
174
 
  }
175
 
 
176
 
  void setAlias(const char *arg)
177
 
  {
178
 
    _alias= arg;
179
 
  }
180
 
 
181
 
private:
182
 
  std::string _alias; /**< alias or table name if no alias */
183
 
public:
184
 
 
 
97
  order_st *group;
 
98
  const char *alias; /**< alias or table name if no alias */
185
99
  unsigned char *null_flags;
186
100
 
187
101
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
188
102
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
189
103
  uint32_t lock_count; /**< Number of locks */
190
104
  uint32_t used_fields;
191
 
  uint32_t status; /* What's in getInsertRecord() */
 
105
  uint32_t status; /* What's in record[0] */
192
106
  /* number of select if it is derived table */
193
107
  uint32_t derived_select_number;
194
108
  int current_lock; /**< Type of lock on table */
208
122
  bool null_row;
209
123
 
210
124
  bool force_index;
211
 
  bool distinct;
212
 
  bool const_table;
213
 
  bool no_rows;
 
125
  bool distinct,const_table,no_rows;
214
126
  bool key_read;
215
127
  bool no_keyread;
216
128
  /*
363
275
    return mem_root.strmake_root(str_arg, len_arg);
364
276
  }
365
277
 
366
 
  filesort_info sort;
 
278
  filesort_info_st sort;
367
279
 
368
280
  Table();
369
 
  virtual ~Table();
 
281
  virtual ~Table() { };
370
282
 
371
283
  int report_error(int error);
372
284
  /**
375
287
   * @param If true if we also want to free table_share
376
288
   * @note this should all be the destructor
377
289
   */
378
 
  int delete_table(bool free_share= false);
 
290
  int delete_table(bool free_share);
379
291
 
380
292
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
381
293
 
382
294
  /* SHARE methods */
383
 
  virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
384
 
  virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
385
 
  virtual bool hasShare() const= 0; /* Get rid of this long term */
386
 
  virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
387
 
 
388
 
  virtual void release(void)= 0;
389
 
 
390
 
  uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
391
 
  uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
392
 
  uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
393
 
  uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
394
 
  uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
395
 
 
396
 
public:
397
 
  virtual bool hasVariableWidth() const
398
 
  {
399
 
    return getShare()->hasVariableWidth(); // We should calculate this.
400
 
  }
401
 
 
402
 
  virtual void setVariableWidth(void);
403
 
 
404
 
  Field_blob *getBlobFieldAt(uint32_t arg) const
405
 
  {
406
 
    if (arg < getShare()->blob_fields)
407
 
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
408
 
 
409
 
    return NULL;
410
 
  }
411
 
  inline uint8_t getBlobPtrSize() { return getShare()->blob_ptr_size; }
412
 
  inline uint32_t getNullBytes() { return getShare()->null_bytes; }
413
 
  inline uint32_t getNullFields() { return getShare()->null_fields; }
414
 
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
415
 
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
416
 
  inline const char *getTableName()  const { return getShare()->getTableName(); }
417
 
 
418
 
  inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
419
 
  inline bool isNameLock() const { return open_placeholder; }
 
295
  inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
 
296
  inline TableShare *getMutableShare() { assert(s); return s; } /* Get rid of this long term */
 
297
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
 
298
  inline uint32_t sizeKeys() { return s->keys; }
 
299
  inline uint32_t sizeFields() { return s->fields; }
 
300
  inline uint32_t getRecordLength() { return s->reclength; }
 
301
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
 
302
  inline uint32_t *getBlobField() { return s->blob_field; }
 
303
  inline uint32_t getNullBytes() { return s->null_bytes; }
 
304
  inline uint32_t getNullFields() { return s->null_fields; }
 
305
  inline unsigned char *getDefaultValues() { return s->default_values; }
 
306
 
 
307
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
 
308
  inline bool isNameLock() { return s->name_lock; }
 
309
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
310
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
420
311
 
421
312
  uint32_t index_flags(uint32_t idx) const
422
313
  {
423
 
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
 
314
    return s->storage_engine->index_flags(s->key_info[idx].algorithm);
424
315
  }
425
316
 
426
317
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
427
318
  {
428
 
    return getShare()->storage_engine;
 
319
    return s->storage_engine;
429
320
  }
430
321
 
431
322
  Cursor &getCursor() const /* table_type for handler */
434
325
    return *cursor;
435
326
  }
436
327
 
 
328
  /* For TMP tables, should be pulled out as a class */
 
329
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
 
330
  bool create_myisam_tmp_table(KeyInfo *keyinfo,
 
331
                               MI_COLUMNDEF *start_recinfo,
 
332
                               MI_COLUMNDEF **recinfo,
 
333
                               uint64_t options);
 
334
  void free_tmp_table(Session *session);
 
335
  bool open_tmp_table();
437
336
  size_t max_row_length(const unsigned char *data);
438
337
  uint32_t find_shortest_key(const key_map *usable_keys);
439
338
  bool compare_record(Field **ptr);
440
 
  bool records_are_comparable();
441
 
  bool compare_records();
 
339
  bool compare_record();
442
340
  /* TODO: the (re)storeRecord's may be able to be further condensed */
443
341
  void storeRecord();
444
342
  void storeRecordAsInsert();
447
345
  void restoreRecordAsDefault();
448
346
  void emptyRecord();
449
347
 
450
 
 
451
348
  /* See if this can be blown away */
452
349
  inline uint32_t getDBStat () { return db_stat; }
453
350
  inline uint32_t setDBStat () { return db_stat; }
470
367
  bool fill_item_list(List<Item> *item_list) const;
471
368
  void clear_column_bitmaps(void);
472
369
  void prepare_for_position(void);
473
 
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
 
370
  void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
474
371
  void mark_columns_used_by_index_no_reset(uint32_t index);
475
372
  void mark_columns_used_by_index(uint32_t index);
476
373
  void restore_column_maps_after_mark_index();
478
375
  void mark_columns_needed_for_update(void);
479
376
  void mark_columns_needed_for_delete(void);
480
377
  void mark_columns_needed_for_insert(void);
481
 
  void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
482
 
                          boost::dynamic_bitset<>& write_set_arg);
483
 
 
484
 
  void restore_column_map(const boost::dynamic_bitset<>& old);
485
 
 
486
 
  const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
 
378
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
 
379
                                 MyBitmap *write_set_arg)
 
380
  {
 
381
    read_set= read_set_arg;
 
382
    write_set= write_set_arg;
 
383
  }
 
384
 
 
385
  void restore_column_map(my_bitmap_map *old);
 
386
 
 
387
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
487
388
  inline void use_all_columns()
488
389
  {
489
 
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
 
390
    column_bitmaps_set(&s->all_set, &s->all_set);
490
391
  }
491
392
 
492
393
  inline void default_column_bitmaps()
498
399
  /* Both of the below should go away once we can move this bit to the field objects */
499
400
  inline bool isReadSet(uint32_t index)
500
401
  {
501
 
    return read_set->test(index);
 
402
    return read_set->isBitSet(index);
502
403
  }
503
404
 
504
405
  inline void setReadSet(uint32_t index)
505
406
  {
506
 
    read_set->set(index);
 
407
    read_set->setBit(index);
507
408
  }
508
409
 
509
410
  inline void setReadSet()
510
411
  {
511
 
    read_set->set();
 
412
    read_set->setAll();
512
413
  }
513
414
 
514
415
  inline void clearReadSet(uint32_t index)
515
416
  {
516
 
    read_set->reset(index);
 
417
    read_set->clearBit(index);
517
418
  }
518
419
 
519
420
  inline void clearReadSet()
520
421
  {
521
 
    read_set->reset();
 
422
    read_set->clearAll();
522
423
  }
523
424
 
524
425
  inline bool isWriteSet(uint32_t index)
525
426
  {
526
 
    return write_set->test(index);
 
427
    return write_set->isBitSet(index);
527
428
  }
528
429
 
529
430
  inline void setWriteSet(uint32_t index)
530
431
  {
531
 
    write_set->set(index);
 
432
    write_set->setBit(index);
532
433
  }
533
434
 
534
435
  inline void setWriteSet()
535
436
  {
536
 
    write_set->set();
 
437
    write_set->setAll();
537
438
  }
538
439
 
539
440
  inline void clearWriteSet(uint32_t index)
540
441
  {
541
 
    write_set->reset(index);
 
442
    write_set->clearBit(index);
542
443
  }
543
444
 
544
445
  inline void clearWriteSet()
545
446
  {
546
 
    write_set->reset();
 
447
    write_set->clearAll();
547
448
  }
548
449
 
549
450
  /* Is table open or should be treated as such by name-locking? */
556
457
  */
557
458
  inline bool needs_reopen_or_name_lock()
558
459
  { 
559
 
    return getShare()->getVersion() != refresh_version;
 
460
    return s->version != refresh_version;
560
461
  }
561
462
 
562
463
  /**
571
472
  {
572
473
    null_row= 1;
573
474
    status|= STATUS_NULL_ROW;
574
 
    memset(null_flags, 255, getShare()->null_bytes);
 
475
    memset(null_flags, 255, s->null_bytes);
575
476
  }
576
477
 
 
478
  bool renameAlterTemporaryTable(TableIdentifier &identifier);
577
479
  void free_io_cache();
578
480
  void filesort_free_buffers(bool full= false);
579
481
  void intern_close_table();
580
482
 
581
483
  void print_error(int error, myf errflag)
582
484
  {
583
 
    getShare()->storage_engine->print_error(error, errflag, *this);
 
485
    s->storage_engine->print_error(error, errflag, *this);
584
486
  }
585
487
 
586
488
  /**
603
505
  */
604
506
  bool operator<(const Table &right) const
605
507
  {
606
 
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
 
508
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
 
509
 
 
510
    if (result <  0)
 
511
      return true;
 
512
 
 
513
    if (result >  0)
 
514
      return false;
 
515
 
 
516
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
 
517
 
 
518
    if (result <  0)
 
519
      return true;
 
520
 
 
521
    if (result >  0)
 
522
      return false;
 
523
 
 
524
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
 
525
      return true;
 
526
 
 
527
    return false;
607
528
  }
608
529
 
609
530
  static bool compare(const Table *a, const Table *b)
613
534
 
614
535
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
615
536
  {
616
 
    if (table.getShare())
617
 
    {
618
 
      output << "Table:(";
619
 
      output << table.getShare()->getSchemaName();
620
 
      output << ", ";
621
 
      output <<  table.getShare()->getTableName();
622
 
      output << ", ";
623
 
      output <<  table.getShare()->getTableTypeAsString();
624
 
      output << ")";
625
 
    }
626
 
    else
627
 
    {
628
 
      output << "Table:(has no share)";
629
 
    }
 
537
    output << "Table:(";
 
538
    output << table.getShare()->getSchemaName();
 
539
    output << ", ";
 
540
    output <<  table.getShare()->getTableName();
 
541
    output << ", ";
 
542
    output <<  table.getShare()->getTableTypeAsString();
 
543
    output << ")";
630
544
 
631
545
    return output;  // for multiple << operators.
632
546
  }
633
547
 
 
548
protected:
 
549
  bool is_placeholder_created;
 
550
 
634
551
public:
635
 
  virtual bool isPlaceHolder(void) const
 
552
  bool isPlaceHolder()
636
553
  {
637
 
    return false;
 
554
    return is_placeholder_created;
638
555
  }
639
556
};
640
557
 
820
737
class select_union;
821
738
class Tmp_Table_Param;
822
739
 
 
740
struct open_table_list_st
 
741
{
 
742
  std::string   db;
 
743
  std::string   table;
 
744
  uint32_t in_use;
 
745
  uint32_t locked;
 
746
 
 
747
  open_table_list_st() :
 
748
    in_use(0),
 
749
    locked(0)
 
750
  { }
 
751
 
 
752
};
 
753
 
823
754
void free_blobs(Table *table);
824
755
int set_zone(int nr,int min_zone,int max_zone);
825
756
uint32_t convert_period_to_month(uint32_t period);
830
761
 
831
762
namespace optimizer { class SqlSelect; }
832
763
 
 
764
ha_rows filesort(Session *session,
 
765
                 Table *form,
 
766
                 st_sort_field *sortorder,
 
767
                 uint32_t s_length,
 
768
                 optimizer::SqlSelect *select,
 
769
                 ha_rows max_rows,
 
770
                 bool sort_positions,
 
771
                 ha_rows *examined_rows);
 
772
 
 
773
void filesort_free_buffers(Table *table, bool full);
833
774
void change_double_for_sort(double nr,unsigned char *to);
834
775
double my_double_round(double value, int64_t dec, bool dec_unsigned,
835
776
                       bool truncate);
839
780
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
840
781
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
841
782
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
 
783
ulong next_io_size(ulong pos);
842
784
void append_unescaped(String *res, const char *pos, uint32_t length);
843
785
 
844
786
int rename_file_ext(const char * from,const char * to,const char * ext);
845
787
bool check_column_name(const char *name);
846
 
bool check_db_name(Session *session, SchemaIdentifier &schema);
 
788
bool check_db_name(SchemaIdentifier &schema);
847
789
bool check_table_name(const char *name, uint32_t length);
848
790
 
849
791
} /* namespace drizzled */
850
792
 
851
 
#include "drizzled/table/instance.h"
852
 
#include "drizzled/table/concurrent.h"
853
 
 
854
793
#endif /* DRIZZLED_TABLE_H */