1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
17
/* Structs that defines the Table */
23
19
#ifndef DRIZZLED_TABLE_H
24
20
#define DRIZZLED_TABLE_H
27
#include <boost/dynamic_bitset.hpp>
29
#include "drizzled/order.h"
30
#include "drizzled/filesort_info.h"
31
#include "drizzled/natural_join_column.h"
32
#include "drizzled/field_iterator.h"
33
#include "drizzled/cursor.h"
34
#include "drizzled/lex_string.h"
35
#include "drizzled/table_list.h"
36
#include "drizzled/definition/table.h"
37
#include "drizzled/atomics.h"
38
#include "drizzled/query_id.h"
22
#include <storage/myisam/myisam.h>
23
#include <drizzled/order.h>
24
#include <drizzled/filesort_info.h>
25
#include <drizzled/natural_join_column.h>
26
#include <drizzled/nested_join.h>
27
#include <drizzled/field_iterator.h>
29
class Item; /* Needed by order_st */
44
30
class Item_subselect;
45
class Select_Lex_Unit;
31
class st_select_lex_unit;
48
class SecurityContext;
34
class Security_context;
37
/*************************************************************************/
41
NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
42
INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE, TMP_TABLE_FRM_FILE_ONLY
45
bool mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
48
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
51
Values in this enum are used to indicate how a tables TIMESTAMP field
52
should be treated. It can be set to the current timestamp on insert or
54
WARNING: The values are used for bit operations. If you change the
55
enum, you must keep the bitwise relation of the values. For example:
56
(int) TIMESTAMP_AUTO_SET_ON_BOTH must be equal to
57
(int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE.
58
We use an enum here so that the debugger can display the value names.
60
enum timestamp_auto_set_type
62
TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1,
63
TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3
65
#define clear_timestamp_auto_bits(_target_, _bits_) \
66
(_target_)= (enum timestamp_auto_set_type)((int)(_target_) & ~(int)(_bits_))
50
68
class Field_timestamp;
53
extern uint64_t refresh_version;
72
Category of table found in the table share.
74
enum enum_table_category
79
TABLE_UNKNOWN_CATEGORY=0,
83
The table is visible only in the session.
85
- FLUSH TABLES WITH READ LOCK
86
- SET GLOBAL READ_ONLY = ON
87
do not apply to this table.
88
Note that LOCK Table t FOR READ/WRITE
89
can be used on temporary tables.
90
Temporary tables are not part of the table cache.
92
TABLE_CATEGORY_TEMPORARY=1,
96
These tables do honor:
97
- LOCK Table t FOR READ/WRITE
98
- FLUSH TABLES WITH READ LOCK
99
- SET GLOBAL READ_ONLY = ON
100
User tables are cached in the table cache.
102
TABLE_CATEGORY_USER=2,
105
Information schema tables.
106
These tables are an interface provided by the system
107
to inspect the system metadata.
108
These tables do *not* honor:
109
- LOCK Table t FOR READ/WRITE
110
- FLUSH TABLES WITH READ LOCK
111
- SET GLOBAL READ_ONLY = ON
112
as there is no point in locking explicitely
113
an INFORMATION_SCHEMA table.
114
Nothing is directly written to information schema tables.
115
Note that this value is not used currently,
116
since information schema tables are not shared,
117
but implemented as session specific temporary tables.
120
TODO: Fixing the performance issues of I_S will lead
121
to I_S tables in the table cache, which should use
124
TABLE_CATEGORY_INFORMATION
55
126
typedef enum enum_table_category TABLE_CATEGORY;
56
typedef struct st_columndef MI_COLUMNDEF;
59
* Class representing a set of records, either in a temporary,
60
* normal, or derived table.
64
Field **field; /**< Pointer to fields collection */
67
Field **getFields() const
72
Field *getField(uint32_t arg) const
77
void setFields(Field **arg)
82
void setFieldAt(Field *arg, uint32_t arg_pos)
87
Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
91
Table *getNext() const
101
void setNext(Table *arg)
108
getNext()->setPrev(getPrev()); /* remove from used chain */
109
getPrev()->setNext(getNext());
115
Table *getPrev() const
125
void setPrev(Table *arg)
130
boost::dynamic_bitset<> *read_set; /* Active column sets */
131
boost::dynamic_bitset<> *write_set; /* Active column sets */
134
uint32_t db_stat; /**< information about the cursor as in Cursor.h */
136
boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
137
boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
138
boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
140
Session *in_use; /**< Pointer to the current session using this object */
141
Session *getSession()
146
unsigned char *getInsertRecord()
151
unsigned char *getUpdateRecord()
156
unsigned char *record[2]; /**< Pointer to "records" */
157
std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
158
KeyInfo *key_info; /**< data of keys in database */
159
Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
160
Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
161
Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
163
TableList *pos_in_table_list; /* Element referring to this table */
166
const char *getAlias() const
168
return _alias.c_str();
176
void setAlias(const char *arg)
182
std::string _alias; /**< alias or table name if no alias */
185
unsigned char *null_flags;
187
uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
188
uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
189
uint32_t lock_count; /**< Number of locks */
190
uint32_t used_fields;
191
uint32_t status; /* What's in getInsertRecord() */
128
TABLE_CATEGORY get_table_category(const LEX_STRING *db,
129
const LEX_STRING *name);
132
This structure is shared between different table objects. There is one
133
instance of table share per one table in the database.
136
typedef struct st_table_share
138
st_table_share() {} /* Remove gcc warning */
140
/** Category of this table. */
141
TABLE_CATEGORY table_category;
143
/* hash of field names (contains pointers to elements of field array) */
144
HASH name_hash; /* hash of field names */
146
TYPELIB keynames; /* Pointers to keynames */
147
TYPELIB fieldnames; /* Pointer to fieldnames */
148
TYPELIB *intervals; /* pointer to interval info */
149
pthread_mutex_t mutex; /* For locking the share */
150
pthread_cond_t cond; /* To signal that share is ready */
151
struct st_table_share *next, /* Link to unused shares */
154
/* The following is copied to each Table on OPEN */
156
Field **found_next_number_field;
157
Field *timestamp_field; /* Used only during open */
158
KEY *key_info; /* data of keys in database */
159
uint *blob_field; /* Index to blobs in Field arrray*/
161
uchar *default_values; /* row with default values */
162
LEX_STRING comment; /* Comment about table */
163
const CHARSET_INFO *table_charset; /* Default charset of string fields */
167
Key which is used for looking-up table in table cache and in the list
168
of thread's temporary tables. Has the form of:
169
"database_name\0table_name\0" + optional part for temporary tables.
171
Note that all three 'table_cache_key', 'db' and 'table_name' members
172
must be set (and be non-zero) for tables in table cache. They also
173
should correspond to each other.
174
To ensure this one can use set_table_cache() methods.
176
LEX_STRING table_cache_key;
177
LEX_STRING db; /* Pointer to db */
178
LEX_STRING table_name; /* Table name (for open) */
179
LEX_STRING path; /* Path to .frm file (from datadir) */
180
LEX_STRING normalized_path; /* unpack_filename(path) */
181
LEX_STRING connect_string;
184
Set of keys in use, implemented as a Bitmap.
185
Excludes keys disabled by ALTER Table ... DISABLE KEYS.
188
key_map keys_for_keyread;
189
ha_rows min_rows, max_rows; /* create information */
190
uint32_t avg_row_length; /* create information */
191
uint32_t block_size; /* create information */
192
uint32_t version, mysql_version;
193
uint32_t timestamp_offset; /* Set to offset+1 of record */
194
uint32_t reclength; /* Recordlength */
196
plugin_ref db_plugin; /* storage engine plugin */
197
inline handlerton *db_type() const /* table_type for handler */
199
// assert(db_plugin);
200
return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
202
enum row_type row_type; /* How rows are stored */
203
enum tmp_table_type tmp_table;
204
enum ha_choice transactional;
205
enum ha_choice page_checksum;
207
uint ref_count; /* How many Table objects uses this */
208
uint open_count; /* Number of tables in open list */
209
uint blob_ptr_size; /* 4 or 8 */
210
uint key_block_size; /* create key_block_size, if used */
211
uint null_bytes, last_null_bit_pos;
212
uint fields; /* Number of fields */
213
uint rec_buff_length; /* Size of table->record[] buffer */
214
uint keys, key_parts;
215
uint max_key_length, max_unique_length, total_key_length;
216
uint uniques; /* Number of UNIQUE index */
217
uint null_fields; /* number of null fields */
218
uint blob_fields; /* number of blob fields */
219
uint timestamp_field_offset; /* Field number for timestamp field */
220
uint varchar_fields; /* number of varchar fields */
221
uint db_create_options; /* Create options from database */
222
uint db_options_in_use; /* Options in use */
223
uint db_record_offset; /* if HA_REC_IN_SEQ */
224
uint rowid_field_offset; /* Field_nr +1 to rowid field */
225
/* Index of auto-updated TIMESTAMP field in field array */
227
uint next_number_index; /* autoincrement key number */
228
uint next_number_key_offset; /* autoinc keypart offset in a key */
229
uint next_number_keypart; /* autoinc keypart number in a key */
230
uint error, open_errno, errarg; /* error from open_table_def() */
231
uint column_bitmap_size;
233
bool null_field_first;
234
bool db_low_byte_first; /* Portable row format */
236
bool name_lock, replace_with_name_lock;
237
bool waiting_on_cond; /* Protection against free */
238
uint32_t table_map_id; /* for row-based replication */
239
uint64_t table_map_version;
242
Cache for row-based replication table share checks that does not
243
need to be repeated. Possible values are: -1 when cache value is
244
not calculated yet, 0 when table *shall not* be replicated, 1 when
245
table *may* be replicated.
247
int cached_row_logging_check;
250
Set share's table cache key and update its db and table name appropriately.
253
set_table_cache_key()
254
key_buff Buffer with already built table cache key to be
255
referenced from share.
256
key_length Key length.
259
Since 'key_buff' buffer will be referenced from share it should has same
260
life-time as share itself.
261
This method automatically ensures that TABLE_SHARE::table_name/db have
262
appropriate values by using table cache key as their source.
265
void set_table_cache_key(char *key_buff, uint key_length)
267
table_cache_key.str= key_buff;
268
table_cache_key.length= key_length;
270
Let us use the fact that the key is "db/0/table_name/0" + optional
271
part for temporary tables.
273
db.str= table_cache_key.str;
274
db.length= strlen(db.str);
275
table_name.str= db.str + db.length + 1;
276
table_name.length= strlen(table_name.str);
281
Set share's table cache key and update its db and table name appropriately.
284
set_table_cache_key()
285
key_buff Buffer to be used as storage for table cache key
286
(should be at least key_length bytes).
287
key Value for table cache key.
288
key_length Key length.
291
Since 'key_buff' buffer will be used as storage for table cache key
292
it should has same life-time as share itself.
295
void set_table_cache_key(char *key_buff, const char *key, uint key_length)
297
memcpy(key_buff, key, key_length);
298
set_table_cache_key(key_buff, key_length);
301
inline bool honor_global_locks()
303
return (table_category == TABLE_CATEGORY_USER);
306
inline uint32_t get_table_def_version()
314
extern uint32_t refresh_version;
316
/* Information for one open table */
324
typedef struct st_table_field_w_type
329
} TABLE_FIELD_W_TYPE;
331
bool create_myisam_from_heap(THD *thd, Table *table,
332
MI_COLUMNDEF *start_recinfo,
333
MI_COLUMNDEF **recinfo,
334
int error, bool ignore_last_dupp_key_error);
340
Table() {} /* Remove gcc warning */
343
inline TABLE_SHARE *getShare() { return s; } /* Get rid of this long term */
344
inline void setShare(TABLE_SHARE *new_share) { s= new_share; } /* Get rid of this long term */
345
inline uint sizeKeys() { return s->keys; }
346
inline uint sizeFields() { return s->fields; }
347
inline uint getRecordLength() { return s->reclength; }
348
inline uint sizeBlobFields() { return s->blob_fields; }
349
inline uint *getBlobField() { return s->blob_field; }
350
inline uint getNullBytes() { return s->null_bytes; }
351
inline uint getNullFields() { return s->null_fields; }
352
inline unsigned char *getDefaultValues() { return s->default_values; }
354
inline bool isNullFieldFirst() { return s->null_field_first; }
355
inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
356
inline bool isCrashed() { return s->crashed; }
357
inline bool isNameLock() { return s->name_lock; }
358
inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
359
inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
361
/* For TMP tables, should be pulled out as a class */
362
void updateCreateInfo(HA_CREATE_INFO *create_info);
363
void setup_tmp_table_column_bitmaps(uchar *bitmaps);
364
bool create_myisam_tmp_table(KEY *keyinfo,
365
MI_COLUMNDEF *start_recinfo,
366
MI_COLUMNDEF **recinfo,
368
void free_tmp_table(THD *thd);
369
bool open_tmp_table();
370
size_t max_row_length(const uchar *data);
371
uint find_shortest_key(const key_map *usable_keys);
372
bool compare_record(Field **ptr);
373
bool compare_record();
375
bool table_check_intact(const uint table_f_count, const TABLE_FIELD_W_TYPE *table_def);
377
/* See if this can be blown away */
378
inline uint getDBStat () { return db_stat; }
379
inline uint setDBStat () { return db_stat; }
380
uint db_stat; /* mode of file as in handler.h */
385
THD *in_use; /* Which thread uses this */
386
Field **field; /* Pointer to fields */
388
uchar *record[2]; /* Pointer to records */
389
uchar *write_row_record; /* Used as optimisation in
391
uchar *insert_values; /* used by INSERT ... UPDATE */
393
Map of keys that can be used to retrieve all data from this table
394
needed by the query without reading the row.
396
key_map covering_keys;
397
key_map quick_keys, merge_keys;
399
A set of keys that can be used in the query that references this
402
All indexes disabled on the table's TABLE_SHARE (see Table::s) will be
403
subtracted from this set upon instantiation. Thus for any Table t it holds
404
that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
405
must not introduce any new keys here (see setup_tables).
407
The set is implemented as a bitmap.
409
key_map keys_in_use_for_query;
410
/* Map of keys that can be used to calculate GROUP BY without sorting */
411
key_map keys_in_use_for_group_by;
412
/* Map of keys that can be used to calculate ORDER BY without sorting */
413
key_map keys_in_use_for_order_by;
414
KEY *key_info; /* data of keys in database */
416
Field *next_number_field; /* Set if next_number is activated */
417
Field *found_next_number_field; /* Set on open */
418
Field_timestamp *timestamp_field;
420
TableList *pos_in_table_list;/* Element referring to this table */
422
const char *alias; /* alias or table name */
424
my_bitmap_map *bitmap_init_value;
425
MY_BITMAP def_read_set, def_write_set, tmp_set; /* containers */
426
MY_BITMAP *read_set, *write_set; /* Active column sets */
428
The ID of the query that opened and is using this table. Has different
429
meanings depending on the table type.
433
table->query_id is set to thd->query_id for the duration of a statement
434
and is reset to 0 once it is closed by the same statement. A non-zero
435
table->query_id means that a statement is using the table even if it's
436
not the current statement (table is in use by some outer statement).
438
Non-temporary tables:
440
Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
441
for the duration of a statement and is reset to 0 once it is closed by
442
the same statement. A non-zero query_id is used to control which tables
443
in the list of pre-opened and locked tables are actually being used.
448
For each key that has quick_keys.is_set(key) == true: estimate of #records
449
and max #key parts that range access would use.
451
ha_rows quick_rows[MAX_KEY];
453
/* Bitmaps of key parts that =const for the entire join. */
454
key_part_map const_key_parts[MAX_KEY];
456
uint quick_key_parts[MAX_KEY];
457
uint quick_n_ranges[MAX_KEY];
460
Estimate of number of records that satisfy SARGable part of the table
461
condition, or table->file->records if no SARGable condition could be
463
This value is used by join optimizer as an estimate of number of records
464
that will pass the table condition (condition that depends on fields of
465
this table and constants)
467
ha_rows quick_condition_rows;
470
If this table has TIMESTAMP field with auto-set property (pointed by
471
timestamp_field member) then this variable indicates during which
472
operations (insert only/on update/in both cases) we should set this
473
field to current timestamp. If there are no such field in this table
474
or we should not automatically set its value during execution of current
475
statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
477
Value of this variable is set for each statement in open_table() and
478
if needed cleared later in statement processing code (see mysql_update()
481
timestamp_auto_set_type timestamp_field_type;
482
table_map map; /* ID bit of table (1,2,4,8,16...) */
484
uint lock_position; /* Position in DRIZZLE_LOCK.table */
485
uint lock_data_start; /* Start pos. in DRIZZLE_LOCK.locks */
486
uint lock_count; /* Number of locks */
487
uint tablenr,used_fields;
488
uint temp_pool_slot; /* Used by intern temp tables */
489
uint status; /* What's in record[0] */
192
490
/* number of select if it is derived table */
193
uint32_t derived_select_number;
194
int current_lock; /**< Type of lock on table */
195
bool copy_blobs; /**< Should blobs by copied when storing? */
491
uint derived_select_number;
492
int current_lock; /* Type of lock on table */
493
bool copy_blobs; /* copy_blobs when storing */
198
496
0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
226
521
- setting version to 0 - this will force other threads to close
227
522
the instance of this table and wait (this is the same approach
228
523
as used for usual name locks).
229
An exclusively name-locked table currently can have no Cursor
524
An exclusively name-locked table currently can have no handler
230
525
object associated with it (db_stat is always 0), but please do
231
526
not rely on that.
233
528
bool open_placeholder;
529
bool locked_by_logger;
234
531
bool locked_by_name;
533
/* To signal that the table is associated with a HANDLER statement */
534
bool open_by_handler;
237
536
To indicate that a non-null value of the auto_increment field
238
537
was provided by the user or retrieved from the current record.
239
538
Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
241
540
bool auto_increment_field_not_null;
242
bool alias_name_used; /* true if table_name is alias */
245
The ID of the query that opened and is using this table. Has different
246
meanings depending on the table type.
250
table->query_id is set to session->query_id for the duration of a statement
251
and is reset to 0 once it is closed by the same statement. A non-zero
252
table->query_id means that a statement is using the table even if it's
253
not the current statement (table is in use by some outer statement).
255
Non-temporary tables:
257
Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
258
for the duration of a statement and is reset to 0 once it is closed by
259
the same statement. A non-zero query_id is used to control which tables
260
in the list of pre-opened and locked tables are actually being used.
265
* Estimate of number of records that satisfy SARGable part of the table
266
* condition, or table->cursor->records if no SARGable condition could be
268
* This value is used by join optimizer as an estimate of number of records
269
* that will pass the table condition (condition that depends on fields of
270
* this table and constants)
272
ha_rows quick_condition_rows;
275
If this table has TIMESTAMP field with auto-set property (pointed by
276
timestamp_field member) then this variable indicates during which
277
operations (insert only/on update/in both cases) we should set this
278
field to current timestamp. If there are no such field in this table
279
or we should not automatically set its value during execution of current
280
statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
282
Value of this variable is set for each statement in open_table() and
283
if needed cleared later in statement processing code (see mysql_update()
286
timestamp_auto_set_type timestamp_field_type;
287
table_map map; ///< ID bit of table (1,2,4,8,16...)
289
RegInfo reginfo; /* field connections */
292
Map of keys that can be used to retrieve all data from this table
293
needed by the query without reading the row.
295
key_map covering_keys;
300
A set of keys that can be used in the query that references this
303
All indexes disabled on the table's TableShare (see Table::s) will be
304
subtracted from this set upon instantiation. Thus for any Table t it holds
305
that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
306
must not introduce any new keys here (see setup_tables).
308
The set is implemented as a bitmap.
310
key_map keys_in_use_for_query;
311
/* Map of keys that can be used to calculate GROUP BY without sorting */
312
key_map keys_in_use_for_group_by;
313
/* Map of keys that can be used to calculate ORDER BY without sorting */
314
key_map keys_in_use_for_order_by;
317
For each key that has quick_keys.test(key) == true: estimate of #records
318
and max #key parts that range access would use.
320
ha_rows quick_rows[MAX_KEY];
322
/* Bitmaps of key parts that =const for the entire join. */
323
key_part_map const_key_parts[MAX_KEY];
325
uint32_t quick_key_parts[MAX_KEY];
326
uint32_t quick_n_ranges[MAX_KEY];
329
memory::Root mem_root;
333
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
336
memory::Root *getMemRoot()
338
if (not mem_root.alloc_root_inited())
346
void *alloc_root(size_t arg)
348
if (not mem_root.alloc_root_inited())
353
return mem_root.alloc_root(arg);
356
char *strmake_root(const char *str_arg, size_t len_arg)
358
if (not mem_root.alloc_root_inited())
363
return mem_root.strmake_root(str_arg, len_arg);
371
int report_error(int error);
373
* Free information allocated by openfrm
375
* @param If true if we also want to free table_share
376
* @note this should all be the destructor
378
int delete_table(bool free_share= false);
380
void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
383
virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
384
virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
385
virtual bool hasShare() const= 0; /* Get rid of this long term */
386
virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
388
virtual void release(void)= 0;
390
uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
391
uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
392
uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
393
uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
394
uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
397
virtual bool hasVariableWidth() const
399
return getShare()->hasVariableWidth(); // We should calculate this.
402
virtual void setVariableWidth(void);
404
Field_blob *getBlobFieldAt(uint32_t arg) const
406
if (arg < getShare()->blob_fields)
407
return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
411
inline uint8_t getBlobPtrSize() { return getShare()->blob_ptr_size; }
412
inline uint32_t getNullBytes() { return getShare()->null_bytes; }
413
inline uint32_t getNullFields() { return getShare()->null_fields; }
414
inline unsigned char *getDefaultValues() { return getMutableShare()->getDefaultValues(); }
415
inline const char *getSchemaName() const { return getShare()->getSchemaName(); }
416
inline const char *getTableName() const { return getShare()->getTableName(); }
418
inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
419
inline bool isNameLock() const { return open_placeholder; }
421
uint32_t index_flags(uint32_t idx) const
423
return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
426
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
428
return getShare()->storage_engine;
431
Cursor &getCursor() const /* table_type for handler */
437
size_t max_row_length(const unsigned char *data);
438
uint32_t find_shortest_key(const key_map *usable_keys);
439
bool compare_record(Field **ptr);
440
bool records_are_comparable();
441
bool compare_records();
442
/* TODO: the (re)storeRecord's may be able to be further condensed */
444
void storeRecordAsInsert();
445
void storeRecordAsDefault();
446
void restoreRecord();
447
void restoreRecordAsDefault();
451
/* See if this can be blown away */
452
inline uint32_t getDBStat () { return db_stat; }
453
inline uint32_t setDBStat () { return db_stat; }
455
* Create Item_field for each column in the table.
457
* @param[out] a pointer to an empty list used to store items
461
* Create Item_field object for each column in the table and
462
* initialize it with the corresponding Field. New items are
463
* created in the current Session memory root.
468
* true when out of memory
541
bool insert_or_update; /* Can be used by the handler */
542
bool alias_name_used; /* true if table_name is alias */
543
bool get_fields_in_item_tree; /* Signal to fix_field */
545
REGINFO reginfo; /* field connections */
547
filesort_info_st sort;
470
549
bool fill_item_list(List<Item> *item_list) const;
550
void reset_item_list(List<Item> *item_list) const;
471
551
void clear_column_bitmaps(void);
472
552
void prepare_for_position(void);
473
void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
474
void mark_columns_used_by_index_no_reset(uint32_t index);
475
void mark_columns_used_by_index(uint32_t index);
553
void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map);
554
void mark_columns_used_by_index(uint index);
476
555
void restore_column_maps_after_mark_index();
477
556
void mark_auto_increment_column(void);
478
557
void mark_columns_needed_for_update(void);
479
558
void mark_columns_needed_for_delete(void);
480
559
void mark_columns_needed_for_insert(void);
481
void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
482
boost::dynamic_bitset<>& write_set_arg);
484
void restore_column_map(const boost::dynamic_bitset<>& old);
486
const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
560
inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
561
MY_BITMAP *write_set_arg)
563
read_set= read_set_arg;
564
write_set= write_set_arg;
566
file->column_bitmaps_signal();
568
inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
569
MY_BITMAP *write_set_arg)
571
read_set= read_set_arg;
572
write_set= write_set_arg;
575
void restore_column_map(my_bitmap_map *old);
577
my_bitmap_map *use_all_columns(MY_BITMAP *bitmap);
487
578
inline void use_all_columns()
489
column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
580
column_bitmaps_set(&s->all_set, &s->all_set);
492
583
inline void default_column_bitmaps()
495
586
write_set= &def_write_set;
498
/* Both of the below should go away once we can move this bit to the field objects */
499
inline bool isReadSet(uint32_t index)
501
return read_set->test(index);
504
inline void setReadSet(uint32_t index)
506
read_set->set(index);
509
inline void setReadSet()
514
inline void clearReadSet(uint32_t index)
516
read_set->reset(index);
519
inline void clearReadSet()
524
inline bool isWriteSet(uint32_t index)
526
return write_set->test(index);
529
inline void setWriteSet(uint32_t index)
531
write_set->set(index);
534
inline void setWriteSet()
539
inline void clearWriteSet(uint32_t index)
541
write_set->reset(index);
544
inline void clearWriteSet()
549
589
/* Is table open or should be treated as such by name-locking? */
550
inline bool is_name_opened()
552
return db_stat || open_placeholder;
590
inline bool is_name_opened() { return db_stat || open_placeholder; }
555
592
Is this instance of the table should be reopen or represents a name-lock?
557
594
inline bool needs_reopen_or_name_lock()
559
return getShare()->getVersion() != refresh_version;
563
clean/setup table fields and map.
565
@param table Table structure pointer (which should be setup)
566
@param table_list TableList structure pointer (owner of Table)
567
@param tablenr table number
569
void setup_table_map(TableList *table_list, uint32_t tablenr);
570
inline void mark_as_null_row()
573
status|= STATUS_NULL_ROW;
574
memset(null_flags, 255, getShare()->null_bytes);
577
void free_io_cache();
578
void filesort_free_buffers(bool full= false);
579
void intern_close_table();
581
void print_error(int error, myf errflag)
583
getShare()->storage_engine->print_error(error, errflag, *this);
588
key if error because of duplicated keys
590
uint32_t get_dup_key(int error)
592
cursor->errkey = (uint32_t) -1;
593
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
594
error == HA_ERR_FOUND_DUPP_UNIQUE ||
595
error == HA_ERR_DROP_INDEX_FK)
596
cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
598
return(cursor->errkey);
602
This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
604
bool operator<(const Table &right) const
606
return getShare()->getCacheKey() < right.getShare()->getCacheKey();
609
static bool compare(const Table *a, const Table *b)
614
friend std::ostream& operator<<(std::ostream& output, const Table &table)
616
if (table.getShare())
619
output << table.getShare()->getSchemaName();
621
output << table.getShare()->getTableName();
623
output << table.getShare()->getTableTypeAsString();
628
output << "Table:(has no share)";
631
return output; // for multiple << operators.
635
virtual bool isPlaceHolder(void) const
646
* This class defines the information for foreign keys.
653
* This is the constructor with all properties set.
655
* @param[in] in_foreign_id The id of the foreign key
656
* @param[in] in_referenced_db The referenced database name of the foreign key
657
* @param[in] in_referenced_table The referenced table name of the foreign key
658
* @param[in] in_update_method The update method of the foreign key.
659
* @param[in] in_delete_method The delete method of the foreign key.
660
* @param[in] in_referenced_key_name The name of referenced key
661
* @param[in] in_foreign_fields The foreign fields
662
* @param[in] in_referenced_fields The referenced fields
664
ForeignKeyInfo(LEX_STRING *in_foreign_id,
665
LEX_STRING *in_referenced_db,
666
LEX_STRING *in_referenced_table,
667
LEX_STRING *in_update_method,
668
LEX_STRING *in_delete_method,
669
LEX_STRING *in_referenced_key_name,
670
List<LEX_STRING> in_foreign_fields,
671
List<LEX_STRING> in_referenced_fields)
673
foreign_id(in_foreign_id),
674
referenced_db(in_referenced_db),
675
referenced_table(in_referenced_table),
676
update_method(in_update_method),
677
delete_method(in_delete_method),
678
referenced_key_name(in_referenced_key_name),
679
foreign_fields(in_foreign_fields),
680
referenced_fields(in_referenced_fields)
685
* This is the default constructor. All properties are set to default values for their types.
688
: foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
689
update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
694
* Gets the foreign id.
696
* @ retval the foreign id
698
const LEX_STRING *getForeignId() const
705
* Gets the name of the referenced database.
707
* @ retval the name of the referenced database
709
const LEX_STRING *getReferencedDb() const
711
return referenced_db;
716
* Gets the name of the referenced table.
718
* @ retval the name of the referenced table
720
const LEX_STRING *getReferencedTable() const
722
return referenced_table;
727
* Gets the update method.
729
* @ retval the update method
731
const LEX_STRING *getUpdateMethod() const
733
return update_method;
738
* Gets the delete method.
740
* @ retval the delete method
742
const LEX_STRING *getDeleteMethod() const
744
return delete_method;
749
* Gets the name of the referenced key.
751
* @ retval the name of the referenced key
753
const LEX_STRING *getReferencedKeyName() const
755
return referenced_key_name;
760
* Gets the foreign fields.
762
* @ retval the foreign fields
764
const List<LEX_STRING> &getForeignFields() const
766
return foreign_fields;
771
* Gets the referenced fields.
773
* @ retval the referenced fields
775
const List<LEX_STRING> &getReferencedFields() const
777
return referenced_fields;
783
LEX_STRING *foreign_id;
785
* The name of the reference database.
787
LEX_STRING *referenced_db;
789
* The name of the reference table.
791
LEX_STRING *referenced_table;
795
LEX_STRING *update_method;
799
LEX_STRING *delete_method;
801
* The name of the referenced key.
803
LEX_STRING *referenced_key_name;
805
* The foreign fields.
807
List<LEX_STRING> foreign_fields;
809
* The referenced fields.
811
List<LEX_STRING> referenced_fields;
595
{ return s->version != refresh_version; }
597
int report_error(int error);
600
typedef struct st_foreign_key_info
602
LEX_STRING *forein_id;
603
LEX_STRING *referenced_db;
604
LEX_STRING *referenced_table;
605
LEX_STRING *update_method;
606
LEX_STRING *delete_method;
607
LEX_STRING *referenced_key_name;
608
List<LEX_STRING> foreign_fields;
609
List<LEX_STRING> referenced_fields;
613
Make sure that the order of schema_tables and enum_schema_tables are the same.
616
enum enum_schema_tables
620
SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
623
SCH_GLOBAL_VARIABLES,
624
SCH_KEY_COLUMN_USAGE,
628
SCH_REFERENTIAL_CONSTRAINTS,
631
SCH_SESSION_VARIABLES,
635
SCH_TABLE_CONSTRAINTS,
641
#define MY_I_S_MAYBE_NULL 1
642
#define MY_I_S_UNSIGNED 2
645
#define SKIP_OPEN_TABLE 0 // do not open table
646
#define OPEN_FRM_ONLY 1 // open FRM file only
647
#define OPEN_FULL_TABLE 2 // open FRM,MYD, MYI files
649
typedef struct st_field_info
652
This is used as column name.
654
const char* field_name;
656
For string-type columns, this is the maximum number of
657
characters. Otherwise, it is the 'display-length' for the column.
661
This denotes data type for the column. For the most part, there seems to
662
be one entry in the enum for each SQL data type, although there seem to
663
be a number of additional entries in the enum.
665
enum enum_field_types field_type;
668
This is used to set column attributes. By default, columns are @c NOT
669
@c NULL and @c SIGNED, and you can deviate from the default
670
by setting the appopriate flags. You can use either one of the flags
671
@c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
672
combine them using the bitwise or operator @c |. Both flags are
675
uint field_flags; // Field atributes(maybe_null, signed, unsigned etc.)
676
const char* old_name;
678
This should be one of @c SKIP_OPEN_TABLE,
679
@c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
816
#define JOIN_TYPE_LEFT 1
817
#define JOIN_TYPE_RIGHT 2
686
typedef class Item COND;
688
struct ST_SCHEMA_TABLE
690
const char* table_name;
691
ST_FIELD_INFO *fields_info;
692
/* Create information_schema table */
693
Table *(*create_table) (THD *thd, TableList *table_list);
694
/* Fill table with data */
695
int (*fill_table) (THD *thd, TableList *tables, COND *cond);
696
/* Handle fileds for old SHOW */
697
int (*old_format) (THD *thd, struct ST_SCHEMA_TABLE *schema_table);
698
int (*process_table) (THD *thd, TableList *tables, Table *table,
699
bool res, LEX_STRING *db_name, LEX_STRING *table_name);
700
int idx_field1, idx_field2;
702
uint i_s_requested_object; /* the object we need to open(Table | VIEW) */
706
#define JOIN_TYPE_LEFT 1
707
#define JOIN_TYPE_RIGHT 2
820
710
class select_union;
821
class Tmp_Table_Param;
823
void free_blobs(Table *table);
824
int set_zone(int nr,int min_zone,int max_zone);
825
uint32_t convert_period_to_month(uint32_t period);
826
uint32_t convert_month_to_period(uint32_t month);
828
int test_if_number(char *str,int *res,bool allow_wildcards);
829
void change_byte(unsigned char *,uint,char,char);
831
namespace optimizer { class SqlSelect; }
833
void change_double_for_sort(double nr,unsigned char *to);
834
double my_double_round(double value, int64_t dec, bool dec_unsigned,
836
int get_quick_record(optimizer::SqlSelect *select);
838
void find_date(char *pos,uint32_t *vek,uint32_t flag);
839
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
840
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
841
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
842
void append_unescaped(String *res, const char *pos, uint32_t length);
844
int rename_file_ext(const char * from,const char * to,const char * ext);
845
bool check_column_name(const char *name);
846
bool check_db_name(Session *session, SchemaIdentifier &schema);
847
bool check_table_name(const char *name, uint32_t length);
849
} /* namespace drizzled */
851
#include "drizzled/table/instance.h"
852
#include "drizzled/table/concurrent.h"
711
class TMP_TABLE_PARAM;
713
struct Field_translator
720
typedef struct st_changed_table_list
722
struct st_changed_table_list *next;
728
typedef struct st_open_table_list
730
struct st_open_table_list *next;
732
uint32_t in_use,locked;
854
736
#endif /* DRIZZLED_TABLE_H */