~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2010-08-03 19:24:14 UTC
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: brian@gaz-20100803192414-jk20j0u6cnze3ja6
Do comparison via non-case.

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
 
127
130
    prev= arg;
128
131
  }
129
132
 
130
 
  boost::dynamic_bitset<> *read_set; /* Active column sets */
131
 
  boost::dynamic_bitset<> *write_set; /* Active column sets */
 
133
  MyBitmap *read_set; /* Active column sets */
 
134
  MyBitmap *write_set; /* Active column sets */
132
135
 
133
136
  uint32_t tablenr;
134
137
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
135
138
 
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... */
 
139
  MyBitmap def_read_set; /**< Default read set of columns */
 
140
  MyBitmap def_write_set; /**< Default write set of columns */
 
141
  MyBitmap tmp_set; /* Not sure about this... */
139
142
 
140
143
  Session *in_use; /**< Pointer to the current session using this object */
141
144
  Session *getSession()
161
164
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
162
165
 
163
166
  TableList *pos_in_table_list; /* Element referring to this table */
164
 
  Order *group;
 
167
  order_st *group;
165
168
  
166
169
  const char *getAlias() const
167
170
  {
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:
 
171
    return alias;
 
172
  }
 
173
 
 
174
  const char *alias; /**< alias or table name if no alias */
184
175
 
185
176
  unsigned char *null_flags;
186
177
 
363
354
    return mem_root.strmake_root(str_arg, len_arg);
364
355
  }
365
356
 
366
 
  filesort_info sort;
 
357
  filesort_info_st sort;
367
358
 
368
359
  Table();
369
 
  virtual ~Table();
 
360
  virtual ~Table() { };
370
361
 
371
362
  int report_error(int error);
372
363
  /**
380
371
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
381
372
 
382
373
  /* 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);
 
374
  inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
 
375
  inline bool hasShare() const { return s ? true : false ; } /* Get rid of this long term */
 
376
  inline TableShare *getMutableShare() { assert(s); return s; } /* Get rid of this long term */
 
377
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
 
378
  inline uint32_t sizeKeys() { return s->sizeKeys(); }
 
379
  inline uint32_t sizeFields() { return s->sizeFields(); }
 
380
  inline uint32_t getRecordLength() const { return s->getRecordLength(); }
 
381
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
 
382
  inline uint32_t *getBlobField() { return &s->blob_field[0]; }
403
383
 
404
384
  Field_blob *getBlobFieldAt(uint32_t arg) const
405
385
  {
406
 
    if (arg < getShare()->blob_fields)
407
 
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
 
386
    if (arg < s->blob_fields)
 
387
      return (Field_blob*) field[s->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
408
388
 
409
389
    return NULL;
410
390
  }
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(); }
 
391
  inline uint8_t getBlobPtrSize() { return s->blob_ptr_size; }
 
392
  inline uint32_t getNullBytes() { return s->null_bytes; }
 
393
  inline uint32_t getNullFields() { return s->null_fields; }
 
394
  inline unsigned char *getDefaultValues() { return  s->getDefaultValues(); }
 
395
  inline const char *getSchemaName()  const { return s->getSchemaName(); }
 
396
  inline const char *getTableName()  const { return s->getTableName(); }
417
397
 
418
 
  inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
419
 
  inline bool isNameLock() const { return open_placeholder; }
 
398
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
 
399
  inline bool isNameLock() const { return s->isNameLock(); }
 
400
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
401
  inline bool isWaitingOnCondition() const { return s->isWaitingOnCondition(); } /* Protection against free */
420
402
 
421
403
  uint32_t index_flags(uint32_t idx) const
422
404
  {
423
 
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
 
405
    return s->storage_engine->index_flags(s->getKeyInfo(idx).algorithm);
424
406
  }
425
407
 
426
408
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
427
409
  {
428
 
    return getShare()->storage_engine;
 
410
    return s->storage_engine;
429
411
  }
430
412
 
431
413
  Cursor &getCursor() const /* table_type for handler */
434
416
    return *cursor;
435
417
  }
436
418
 
 
419
  /* For TMP tables, should be pulled out as a class */
 
420
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
 
421
  bool create_myisam_tmp_table(KeyInfo *keyinfo,
 
422
                               MI_COLUMNDEF *start_recinfo,
 
423
                               MI_COLUMNDEF **recinfo,
 
424
                               uint64_t options);
 
425
  void free_tmp_table(Session *session);
 
426
  bool open_tmp_table();
437
427
  size_t max_row_length(const unsigned char *data);
438
428
  uint32_t find_shortest_key(const key_map *usable_keys);
439
429
  bool compare_record(Field **ptr);
440
 
  bool records_are_comparable();
441
 
  bool compare_records();
 
430
  bool compare_record();
442
431
  /* TODO: the (re)storeRecord's may be able to be further condensed */
443
432
  void storeRecord();
444
433
  void storeRecordAsInsert();
447
436
  void restoreRecordAsDefault();
448
437
  void emptyRecord();
449
438
 
450
 
 
451
439
  /* See if this can be blown away */
452
440
  inline uint32_t getDBStat () { return db_stat; }
453
441
  inline uint32_t setDBStat () { return db_stat; }
470
458
  bool fill_item_list(List<Item> *item_list) const;
471
459
  void clear_column_bitmaps(void);
472
460
  void prepare_for_position(void);
473
 
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
 
461
  void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
474
462
  void mark_columns_used_by_index_no_reset(uint32_t index);
475
463
  void mark_columns_used_by_index(uint32_t index);
476
464
  void restore_column_maps_after_mark_index();
478
466
  void mark_columns_needed_for_update(void);
479
467
  void mark_columns_needed_for_delete(void);
480
468
  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);
 
469
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
 
470
                                 MyBitmap *write_set_arg)
 
471
  {
 
472
    read_set= read_set_arg;
 
473
    write_set= write_set_arg;
 
474
  }
 
475
 
 
476
  void restore_column_map(my_bitmap_map *old);
 
477
 
 
478
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
487
479
  inline void use_all_columns()
488
480
  {
489
 
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
 
481
    column_bitmaps_set(&s->all_set, &s->all_set);
490
482
  }
491
483
 
492
484
  inline void default_column_bitmaps()
498
490
  /* Both of the below should go away once we can move this bit to the field objects */
499
491
  inline bool isReadSet(uint32_t index)
500
492
  {
501
 
    return read_set->test(index);
 
493
    return read_set->isBitSet(index);
502
494
  }
503
495
 
504
496
  inline void setReadSet(uint32_t index)
505
497
  {
506
 
    read_set->set(index);
 
498
    read_set->setBit(index);
507
499
  }
508
500
 
509
501
  inline void setReadSet()
510
502
  {
511
 
    read_set->set();
 
503
    read_set->setAll();
512
504
  }
513
505
 
514
506
  inline void clearReadSet(uint32_t index)
515
507
  {
516
 
    read_set->reset(index);
 
508
    read_set->clearBit(index);
517
509
  }
518
510
 
519
511
  inline void clearReadSet()
520
512
  {
521
 
    read_set->reset();
 
513
    read_set->clearAll();
522
514
  }
523
515
 
524
516
  inline bool isWriteSet(uint32_t index)
525
517
  {
526
 
    return write_set->test(index);
 
518
    return write_set->isBitSet(index);
527
519
  }
528
520
 
529
521
  inline void setWriteSet(uint32_t index)
530
522
  {
531
 
    write_set->set(index);
 
523
    write_set->setBit(index);
532
524
  }
533
525
 
534
526
  inline void setWriteSet()
535
527
  {
536
 
    write_set->set();
 
528
    write_set->setAll();
537
529
  }
538
530
 
539
531
  inline void clearWriteSet(uint32_t index)
540
532
  {
541
 
    write_set->reset(index);
 
533
    write_set->clearBit(index);
542
534
  }
543
535
 
544
536
  inline void clearWriteSet()
545
537
  {
546
 
    write_set->reset();
 
538
    write_set->clearAll();
547
539
  }
548
540
 
549
541
  /* Is table open or should be treated as such by name-locking? */
556
548
  */
557
549
  inline bool needs_reopen_or_name_lock()
558
550
  { 
559
 
    return getShare()->getVersion() != refresh_version;
 
551
    return s->getVersion() != refresh_version;
560
552
  }
561
553
 
562
554
  /**
571
563
  {
572
564
    null_row= 1;
573
565
    status|= STATUS_NULL_ROW;
574
 
    memset(null_flags, 255, getShare()->null_bytes);
 
566
    memset(null_flags, 255, s->null_bytes);
575
567
  }
576
568
 
577
569
  void free_io_cache();
580
572
 
581
573
  void print_error(int error, myf errflag)
582
574
  {
583
 
    getShare()->storage_engine->print_error(error, errflag, *this);
 
575
    s->storage_engine->print_error(error, errflag, *this);
584
576
  }
585
577
 
586
578
  /**
603
595
  */
604
596
  bool operator<(const Table &right) const
605
597
  {
606
 
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
 
598
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
 
599
 
 
600
    if (result <  0)
 
601
      return true;
 
602
 
 
603
    if (result >  0)
 
604
      return false;
 
605
 
 
606
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
 
607
 
 
608
    if (result <  0)
 
609
      return true;
 
610
 
 
611
    if (result >  0)
 
612
      return false;
 
613
 
 
614
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
 
615
      return true;
 
616
 
 
617
    return false;
607
618
  }
608
619
 
609
620
  static bool compare(const Table *a, const Table *b)
613
624
 
614
625
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
615
626
  {
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
 
    }
 
627
    output << "Table:(";
 
628
    output << table.getShare()->getSchemaName();
 
629
    output << ", ";
 
630
    output <<  table.getShare()->getTableName();
 
631
    output << ", ";
 
632
    output <<  table.getShare()->getTableTypeAsString();
 
633
    output << ")";
630
634
 
631
635
    return output;  // for multiple << operators.
632
636
  }
633
637
 
 
638
protected:
 
639
  bool is_placeholder_created;
 
640
 
634
641
public:
635
 
  virtual bool isPlaceHolder(void) const
 
642
  bool isPlaceHolder()
636
643
  {
637
 
    return false;
 
644
    return is_placeholder_created;
638
645
  }
639
646
};
640
647
 
820
827
class select_union;
821
828
class Tmp_Table_Param;
822
829
 
 
830
struct open_table_list_st
 
831
{
 
832
  std::string   db;
 
833
  std::string   table;
 
834
  uint32_t in_use;
 
835
  uint32_t locked;
 
836
 
 
837
  open_table_list_st() :
 
838
    in_use(0),
 
839
    locked(0)
 
840
  { }
 
841
 
 
842
};
 
843
 
823
844
void free_blobs(Table *table);
824
845
int set_zone(int nr,int min_zone,int max_zone);
825
846
uint32_t convert_period_to_month(uint32_t period);
830
851
 
831
852
namespace optimizer { class SqlSelect; }
832
853
 
 
854
ha_rows filesort(Session *session,
 
855
                 Table *form,
 
856
                 st_sort_field *sortorder,
 
857
                 uint32_t s_length,
 
858
                 optimizer::SqlSelect *select,
 
859
                 ha_rows max_rows,
 
860
                 bool sort_positions,
 
861
                 ha_rows *examined_rows);
 
862
 
 
863
void filesort_free_buffers(Table *table, bool full);
833
864
void change_double_for_sort(double nr,unsigned char *to);
834
865
double my_double_round(double value, int64_t dec, bool dec_unsigned,
835
866
                       bool truncate);
839
870
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
840
871
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
841
872
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
 
873
ulong next_io_size(ulong pos);
842
874
void append_unescaped(String *res, const char *pos, uint32_t length);
843
875
 
844
876
int rename_file_ext(const char * from,const char * to,const char * ext);
848
880
 
849
881
} /* namespace drizzled */
850
882
 
851
 
#include "drizzled/table/instance.h"
852
 
#include "drizzled/table/concurrent.h"
853
 
 
854
883
#endif /* DRIZZLED_TABLE_H */