68
68
Table *unused_tables; /* Used by mysql_test */
69
69
HASH open_cache; /* Used by mysql_test */
70
static int open_unireg_entry(Session *session, Table *entry, TableList *table_list,
70
static int open_unireg_entry(Session *session,
72
73
char *cache_key, uint32_t cache_key_length);
73
74
void free_cache_entry(void *entry);
86
87
Table *entry=(Table*) record;
87
*length= entry->s->table_cache_key.length;
88
return (unsigned char*) entry->s->table_cache_key.str;
88
*length= entry->s->getCacheKeySize();
89
return (unsigned char*) entry->s->getCacheKey();
91
92
HASH *get_open_cache()
150
149
This has to be done to ensure that the table share is removed from
151
150
the table defintion cache as soon as the last instance is removed
153
if (multi_alloc_root(mem_root,
154
&share, sizeof(*share),
155
&key_buff, old_share->table_cache_key.length,
158
memset(share, 0, sizeof(*share));
159
share->set_table_cache_key(key_buff, old_share->table_cache_key.str,
160
old_share->table_cache_key.length);
161
share->tmp_table= message::Table::INTERNAL; // for intern_close_table()
152
share= new TableShare(const_cast<char *>(old_share->getCacheKey()), static_cast<uint32_t>(old_share->getCacheKeySize()));
153
share->tmp_table= message::Table::INTERNAL; // for intern_close_table()
164
155
table->cursor->close();
165
156
table->db_stat= 0; // Mark cursor closed
635
628
if (table->s->tmp_table == message::Table::TEMPORARY)
637
if (identifier.compare(table->s->getSchemaName(), table->s->table_name.str))
630
if (identifier.compare(table->s->getSchemaName(), table->s->getTableName()))
652
645
if (table->s->tmp_table == message::Table::TEMPORARY)
654
if (identifier.compare(table->s->getSchemaName(), table->s->table_name.str))
647
if (identifier.compare(table->s->getSchemaName(), table->s->getTableName()))
656
649
table_proto.CopyFrom(*(table->s->getTableProto()));
673
666
for (Table *table= temporary_tables ; table ; table= table->next)
675
if (table->s->table_cache_key.length == key_length &&
676
not memcmp(table->s->table_cache_key.str, key, key_length))
668
if (table->s->getCacheKeySize() == key_length &&
669
not memcmp(table->s->getCacheKey(), key, key_length))
696
689
for (Table *table= temporary_tables ; table ; table= table->next)
698
if (table->s->table_cache_key.length == key_length &&
699
not memcmp(table->s->table_cache_key.str, key, key_length))
691
if (table->s->getCacheKeySize() == key_length &&
692
not memcmp(table->s->getCacheKey(), key, key_length))
779
772
void Session::unlink_open_table(Table *find)
781
774
char key[MAX_DBKEY_LENGTH];
782
uint32_t key_length= find->s->table_cache_key.length;
775
uint32_t key_length= find->s->getCacheKeySize();
783
776
Table *list, **prev;
785
778
safe_mutex_assert_owner(&LOCK_open);
787
memcpy(key, find->s->table_cache_key.str, key_length);
780
memcpy(key, find->s->getCacheKey(), key_length);
789
782
Note that we need to hold LOCK_open while changing the
790
783
open_tables list. Another thread may work on it.
799
if (list->s->table_cache_key.length == key_length &&
800
not memcmp(list->s->table_cache_key.str, key, key_length))
792
if (list->s->getCacheKeySize() == key_length &&
793
not memcmp(list->s->getCacheKey(), key, key_length))
802
795
/* Remove table from open_tables list. */
803
796
*prev= list->next;
935
928
orig_table= *table;
937
if (open_unireg_entry(this, table, table_list, table_name,
938
table->s->table_cache_key.str,
939
table->s->table_cache_key.length))
930
if (open_unireg_entry(this, table, table_name,
931
const_cast<char *>(table->s->getCacheKey()),
932
table->s->getCacheKeySize()))
941
934
table->intern_close_table();
1161
1154
for (table= temporary_tables; table ; table=table->next)
1163
if (table->s->table_cache_key.length == key_length && !memcmp(table->s->table_cache_key.str, key, key_length))
1156
if (table->s->getCacheKeySize() == key_length && !memcmp(table->s->getCacheKey(), key, key_length))
1166
1159
We're trying to use the same temporary table twice in a query.
1277
1270
if (table->open_placeholder && table->in_use == this)
1279
1272
pthread_mutex_unlock(&LOCK_open);
1280
my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->table_name.str);
1273
my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->getTableName());
1386
error= open_unireg_entry(this, table, table_list, alias, key, key_length);
1379
error= open_unireg_entry(this, table, alias, key, key_length);
1387
1380
if (error != 0)
1407
1400
if (lex->need_correct_ident())
1408
1401
table->alias_name_used= my_strcasecmp(table_alias_charset,
1409
table->s->table_name.str, alias);
1402
table->s->getTableName(), alias);
1410
1403
/* Fix alias if table name changes */
1411
1404
if (strcmp(table->alias, alias))
1474
1467
table_list.db= const_cast<char *>(table->s->getSchemaName());
1475
table_list.table_name= table->s->table_name.str;
1468
table_list.table_name= table->s->getTableName();
1476
1469
table_list.table= table;
1478
1471
if (wait_for_locked_table_names(session, &table_list))
1481
1474
if (open_unireg_entry(session, &tmp, &table_list,
1483
table->s->table_cache_key.str,
1484
table->s->table_cache_key.length))
1476
table->s->getCacheKey(),
1477
table->s->getCacheKeySize()))
1487
1480
/* This list copies variables set by open_table */
1569
1562
for (table= open_tables; table ; table=table->next)
1571
if (!strcmp(table->s->table_name.str, identifier.getTableName().c_str()) &&
1564
if (!strcmp(table->s->getTableName(), identifier.getTableName().c_str()) &&
1572
1565
!strcasecmp(table->s->getSchemaName(), identifier.getSchemaName().c_str()))
1574
1567
table->open_placeholder= true;
1776
char *key= table->s->table_cache_key.str;
1777
uint32_t key_length= table->s->table_cache_key.length;
1769
char *key= const_cast<char *>(table->s->getCacheKey());
1770
uint32_t key_length= table->s->getCacheKeySize();
1779
1772
HASH_SEARCH_STATE state;
1780
1773
for (Table *search= (Table*) hash_first(&open_cache, (unsigned char*) key,
1872
1865
for (table= session->open_tables; table ; table=next)
1874
1867
next=table->next;
1875
if (!strcmp(table->s->table_name.str, table_name) &&
1868
if (!strcmp(table->s->getTableName(), table_name) &&
1876
1869
!strcasecmp(table->s->getSchemaName(), db))
1878
1871
mysql_lock_remove(session, table);
1919
1912
for (table= session->open_tables; table ; table= table->next)
1921
if (!strcmp(table->s->table_name.str, table_name) &&
1914
if (!strcmp(table->s->getTableName(), table_name) &&
1922
1915
!strcmp(table->s->getSchemaName(), db))
1924
1917
/* If MERGE child, forward lock handling to parent. */
1952
static int open_unireg_entry(Session *session, Table *entry, TableList *table_list,
1945
static int open_unireg_entry(Session *session,
1953
1947
const char *alias,
1954
1948
char *cache_key, uint32_t cache_key_length)
1960
1954
safe_mutex_assert_owner(&LOCK_open);
1962
if (not (share= TableShare::getShare(session, table_list, cache_key,
1956
if (not (share= TableShare::getShare(session, cache_key,
1963
1957
cache_key_length,
1964
table_list->i_s_requested_object,
2298
2291
Table *new_tmp_table;
2299
2292
TableShare *share;
2300
char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path;
2301
uint32_t key_length, path_length;
2302
TableList table_list;
2293
char cache_key[MAX_DBKEY_LENGTH];
2294
uint32_t key_length;
2304
table_list.db= const_cast<char*>(identifier.getSchemaName().c_str());
2305
table_list.table_name= const_cast<char*>(identifier.getTableName().c_str());
2306
2296
/* Create the cache_key for temporary tables */
2307
key_length= table_list.create_table_def_key(cache_key);
2308
path_length= identifier.getPath().length();
2310
if (!(new_tmp_table= (Table*) malloc(sizeof(*new_tmp_table) + sizeof(*share) +
2311
path_length + 1 + key_length)))
2297
key_length= TableShare::createKey(cache_key, const_cast<char*>(identifier.getSchemaName().c_str()),
2298
const_cast<char*>(identifier.getTableName().c_str()));
2300
share= new TableShare(cache_key, key_length,
2301
const_cast<char *>(identifier.getPath().c_str()), static_cast<uint32_t>(identifier.getPath().length()));
2303
if (!(new_tmp_table= (Table*) malloc(sizeof(*new_tmp_table))))
2314
share= (TableShare*) (new_tmp_table+1);
2315
tmp_path= (char*) (share+1);
2316
saved_cache_key= strcpy(tmp_path, identifier.getPath().c_str())+path_length+1;
2317
memcpy(saved_cache_key, cache_key, key_length);
2319
share->init(saved_cache_key, key_length, strchr(saved_cache_key, '\0')+1, tmp_path);
2322
2308
First open the share, and then open the table from the share we just opened.