54
57
typedef enum enum_table_category TABLE_CATEGORY;
55
58
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
61
* Class representing a set of records, either in a temporary,
64
62
* normal, or derived table.
70
TableShare *s; /**< Pointer to the shared metadata about the table */
71
66
Field **field; /**< Pointer to fields collection */
69
Field **getFields() const
74
Field *getField(uint32_t arg) const
79
void setFields(Field **arg)
84
void setFieldAt(Field *arg, uint32_t arg_pos)
73
89
Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
93
Table *getNext() const
103
void setNext(Table *arg)
110
getNext()->setPrev(getPrev()); /* remove from used chain */
111
getPrev()->setNext(getNext());
77
MyBitmap *read_set; /* Active column sets */
78
MyBitmap *write_set; /* Active column sets */
117
Table *getPrev() const
127
void setPrev(Table *arg)
132
boost::dynamic_bitset<> *read_set; /* Active column sets */
133
boost::dynamic_bitset<> *write_set; /* Active column sets */
81
136
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... */
138
boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
139
boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
140
boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
87
142
Session *in_use; /**< Pointer to the current session using this object */
88
143
Session *getSession()
148
unsigned char *getInsertRecord()
153
unsigned char *getUpdateRecord()
93
158
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 */
159
std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
160
KeyInfo *key_info; /**< data of keys in database */
96
161
Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
97
162
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 */
163
field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
100
165
TableList *pos_in_table_list; /* Element referring to this table */
102
const char *alias; /**< alias or table name if no alias */
168
const char *getAlias() const
170
return _alias.c_str();
178
void setAlias(const char *arg)
184
std::string _alias; /**< alias or table name if no alias */
103
187
unsigned char *null_flags;
105
189
uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
106
190
uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
107
191
uint32_t lock_count; /**< Number of locks */
108
192
uint32_t used_fields;
109
uint32_t status; /* What's in record[0] */
193
uint32_t status; /* What's in getInsertRecord() */
110
194
/* number of select if it is derived table */
111
195
uint32_t derived_select_number;
112
196
int current_lock; /**< Type of lock on table */
241
327
uint32_t quick_key_parts[MAX_KEY];
242
328
uint32_t quick_n_ranges[MAX_KEY];
244
331
memory::Root mem_root;
245
filesort_info_st sort;
335
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
338
memory::Root *getMemRoot()
340
if (not mem_root.alloc_root_inited())
348
void *alloc_root(size_t arg)
350
if (not mem_root.alloc_root_inited())
355
return mem_root.alloc_root(arg);
358
char *strmake_root(const char *str_arg, size_t len_arg)
360
if (not mem_root.alloc_root_inited())
365
return mem_root.strmake_root(str_arg, len_arg);
249
373
int report_error(int error);
251
375
* Free information allocated by openfrm
253
377
* @param If true if we also want to free table_share
378
* @note this should all be the destructor
255
int closefrm(bool free_share);
380
int delete_table(bool free_share= false);
257
382
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
259
384
/* 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 */
385
virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
386
virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
387
virtual bool hasShare() const= 0; /* Get rid of this long term */
388
virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
390
virtual void release(void)= 0;
392
uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
393
uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
394
uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
395
uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
396
uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
399
virtual bool hasVariableWidth() const
401
return getShare()->hasVariableWidth(); // We should calculate this.
404
virtual void setVariableWidth(void);
406
Field_blob *getBlobFieldAt(uint32_t arg) const
408
if (arg < getShare()->blob_fields)
409
return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
413
inline uint8_t getBlobPtrSize() { return getShare()->blob_ptr_size; }
414
inline uint32_t getNullBytes() { return getShare()->null_bytes; }
415
inline uint32_t getNullFields() { return getShare()->null_fields; }
416
inline unsigned char *getDefaultValues() { return getMutableShare()->getDefaultValues(); }
417
inline const char *getSchemaName() const { return getShare()->getSchemaName(); }
418
inline const char *getTableName() const { return getShare()->getTableName(); }
420
inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
421
inline bool isNameLock() const { return open_placeholder; }
276
423
uint32_t index_flags(uint32_t idx) const
278
return s->storage_engine->index_flags(s->key_info[idx].algorithm);
425
return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
281
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
428
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
283
return s->storage_engine;
430
return getShare()->storage_engine;
286
Cursor &getCursor() const /* table_type for handler */
433
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
439
size_t max_row_length(const unsigned char *data);
302
440
uint32_t find_shortest_key(const key_map *usable_keys);
303
441
bool compare_record(Field **ptr);
304
bool compare_record();
442
bool records_are_comparable();
443
bool compare_records();
305
444
/* TODO: the (re)storeRecord's may be able to be further condensed */
306
445
void storeRecord();
307
446
void storeRecordAsInsert();
500
616
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();
618
if (table.getShare())
621
output << table.getShare()->getSchemaName();
623
output << table.getShare()->getTableName();
625
output << table.getShare()->getTableTypeAsString();
630
output << "Table:(has no share)";
510
633
return output; // for multiple << operators.
637
virtual bool isPlaceHolder(void) const
515
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
517
typedef struct st_foreign_key_info
648
* 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;
655
* This is the constructor with all properties set.
657
* @param[in] in_foreign_id The id of the foreign key
658
* @param[in] in_referenced_db The referenced database name of the foreign key
659
* @param[in] in_referenced_table The referenced table name of the foreign key
660
* @param[in] in_update_method The update method of the foreign key.
661
* @param[in] in_delete_method The delete method of the foreign key.
662
* @param[in] in_referenced_key_name The name of referenced key
663
* @param[in] in_foreign_fields The foreign fields
664
* @param[in] in_referenced_fields The referenced fields
666
ForeignKeyInfo(LEX_STRING *in_foreign_id,
667
LEX_STRING *in_referenced_db,
668
LEX_STRING *in_referenced_table,
669
LEX_STRING *in_update_method,
670
LEX_STRING *in_delete_method,
671
LEX_STRING *in_referenced_key_name,
672
List<LEX_STRING> in_foreign_fields,
673
List<LEX_STRING> in_referenced_fields)
675
foreign_id(in_foreign_id),
676
referenced_db(in_referenced_db),
677
referenced_table(in_referenced_table),
678
update_method(in_update_method),
679
delete_method(in_delete_method),
680
referenced_key_name(in_referenced_key_name),
681
foreign_fields(in_foreign_fields),
682
referenced_fields(in_referenced_fields)
687
* This is the default constructor. All properties are set to default values for their types.
690
: foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
691
update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
696
* Gets the foreign id.
698
* @ retval the foreign id
700
const LEX_STRING *getForeignId() const
707
* Gets the name of the referenced database.
709
* @ retval the name of the referenced database
711
const LEX_STRING *getReferencedDb() const
713
return referenced_db;
718
* Gets the name of the referenced table.
720
* @ retval the name of the referenced table
722
const LEX_STRING *getReferencedTable() const
724
return referenced_table;
729
* Gets the update method.
731
* @ retval the update method
733
const LEX_STRING *getUpdateMethod() const
735
return update_method;
740
* Gets the delete method.
742
* @ retval the delete method
744
const LEX_STRING *getDeleteMethod() const
746
return delete_method;
751
* Gets the name of the referenced key.
753
* @ retval the name of the referenced key
755
const LEX_STRING *getReferencedKeyName() const
757
return referenced_key_name;
762
* Gets the foreign fields.
764
* @ retval the foreign fields
766
const List<LEX_STRING> &getForeignFields() const
768
return foreign_fields;
773
* Gets the referenced fields.
775
* @ retval the referenced fields
777
const List<LEX_STRING> &getReferencedFields() const
779
return referenced_fields;
785
LEX_STRING *foreign_id;
787
* The name of the reference database.
789
LEX_STRING *referenced_db;
791
* The name of the reference table.
793
LEX_STRING *referenced_table;
797
LEX_STRING *update_method;
801
LEX_STRING *delete_method;
803
* The name of the referenced key.
805
LEX_STRING *referenced_key_name;
807
* The foreign fields.
809
List<LEX_STRING> foreign_fields;
811
* The referenced fields.
813
List<LEX_STRING> referenced_fields;
533
#define JOIN_TYPE_LEFT 1
534
#define JOIN_TYPE_RIGHT 2
818
#define JOIN_TYPE_LEFT 1
819
#define JOIN_TYPE_RIGHT 2
537
822
class select_union;
538
823
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
825
void free_blobs(Table *table);
562
826
int set_zone(int nr,int min_zone,int max_zone);
563
827
uint32_t convert_period_to_month(uint32_t period);
587
841
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
588
842
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
589
843
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
590
ulong next_io_size(ulong pos);
591
844
void append_unescaped(String *res, const char *pos, uint32_t length);
593
846
int rename_file_ext(const char * from,const char * to,const char * ext);
594
847
bool check_column_name(const char *name);
595
bool check_db_name(SchemaIdentifier &schema);
848
bool check_db_name(Session *session, identifier::Schema &schema);
596
849
bool check_table_name(const char *name, uint32_t length);
598
851
} /* namespace drizzled */
853
#include "drizzled/table/singular.h"
854
#include "drizzled/table/concurrent.h"
600
856
#endif /* DRIZZLED_TABLE_H */