99
105
refresh_version++; // Force close of open tables
101
107
while (unused_tables)
102
hash_delete(&open_cache,(unsigned char*) unused_tables);
108
hash_delete(&open_cache, (unsigned char*) unused_tables);
104
if (!open_cache.records) // Safety first
110
if (not open_cache.records) // Safety first
105
111
hash_free(&open_cache);
166
Create a list for all open tables matching SQL expression
170
wild SQL like expression
173
One gets only a list of tables for which one has any kind of privilege.
174
db and table names are allocated in result struct, so one doesn't need
175
a lock on LOCK_open when traversing the return list.
181
bool list_open_tables(const char *db,
183
bool(*func)(Table *table,
184
open_table_list_st& open_list,
185
plugin::InfoSchemaTable *schema_table),
187
plugin::InfoSchemaTable *schema_table)
189
vector<open_table_list_st> open_list;
190
vector<open_table_list_st>::iterator it;
191
open_table_list_st table;
193
/* What we really need is an optimization for knowing unique tables */
195
open_list.reserve(sizeof(open_table_list_st) * (open_cache.records % 2));
197
open_list.reserve(sizeof(open_table_list_st) * open_cache.records);
199
pthread_mutex_lock(&LOCK_open); /* List all open tables */
201
for (uint32_t idx= 0; idx < open_cache.records; idx++)
204
Table *entry=(Table*) hash_element(&open_cache,idx);
206
if (db && my_strcasecmp(system_charset_info, db, entry->s->db.str))
208
if (wild && internal::wild_compare(entry->s->table_name.str, wild, 0))
211
for (it= open_list.begin(); it < open_list.end(); it++)
213
if (!(*it).table.compare(entry->s->table_name.str) &&
214
!(*it).db.compare(entry->s->db.str))
218
if (entry->locked_by_name)
230
table.db= entry->s->db.str;
231
table.table= entry->s->table_name.str;
232
open_list.push_back(table);
234
pthread_mutex_unlock(&LOCK_open);
236
for (it= open_list.begin(); it < open_list.end(); it++)
238
if (func(display, *it, schema_table))
245
170
/*****************************************************************************
246
171
* Functions to free open table cache
247
172
****************************************************************************/
567
492
for (; table; table= table->*link )
569
if ((table->table == 0 || table->table->s->tmp_table == NO_TMP_TABLE) &&
494
if ((table->table == 0 || table->table->s->tmp_table == STANDARD_TABLE) &&
570
495
strcmp(table->db, db_name) == 0 &&
571
496
strcmp(table->table_name, table_name) == 0)
589
void Session::doGetTableNames(CachedDirectory &,
590
const std::string& db_name,
591
std::set<std::string>& set_of_names)
593
for (Table *table= temporary_tables ; table ; table= table->next)
595
if (not db_name.compare(table->s->db.str))
597
set_of_names.insert(table->s->table_name.str);
602
int Session::doGetTableDefinition(const char *,
604
const char *table_name_arg,
606
message::Table *table_proto)
608
for (Table *table= temporary_tables ; table ; table= table->next)
610
if (table->s->tmp_table == TEMP_TABLE)
612
if (not strcmp(db_arg, table->s->db.str))
614
if (not strcmp(table_name_arg, table->s->table_name.str))
617
table_proto->CopyFrom(*(table->s->getTableProto()));
664
628
Table *Session::find_temporary_table(const char *new_db, const char *table_name)
666
630
char key[MAX_DBKEY_LENGTH];
829
793
that something has happened.
831
795
unlink_open_table(table);
832
TableIdentifier identifier(db_name, table_name, NO_TMP_TABLE);
796
TableIdentifier identifier(db_name, table_name, STANDARD_TABLE);
833
797
quick_rm_table(*this, identifier);
834
798
pthread_mutex_unlock(&LOCK_open);
1326
1290
if (table_list->create)
1328
TableIdentifier lock_table_identifier(table_list->db, table_list->table_name, NO_TMP_TABLE);
1292
TableIdentifier lock_table_identifier(table_list->db, table_list->table_name, STANDARD_TABLE);
1330
if (plugin::StorageEngine::getTableDefinition(*this, lock_table_identifier) != EEXIST)
1294
if (not plugin::StorageEngine::doesTableExist(*this, lock_table_identifier))
1333
1297
Table to be created, so we need to create placeholder in table-cache.
1379
1343
table->reginfo.lock_type= TL_READ; /* Assume read */
1382
assert(table->s->ref_count > 0 || table->s->tmp_table != NO_TMP_TABLE);
1346
assert(table->s->ref_count > 0 || table->s->tmp_table != STANDARD_TABLE);
1384
1348
if (lex->need_correct_ident())
1385
1349
table->alias_name_used= my_strcasecmp(table_alias_charset,
2039
* Is the user authorized to see this table? Do this before we check
2040
* to see if it exists so that an unauthorized user cannot phish for
2041
* table/schema information via error messages
2043
if (not plugin::Authorization::isAuthorized(getSecurityContext(),
2045
string(tables->table_name)))
2047
result= -1; // Fatal error
2075
2053
Not a placeholder: must be a base table or a view, and the table is
2076
2054
not opened yet. Try to open the table.
2111
2089
if (tables->lock_type == TL_WRITE_DEFAULT)
2112
2090
tables->table->reginfo.lock_type= update_lock_default;
2113
else if (tables->table->s->tmp_table == NO_TMP_TABLE)
2091
else if (tables->table->s->tmp_table == STANDARD_TABLE)
2114
2092
tables->table->reginfo.lock_type= tables->lock_type;
4148
TODO: in the case when we skipped all columns because there was a
4149
qualified '*', and all columns were coalesced, we have to give a more
4150
meaningful message than ER_BAD_TABLE_ERROR.
4126
@TODO in the case when we skipped all columns because there was a
4127
qualified '*', and all columns were coalesced, we have to give a more
4128
meaningful message than ER_BAD_TABLE_ERROR.
4152
4130
if (!table_name)
4153
4131
my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
4418
4396
and afterwards delete those marked unused.
4421
void remove_db_from_cache(const char *db)
4399
void remove_db_from_cache(const std::string schema_name)
4423
4401
safe_mutex_assert_owner(&LOCK_open);
4425
4403
for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
4427
4405
Table *table=(Table*) hash_element(&open_cache,idx);
4428
if (!strcmp(table->s->db.str, db))
4406
if (not strcmp(table->s->db.str, schema_name.c_str()))
4430
4408
table->s->version= 0L; /* Free when thread is ready */
4409
if (not table->in_use)
4432
4410
relink_unused(table);