54
61
typedef enum enum_table_category TABLE_CATEGORY;
55
62
typedef struct st_columndef MI_COLUMNDEF;
57
bool create_myisam_from_heap(Session *session, Table *table,
58
MI_COLUMNDEF *start_recinfo,
59
MI_COLUMNDEF **recinfo,
60
int error, bool ignore_last_dupp_key_error);
63
65
* Class representing a set of records, either in a temporary,
64
66
* normal, or derived table.
68
class DRIZZLED_API Table
70
TableShare *s; /**< Pointer to the shared metadata about the table */
71
70
Field **field; /**< Pointer to fields collection */
73
Field **getFields() const
78
Field *getField(uint32_t arg) const
83
void setFields(Field **arg)
88
void setFieldAt(Field *arg, uint32_t arg_pos)
73
93
Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
99
Table *getNext() const
109
void setNext(Table *arg)
116
getNext()->setPrev(getPrev()); /* remove from used chain */
117
getPrev()->setNext(getNext());
77
MyBitmap *read_set; /* Active column sets */
78
MyBitmap *write_set; /* Active column sets */
123
Table *getPrev() const
133
void setPrev(Table *arg)
138
boost::dynamic_bitset<> *read_set; /* Active column sets */
139
boost::dynamic_bitset<> *write_set; /* Active column sets */
81
142
uint32_t db_stat; /**< information about the cursor as in Cursor.h */
83
MyBitmap def_read_set; /**< Default read set of columns */
84
MyBitmap def_write_set; /**< Default write set of columns */
85
MyBitmap tmp_set; /* Not sure about this... */
144
boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
145
boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
146
boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
87
148
Session *in_use; /**< Pointer to the current session using this object */
88
149
Session *getSession()
154
unsigned char *getInsertRecord()
159
unsigned char *getUpdateRecord()
93
164
unsigned char *record[2]; /**< Pointer to "records" */
94
unsigned char *insert_values; /* used by INSERT ... UPDATE */
95
KEY *key_info; /**< data of keys in database */
165
std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
166
KeyInfo *key_info; /**< data of keys in database */
96
167
Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
97
168
Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
98
Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
169
field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
100
171
TableList *pos_in_table_list; /* Element referring to this table */
102
const char *alias; /**< alias or table name if no alias */
174
const char *getAlias() const
176
return _alias.c_str();
184
void setAlias(const char *arg)
190
std::string _alias; /**< alias or table name if no alias */
103
193
unsigned char *null_flags;
105
195
uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
106
196
uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
107
197
uint32_t lock_count; /**< Number of locks */
108
198
uint32_t used_fields;
109
uint32_t status; /* What's in record[0] */
199
uint32_t status; /* What's in getInsertRecord() */
110
200
/* number of select if it is derived table */
111
201
uint32_t derived_select_number;
112
202
int current_lock; /**< Type of lock on table */
241
335
uint32_t quick_key_parts[MAX_KEY];
242
336
uint32_t quick_n_ranges[MAX_KEY];
244
339
memory::Root mem_root;
245
filesort_info_st sort;
343
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
346
memory::Root *getMemRoot()
348
if (not mem_root.alloc_root_inited())
356
void *alloc_root(size_t arg)
358
if (not mem_root.alloc_root_inited())
363
return mem_root.alloc_root(arg);
366
char *strmake_root(const char *str_arg, size_t len_arg)
368
if (not mem_root.alloc_root_inited())
373
return mem_root.strmake_root(str_arg, len_arg);
249
381
int report_error(int error);
251
383
* Free information allocated by openfrm
253
385
* @param If true if we also want to free table_share
386
* @note this should all be the destructor
255
int closefrm(bool free_share);
388
int delete_table(bool free_share= false);
257
390
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
259
392
/* SHARE methods */
260
inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
261
inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
262
inline uint32_t sizeKeys() { return s->keys; }
263
inline uint32_t sizeFields() { return s->fields; }
264
inline uint32_t getRecordLength() { return s->reclength; }
265
inline uint32_t sizeBlobFields() { return s->blob_fields; }
266
inline uint32_t *getBlobField() { return s->blob_field; }
267
inline uint32_t getNullBytes() { return s->null_bytes; }
268
inline uint32_t getNullFields() { return s->null_fields; }
269
inline unsigned char *getDefaultValues() { return s->default_values; }
271
inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
272
inline bool isNameLock() { return s->name_lock; }
273
inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
274
inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
393
virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
394
virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
395
virtual bool hasShare() const= 0; /* Get rid of this long term */
396
virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
398
virtual void release(void)= 0;
400
uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
401
uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
402
uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
403
uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
404
uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
407
virtual bool hasVariableWidth() const
409
return getShare()->hasVariableWidth(); // We should calculate this.
412
virtual void setVariableWidth(void);
414
Field_blob *getBlobFieldAt(uint32_t arg) const
416
if (arg < getShare()->blob_fields)
417
return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
421
inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
422
inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
423
inline uint32_t getNullFields() const { return getShare()->null_fields; }
424
inline unsigned char *getDefaultValues() { return getMutableShare()->getDefaultValues(); }
425
inline const char *getSchemaName() const { return getShare()->getSchemaName(); }
426
inline const char *getTableName() const { return getShare()->getTableName(); }
428
inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
429
inline bool isNameLock() const { return open_placeholder; }
276
431
uint32_t index_flags(uint32_t idx) const
278
return s->storage_engine->index_flags(s->key_info[idx].algorithm);
433
return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
281
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
436
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
283
return s->storage_engine;
438
return getShare()->storage_engine;
286
Cursor &getCursor() const /* table_type for handler */
441
Cursor &getCursor() const /* table_type for handler */
292
/* For TMP tables, should be pulled out as a class */
293
void updateCreateInfo(message::Table *table_proto);
294
void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
295
bool create_myisam_tmp_table(KEY *keyinfo,
296
MI_COLUMNDEF *start_recinfo,
297
MI_COLUMNDEF **recinfo,
299
void free_tmp_table(Session *session);
300
bool open_tmp_table();
301
447
size_t max_row_length(const unsigned char *data);
302
448
uint32_t find_shortest_key(const key_map *usable_keys);
303
449
bool compare_record(Field **ptr);
304
bool compare_record();
450
bool records_are_comparable();
451
bool compare_records();
305
452
/* TODO: the (re)storeRecord's may be able to be further condensed */
306
453
void storeRecord();
307
454
void storeRecordAsInsert();
500
624
friend std::ostream& operator<<(std::ostream& output, const Table &table)
503
output << table.getShare()->getSchemaName();
505
output << table.getShare()->getTableName();
507
output << table.getShare()->getTableTypeAsString();
626
if (table.getShare())
629
output << table.getShare()->getSchemaName();
631
output << table.getShare()->getTableName();
633
output << table.getShare()->getTableTypeAsString();
638
output << "Table:(has no share)";
510
641
return output; // for multiple << operators.
645
virtual bool isPlaceHolder(void) const
515
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
517
typedef struct st_foreign_key_info
656
* This class defines the information for foreign keys.
519
LEX_STRING *forein_id;
520
LEX_STRING *referenced_db;
521
LEX_STRING *referenced_table;
522
LEX_STRING *update_method;
523
LEX_STRING *delete_method;
524
LEX_STRING *referenced_key_name;
525
List<LEX_STRING> foreign_fields;
526
List<LEX_STRING> referenced_fields;
663
* This is the constructor with all properties set.
665
* @param[in] in_foreign_id The id of the foreign key
666
* @param[in] in_referenced_db The referenced database name of the foreign key
667
* @param[in] in_referenced_table The referenced table name of the foreign key
668
* @param[in] in_update_method The update method of the foreign key.
669
* @param[in] in_delete_method The delete method of the foreign key.
670
* @param[in] in_referenced_key_name The name of referenced key
671
* @param[in] in_foreign_fields The foreign fields
672
* @param[in] in_referenced_fields The referenced fields
674
ForeignKeyInfo(LEX_STRING *in_foreign_id,
675
LEX_STRING *in_referenced_db,
676
LEX_STRING *in_referenced_table,
677
LEX_STRING *in_update_method,
678
LEX_STRING *in_delete_method,
679
LEX_STRING *in_referenced_key_name,
680
List<LEX_STRING> in_foreign_fields,
681
List<LEX_STRING> in_referenced_fields)
683
foreign_id(in_foreign_id),
684
referenced_db(in_referenced_db),
685
referenced_table(in_referenced_table),
686
update_method(in_update_method),
687
delete_method(in_delete_method),
688
referenced_key_name(in_referenced_key_name),
689
foreign_fields(in_foreign_fields),
690
referenced_fields(in_referenced_fields)
695
* This is the default constructor. All properties are set to default values for their types.
698
: foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
699
update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
704
* Gets the foreign id.
706
* @ retval the foreign id
708
const LEX_STRING *getForeignId() const
715
* Gets the name of the referenced database.
717
* @ retval the name of the referenced database
719
const LEX_STRING *getReferencedDb() const
721
return referenced_db;
726
* Gets the name of the referenced table.
728
* @ retval the name of the referenced table
730
const LEX_STRING *getReferencedTable() const
732
return referenced_table;
737
* Gets the update method.
739
* @ retval the update method
741
const LEX_STRING *getUpdateMethod() const
743
return update_method;
748
* Gets the delete method.
750
* @ retval the delete method
752
const LEX_STRING *getDeleteMethod() const
754
return delete_method;
759
* Gets the name of the referenced key.
761
* @ retval the name of the referenced key
763
const LEX_STRING *getReferencedKeyName() const
765
return referenced_key_name;
770
* Gets the foreign fields.
772
* @ retval the foreign fields
774
const List<LEX_STRING> &getForeignFields() const
776
return foreign_fields;
781
* Gets the referenced fields.
783
* @ retval the referenced fields
785
const List<LEX_STRING> &getReferencedFields() const
787
return referenced_fields;
793
LEX_STRING *foreign_id;
795
* The name of the reference database.
797
LEX_STRING *referenced_db;
799
* The name of the reference table.
801
LEX_STRING *referenced_table;
805
LEX_STRING *update_method;
809
LEX_STRING *delete_method;
811
* The name of the referenced key.
813
LEX_STRING *referenced_key_name;
815
* The foreign fields.
817
List<LEX_STRING> foreign_fields;
819
* The referenced fields.
821
List<LEX_STRING> referenced_fields;
533
#define JOIN_TYPE_LEFT 1
534
#define JOIN_TYPE_RIGHT 2
826
#define JOIN_TYPE_LEFT 1
827
#define JOIN_TYPE_RIGHT 2
537
830
class select_union;
538
831
class Tmp_Table_Param;
540
struct open_table_list_st
547
open_table_list_st() :
554
TableShare *alloc_table_share(TableList *table_list, char *key,
555
uint32_t key_length);
556
int open_table_def(Session& session, TableIdentifier &identifier, TableShare *share);
557
void open_table_error(TableShare *share, int error, int db_errno, int errarg);
558
int open_table_from_share(Session *session, TableShare *share, const char *alias,
559
uint32_t db_stat, uint32_t ha_open_flags,
561
833
void free_blobs(Table *table);
562
834
int set_zone(int nr,int min_zone,int max_zone);
563
835
uint32_t convert_period_to_month(uint32_t period);
587
849
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
588
850
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
589
851
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
590
ulong next_io_size(ulong pos);
591
852
void append_unescaped(String *res, const char *pos, uint32_t length);
593
int rename_file_ext(const char * from,const char * to,const char * ext);
854
DRIZZLED_API int rename_file_ext(const char * from,const char * to,const char * ext);
594
855
bool check_column_name(const char *name);
595
bool check_db_name(SchemaIdentifier &schema);
856
bool check_db_name(Session *session, identifier::Schema &schema);
596
857
bool check_table_name(const char *name, uint32_t length);
598
859
} /* namespace drizzled */
861
#include "drizzled/table/singular.h"
862
#include "drizzled/table/concurrent.h"
600
864
#endif /* DRIZZLED_TABLE_H */