~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Monty Taylor
  • Date: 2010-06-16 22:09:44 UTC
  • mto: (1627.2.5 build)
  • mto: This revision was merged to the branch mainline in revision 1628.
  • Revision ID: mordred@inaugust.com-20100616220944-dlpupc1e45iehyfy
Fixed the visibility header to match the project name.

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
public:
 
64
  TableShare *s; /**< Pointer to the shared metadata about the table */
 
65
 
 
66
private:
64
67
  Field **field; /**< Pointer to fields collection */
65
68
public:
66
69
 
103
106
    next= arg;
104
107
  }
105
108
 
106
 
  void unlink()
107
 
  {
108
 
    getNext()->setPrev(getPrev());              /* remove from used chain */
109
 
    getPrev()->setNext(getNext());
110
 
  }
111
 
 
112
109
private:
113
110
  Table *prev;
114
111
public:
127
124
    prev= arg;
128
125
  }
129
126
 
130
 
  boost::dynamic_bitset<> *read_set; /* Active column sets */
131
 
  boost::dynamic_bitset<> *write_set; /* Active column sets */
 
127
  MyBitmap *read_set; /* Active column sets */
 
128
  MyBitmap *write_set; /* Active column sets */
132
129
 
133
130
  uint32_t tablenr;
134
131
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
135
132
 
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... */
 
133
  MyBitmap def_read_set; /**< Default read set of columns */
 
134
  MyBitmap def_write_set; /**< Default write set of columns */
 
135
  MyBitmap tmp_set; /* Not sure about this... */
139
136
 
140
137
  Session *in_use; /**< Pointer to the current session using this object */
141
138
  Session *getSession()
143
140
    return in_use;
144
141
  }
145
142
 
146
 
  unsigned char *getInsertRecord()
147
 
  {
148
 
    return record[0];
149
 
  }
150
 
 
151
 
  unsigned char *getUpdateRecord()
152
 
  {
153
 
    return record[1];
154
 
  }
155
 
 
156
143
  unsigned char *record[2]; /**< Pointer to "records" */
157
 
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
 
144
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
158
145
  KeyInfo  *key_info; /**< data of keys in database */
159
146
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
160
147
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
161
148
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
162
149
 
163
150
  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
 
 
 
151
  order_st *group;
 
152
  const char *alias; /**< alias or table name if no alias */
185
153
  unsigned char *null_flags;
186
154
 
187
155
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
188
156
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
189
157
  uint32_t lock_count; /**< Number of locks */
190
158
  uint32_t used_fields;
191
 
  uint32_t status; /* What's in getInsertRecord() */
 
159
  uint32_t status; /* What's in record[0] */
192
160
  /* number of select if it is derived table */
193
161
  uint32_t derived_select_number;
194
162
  int current_lock; /**< Type of lock on table */
208
176
  bool null_row;
209
177
 
210
178
  bool force_index;
211
 
  bool distinct;
212
 
  bool const_table;
213
 
  bool no_rows;
 
179
  bool distinct,const_table,no_rows;
214
180
  bool key_read;
215
181
  bool no_keyread;
216
182
  /*
363
329
    return mem_root.strmake_root(str_arg, len_arg);
364
330
  }
365
331
 
366
 
  filesort_info sort;
 
332
  filesort_info_st sort;
367
333
 
368
334
  Table();
369
 
  virtual ~Table();
 
335
  virtual ~Table() { };
370
336
 
371
337
  int report_error(int error);
372
338
  /**
375
341
   * @param If true if we also want to free table_share
376
342
   * @note this should all be the destructor
377
343
   */
378
 
  int delete_table(bool free_share= false);
 
344
  int delete_table(bool free_share);
379
345
 
380
346
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
381
347
 
382
348
  /* 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);
 
349
  inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
 
350
  inline bool hasShare() const { return s ? true : false ; } /* Get rid of this long term */
 
351
  inline TableShare *getMutableShare() { assert(s); return s; } /* Get rid of this long term */
 
352
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
 
353
  inline uint32_t sizeKeys() { return s->sizeKeys(); }
 
354
  inline uint32_t sizeFields() { return s->sizeFields(); }
 
355
  inline uint32_t getRecordLength() const { return s->getRecordLength(); }
 
356
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
 
357
  inline uint32_t *getBlobField() { return &s->blob_field[0]; }
403
358
 
404
359
  Field_blob *getBlobFieldAt(uint32_t arg) const
405
360
  {
406
 
    if (arg < getShare()->blob_fields)
407
 
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
 
361
    if (arg < s->blob_fields)
 
362
      return (Field_blob*) field[s->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
408
363
 
409
364
    return NULL;
410
365
  }
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(); }
 
366
  inline uint8_t getBlobPtrSize() { return s->blob_ptr_size; }
 
367
  inline uint32_t getNullBytes() { return s->null_bytes; }
 
368
  inline uint32_t getNullFields() { return s->null_fields; }
 
369
  inline unsigned char *getDefaultValues() { return  s->getDefaultValues(); }
 
370
  inline const char *getSchemaName()  const { return s->getSchemaName(); }
 
371
  inline const char *getTableName()  const { return s->getTableName(); }
417
372
 
418
 
  inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
419
 
  inline bool isNameLock() const { return open_placeholder; }
 
373
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
 
374
  inline bool isNameLock() const { return s->isNameLock(); }
 
375
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
376
  inline bool isWaitingOnCondition() const { return s->isWaitingOnCondition(); } /* Protection against free */
420
377
 
421
378
  uint32_t index_flags(uint32_t idx) const
422
379
  {
423
 
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
 
380
    return s->storage_engine->index_flags(s->getKeyInfo(idx).algorithm);
424
381
  }
425
382
 
426
383
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
427
384
  {
428
 
    return getShare()->storage_engine;
 
385
    return s->storage_engine;
429
386
  }
430
387
 
431
388
  Cursor &getCursor() const /* table_type for handler */
434
391
    return *cursor;
435
392
  }
436
393
 
 
394
  /* For TMP tables, should be pulled out as a class */
 
395
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
 
396
  bool create_myisam_tmp_table(KeyInfo *keyinfo,
 
397
                               MI_COLUMNDEF *start_recinfo,
 
398
                               MI_COLUMNDEF **recinfo,
 
399
                               uint64_t options);
 
400
  void free_tmp_table(Session *session);
 
401
  bool open_tmp_table();
437
402
  size_t max_row_length(const unsigned char *data);
438
403
  uint32_t find_shortest_key(const key_map *usable_keys);
439
404
  bool compare_record(Field **ptr);
440
 
  bool records_are_comparable();
441
 
  bool compare_records();
 
405
  bool compare_record();
442
406
  /* TODO: the (re)storeRecord's may be able to be further condensed */
443
407
  void storeRecord();
444
408
  void storeRecordAsInsert();
447
411
  void restoreRecordAsDefault();
448
412
  void emptyRecord();
449
413
 
450
 
 
451
414
  /* See if this can be blown away */
452
415
  inline uint32_t getDBStat () { return db_stat; }
453
416
  inline uint32_t setDBStat () { return db_stat; }
470
433
  bool fill_item_list(List<Item> *item_list) const;
471
434
  void clear_column_bitmaps(void);
472
435
  void prepare_for_position(void);
473
 
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
 
436
  void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
474
437
  void mark_columns_used_by_index_no_reset(uint32_t index);
475
438
  void mark_columns_used_by_index(uint32_t index);
476
439
  void restore_column_maps_after_mark_index();
478
441
  void mark_columns_needed_for_update(void);
479
442
  void mark_columns_needed_for_delete(void);
480
443
  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);
 
444
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
 
445
                                 MyBitmap *write_set_arg)
 
446
  {
 
447
    read_set= read_set_arg;
 
448
    write_set= write_set_arg;
 
449
  }
 
450
 
 
451
  void restore_column_map(my_bitmap_map *old);
 
452
 
 
453
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
487
454
  inline void use_all_columns()
488
455
  {
489
 
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
 
456
    column_bitmaps_set(&s->all_set, &s->all_set);
490
457
  }
491
458
 
492
459
  inline void default_column_bitmaps()
498
465
  /* Both of the below should go away once we can move this bit to the field objects */
499
466
  inline bool isReadSet(uint32_t index)
500
467
  {
501
 
    return read_set->test(index);
 
468
    return read_set->isBitSet(index);
502
469
  }
503
470
 
504
471
  inline void setReadSet(uint32_t index)
505
472
  {
506
 
    read_set->set(index);
 
473
    read_set->setBit(index);
507
474
  }
508
475
 
509
476
  inline void setReadSet()
510
477
  {
511
 
    read_set->set();
 
478
    read_set->setAll();
512
479
  }
513
480
 
514
481
  inline void clearReadSet(uint32_t index)
515
482
  {
516
 
    read_set->reset(index);
 
483
    read_set->clearBit(index);
517
484
  }
518
485
 
519
486
  inline void clearReadSet()
520
487
  {
521
 
    read_set->reset();
 
488
    read_set->clearAll();
522
489
  }
523
490
 
524
491
  inline bool isWriteSet(uint32_t index)
525
492
  {
526
 
    return write_set->test(index);
 
493
    return write_set->isBitSet(index);
527
494
  }
528
495
 
529
496
  inline void setWriteSet(uint32_t index)
530
497
  {
531
 
    write_set->set(index);
 
498
    write_set->setBit(index);
532
499
  }
533
500
 
534
501
  inline void setWriteSet()
535
502
  {
536
 
    write_set->set();
 
503
    write_set->setAll();
537
504
  }
538
505
 
539
506
  inline void clearWriteSet(uint32_t index)
540
507
  {
541
 
    write_set->reset(index);
 
508
    write_set->clearBit(index);
542
509
  }
543
510
 
544
511
  inline void clearWriteSet()
545
512
  {
546
 
    write_set->reset();
 
513
    write_set->clearAll();
547
514
  }
548
515
 
549
516
  /* Is table open or should be treated as such by name-locking? */
556
523
  */
557
524
  inline bool needs_reopen_or_name_lock()
558
525
  { 
559
 
    return getShare()->getVersion() != refresh_version;
 
526
    return s->getVersion() != refresh_version;
560
527
  }
561
528
 
562
529
  /**
571
538
  {
572
539
    null_row= 1;
573
540
    status|= STATUS_NULL_ROW;
574
 
    memset(null_flags, 255, getShare()->null_bytes);
 
541
    memset(null_flags, 255, s->null_bytes);
575
542
  }
576
543
 
577
544
  void free_io_cache();
580
547
 
581
548
  void print_error(int error, myf errflag)
582
549
  {
583
 
    getShare()->storage_engine->print_error(error, errflag, *this);
 
550
    s->storage_engine->print_error(error, errflag, *this);
584
551
  }
585
552
 
586
553
  /**
603
570
  */
604
571
  bool operator<(const Table &right) const
605
572
  {
606
 
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
 
573
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
 
574
 
 
575
    if (result <  0)
 
576
      return true;
 
577
 
 
578
    if (result >  0)
 
579
      return false;
 
580
 
 
581
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
 
582
 
 
583
    if (result <  0)
 
584
      return true;
 
585
 
 
586
    if (result >  0)
 
587
      return false;
 
588
 
 
589
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
 
590
      return true;
 
591
 
 
592
    return false;
607
593
  }
608
594
 
609
595
  static bool compare(const Table *a, const Table *b)
613
599
 
614
600
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
615
601
  {
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
 
    }
 
602
    output << "Table:(";
 
603
    output << table.getShare()->getSchemaName();
 
604
    output << ", ";
 
605
    output <<  table.getShare()->getTableName();
 
606
    output << ", ";
 
607
    output <<  table.getShare()->getTableTypeAsString();
 
608
    output << ")";
630
609
 
631
610
    return output;  // for multiple << operators.
632
611
  }
633
612
 
 
613
protected:
 
614
  bool is_placeholder_created;
 
615
 
634
616
public:
635
 
  virtual bool isPlaceHolder(void) const
 
617
  bool isPlaceHolder()
636
618
  {
637
 
    return false;
 
619
    return is_placeholder_created;
638
620
  }
639
621
};
640
622
 
820
802
class select_union;
821
803
class Tmp_Table_Param;
822
804
 
 
805
struct open_table_list_st
 
806
{
 
807
  std::string   db;
 
808
  std::string   table;
 
809
  uint32_t in_use;
 
810
  uint32_t locked;
 
811
 
 
812
  open_table_list_st() :
 
813
    in_use(0),
 
814
    locked(0)
 
815
  { }
 
816
 
 
817
};
 
818
 
823
819
void free_blobs(Table *table);
824
820
int set_zone(int nr,int min_zone,int max_zone);
825
821
uint32_t convert_period_to_month(uint32_t period);
830
826
 
831
827
namespace optimizer { class SqlSelect; }
832
828
 
 
829
ha_rows filesort(Session *session,
 
830
                 Table *form,
 
831
                 st_sort_field *sortorder,
 
832
                 uint32_t s_length,
 
833
                 optimizer::SqlSelect *select,
 
834
                 ha_rows max_rows,
 
835
                 bool sort_positions,
 
836
                 ha_rows *examined_rows);
 
837
 
 
838
void filesort_free_buffers(Table *table, bool full);
833
839
void change_double_for_sort(double nr,unsigned char *to);
834
840
double my_double_round(double value, int64_t dec, bool dec_unsigned,
835
841
                       bool truncate);
839
845
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
840
846
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
841
847
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
 
848
ulong next_io_size(ulong pos);
842
849
void append_unescaped(String *res, const char *pos, uint32_t length);
843
850
 
844
851
int rename_file_ext(const char * from,const char * to,const char * ext);
848
855
 
849
856
} /* namespace drizzled */
850
857
 
851
 
#include "drizzled/table/instance.h"
852
 
#include "drizzled/table/concurrent.h"
853
 
 
854
858
#endif /* DRIZZLED_TABLE_H */