23
23
#ifndef DRIZZLED_TABLE_H
24
24
#define DRIZZLED_TABLE_H
26
#include <plugin/myisam/myisam.h>
27
#include <mysys/hash.h>
28
28
#include "drizzled/order.h"
29
29
#include "drizzled/filesort_info.h"
30
30
#include "drizzled/natural_join_column.h"
31
31
#include "drizzled/field_iterator.h"
32
#include "drizzled/cursor.h"
32
#include "drizzled/handler.h"
33
33
#include "drizzled/lex_string.h"
34
34
#include "drizzled/table_list.h"
35
35
#include "drizzled/table_share.h"
36
#include "drizzled/atomics.h"
37
#include "drizzled/query_id.h"
43
42
class Item_subselect;
44
43
class Select_Lex_Unit;
47
class SecurityContext;
46
class Security_context;
49
48
class Field_timestamp;
52
extern uint64_t refresh_version;
54
51
typedef enum enum_table_category TABLE_CATEGORY;
55
typedef struct st_columndef MI_COLUMNDEF;
57
53
bool create_myisam_from_heap(Session *session, Table *table,
58
54
MI_COLUMNDEF *start_recinfo,
78
74
MyBitmap *write_set; /* Active column sets */
81
uint32_t db_stat; /**< information about the cursor as in Cursor.h */
77
uint32_t db_stat; /**< information about the file as in handler.h */
83
79
MyBitmap def_read_set; /**< Default read set of columns */
84
80
MyBitmap def_write_set; /**< Default write set of columns */
85
81
MyBitmap tmp_set; /* Not sure about this... */
87
Session *in_use; /**< Pointer to the current session using this object */
83
Session *in_use; /**< Pointer to the current session using this object */
93
85
unsigned char *record[2]; /**< Pointer to "records" */
94
86
unsigned char *insert_values; /* used by INSERT ... UPDATE */
175
167
the same statement. A non-zero query_id is used to control which tables
176
168
in the list of pre-opened and locked tables are actually being used.
181
* Estimate of number of records that satisfy SARGable part of the table
182
* condition, or table->cursor->records if no SARGable condition could be
184
* This value is used by join optimizer as an estimate of number of records
185
* that will pass the table condition (condition that depends on fields of
186
* this table and constants)
173
Estimate of number of records that satisfy SARGable part of the table
174
condition, or table->file->records if no SARGable condition could be
176
This value is used by join optimizer as an estimate of number of records
177
that will pass the table condition (condition that depends on fields of
178
this table and constants)
188
180
ha_rows quick_condition_rows;
241
233
uint32_t quick_key_parts[MAX_KEY];
242
234
uint32_t quick_n_ranges[MAX_KEY];
244
memory::Root mem_root;
245
237
filesort_info_st sort;
252
next_number_field(NULL),
253
found_next_number_field(NULL),
254
timestamp_field(NULL),
255
pos_in_table_list(NULL),
264
derived_select_number(0),
265
current_lock(F_UNLCK),
275
open_placeholder(false),
276
locked_by_name(false),
278
auto_increment_field_not_null(false),
279
alias_name_used(false),
281
quick_condition_rows(0),
282
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
285
record[0]= (unsigned char *) 0;
286
record[1]= (unsigned char *) 0;
288
covering_keys.reset();
293
keys_in_use_for_query.reset();
294
keys_in_use_for_group_by.reset();
295
keys_in_use_for_order_by.reset();
297
memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
298
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
300
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
301
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
303
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
304
memset(&sort, 0, sizeof(filesort_info_st));
249
307
int report_error(int error);
251
* Free information allocated by openfrm
253
* @param If true if we also want to free table_share
255
308
int closefrm(bool free_share);
257
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
310
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg)
323
db_stat= db_stat_arg;
326
record[0]= (unsigned char *) 0;
327
record[1]= (unsigned char *) 0;
331
next_number_field= NULL;
332
found_next_number_field= NULL;
333
timestamp_field= NULL;
335
pos_in_table_list= NULL;
345
derived_select_number= 0;
346
current_lock= F_UNLCK;
360
open_placeholder= false;
361
locked_by_name= false;
364
auto_increment_field_not_null= false;
365
alias_name_used= false;
368
quick_condition_rows= 0;
370
timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
375
covering_keys.reset();
380
keys_in_use_for_query.reset();
381
keys_in_use_for_group_by.reset();
382
keys_in_use_for_order_by.reset();
384
memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
385
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
387
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
388
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
390
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
391
memset(&sort, 0, sizeof(filesort_info_st));
259
394
/* SHARE methods */
260
inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
395
inline TableShare *getShare() { return s; } /* Get rid of this long term */
261
396
inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
262
397
inline uint32_t sizeKeys() { return s->keys; }
263
398
inline uint32_t sizeFields() { return s->fields; }
269
404
inline unsigned char *getDefaultValues() { return s->default_values; }
271
406
inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
407
inline bool isCrashed() { return s->crashed; }
272
408
inline bool isNameLock() { return s->name_lock; }
273
409
inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
274
410
inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
276
uint32_t index_flags(uint32_t idx) const
278
return s->storage_engine->index_flags(s->key_info[idx].algorithm);
281
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
283
return s->storage_engine;
286
Cursor &getCursor() const /* table_type for handler */
292
412
/* For TMP tables, should be pulled out as a class */
293
void updateCreateInfo(message::Table *table_proto);
413
void updateCreateInfo(HA_CREATE_INFO *create_info,
414
drizzled::message::Table *table_proto);
294
415
void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
295
416
bool create_myisam_tmp_table(KEY *keyinfo,
296
417
MI_COLUMNDEF *start_recinfo,
313
434
/* See if this can be blown away */
314
435
inline uint32_t getDBStat () { return db_stat; }
315
436
inline uint32_t setDBStat () { return db_stat; }
317
* Create Item_field for each column in the table.
319
* @param[out] a pointer to an empty list used to store items
323
* Create Item_field object for each column in the table and
324
* initialize it with the corresponding Field. New items are
325
* created in the current Session memory root.
330
* true when out of memory
332
437
bool fill_item_list(List<Item> *item_list) const;
333
438
void clear_column_bitmaps(void);
334
439
void prepare_for_position(void);
440
537
memset(null_flags, 255, s->null_bytes);
443
bool renameAlterTemporaryTable(TableIdentifier &identifier);
540
bool rename_temporary_table(const char *db, const char *table_name);
444
541
void free_io_cache();
445
542
void filesort_free_buffers(bool full= false);
446
543
void intern_close_table();
448
void print_error(int error, myf errflag)
450
s->storage_engine->print_error(error, errflag, *this);
455
key if error because of duplicated keys
457
uint32_t get_dup_key(int error)
459
cursor->errkey = (uint32_t) -1;
460
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
461
error == HA_ERR_FOUND_DUPP_UNIQUE ||
462
error == HA_ERR_DROP_INDEX_FK)
463
cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
465
return(cursor->errkey);
469
This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
471
bool operator<(const Table &right) const
473
int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
481
result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
489
if (this->getShare()->getTableProto()->type() < right.getShare()->getTableProto()->type())
495
static bool compare(const Table *a, const Table *b)
500
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();
510
return output; // for multiple << operators.
515
546
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
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
void free_blobs(Table *table);
562
int set_zone(int nr,int min_zone,int max_zone);
563
uint32_t convert_period_to_month(uint32_t period);
564
uint32_t convert_month_to_period(uint32_t month);
566
int test_if_number(char *str,int *res,bool allow_wildcards);
567
void change_byte(unsigned char *,uint,char,char);
569
namespace optimizer { class SqlSelect; }
571
ha_rows filesort(Session *session,
573
st_sort_field *sortorder,
575
optimizer::SqlSelect *select,
578
ha_rows *examined_rows);
580
void filesort_free_buffers(Table *table, bool full);
581
void change_double_for_sort(double nr,unsigned char *to);
582
double my_double_round(double value, int64_t dec, bool dec_unsigned,
584
int get_quick_record(optimizer::SqlSelect *select);
586
void find_date(char *pos,uint32_t *vek,uint32_t flag);
587
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
588
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
589
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
590
ulong next_io_size(ulong pos);
591
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);
594
bool check_column_name(const char *name);
595
bool check_db_name(SchemaIdentifier &schema);
596
bool check_table_name(const char *name, uint32_t length);
598
} /* namespace drizzled */
600
592
#endif /* DRIZZLED_TABLE_H */