~vjsamuel/drizzle/rplugin-rabbitmq

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2009-04-28 21:46:57 UTC
  • mto: This revision was merged to the branch mainline in revision 1001.
  • Revision ID: brian@gaz-20090428214657-8vxn7n9dc6epb3zy
Renamed TABLE_SHARE to TableShare

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
Table *unused_tables;                           /* Used by mysql_test */
59
59
HASH open_cache;                                /* Used by mysql_test */
60
60
static HASH table_def_cache;
61
 
static TABLE_SHARE *oldest_unused_share, end_of_unused_share;
 
61
static TableShare *oldest_unused_share, end_of_unused_share;
62
62
static pthread_mutex_t LOCK_table_share;
63
63
static bool table_def_inited= 0;
64
64
 
150
150
 
151
151
 
152
152
/*****************************************************************************
153
 
  Functions to handle table definition cach (TABLE_SHARE)
 
153
  Functions to handle table definition cach (TableShare)
154
154
*****************************************************************************/
155
155
 
156
156
extern "C" unsigned char *table_def_key(const unsigned char *record, size_t *length,
157
157
                                bool )
158
158
{
159
 
  TABLE_SHARE *entry=(TABLE_SHARE*) record;
 
159
  TableShare *entry=(TableShare*) record;
160
160
  *length= entry->table_cache_key.length;
161
161
  return (unsigned char*) entry->table_cache_key.str;
162
162
}
163
163
 
164
164
 
165
 
static void table_def_free_entry(TABLE_SHARE *share)
 
165
static void table_def_free_entry(TableShare *share)
166
166
{
167
167
  if (share->prev)
168
168
  {
209
209
 
210
210
 
211
211
/*
212
 
  Get TABLE_SHARE for a table.
 
212
  Get TableShare for a table.
213
213
 
214
214
  get_table_share()
215
215
  session                       Thread handle
233
233
   #  Share for table
234
234
*/
235
235
 
236
 
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
 
236
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
237
237
                             uint32_t key_length, uint32_t db_flags, int *error)
238
238
{
239
 
  TABLE_SHARE *share;
 
239
  TableShare *share;
240
240
 
241
241
  *error= 0;
242
242
 
243
243
  /* Read table definition from cache */
244
 
  if ((share= (TABLE_SHARE*) hash_search(&table_def_cache,(unsigned char*) key,
 
244
  if ((share= (TableShare*) hash_search(&table_def_cache,(unsigned char*) key,
245
245
                                         key_length)))
246
246
    goto found;
247
247
 
320
320
  For arguments and return values, see get_table_from_share()
321
321
*/
322
322
 
323
 
static TABLE_SHARE
 
323
static TableShare
324
324
*get_table_share_with_create(Session *session, TableList *table_list,
325
325
                             char *key, uint32_t key_length,
326
326
                             uint32_t db_flags, int *error)
327
327
{
328
 
  TABLE_SHARE *share;
 
328
  TableShare *share;
329
329
 
330
330
  share= get_table_share(session, table_list, key, key_length, db_flags, error);
331
331
  /*
376
376
     that the table is deleted or the thread is killed.
377
377
*/
378
378
 
379
 
void release_table_share(TABLE_SHARE *share,
 
379
void release_table_share(TableShare *share,
380
380
                         enum release_type )
381
381
{
382
382
  bool to_be_deleted= 0;
423
423
 
424
424
  RETURN
425
425
    0  Not cached
426
 
    #  TABLE_SHARE for table
 
426
    #  TableShare for table
427
427
*/
428
428
 
429
 
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name)
 
429
TableShare *get_cached_table_share(const char *db, const char *table_name)
430
430
{
431
431
  char key[NAME_LEN*2+2];
432
432
  TableList table_list;
436
436
  table_list.db= (char*) db;
437
437
  table_list.table_name= (char*) table_name;
438
438
  key_length= create_table_def_key((Session*) 0, key, &table_list, 0);
439
 
  return (TABLE_SHARE*) hash_search(&table_def_cache,(unsigned char*) key, key_length);
 
439
  return (TableShare*) hash_search(&table_def_cache,(unsigned char*) key, key_length);
440
440
}
441
441
 
442
442
 
460
460
 
461
461
void close_handle_and_leave_table_as_lock(Table *table)
462
462
{
463
 
  TABLE_SHARE *share, *old_share= table->s;
 
463
  TableShare *share, *old_share= table->s;
464
464
  char *key_buff;
465
465
  MEM_ROOT *mem_root= &table->mem_root;
466
466
 
525
525
  {
526
526
    OPEN_TableList *table;
527
527
    Table *entry=(Table*) hash_element(&open_cache,idx);
528
 
    TABLE_SHARE *share= entry->s;
 
528
    TableShare *share= entry->s;
529
529
 
530
530
    if (db && my_strcasecmp(system_charset_info, db, share->db.str))
531
531
      continue;
827
827
 
828
828
  for (idx= 0; idx < table_def_cache.records; idx++)
829
829
  {
830
 
    TABLE_SHARE *share= (TABLE_SHARE *) hash_element(&table_def_cache, idx);
 
830
    TableShare *share= (TableShare *) hash_element(&table_def_cache, idx);
831
831
 
832
832
    /* Ignore if table is not open or does not have a connect_string */
833
833
    if (!share->connect_string.length || !share->ref_count)
1406
1406
{
1407
1407
  char *key;
1408
1408
  uint32_t key_length;
1409
 
  TABLE_SHARE *share= table->s;
 
1409
  TableShare *share= table->s;
1410
1410
  TableList table_list;
1411
1411
 
1412
1412
  if (!(key=(char*) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH)))
1638
1638
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in)
1639
1639
{
1640
1640
  Table *table= table_list->table;
1641
 
  TABLE_SHARE *share;
 
1641
  TableShare *share;
1642
1642
  char *table_name= table_list->table_name;
1643
1643
  Table orig_table;
1644
1644
 
1718
1718
                                      uint32_t key_length)
1719
1719
{
1720
1720
  Table *table;
1721
 
  TABLE_SHARE *share;
 
1721
  TableShare *share;
1722
1722
  char *key_buff;
1723
1723
 
1724
1724
  safe_mutex_assert_owner(&LOCK_open);
2359
2359
          the function probably has to be adjusted before it can be used
2360
2360
          anywhere outside ALTER Table.
2361
2361
 
2362
 
    @note Must not use TABLE_SHARE::table_name/db of the table being closed,
 
2362
    @note Must not use TableShare::table_name/db of the table being closed,
2363
2363
          the strings are used in a loop even after the share may be freed.
2364
2364
*/
2365
2365
 
2790
2790
                             char *cache_key, uint32_t cache_key_length)
2791
2791
{
2792
2792
  int error;
2793
 
  TABLE_SHARE *share;
 
2793
  TableShare *share;
2794
2794
  uint32_t discover_retry_count= 0;
2795
2795
 
2796
2796
  safe_mutex_assert_owner(&LOCK_open);
3440
3440
                            open_table_mode open_mode)
3441
3441
{
3442
3442
  Table *tmp_table;
3443
 
  TABLE_SHARE *share;
 
3443
  TableShare *share;
3444
3444
  char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path;
3445
3445
  uint32_t key_length, path_length;
3446
3446
  TableList table_list;
3455
3455
                                   path_length + 1 + key_length)))
3456
3456
    return NULL;
3457
3457
 
3458
 
  share= (TABLE_SHARE*) (tmp_table+1);
 
3458
  share= (TableShare*) (tmp_table+1);
3459
3459
  tmp_path= (char*) (share+1);
3460
3460
  saved_cache_key= strcpy(tmp_path, path)+path_length+1;
3461
3461
  memcpy(saved_cache_key, cache_key, key_length);
3515
3515
  if(delete_table_proto_file(path))
3516
3516
    error=1; /* purecov: inspected */
3517
3517
 
3518
 
  file= get_new_handler((TABLE_SHARE*) 0, current_session->mem_root, base);
 
3518
  file= get_new_handler((TableShare*) 0, current_session->mem_root, base);
3519
3519
  if (file && file->ha_delete_table(path))
3520
3520
  {
3521
3521
    error=1;
3703
3703
    if (field_ptr)
3704
3704
    {
3705
3705
      /*
3706
 
        field_ptr points to field in TABLE_SHARE. Convert it to the matching
 
3706
        field_ptr points to field in TableShare. Convert it to the matching
3707
3707
        field in table
3708
3708
      */
3709
3709
      field_ptr= (table->field + (field_ptr - table->s->field));
3932
3932
    if (field_ptr)
3933
3933
    {
3934
3934
      /*
3935
 
        field_ptr points to field in TABLE_SHARE. Convert it to the matching
 
3935
        field_ptr points to field in TableShare. Convert it to the matching
3936
3936
        field in table
3937
3937
      */
3938
3938
      field_ptr= (table->field + (field_ptr - table->s->field));
5787
5787
  char  filePath[FN_REFLEN], filePathCopy[FN_REFLEN];
5788
5788
  MY_DIR *dirp;
5789
5789
  FILEINFO *file;
5790
 
  TABLE_SHARE share;
 
5790
  TableShare share;
5791
5791
  Session *session;
5792
5792
 
5793
5793
  assert(drizzle_tmpdir);
5925
5925
  char *key_pos= key;
5926
5926
  uint32_t key_length;
5927
5927
  Table *table;
5928
 
  TABLE_SHARE *share;
 
5928
  TableShare *share;
5929
5929
  bool result= 0, signalled= 0;
5930
5930
 
5931
5931
  key_pos= strcpy(key_pos, db) + strlen(db);
5987
5987
      hash_delete(&open_cache,(unsigned char*) unused_tables);
5988
5988
 
5989
5989
    /* Remove table from table definition cache if it's not in use */
5990
 
    if ((share= (TABLE_SHARE*) hash_search(&table_def_cache,(unsigned char*) key,
 
5990
    if ((share= (TableShare*) hash_search(&table_def_cache,(unsigned char*) key,
5991
5991
                                           key_length)))
5992
5992
    {
5993
5993
      share->version= 0;                          // Mark for delete