27
27
#include <drizzled/order.h>
28
28
#include <drizzled/filesort_info.h>
29
29
#include <drizzled/natural_join_column.h>
30
#include <drizzled/nested_join.h>
31
30
#include <drizzled/field_iterator.h>
31
#include <mysys/hash.h>
32
#include <drizzled/handler.h>
33
#include <drizzled/lex_string.h>
34
#include <drizzled/table_list.h>
35
#include <drizzled/table_share.h>
33
class Item; /* Needed by order_st */
34
38
class Item_subselect;
35
class st_select_lex_unit;
39
class Select_Lex_Unit;
38
42
class Security_context;
41
45
/*************************************************************************/
45
NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
46
INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE, TMP_TABLE_FRM_FILE_ONLY
49
bool mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
52
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
55
Values in this enum are used to indicate how a tables TIMESTAMP field
56
should be treated. It can be set to the current timestamp on insert or
58
WARNING: The values are used for bit operations. If you change the
59
enum, you must keep the bitwise relation of the values. For example:
60
(int) TIMESTAMP_AUTO_SET_ON_BOTH must be equal to
61
(int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE.
62
We use an enum here so that the debugger can display the value names.
64
enum timestamp_auto_set_type
66
TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1,
67
TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3
69
#define clear_timestamp_auto_bits(_target_, _bits_) \
70
(_target_)= (enum timestamp_auto_set_type)((int)(_target_) & ~(int)(_bits_))
72
48
class Field_timestamp;
76
Category of table found in the table share.
78
enum enum_table_category
83
TABLE_UNKNOWN_CATEGORY=0,
87
The table is visible only in the session.
89
- FLUSH TABLES WITH READ LOCK
90
- SET GLOBAL READ_ONLY = ON
91
do not apply to this table.
92
Note that LOCK Table t FOR READ/WRITE
93
can be used on temporary tables.
94
Temporary tables are not part of the table cache.
96
TABLE_CATEGORY_TEMPORARY=1,
100
These tables do honor:
101
- LOCK Table t FOR READ/WRITE
102
- FLUSH TABLES WITH READ LOCK
103
- SET GLOBAL READ_ONLY = ON
104
User tables are cached in the table cache.
106
TABLE_CATEGORY_USER=2,
109
Information schema tables.
110
These tables are an interface provided by the system
111
to inspect the system metadata.
112
These tables do *not* honor:
113
- LOCK Table t FOR READ/WRITE
114
- FLUSH TABLES WITH READ LOCK
115
- SET GLOBAL READ_ONLY = ON
116
as there is no point in locking explicitely
117
an INFORMATION_SCHEMA table.
118
Nothing is directly written to information schema tables.
119
Note that this value is not used currently,
120
since information schema tables are not shared,
121
but implemented as session specific temporary tables.
124
TODO: Fixing the performance issues of I_S will lead
125
to I_S tables in the table cache, which should use
128
TABLE_CATEGORY_INFORMATION
130
51
typedef enum enum_table_category TABLE_CATEGORY;
132
53
TABLE_CATEGORY get_table_category(const LEX_STRING *db,
133
54
const LEX_STRING *name);
136
This structure is shared between different table objects. There is one
137
instance of table share per one table in the database.
140
typedef struct st_table_share
142
st_table_share() {} /* Remove gcc warning */
144
/** Category of this table. */
145
TABLE_CATEGORY table_category;
147
/* hash of field names (contains pointers to elements of field array) */
148
HASH name_hash; /* hash of field names */
150
TYPELIB keynames; /* Pointers to keynames */
151
TYPELIB fieldnames; /* Pointer to fieldnames */
152
TYPELIB *intervals; /* pointer to interval info */
153
pthread_mutex_t mutex; /* For locking the share */
154
pthread_cond_t cond; /* To signal that share is ready */
155
struct st_table_share *next, /* Link to unused shares */
158
/* The following is copied to each Table on OPEN */
160
Field **found_next_number_field;
161
Field *timestamp_field; /* Used only during open */
162
KEY *key_info; /* data of keys in database */
163
uint *blob_field; /* Index to blobs in Field arrray*/
165
unsigned char *default_values; /* row with default values */
166
LEX_STRING comment; /* Comment about table */
167
const CHARSET_INFO *table_charset; /* Default charset of string fields */
171
Key which is used for looking-up table in table cache and in the list
172
of thread's temporary tables. Has the form of:
173
"database_name\0table_name\0" + optional part for temporary tables.
175
Note that all three 'table_cache_key', 'db' and 'table_name' members
176
must be set (and be non-zero) for tables in table cache. They also
177
should correspond to each other.
178
To ensure this one can use set_table_cache() methods.
180
LEX_STRING table_cache_key;
181
LEX_STRING db; /* Pointer to db */
182
LEX_STRING table_name; /* Table name (for open) */
183
LEX_STRING path; /* Path to .frm file (from datadir) */
184
LEX_STRING normalized_path; /* unpack_filename(path) */
185
LEX_STRING connect_string;
188
Set of keys in use, implemented as a Bitmap.
189
Excludes keys disabled by ALTER Table ... DISABLE KEYS.
192
key_map keys_for_keyread;
193
ha_rows min_rows, max_rows; /* create information */
194
uint32_t avg_row_length; /* create information */
195
uint32_t block_size; /* create information */
196
uint32_t version, mysql_version;
197
uint32_t timestamp_offset; /* Set to offset+1 of record */
198
uint32_t reclength; /* Recordlength */
200
plugin_ref db_plugin; /* storage engine plugin */
201
inline handlerton *db_type() const /* table_type for handler */
203
// assert(db_plugin);
204
return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
206
enum row_type row_type; /* How rows are stored */
207
enum tmp_table_type tmp_table;
208
enum ha_choice transactional;
209
enum ha_choice page_checksum;
211
uint32_t ref_count; /* How many Table objects uses this */
212
uint32_t open_count; /* Number of tables in open list */
213
uint32_t blob_ptr_size; /* 4 or 8 */
214
uint32_t key_block_size; /* create key_block_size, if used */
215
uint32_t null_bytes, last_null_bit_pos;
216
uint32_t fields; /* Number of fields */
217
uint32_t rec_buff_length; /* Size of table->record[] buffer */
218
uint32_t keys, key_parts;
219
uint32_t max_key_length, max_unique_length, total_key_length;
220
uint32_t uniques; /* Number of UNIQUE index */
221
uint32_t null_fields; /* number of null fields */
222
uint32_t blob_fields; /* number of blob fields */
223
uint32_t timestamp_field_offset; /* Field number for timestamp field */
224
uint32_t varchar_fields; /* number of varchar fields */
225
uint32_t db_create_options; /* Create options from database */
226
uint32_t db_options_in_use; /* Options in use */
227
uint32_t db_record_offset; /* if HA_REC_IN_SEQ */
228
uint32_t rowid_field_offset; /* Field_nr +1 to rowid field */
229
/* Index of auto-updated TIMESTAMP field in field array */
230
uint32_t primary_key;
231
uint32_t next_number_index; /* autoincrement key number */
232
uint32_t next_number_key_offset; /* autoinc keypart offset in a key */
233
uint32_t next_number_keypart; /* autoinc keypart number in a key */
234
uint32_t error, open_errno, errarg; /* error from open_table_def() */
235
uint32_t column_bitmap_size;
236
unsigned char frm_version;
237
bool null_field_first;
238
bool db_low_byte_first; /* Portable row format */
240
bool name_lock, replace_with_name_lock;
241
bool waiting_on_cond; /* Protection against free */
242
uint32_t table_map_id; /* for row-based replication */
243
uint64_t table_map_version;
246
Cache for row-based replication table share checks that does not
247
need to be repeated. Possible values are: -1 when cache value is
248
not calculated yet, 0 when table *shall not* be replicated, 1 when
249
table *may* be replicated.
251
int cached_row_logging_check;
254
Set share's table cache key and update its db and table name appropriately.
257
set_table_cache_key()
258
key_buff Buffer with already built table cache key to be
259
referenced from share.
260
key_length Key length.
263
Since 'key_buff' buffer will be referenced from share it should has same
264
life-time as share itself.
265
This method automatically ensures that TABLE_SHARE::table_name/db have
266
appropriate values by using table cache key as their source.
269
void set_table_cache_key(char *key_buff, uint32_t key_length)
271
table_cache_key.str= key_buff;
272
table_cache_key.length= key_length;
274
Let us use the fact that the key is "db/0/table_name/0" + optional
275
part for temporary tables.
277
db.str= table_cache_key.str;
278
db.length= strlen(db.str);
279
table_name.str= db.str + db.length + 1;
280
table_name.length= strlen(table_name.str);
285
Set share's table cache key and update its db and table name appropriately.
288
set_table_cache_key()
289
key_buff Buffer to be used as storage for table cache key
290
(should be at least key_length bytes).
291
key Value for table cache key.
292
key_length Key length.
295
Since 'key_buff' buffer will be used as storage for table cache key
296
it should has same life-time as share itself.
299
void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
301
memcpy(key_buff, key, key_length);
302
set_table_cache_key(key_buff, key_length);
305
inline bool honor_global_locks()
307
return (table_category == TABLE_CATEGORY_USER);
310
inline uint32_t get_table_def_version()
318
57
extern uint32_t refresh_version;
320
/* Information for one open table */
328
59
typedef struct st_table_field_w_type