38
41
TYPELIB *intervals; /* pointer to interval info */
39
42
pthread_mutex_t mutex; /* For locking the share */
40
43
pthread_cond_t cond; /* To signal that share is ready */
41
TABLE_SHARE *next, /* Link to unused shares */
44
TableShare *next, /* Link to unused shares */
44
47
/* The following is copied to each Table on OPEN */
102
104
uint32_t null_bytes;
103
105
uint32_t last_null_bit_pos;
104
106
uint32_t fields; /* Number of fields */
105
uint32_t stored_fields; /* Number of stored fields
106
(i.e. without generated-only ones) */
107
107
uint32_t rec_buff_length; /* Size of table->record[] buffer */
108
108
uint32_t keys, key_parts;
109
109
uint32_t max_key_length, max_unique_length, total_key_length;
124
124
uint32_t error, open_errno, errarg; /* error from open_table_def() */
125
125
uint32_t column_bitmap_size;
127
uint32_t vfields; /* Number of virtual fields */
128
127
bool db_low_byte_first; /* Portable row format */
130
129
bool name_lock, replace_with_name_lock;
131
130
bool waiting_on_cond; /* Protection against free */
132
uint32_t table_map_id; /* for row-based replication */
133
uint64_t table_map_version;
136
Cache for row-based replication table share checks that does not
137
need to be repeated. Possible values are: -1 when cache value is
138
not calculated yet, 0 when table *shall not* be replicated, 1 when
139
table *may* be replicated.
141
int cached_row_logging_check;
144
133
Set share's table cache key and update its db and table name appropriately.
197
186
return (table_category == TABLE_CATEGORY_USER);
200
inline uint32_t get_table_def_version()
191
Initialize share for temporary tables
196
key Table_cache_key, as generated from create_table_def_key.
197
must start with db name.
198
key_length Length of key
199
table_name Table name
200
path Path to file (possible in lower case) without .frm
203
This is different from alloc_table_share() because temporary tables
204
don't have to be shared between threads or put into the table def
205
cache, so we can do some things notable simpler and faster
207
If table is not put in session->temporary_tables (happens only when
208
one uses OPEN TEMPORARY) then one can specify 'db' as key and
209
use key_length= 0 as neither table_cache_key or key_length will be used).
217
void init(const char *new_table_name,
218
const char *new_path)
220
init("", 0, new_table_name, new_path);
223
void init(const char *key,
224
uint32_t key_length, const char *new_table_name,
225
const char *new_path)
227
memset(this, 0, sizeof(TableShare));
228
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
229
table_category= TABLE_CATEGORY_TEMPORARY;
230
tmp_table= INTERNAL_TMP_TABLE;
232
db.length= strlen(key);
233
table_cache_key.str= (char*) key;
234
table_cache_key.length= key_length;
235
table_name.str= (char*) new_table_name;
236
table_name.length= strlen(new_table_name);
237
path.str= (char*) new_path;
238
normalized_path.str= (char*) new_path;
239
path.length= normalized_path.length= strlen(new_path);
245
Free table share and memory used by it
252
share->mutex must be locked when we come here if it's not a temp table
255
void free_table_share()
257
MEM_ROOT new_mem_root;
258
assert(ref_count == 0);
261
If someone is waiting for this to be deleted, inform it about this.
262
Don't do a delete until we know that no one is refering to this anymore.
264
if (tmp_table == NO_TMP_TABLE)
266
/* share->mutex is locked in release_table_share() */
267
while (waiting_on_cond)
269
pthread_cond_broadcast(&cond);
270
pthread_cond_wait(&cond, &mutex);
272
/* No thread refers to this anymore */
273
pthread_mutex_unlock(&mutex);
274
pthread_mutex_destroy(&mutex);
275
pthread_cond_destroy(&cond);
277
hash_free(&name_hash);
279
storage_engine= NULL;
281
/* We must copy mem_root from share because share is allocated through it */
282
memcpy(&new_mem_root, &mem_root, sizeof(new_mem_root));
283
free_root(&new_mem_root, MYF(0)); // Free's share