35
32
#include "drizzled/cursor.h"
36
33
#include "drizzled/lex_string.h"
37
34
#include "drizzled/table_list.h"
38
#include "drizzled/table/instance.h"
35
#include "drizzled/table_share.h"
39
36
#include "drizzled/atomics.h"
40
37
#include "drizzled/query_id.h"
42
#include "drizzled/visibility.h"
50
43
class Item_subselect;
44
class Select_Lex_Unit;
51
47
class SecurityContext;
53
class Select_Lex_Unit;
55
namespace field { class Epoch; }
56
namespace plugin { class StorageEngine; }
49
class Field_timestamp;
52
extern uint64_t refresh_version;
58
54
typedef enum enum_table_category TABLE_CATEGORY;
59
55
typedef struct st_columndef MI_COLUMNDEF;
135
boost::dynamic_bitset<> *read_set; /* Active column sets */
136
boost::dynamic_bitset<> *write_set; /* Active column sets */
133
MyBitmap *read_set; /* Active column sets */
134
MyBitmap *write_set; /* Active column sets */
138
136
uint32_t tablenr;
139
137
uint32_t db_stat; /**< information about the cursor as in Cursor.h */
141
boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
142
boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
143
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... */
145
143
Session *in_use; /**< Pointer to the current session using this object */
146
144
Session *getSession()
163
161
KeyInfo *key_info; /**< data of keys in database */
164
162
Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
165
163
Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
166
field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
164
Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
168
166
TableList *pos_in_table_list; /* Element referring to this table */
171
169
const char *getAlias() const
173
return _alias.c_str();
181
void setAlias(const char *arg)
187
std::string _alias; /**< alias or table name if no alias */
174
const char *alias; /**< alias or table name if no alias */
190
176
unsigned char *null_flags;
387
371
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
389
373
/* SHARE methods */
390
virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
391
virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
392
virtual bool hasShare() const= 0; /* Get rid of this long term */
393
virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
395
virtual void release(void)= 0;
397
uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
398
uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
399
uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
400
uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
401
uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
404
virtual bool hasVariableWidth() const
406
return getShare()->hasVariableWidth(); // We should calculate this.
409
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]; }
411
384
Field_blob *getBlobFieldAt(uint32_t arg) const
413
if (arg < getShare()->blob_fields)
414
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. */
418
inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
419
inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
420
inline uint32_t getNullFields() const { return getShare()->null_fields; }
421
inline unsigned char *getDefaultValues() { return getMutableShare()->getDefaultValues(); }
422
inline const char *getSchemaName() const { return getShare()->getSchemaName(); }
423
inline const char *getTableName() const { return getShare()->getTableName(); }
425
inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
426
inline bool isNameLock() const { return open_placeholder; }
428
uint32_t index_flags(uint32_t idx) const;
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(); }
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; }
402
uint32_t index_flags(uint32_t idx) const
404
return s->storage_engine->index_flags(s->getKeyInfo(idx).algorithm);
430
407
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
432
return getShare()->getEngine();
409
return s->storage_engine;
435
412
Cursor &getCursor() const /* table_type for handler */
418
/* For TMP tables, should be pulled out as a class */
419
void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
420
bool create_myisam_tmp_table(KeyInfo *keyinfo,
421
MI_COLUMNDEF *start_recinfo,
422
MI_COLUMNDEF **recinfo,
424
void free_tmp_table(Session *session);
425
bool open_tmp_table();
441
426
size_t max_row_length(const unsigned char *data);
442
427
uint32_t find_shortest_key(const key_map *usable_keys);
443
428
bool compare_record(Field **ptr);
444
bool records_are_comparable();
445
bool compare_records();
429
bool compare_record();
446
430
/* TODO: the (re)storeRecord's may be able to be further condensed */
447
431
void storeRecord();
448
432
void storeRecordAsInsert();
474
457
bool fill_item_list(List<Item> *item_list) const;
475
458
void clear_column_bitmaps(void);
476
459
void prepare_for_position(void);
477
void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
460
void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
478
461
void mark_columns_used_by_index_no_reset(uint32_t index);
479
462
void mark_columns_used_by_index(uint32_t index);
480
463
void restore_column_maps_after_mark_index();
482
465
void mark_columns_needed_for_update(void);
483
466
void mark_columns_needed_for_delete(void);
484
467
void mark_columns_needed_for_insert(void);
485
void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
486
boost::dynamic_bitset<>& write_set_arg);
488
void restore_column_map(const boost::dynamic_bitset<>& old);
490
const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
468
inline void column_bitmaps_set(MyBitmap *read_set_arg,
469
MyBitmap *write_set_arg)
471
read_set= read_set_arg;
472
write_set= write_set_arg;
475
void restore_column_map(my_bitmap_map *old);
477
my_bitmap_map *use_all_columns(MyBitmap *bitmap);
491
478
inline void use_all_columns()
493
column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
480
column_bitmaps_set(&s->all_set, &s->all_set);
496
483
inline void default_column_bitmaps()
502
489
/* Both of the below should go away once we can move this bit to the field objects */
503
490
inline bool isReadSet(uint32_t index)
505
return read_set->test(index);
492
return read_set->isBitSet(index);
508
495
inline void setReadSet(uint32_t index)
510
read_set->set(index);
497
read_set->setBit(index);
513
500
inline void setReadSet()
518
505
inline void clearReadSet(uint32_t index)
520
read_set->reset(index);
507
read_set->clearBit(index);
523
510
inline void clearReadSet()
512
read_set->clearAll();
528
515
inline bool isWriteSet(uint32_t index)
530
return write_set->test(index);
517
return write_set->isBitSet(index);
533
520
inline void setWriteSet(uint32_t index)
535
write_set->set(index);
522
write_set->setBit(index);
538
525
inline void setWriteSet()
543
530
inline void clearWriteSet(uint32_t index)
545
write_set->reset(index);
532
write_set->clearBit(index);
548
535
inline void clearWriteSet()
537
write_set->clearAll();
553
540
/* Is table open or should be treated as such by name-locking? */
575
564
status|= STATUS_NULL_ROW;
576
memset(null_flags, 255, getShare()->null_bytes);
565
memset(null_flags, 255, s->null_bytes);
579
568
void free_io_cache();
580
569
void filesort_free_buffers(bool full= false);
581
570
void intern_close_table();
583
void print_error(int error, myf errflag) const;
572
void print_error(int error, myf errflag)
574
s->storage_engine->print_error(error, errflag, *this);
587
579
key if error because of duplicated keys
589
uint32_t get_dup_key(int error) const
581
uint32_t get_dup_key(int error)
591
583
cursor->errkey = (uint32_t) -1;
592
584
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
613
624
friend std::ostream& operator<<(std::ostream& output, const Table &table)
615
if (table.getShare())
618
output << table.getShare()->getSchemaName();
620
output << table.getShare()->getTableName();
622
output << table.getShare()->getTableTypeAsString();
627
output << "Table:(has no share)";
627
output << table.getShare()->getSchemaName();
629
output << table.getShare()->getTableName();
631
output << table.getShare()->getTableTypeAsString();
630
634
return output; // for multiple << operators.
638
bool is_placeholder_created;
634
virtual bool isPlaceHolder(void) const
643
return is_placeholder_created;
830
851
namespace optimizer { class SqlSelect; }
853
ha_rows filesort(Session *session,
855
SortField *sortorder,
857
optimizer::SqlSelect *select,
860
ha_rows *examined_rows);
862
void filesort_free_buffers(Table *table, bool full);
832
863
void change_double_for_sort(double nr,unsigned char *to);
864
double my_double_round(double value, int64_t dec, bool dec_unsigned,
833
866
int get_quick_record(optimizer::SqlSelect *select);
835
868
void find_date(char *pos,uint32_t *vek,uint32_t flag);
836
869
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
837
870
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
838
871
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
872
ulong next_io_size(ulong pos);
839
873
void append_unescaped(String *res, const char *pos, uint32_t length);
841
DRIZZLED_API int rename_file_ext(const char * from,const char * to,const char * ext);
875
int rename_file_ext(const char * from,const char * to,const char * ext);
842
876
bool check_column_name(const char *name);
843
bool check_db_name(Session *session, identifier::Schema &schema);
877
bool check_db_name(Session *session, SchemaIdentifier &schema);
844
878
bool check_table_name(const char *name, uint32_t length);
846
880
} /* namespace drizzled */
848
#include "drizzled/table/singular.h"
849
#include "drizzled/table/concurrent.h"
851
882
#endif /* DRIZZLED_TABLE_H */