~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2009-07-11 05:59:19 UTC
  • mfrom: (1089.1.9 merge)
  • Revision ID: brian@gaz-20090711055919-m4px3crrdgta5lie
Collection of patches from new-cleanup (includes asserts for field in debug)

Show diffs side-by-side

added added

removed removed

Lines of Context:
334
334
TableShare *get_cached_table_share(const char *db, const char *table_name)
335
335
{
336
336
  char key[NAME_LEN*2+2];
337
 
  TableList table_list;
338
337
  uint32_t key_length;
339
338
  safe_mutex_assert_owner(&LOCK_open);
340
339
 
341
 
  table_list.db= (char*) db;
342
 
  table_list.table_name= (char*) table_name;
343
 
  key_length= table_list.create_table_def_key(key);
 
340
  key_length= TableShare::createKey(key, db, table_name);
 
341
 
344
342
  return (TableShare*) hash_search(&table_def_cache,(unsigned char*) key, key_length);
345
343
}
346
344
 
634
632
    session->mysys_var->current_cond= &COND_refresh;
635
633
    session->set_proc_info("Flushing tables");
636
634
 
637
 
    session->close_old_data_files(true, true);
 
635
    session->close_old_data_files();
638
636
 
639
637
    bool found= true;
640
638
    /* Wait until all threads has closed all the tables we had locked */
710
708
  move one table to free list 
711
709
*/
712
710
 
713
 
static bool free_cached_table(Session *session, Table **table_ptr)
 
711
bool Session::free_cached_table()
714
712
{
715
713
  bool found_old_table= false;
716
 
  Table *table= *table_ptr;
 
714
  Table *table= open_tables;
717
715
 
718
716
  safe_mutex_assert_owner(&LOCK_open);
719
717
  assert(table->key_read == 0);
720
718
  assert(!table->file || table->file->inited == handler::NONE);
721
719
 
722
 
  *table_ptr= table->next;
 
720
  open_tables= table->next;
723
721
 
724
722
  if (table->needs_reopen_or_name_lock() ||
725
 
      session->version != refresh_version || !table->db_stat)
 
723
      version != refresh_version || !table->db_stat)
726
724
  {
727
725
    hash_delete(&open_cache,(unsigned char*) table);
728
726
    found_old_table= true;
738
736
    /* Free memory and reset for next loop */
739
737
    table->file->ha_reset();
740
738
    table->in_use= false;
 
739
 
741
740
    if (unused_tables)
742
741
    {
743
 
      table->next=unused_tables;                /* Link in last */
744
 
      table->prev=unused_tables->prev;
745
 
      unused_tables->prev=table;
746
 
      table->prev->next=table;
 
742
      table->next= unused_tables;               /* Link in last */
 
743
      table->prev= unused_tables->prev;
 
744
      unused_tables->prev= table;
 
745
      table->prev->next= table;
747
746
    }
748
747
    else
749
 
      unused_tables=table->next=table->prev=table;
 
748
      unused_tables= table->next=table->prev=table;
750
749
  }
751
750
 
752
751
  return found_old_table;
770
769
  pthread_mutex_lock(&LOCK_open); /* Close all open tables on Session */
771
770
 
772
771
  while (open_tables)
773
 
    found_old_table|= free_cached_table(this, &open_tables);
 
772
    found_old_table|= free_cached_table();
774
773
  some_tables_deleted= false;
775
774
 
776
775
  if (found_old_table)
906
905
 
907
906
Table *Session::find_temporary_table(const char *new_db, const char *table_name)
908
907
{
909
 
  TableList table_list;
910
 
 
911
 
  table_list.db= (char*) new_db;
912
 
  table_list.table_name= (char*) table_name;
913
 
 
914
 
  return find_temporary_table(&table_list);
915
 
}
916
 
 
917
 
 
918
 
Table *Session::find_temporary_table(TableList *table_list)
919
 
{
920
908
  char  key[MAX_DBKEY_LENGTH];
921
909
  uint  key_length;
922
910
  Table *table;
923
911
 
924
 
  key_length= table_list->create_table_def_key(key);
 
912
  key_length= TableShare::createKey(key, new_db, table_name);
 
913
 
925
914
  for (table= temporary_tables ; table ; table= table->next)
926
915
  {
927
916
    if (table->s->table_cache_key.length == key_length &&
931
920
  return NULL;                               // Not a temporary table
932
921
}
933
922
 
 
923
Table *Session::find_temporary_table(TableList *table_list)
 
924
{
 
925
  return find_temporary_table(table_list->db, table_list->table_name);
 
926
}
 
927
 
934
928
 
935
929
/**
936
930
  Drop a temporary table.
1046
1040
  char *key;
1047
1041
  uint32_t key_length;
1048
1042
  TableShare *share= table->s;
1049
 
  TableList table_list;
1050
1043
 
1051
1044
  if (!(key=(char*) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH)))
1052
1045
    return true;                                /* purecov: inspected */
1053
1046
 
1054
 
  table_list.db= (char*) db;
1055
 
  table_list.table_name= (char*) table_name;
1056
 
  key_length= table_list.create_table_def_key(key);
 
1047
  key_length= TableShare::createKey(key, db, table_name);
1057
1048
  share->set_table_cache_key(key, key_length);
1058
1049
 
1059
1050
  return false;