~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/table_share.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "drizzled/error.h"
34
34
#include "drizzled/gettext.h"
35
35
#include "drizzled/sql_base.h"
36
 
#include "drizzled/hash.h"
37
36
#include "drizzled/pthread_globals.h"
38
37
#include "drizzled/internal/my_pthread.h"
39
38
 
43
42
{
44
43
 
45
44
extern size_t table_def_size;
46
 
typedef hash_map<string, TableShare *> TableDefCache;
47
 
TableDefCache table_def_cache;
 
45
TableDefinitionCache table_def_cache;
48
46
static pthread_mutex_t LOCK_table_share;
49
47
bool table_def_inited= false;
50
48
 
60
58
  /* 
61
59
   * This is going to overalloc a bit - as rehash sets the number of
62
60
   * buckets, not the number of elements. BUT, it'll allow us to not need
63
 
   * to rehash later on as the hash_map grows.
 
61
   * to rehash later on as the unordered_map grows.
64
62
   */
65
63
  table_def_cache.rehash(table_def_size);
66
64
}
110
108
  {
111
109
    const string key_string(share->table_cache_key.str,
112
110
                            share->table_cache_key.length);
113
 
    TableDefCache::iterator iter= table_def_cache.find(key_string);
 
111
    TableDefinitionCache::iterator iter= table_def_cache.find(key_string);
114
112
    if (iter != table_def_cache.end())
115
113
    {
116
114
      (*iter).second->free_table_share();
125
123
{
126
124
  const string key_string(key, key_length);
127
125
 
128
 
  TableDefCache::iterator iter= table_def_cache.find(key_string);
 
126
  TableDefinitionCache::iterator iter= table_def_cache.find(key_string);
129
127
  if (iter != table_def_cache.end())
130
128
  {
131
129
    TableShare *share= (*iter).second;
197
195
  *error= 0;
198
196
 
199
197
  /* Read table definition from cache */
200
 
  TableDefCache::iterator iter= table_def_cache.find(key_string);
 
198
  TableDefinitionCache::iterator iter= table_def_cache.find(key_string);
201
199
  if (iter != table_def_cache.end())
202
200
  {
203
201
    share= (*iter).second;
204
202
    return foundTableShare(share);
205
203
  }
206
204
 
207
 
  if (!(share= alloc_table_share(table_list, key, key_length)))
 
205
  if (not (share= alloc_table_share(table_list, key, key_length)))
208
206
  {
209
207
    return NULL;
210
208
  }
218
216
  /**
219
217
   * @TODO: we need to eject something if we exceed table_def_size
220
218
   */
221
 
  pair<TableDefCache::iterator, bool> ret=
 
219
  pair<TableDefinitionCache::iterator, bool> ret=
222
220
    table_def_cache.insert(make_pair(key_string, share));
223
221
  if (ret.second == false)
224
222
  {
226
224
    return NULL;
227
225
  }
228
226
  
229
 
  if (open_table_def(*session, share))
 
227
  TableIdentifier identifier(share->getSchemaName(), share->getTableName());
 
228
  if (open_table_def(*session, identifier, share))
230
229
  {
231
230
    *error= share->error;
232
231
    table_def_cache.erase(key_string);
235
234
  }
236
235
  share->ref_count++;                           // Mark in use
237
236
  (void) pthread_mutex_unlock(&share->mutex);
 
237
 
238
238
  return share;
239
 
 
240
239
}
241
240
 
242
241
 
252
251
  0  Not cached
253
252
#  TableShare for table
254
253
*/
255
 
 
256
 
TableShare *TableShare::getShare(const char *db, const char *table_name)
 
254
TableShare *TableShare::getShare(TableIdentifier &identifier)
257
255
{
258
 
  char key[NAME_LEN*2+2];
 
256
  char key[MAX_DBKEY_LENGTH];
259
257
  uint32_t key_length;
260
258
  safe_mutex_assert_owner(&LOCK_open);
261
259
 
262
 
  key_length= TableShare::createKey(key, db, table_name);
 
260
  key_length= TableShare::createKey(key, identifier);
263
261
 
264
262
  const string key_string(key, key_length);
265
 
  TableDefCache::iterator iter= table_def_cache.find(key_string);
 
263
 
 
264
  TableDefinitionCache::iterator iter= table_def_cache.find(key_string);
266
265
  if (iter != table_def_cache.end())
267
266
  {
268
267
    return (*iter).second;
300
299
  return false;
301
300
}
302
301
 
 
302
TableDefinitionCache &TableShare::getCache()
 
303
{
 
304
  return table_def_cache;
 
305
}
 
306
 
303
307
} /* namespace drizzled */