~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2009-04-29 01:45:36 UTC
  • mfrom: (1000.1.6 merge)
  • Revision ID: brian@gaz-20090429014536-pwu5m8ug6n8fvh68
Merge refactoring (mainly around TABLE_SHARE... one step forward...)

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
/* Functions defined in this file */
53
53
 
54
 
void open_table_error(TABLE_SHARE *share, int error, int db_errno,
 
54
void open_table_error(TableShare *share, int error, int db_errno,
55
55
                      myf errortype, int errarg);
56
56
static void fix_type_pointers(const char ***array, TYPELIB *point_to_type,
57
57
                              uint32_t types, char **names);
114
114
 
115
115
 
116
116
/*
117
 
  Allocate a setup TABLE_SHARE structure
 
117
  Allocate a setup TableShare structure
118
118
 
119
119
  SYNOPSIS
120
120
    alloc_table_share()
127
127
    #  Share
128
128
*/
129
129
 
130
 
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
 
130
TableShare *alloc_table_share(TableList *table_list, char *key,
131
131
                               uint32_t key_length)
132
132
{
133
133
  MEM_ROOT mem_root;
134
 
  TABLE_SHARE *share;
 
134
  TableShare *share;
135
135
  char *key_buff, *path_buff;
136
136
  char path[FN_REFLEN];
137
137
  uint32_t path_length;
158
158
 
159
159
    share->version=       refresh_version;
160
160
 
161
 
    /*
162
 
      This constant is used to mark that no table map version has been
163
 
      assigned.  No arithmetic is done on the value: it will be
164
 
      overwritten with a value taken from DRIZZLE_BIN_LOG.
165
 
    */
166
 
    share->table_map_version= UINT64_MAX;
167
 
 
168
 
    /*
169
 
      Since alloc_table_share() can be called without any locking (for
170
 
      example, ha_create_table... functions), we do not assign a table
171
 
      map id here.  Instead we assign a value that is not used
172
 
      elsewhere, and then assign a table map id inside open_table()
173
 
      under the protection of the LOCK_open mutex.
174
 
    */
175
 
    share->table_map_id= UINT32_MAX;
176
 
    share->cached_row_logging_check= -1;
177
 
 
178
161
    memcpy(&share->mem_root, &mem_root, sizeof(mem_root));
179
162
    pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST);
180
163
    pthread_cond_init(&share->cond, NULL);
183
166
}
184
167
 
185
168
 
186
 
/*
187
 
  Initialize share for temporary tables
188
 
 
189
 
  SYNOPSIS
190
 
    init_tmp_table_share()
191
 
    session         thread handle
192
 
    share       Share to fill
193
 
    key         Table_cache_key, as generated from create_table_def_key.
194
 
                must start with db name.
195
 
    key_length  Length of key
196
 
    table_name  Table name
197
 
    path        Path to file (possible in lower case) without .frm
198
 
 
199
 
  NOTES
200
 
    This is different from alloc_table_share() because temporary tables
201
 
    don't have to be shared between threads or put into the table def
202
 
    cache, so we can do some things notable simpler and faster
203
 
 
204
 
    If table is not put in session->temporary_tables (happens only when
205
 
    one uses OPEN TEMPORARY) then one can specify 'db' as key and
206
 
    use key_length= 0 as neither table_cache_key or key_length will be used).
207
 
*/
208
 
 
209
 
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
210
 
                          uint32_t key_length, const char *table_name,
211
 
                          const char *path)
212
 
{
213
 
 
214
 
  memset(share, 0, sizeof(*share));
215
 
  init_sql_alloc(&share->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
216
 
  share->table_category=         TABLE_CATEGORY_TEMPORARY;
217
 
  share->tmp_table=              INTERNAL_TMP_TABLE;
218
 
  share->db.str=                 (char*) key;
219
 
  share->db.length=              strlen(key);
220
 
  share->table_cache_key.str=    (char*) key;
221
 
  share->table_cache_key.length= key_length;
222
 
  share->table_name.str=         (char*) table_name;
223
 
  share->table_name.length=      strlen(table_name);
224
 
  share->path.str=               (char*) path;
225
 
  share->normalized_path.str=    (char*) path;
226
 
  share->path.length= share->normalized_path.length= strlen(path);
227
 
 
228
 
  /*
229
 
    Temporary tables are not replicated, but we set up these fields
230
 
    anyway to be able to catch errors.
231
 
   */
232
 
  share->table_map_version= ~(uint64_t)0;
233
 
  share->cached_row_logging_check= -1;
234
 
 
235
 
  /*
236
 
    table_map_id is also used for MERGE tables to suppress repeated
237
 
    compatibility checks.
238
 
  */
239
 
  share->table_map_id= (ulong) session->query_id;
240
 
 
241
 
  return;
242
 
}
243
 
 
244
 
 
245
 
/*
246
 
  Free table share and memory used by it
247
 
 
248
 
  SYNOPSIS
249
 
    free_table_share()
250
 
    share               Table share
251
 
 
252
 
  NOTES
253
 
    share->mutex must be locked when we come here if it's not a temp table
254
 
*/
255
 
 
256
 
void free_table_share(TABLE_SHARE *share)
257
 
{
258
 
  MEM_ROOT mem_root;
259
 
  assert(share->ref_count == 0);
260
 
 
261
 
  /*
262
 
    If someone is waiting for this to be deleted, inform it about this.
263
 
    Don't do a delete until we know that no one is refering to this anymore.
264
 
  */
265
 
  if (share->tmp_table == NO_TMP_TABLE)
266
 
  {
267
 
    /* share->mutex is locked in release_table_share() */
268
 
    while (share->waiting_on_cond)
269
 
    {
270
 
      pthread_cond_broadcast(&share->cond);
271
 
      pthread_cond_wait(&share->cond, &share->mutex);
272
 
    }
273
 
    /* No thread refers to this anymore */
274
 
    pthread_mutex_unlock(&share->mutex);
275
 
    pthread_mutex_destroy(&share->mutex);
276
 
    pthread_cond_destroy(&share->cond);
277
 
  }
278
 
  hash_free(&share->name_hash);
279
 
 
280
 
  share->storage_engine= NULL;
281
 
 
282
 
  /* We must copy mem_root from share because share is allocated through it */
283
 
  memcpy(&mem_root, &share->mem_root, sizeof(mem_root));
284
 
  free_root(&mem_root, MYF(0));                 // Free's share
285
 
  return;
286
 
}
287
 
 
288
169
enum_field_types proto_field_type_to_drizzle_type(uint32_t proto_field_type)
289
170
{
290
171
  enum_field_types field_type;
365
246
  case DRIZZLE_TYPE_TIMESTAMP:
366
247
  case DRIZZLE_TYPE_DATETIME:
367
248
  case DRIZZLE_TYPE_DATE:
368
 
    if(default_value->compare("NOW()")==0)
 
249
    if (default_value->compare("NOW()") == 0)
369
250
      break;
370
251
  case DRIZZLE_TYPE_ENUM:
371
252
    default_item= new Item_string(default_value->c_str(),
397
278
  return default_item;
398
279
}
399
280
 
400
 
int parse_table_proto(Session *session, drizzled::message::Table &table, TABLE_SHARE *share)
 
281
int parse_table_proto(Session *session, drizzled::message::Table &table, TableShare *share)
401
282
{
402
283
  int error= 0;
403
284
  handler *handler_file= NULL;
1357
1238
  open_table_def()
1358
1239
  session               Thread handler
1359
1240
  share         Fill this with table definition
1360
 
  db_flags      Bit mask of the following flags: OPEN_VIEW
1361
1241
 
1362
1242
  NOTES
1363
1243
    This function is called when the table definition is not cached in
1375
1255
   6    Unknown .frm version
1376
1256
*/
1377
1257
 
1378
 
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t)
 
1258
int open_table_def(Session *session, TableShare *share)
1379
1259
{
1380
1260
  int error;
1381
1261
  bool error_given;
1427
1307
 
1428
1308
 
1429
1309
/*
1430
 
  Open a table based on a TABLE_SHARE
 
1310
  Open a table based on a TableShare
1431
1311
 
1432
1312
  SYNOPSIS
1433
1313
    open_table_from_share()
1454
1334
   7    Table definition has changed in engine
1455
1335
*/
1456
1336
 
1457
 
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
 
1337
int open_table_from_share(Session *session, TableShare *share, const char *alias,
1458
1338
                          uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
1459
1339
                          Table *outparam, open_table_mode open_mode)
1460
1340
{
1716
1596
    if (s->tmp_table == NO_TMP_TABLE)
1717
1597
      release_table_share(s, RELEASE_NORMAL);
1718
1598
    else
1719
 
      free_table_share(s);
 
1599
      s->free_table_share();
1720
1600
  }
1721
1601
  free_root(&mem_root, MYF(0));
1722
1602
 
1880
1760
 
1881
1761
        /* error message when opening a form file */
1882
1762
 
1883
 
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg)
 
1763
void open_table_error(TableShare *share, int error, int db_errno, int errarg)
1884
1764
{
1885
1765
  int err_no;
1886
1766
  char buff[FN_REFLEN];
3349
3229
{
3350
3230
  MEM_ROOT *mem_root_save, own_root;
3351
3231
  Table *table;
3352
 
  TABLE_SHARE *share;
 
3232
  TableShare *share;
3353
3233
  uint  i,field_count,null_count,null_pack_length;
3354
3234
  uint32_t  copy_func_count= param->func_count;
3355
3235
  uint32_t  hidden_null_count, hidden_null_pack_length, hidden_field_count;
3489
3369
  table->keys_in_use_for_query.init();
3490
3370
 
3491
3371
  table->setShare(share);
3492
 
  init_tmp_table_share(session, share, "", 0, tmpname, tmpname);
 
3372
  share->init(tmpname, tmpname);
3493
3373
  share->blob_field= blob_field;
3494
3374
  share->blob_ptr_size= portable_sizeof_char_ptr;
3495
3375
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
4048
3928
  uint32_t *blob_field;
4049
3929
  unsigned char *bitmaps;
4050
3930
  Table *table;
4051
 
  TABLE_SHARE *share;
 
3931
  TableShare *share;
4052
3932
 
4053
3933
  if (!multi_alloc_root(session->mem_root,
4054
3934
                        &table, sizeof(*table),
4195
4075
  int error;
4196
4076
  MI_KEYDEF keydef;
4197
4077
  MI_UNIQUEDEF uniquedef;
4198
 
  TABLE_SHARE *share= s;
 
4078
  TableShare *share= s;
4199
4079
 
4200
4080
  if (share->keys)
4201
4081
  {                                             // Get keys for ni_create
4340
4220
                             int error, bool ignore_last_dupp_key_error)
4341
4221
{
4342
4222
  Table new_table;
4343
 
  TABLE_SHARE share;
 
4223
  TableShare share;
4344
4224
  const char *save_proc_info;
4345
4225
  int write_err;
4346
4226