35
34
#include "drizzled/cursor.h"
36
35
#include "drizzled/lex_string.h"
37
36
#include "drizzled/table_list.h"
38
#include "drizzled/table/instance.h"
37
#include "drizzled/table_share.h"
39
38
#include "drizzled/atomics.h"
40
#include "drizzled/query_id.h"
42
#include "drizzled/visibility.h"
50
41
class Item_subselect;
51
class SecurityContext;
42
class Select_Lex_Unit;
53
class Select_Lex_Unit;
45
class Security_context;
55
namespace field { class Epoch; }
56
namespace plugin { class StorageEngine; }
47
class Field_timestamp;
50
extern drizzled::atomic<uint32_t> refresh_version;
58
52
typedef enum enum_table_category TABLE_CATEGORY;
59
typedef struct st_columndef MI_COLUMNDEF;
54
bool create_myisam_from_heap(Session *session, Table *table,
55
MI_COLUMNDEF *start_recinfo,
56
MI_COLUMNDEF **recinfo,
57
int error, bool ignore_last_dupp_key_error);
62
60
* Class representing a set of records, either in a temporary,
63
61
* normal, or derived table.
65
class DRIZZLED_API Table
67
TableShare *s; /**< Pointer to the shared metadata about the table */
67
68
Field **field; /**< Pointer to fields collection */
70
Field **getFields() const
75
Field *getField(uint32_t arg) const
80
void setFields(Field **arg)
85
void setFieldAt(Field *arg, uint32_t arg_pos)
90
Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
70
Cursor *file; /**< Pointer to the storage engine's Cursor managing this table */
96
Table *getNext() const
106
void setNext(Table *arg)
113
getNext()->setPrev(getPrev()); /* remove from used chain */
114
getPrev()->setNext(getNext());
120
Table *getPrev() const
130
void setPrev(Table *arg)
135
boost::dynamic_bitset<> *read_set; /* Active column sets */
136
boost::dynamic_bitset<> *write_set; /* Active column sets */
74
MyBitmap *read_set; /* Active column sets */
75
MyBitmap *write_set; /* Active column sets */
139
uint32_t db_stat; /**< information about the cursor as in Cursor.h */
78
uint32_t db_stat; /**< information about the file 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... */
80
MyBitmap def_read_set; /**< Default read set of columns */
81
MyBitmap def_write_set; /**< Default write set of columns */
82
MyBitmap tmp_set; /* Not sure about this... */
145
84
Session *in_use; /**< Pointer to the current session using this object */
146
Session *getSession()
151
unsigned char *getInsertRecord() const
156
unsigned char *getUpdateRecord()
161
86
unsigned char *record[2]; /**< Pointer to "records" */
162
std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
163
KeyInfo *key_info; /**< data of keys in database */
87
unsigned char *insert_values; /* used by INSERT ... UPDATE */
88
KEY *key_info; /**< data of keys in database */
164
89
Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
165
90
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 */
91
Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
168
93
TableList *pos_in_table_list; /* Element referring to this table */
171
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 */
95
const char *alias; /**< alias or table name if no alias */
190
96
unsigned char *null_flags;
192
98
uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
193
99
uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
194
100
uint32_t lock_count; /**< Number of locks */
195
101
uint32_t used_fields;
196
uint32_t status; /* What's in getInsertRecord() */
102
uint32_t status; /* What's in record[0] */
197
103
/* number of select if it is derived table */
198
104
uint32_t derived_select_number;
199
105
int current_lock; /**< Type of lock on table */
332
234
uint32_t quick_key_parts[MAX_KEY];
333
235
uint32_t quick_n_ranges[MAX_KEY];
336
memory::Root mem_root;
238
filesort_info_st sort;
253
next_number_field(NULL),
254
found_next_number_field(NULL),
255
timestamp_field(NULL),
256
pos_in_table_list(NULL),
265
derived_select_number(0),
266
current_lock(F_UNLCK),
276
open_placeholder(false),
277
locked_by_name(false),
279
auto_increment_field_not_null(false),
280
alias_name_used(false),
282
quick_condition_rows(0),
283
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
286
record[0]= (unsigned char *) 0;
287
record[1]= (unsigned char *) 0;
289
covering_keys.reset();
294
keys_in_use_for_query.reset();
295
keys_in_use_for_group_by.reset();
296
keys_in_use_for_order_by.reset();
298
memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
299
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
301
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
302
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
340
304
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
343
memory::Root *getMemRoot()
345
if (not mem_root.alloc_root_inited())
353
void *alloc_root(size_t arg)
355
if (not mem_root.alloc_root_inited())
360
return mem_root.alloc_root(arg);
363
char *strmake_root(const char *str_arg, size_t len_arg)
365
if (not mem_root.alloc_root_inited())
370
return mem_root.strmake_root(str_arg, len_arg);
305
memset(&sort, 0, sizeof(filesort_info_st));
378
308
int report_error(int error);
380
310
* Free information allocated by openfrm
382
312
* @param If true if we also want to free table_share
383
* @note this should all be the destructor
385
int delete_table(bool free_share= false);
387
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
314
int closefrm(bool free_share);
316
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg)
329
db_stat= db_stat_arg;
332
record[0]= (unsigned char *) 0;
333
record[1]= (unsigned char *) 0;
337
next_number_field= NULL;
338
found_next_number_field= NULL;
339
timestamp_field= NULL;
341
pos_in_table_list= NULL;
351
derived_select_number= 0;
352
current_lock= F_UNLCK;
366
open_placeholder= false;
367
locked_by_name= false;
370
auto_increment_field_not_null= false;
371
alias_name_used= false;
374
quick_condition_rows= 0;
376
timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
381
covering_keys.reset();
386
keys_in_use_for_query.reset();
387
keys_in_use_for_group_by.reset();
388
keys_in_use_for_order_by.reset();
390
memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
391
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
393
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
394
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
396
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
397
memset(&sort, 0, sizeof(filesort_info_st));
389
400
/* 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);
411
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. */
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;
430
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
432
return getShare()->getEngine();
435
Cursor &getCursor() const /* table_type for handler */
401
inline TableShare *getShare() { return s; } /* Get rid of this long term */
402
inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
403
inline uint32_t sizeKeys() { return s->keys; }
404
inline uint32_t sizeFields() { return s->fields; }
405
inline uint32_t getRecordLength() { return s->reclength; }
406
inline uint32_t sizeBlobFields() { return s->blob_fields; }
407
inline uint32_t *getBlobField() { return s->blob_field; }
408
inline uint32_t getNullBytes() { return s->null_bytes; }
409
inline uint32_t getNullFields() { return s->null_fields; }
410
inline unsigned char *getDefaultValues() { return s->default_values; }
412
inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
413
inline bool isCrashed() { return s->crashed; }
414
inline bool isNameLock() { return s->name_lock; }
415
inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
416
inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
418
/* For TMP tables, should be pulled out as a class */
419
void updateCreateInfo(HA_CREATE_INFO *create_info,
420
drizzled::message::Table *table_proto);
421
void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
422
bool create_myisam_tmp_table(KEY *keyinfo,
423
MI_COLUMNDEF *start_recinfo,
424
MI_COLUMNDEF **recinfo,
426
void free_tmp_table(Session *session);
427
bool open_tmp_table();
441
428
size_t max_row_length(const unsigned char *data);
442
429
uint32_t find_shortest_key(const key_map *usable_keys);
443
430
bool compare_record(Field **ptr);
444
bool records_are_comparable();
445
bool compare_records();
431
bool compare_record();
446
432
/* TODO: the (re)storeRecord's may be able to be further condensed */
447
433
void storeRecord();
448
434
void storeRecordAsInsert();
575
578
status|= STATUS_NULL_ROW;
576
memset(null_flags, 255, getShare()->null_bytes);
579
memset(null_flags, 255, s->null_bytes);
582
bool rename_temporary_table(const char *db, const char *table_name);
579
583
void free_io_cache();
580
584
void filesort_free_buffers(bool full= false);
581
585
void intern_close_table();
583
void print_error(int error, myf errflag) const;
587
key if error because of duplicated keys
589
uint32_t get_dup_key(int error) const
591
cursor->errkey = (uint32_t) -1;
592
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
593
error == HA_ERR_FOUND_DUPP_UNIQUE ||
594
error == HA_ERR_DROP_INDEX_FK)
595
cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
597
return(cursor->errkey);
601
This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
603
bool operator<(const Table &right) const
605
return getShare()->getCacheKey() < right.getShare()->getCacheKey();
608
static bool compare(const Table *a, const Table *b)
613
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)";
630
return output; // for multiple << operators.
634
virtual bool isPlaceHolder(void) const
645
* This class defines the information for foreign keys.
588
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
590
typedef struct st_foreign_key_info
652
* This is the constructor with all properties set.
654
* @param[in] in_foreign_id The id of the foreign key
655
* @param[in] in_referenced_db The referenced database name of the foreign key
656
* @param[in] in_referenced_table The referenced table name of the foreign key
657
* @param[in] in_update_method The update method of the foreign key.
658
* @param[in] in_delete_method The delete method of the foreign key.
659
* @param[in] in_referenced_key_name The name of referenced key
660
* @param[in] in_foreign_fields The foreign fields
661
* @param[in] in_referenced_fields The referenced fields
663
ForeignKeyInfo(LEX_STRING *in_foreign_id,
664
LEX_STRING *in_referenced_db,
665
LEX_STRING *in_referenced_table,
666
LEX_STRING *in_update_method,
667
LEX_STRING *in_delete_method,
668
LEX_STRING *in_referenced_key_name,
669
List<LEX_STRING> in_foreign_fields,
670
List<LEX_STRING> in_referenced_fields)
672
foreign_id(in_foreign_id),
673
referenced_db(in_referenced_db),
674
referenced_table(in_referenced_table),
675
update_method(in_update_method),
676
delete_method(in_delete_method),
677
referenced_key_name(in_referenced_key_name),
678
foreign_fields(in_foreign_fields),
679
referenced_fields(in_referenced_fields)
684
* This is the default constructor. All properties are set to default values for their types.
687
: foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
688
update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
693
* Gets the foreign id.
695
* @ retval the foreign id
697
const LEX_STRING *getForeignId() const
704
* Gets the name of the referenced database.
706
* @ retval the name of the referenced database
708
const LEX_STRING *getReferencedDb() const
710
return referenced_db;
715
* Gets the name of the referenced table.
717
* @ retval the name of the referenced table
719
const LEX_STRING *getReferencedTable() const
721
return referenced_table;
726
* Gets the update method.
728
* @ retval the update method
730
const LEX_STRING *getUpdateMethod() const
732
return update_method;
737
* Gets the delete method.
739
* @ retval the delete method
741
const LEX_STRING *getDeleteMethod() const
743
return delete_method;
748
* Gets the name of the referenced key.
750
* @ retval the name of the referenced key
752
const LEX_STRING *getReferencedKeyName() const
754
return referenced_key_name;
759
* Gets the foreign fields.
761
* @ retval the foreign fields
763
const List<LEX_STRING> &getForeignFields() const
765
return foreign_fields;
770
* Gets the referenced fields.
772
* @ retval the referenced fields
774
const List<LEX_STRING> &getReferencedFields() const
776
return referenced_fields;
782
LEX_STRING *foreign_id;
784
* The name of the reference database.
786
LEX_STRING *referenced_db;
788
* The name of the reference table.
790
LEX_STRING *referenced_table;
794
LEX_STRING *update_method;
798
LEX_STRING *delete_method;
800
* The name of the referenced key.
802
LEX_STRING *referenced_key_name;
804
* The foreign fields.
806
List<LEX_STRING> foreign_fields;
808
* The referenced fields.
810
List<LEX_STRING> referenced_fields;
592
LEX_STRING *forein_id;
593
LEX_STRING *referenced_db;
594
LEX_STRING *referenced_table;
595
LEX_STRING *update_method;
596
LEX_STRING *delete_method;
597
LEX_STRING *referenced_key_name;
598
List<LEX_STRING> foreign_fields;
599
List<LEX_STRING> referenced_fields;
815
#define JOIN_TYPE_LEFT 1
816
#define JOIN_TYPE_RIGHT 2
606
#define JOIN_TYPE_LEFT 1
607
#define JOIN_TYPE_RIGHT 2
819
610
class select_union;
820
611
class Tmp_Table_Param;
822
void free_blobs(Table *table);
823
int set_zone(int nr,int min_zone,int max_zone);
824
uint32_t convert_period_to_month(uint32_t period);
825
uint32_t convert_month_to_period(uint32_t month);
827
int test_if_number(char *str,int *res,bool allow_wildcards);
828
void change_byte(unsigned char *,uint,char,char);
830
namespace optimizer { class SqlSelect; }
832
void change_double_for_sort(double nr,unsigned char *to);
833
int get_quick_record(optimizer::SqlSelect *select);
835
void find_date(char *pos,uint32_t *vek,uint32_t flag);
836
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
837
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
838
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
839
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);
842
bool check_column_name(const char *name);
843
bool check_db_name(Session *session, identifier::Schema &schema);
844
bool check_table_name(const char *name, uint32_t length);
846
} /* namespace drizzled */
848
#include "drizzled/table/singular.h"
849
#include "drizzled/table/concurrent.h"
613
typedef struct st_changed_table_list
615
struct st_changed_table_list *next;
620
struct open_table_list_st
627
open_table_list_st() :
851
634
#endif /* DRIZZLED_TABLE_H */