735
Close all tables which match specified connection string or
736
if specified string is NULL, then any table with a connection string.
739
bool close_cached_connection_tables(Session *session, bool if_wait_for_refresh,
740
LEX_STRING *connection, bool have_lock)
743
TableList tmp, *tables= NULL;
748
pthread_mutex_lock(&LOCK_open);
750
for (idx= 0; idx < table_def_cache.records; idx++)
752
TableShare *share= (TableShare *) hash_element(&table_def_cache, idx);
754
/* Ignore if table is not open or does not have a connect_string */
755
if (!share->connect_string.length || !share->ref_count)
758
/* Compare the connection string */
760
(connection->length > share->connect_string.length ||
761
(connection->length < share->connect_string.length &&
762
(share->connect_string.str[connection->length] != '/' &&
763
share->connect_string.str[connection->length] != '\\')) ||
764
strncasecmp(connection->str, share->connect_string.str,
765
connection->length)))
768
/* close_cached_tables() only uses these elements */
769
tmp.db= share->db.str;
770
tmp.table_name= share->table_name.str;
771
tmp.next_local= tables;
773
tables= (TableList *) memdup_root(session->mem_root, (char*)&tmp,
778
result= close_cached_tables(session, tables, true, false, false);
781
pthread_mutex_unlock(&LOCK_open);
783
if (if_wait_for_refresh)
785
pthread_mutex_lock(&session->mysys_var->mutex);
786
session->mysys_var->current_mutex= 0;
787
session->mysys_var->current_cond= 0;
788
session->set_proc_info(0);
789
pthread_mutex_unlock(&session->mysys_var->mutex);
797
Auxiliary function to close all tables in the open_tables list.
799
@param session Thread context.
801
@remark It should not ordinarily be called directly.
730
move one table to free list
804
void Session::close_open_tables()
806
bool found_old_table= 0;
808
safe_mutex_assert_not_owner(&LOCK_open);
810
pthread_mutex_lock(&LOCK_open);
813
found_old_table|= close_thread_table(this, &open_tables);
814
some_tables_deleted= 0;
816
/* Free tables to hold down open files */
817
while (open_cache.records > table_cache_size && unused_tables)
818
hash_delete(&open_cache,(unsigned char*) unused_tables); /* purecov: tested */
821
/* Tell threads waiting for refresh that something has happened */
825
pthread_mutex_unlock(&LOCK_open);
829
/* move one table to free list */
831
bool close_thread_table(Session *session, Table **table_ptr)
733
static bool free_cached_table(Session *session, Table **table_ptr)
833
735
bool found_old_table= 0;
834
736
Table *table= *table_ptr;
738
safe_mutex_assert_owner(&LOCK_open);
836
739
assert(table->key_read == 0);
837
740
assert(!table->file || table->file->inited == handler::NONE);
839
*table_ptr=table->next;
742
*table_ptr= table->next;
841
744
if (table->needs_reopen_or_name_lock() ||
842
745
session->version != refresh_version || !table->db_stat)
844
747
hash_delete(&open_cache,(unsigned char*) table);
748
found_old_table= true;
866
769
unused_tables=table->next=table->prev=table;
868
return(found_old_table);
772
return found_old_table;
777
Auxiliary function to close all tables in the open_tables list.
779
@param session Thread context.
781
@remark It should not ordinarily be called directly.
784
void Session::close_open_tables()
786
bool found_old_table= false;
788
safe_mutex_assert_not_owner(&LOCK_open);
790
pthread_mutex_lock(&LOCK_open); /* Close all open tables on Session */
793
found_old_table|= free_cached_table(this, &open_tables);
794
some_tables_deleted= false;
798
/* Tell threads waiting for refresh that something has happened */
802
pthread_mutex_unlock(&LOCK_open);
1618
1549
of temporary tables of this thread. In MySQL temporary tables
1619
1550
are always thread-local and "shadow" possible base tables with the
1620
1551
same name. This block implements the behaviour.
1621
TODO: move this block into a separate function.
1552
TODO -> move this block into a separate function.
1554
for (table= session->temporary_tables; table ; table=table->next)
1624
for (table= session->temporary_tables; table ; table=table->next)
1556
if (table->s->table_cache_key.length == key_length && !memcmp(table->s->table_cache_key.str, key, key_length))
1626
if (table->s->table_cache_key.length == key_length && !memcmp(table->s->table_cache_key.str, key, key_length))
1559
We're trying to use the same temporary table twice in a query.
1560
Right now we don't support this because a temporary table
1561
is always represented by only one Table object in Session, and
1562
it can not be cloned. Emit an error for an unsupported behaviour.
1564
if (table->query_id)
1629
We're trying to use the same temporary table twice in a query.
1630
Right now we don't support this because a temporary table
1631
is always represented by only one Table object in Session, and
1632
it can not be cloned. Emit an error for an unsupported behaviour.
1634
if (table->query_id)
1636
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
1639
table->query_id= session->query_id;
1566
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
1569
table->query_id= session->query_id;
1645
1574
if (flags & DRIZZLE_OPEN_TEMPORARY_ONLY)
1647
1576
my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->table_name);
1731
1660
locked tables list was created.
1733
1662
my_error(ER_TABLE_NOT_LOCKED, MYF(0), alias);
1667
If it's the first table from a list of tables used in a query,
1668
remember refresh_version (the version of open_cache state).
1669
If the version changes while we're opening the remaining tables,
1670
we will have to back off, close all the tables opened-so-far,
1671
and try to reopen them.
1673
Note-> refresh_version is currently changed only during FLUSH TABLES.
1675
if (!session->open_tables)
1676
session->version=refresh_version;
1677
else if ((session->version != refresh_version) &&
1678
! (flags & DRIZZLE_LOCK_IGNORE_FLUSH))
1680
/* Someone did a refresh while thread was opening tables */
1683
pthread_mutex_unlock(&LOCK_open);
1689
Before we test the global cache, we test our local session cache.
1691
if (session->cached_table)
1693
assert(false); /* Not implemented yet */
1741
1700
- try to find the table in the table cache.
1742
1701
- if one of the discovered Table instances is name-locked
1743
(table->s->version == 0) or some thread has started FLUSH TABLES
1744
(refresh_version > table->s->version), back off -- we have to wait
1702
(table->s->version == 0) back off -- we have to wait
1745
1703
until no one holds a name lock on the table.
1746
1704
- if there is no such Table in the name cache, read the table definition
1747
1705
and insert it into the cache.
1753
pthread_mutex_lock(&LOCK_open);
1756
If it's the first table from a list of tables used in a query,
1757
remember refresh_version (the version of open_cache state).
1758
If the version changes while we're opening the remaining tables,
1759
we will have to back off, close all the tables opened-so-far,
1760
and try to reopen them.
1761
Note: refresh_version is currently changed only during FLUSH TABLES.
1763
if (!session->open_tables)
1764
session->version=refresh_version;
1765
else if ((session->version != refresh_version) &&
1766
! (flags & DRIZZLE_LOCK_IGNORE_FLUSH))
1768
/* Someone did a refresh while thread was opening tables */
1771
pthread_mutex_unlock(&LOCK_open);
1711
pthread_mutex_lock(&LOCK_open); /* Lock for FLUSH TABLES for open table */
1776
1714
Actually try to find the table in the open_cache.