~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-06-16 17:29:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1625.
  • Revision ID: brian@gaz-20100616172900-fzv6n6nrtyhhny7x
Update for TableShare usage of key (remove a case where we had to build it). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
                               bool )
87
87
{
88
88
  Table *entry=(Table*) record;
89
 
  *length= entry->getShare()->getCacheKeySize();
90
 
  return (unsigned char*) entry->getMutableShare()->getCacheKey();
 
89
  *length= entry->getShare()->getCacheKey().size();
 
90
  return (unsigned char*) &entry->getShare()->getCacheKey()[0];
91
91
}
92
92
 
93
93
HASH *get_open_cache()
142
142
void close_handle_and_leave_table_as_lock(Table *table)
143
143
{
144
144
  TableShare *share, *old_share= table->getMutableShare();
145
 
 
146
145
  assert(table->db_stat);
 
146
  assert(table->getShare()->getType() == message::Table::STANDARD);
147
147
 
148
148
  /*
149
149
    Make a local copy of the table share and free the current one.
151
151
    the table defintion cache as soon as the last instance is removed
152
152
  */
153
153
  TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), message::Table::INTERNAL);
 
154
  const TableIdentifier::Key &key(identifier.getKey());
154
155
  share= new TableShare(identifier.getType(),
155
156
                        identifier,
156
 
                        const_cast<char *>(old_share->getCacheKey()),  static_cast<uint32_t>(old_share->getCacheKeySize()));
 
157
                        const_cast<char *>(&key[0]),  static_cast<uint32_t>(old_share->getCacheKeySize()));
157
158
 
158
159
  table->cursor->close();
159
160
  table->db_stat= 0;                            // Mark cursor closed
687
688
 
688
689
  for (Table *table= temporary_tables ; table ; table= table->getNext())
689
690
  {
690
 
    if (table->getShare()->getCacheKeySize() == key_length &&
691
 
        not memcmp(table->getMutableShare()->getCacheKey(), key, key_length))
 
691
    const TableIdentifier::Key &share_key(table->getShare()->getCacheKey());
 
692
    if (share_key.size() == key_length &&
 
693
        not memcmp(&share_key[0], key, key_length))
692
694
    {
693
695
      return table;
694
696
    }
703
705
 
704
706
Table *Session::find_temporary_table(TableIdentifier &identifier)
705
707
{
706
 
  const TableIdentifier::Key &key(identifier.getKey());
707
 
 
708
708
  for (Table *table= temporary_tables ; table ; table= table->getNext())
709
709
  {
710
 
    if (table->getShare()->getCacheKeySize() == key.size() &&
711
 
        not memcmp(table->getMutableShare()->getCacheKey(), &key[0], key.size()))
712
 
 
 
710
    if (identifier.getKey() == table->getShare()->getCacheKey())
713
711
      return table;
714
712
  }
715
713
 
793
791
  char key[MAX_DBKEY_LENGTH];
794
792
  uint32_t key_length= find->getShare()->getCacheKeySize();
795
793
  Table *list, **prev;
796
 
 
797
794
  safe_mutex_assert_owner(&LOCK_open);
798
795
 
799
 
  memcpy(key, find->getMutableShare()->getCacheKey(), key_length);
 
796
  memcpy(key, &find->getMutableShare()->getCacheKey()[0], key_length);
800
797
  /*
801
798
    Note that we need to hold LOCK_open while changing the
802
799
    open_tables list. Another thread may work on it.
809
806
    list= *prev;
810
807
 
811
808
    if (list->getShare()->getCacheKeySize() == key_length &&
812
 
        not memcmp(list->getMutableShare()->getCacheKey(), key, key_length))
 
809
        not memcmp(&list->getShare()->getCacheKey()[0], key, key_length))
813
810
    {
814
811
      /* Remove table from open_tables list. */
815
812
      *prev= list->getNext();
1158
1155
  */
1159
1156
  for (table= temporary_tables; table ; table=table->getNext())
1160
1157
  {
1161
 
    if (table->getShare()->getCacheKeySize() == key_length && !memcmp(table->getMutableShare()->getCacheKey(), &key[0], key_length))
 
1158
    if (table->getShare()->getCacheKey() == key)
1162
1159
    {
1163
1160
      /*
1164
1161
        We're trying to use the same temporary table twice in a query.
1776
1773
{
1777
1774
  do
1778
1775
  {
1779
 
    char *key= const_cast<char *>(table->getMutableShare()->getCacheKey());
1780
 
    uint32_t key_length= table->getShare()->getCacheKeySize();
 
1776
    const TableIdentifier::Key &key(table->getShare()->getCacheKey());
1781
1777
 
1782
1778
    HASH_SEARCH_STATE state;
1783
 
    for (Table *search= (Table*) hash_first(&open_cache, (unsigned char*) key,
1784
 
                                            key_length, &state);
 
1779
    for (Table *search= (Table*) hash_first(&open_cache, (unsigned char*) &key[0],
 
1780
                                            key.size(), &state);
1785
1781
         search ;
1786
 
         search= (Table*) hash_next(&open_cache, (unsigned char*) key,
1787
 
                                    key_length, &state))
 
1782
         search= (Table*) hash_next(&open_cache, (unsigned char*) &key[0],
 
1783
                                    key.size(), &state))
1788
1784
    {
1789
1785
      if (search->in_use == table->in_use)
1790
1786
        continue;                               // Name locked by this thread