1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 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
22
This class is shared between different table objects. There is one
23
instance of table share per one table in the database.
28
TABLE_SHARE() {} /* Remove gcc warning */
30
/** Category of this table. */
31
enum_table_category table_category;
33
/* hash of field names (contains pointers to elements of field array) */
34
HASH name_hash; /* hash of field names */
36
TYPELIB keynames; /* Pointers to keynames */
37
TYPELIB fieldnames; /* Pointer to fieldnames */
38
TYPELIB *intervals; /* pointer to interval info */
39
pthread_mutex_t mutex; /* For locking the share */
40
pthread_cond_t cond; /* To signal that share is ready */
41
TABLE_SHARE *next, /* Link to unused shares */
44
/* The following is copied to each Table on OPEN */
46
Field **found_next_number_field;
47
Field *timestamp_field; /* Used only during open */
48
KEY *key_info; /* data of keys in database */
49
uint *blob_field; /* Index to blobs in Field arrray*/
51
unsigned char *default_values; /* row with default values */
52
LEX_STRING comment; /* Comment about table */
53
const CHARSET_INFO *table_charset; /* Default charset of string fields */
57
Key which is used for looking-up table in table cache and in the list
58
of thread's temporary tables. Has the form of:
59
"database_name\0table_name\0" + optional part for temporary tables.
61
Note that all three 'table_cache_key', 'db' and 'table_name' members
62
must be set (and be non-zero) for tables in table cache. They also
63
should correspond to each other.
64
To ensure this one can use set_table_cache() methods.
66
LEX_STRING table_cache_key;
67
LEX_STRING db; /* Pointer to db */
68
LEX_STRING table_name; /* Table name (for open) */
69
LEX_STRING path; /* Path to .frm file (from datadir) */
70
LEX_STRING normalized_path; /* unpack_filename(path) */
71
LEX_STRING connect_string;
74
Set of keys in use, implemented as a Bitmap.
75
Excludes keys disabled by ALTER Table ... DISABLE KEYS.
78
key_map keys_for_keyread;
79
ha_rows min_rows, max_rows; /* create information */
80
uint32_t avg_row_length; /* create information */
81
uint32_t block_size; /* create information */
82
uint32_t version, mysql_version;
83
uint32_t timestamp_offset; /* Set to offset+1 of record */
84
uint32_t reclength; /* Recordlength */
85
uint32_t stored_rec_length; /* Stored record length
86
(no generated-only virtual fields) */
88
plugin_ref db_plugin; /* storage engine plugin */
89
inline handlerton *db_type() const /* table_type for handler */
92
return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
94
enum row_type row_type; /* How rows are stored */
95
enum tmp_table_type tmp_table;
96
enum ha_choice transactional;
97
enum ha_choice page_checksum;
99
uint32_t ref_count; /* How many Table objects uses this */
100
uint32_t open_count; /* Number of tables in open list */
101
uint32_t blob_ptr_size; /* 4 or 8 */
102
uint32_t key_block_size; /* create key_block_size, if used */
104
uint32_t last_null_bit_pos;
105
uint32_t fields; /* Number of fields */
106
uint32_t stored_fields; /* Number of stored fields
107
(i.e. without generated-only ones) */
108
uint32_t rec_buff_length; /* Size of table->record[] buffer */
109
uint32_t keys, key_parts;
110
uint32_t max_key_length, max_unique_length, total_key_length;
111
uint32_t uniques; /* Number of UNIQUE index */
112
uint32_t null_fields; /* number of null fields */
113
uint32_t blob_fields; /* number of blob fields */
114
uint32_t timestamp_field_offset; /* Field number for timestamp field */
115
uint32_t varchar_fields; /* number of varchar fields */
116
uint32_t db_create_options; /* Create options from database */
117
uint32_t db_options_in_use; /* Options in use */
118
uint32_t db_record_offset; /* if HA_REC_IN_SEQ */
119
uint32_t rowid_field_offset; /* Field_nr +1 to rowid field */
120
/* Index of auto-updated TIMESTAMP field in field array */
121
uint32_t primary_key;
122
uint32_t next_number_index; /* autoincrement key number */
123
uint32_t next_number_key_offset; /* autoinc keypart offset in a key */
124
uint32_t next_number_keypart; /* autoinc keypart number in a key */
125
uint32_t error, open_errno, errarg; /* error from open_table_def() */
126
uint32_t column_bitmap_size;
128
uint32_t vfields; /* Number of virtual fields */
129
bool null_field_first;
130
bool db_low_byte_first; /* Portable row format */
132
bool name_lock, replace_with_name_lock;
133
bool waiting_on_cond; /* Protection against free */
134
uint32_t table_map_id; /* for row-based replication */
135
uint64_t table_map_version;
138
Cache for row-based replication table share checks that does not
139
need to be repeated. Possible values are: -1 when cache value is
140
not calculated yet, 0 when table *shall not* be replicated, 1 when
141
table *may* be replicated.
143
int cached_row_logging_check;
146
Set share's table cache key and update its db and table name appropriately.
149
set_table_cache_key()
150
key_buff Buffer with already built table cache key to be
151
referenced from share.
152
key_length Key length.
155
Since 'key_buff' buffer will be referenced from share it should has same
156
life-time as share itself.
157
This method automatically ensures that TABLE_SHARE::table_name/db have
158
appropriate values by using table cache key as their source.
161
void set_table_cache_key(char *key_buff, uint32_t key_length)
163
table_cache_key.str= key_buff;
164
table_cache_key.length= key_length;
166
Let us use the fact that the key is "db/0/table_name/0" + optional
167
part for temporary tables.
169
db.str= table_cache_key.str;
170
db.length= strlen(db.str);
171
table_name.str= db.str + db.length + 1;
172
table_name.length= strlen(table_name.str);
177
Set share's table cache key and update its db and table name appropriately.
180
set_table_cache_key()
181
key_buff Buffer to be used as storage for table cache key
182
(should be at least key_length bytes).
183
key Value for table cache key.
184
key_length Key length.
187
Since 'key_buff' buffer will be used as storage for table cache key
188
it should has same life-time as share itself.
191
void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
193
memcpy(key_buff, key, key_length);
194
set_table_cache_key(key_buff, key_length);
197
inline bool honor_global_locks()
199
return (table_category == TABLE_CATEGORY_USER);
202
inline uint32_t get_table_def_version()