summaryrefslogtreecommitdiff
path: root/sql/table_cache.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/table_cache.cc')
-rw-r--r--sql/table_cache.cc39
1 files changed, 28 insertions, 11 deletions
diff --git a/sql/table_cache.cc b/sql/table_cache.cc
index 393fe931a82..5ca4dd9f175 100644
--- a/sql/table_cache.cc
+++ b/sql/table_cache.cc
@@ -46,7 +46,7 @@
TABLE_SHARE::tdc.flushed is true
*/
-#include "my_global.h"
+#include "mariadb.h"
#include "lf.h"
#include "table.h"
#include "sql_base.h"
@@ -56,7 +56,7 @@
ulong tdc_size; /**< Table definition cache threshold for LRU eviction. */
ulong tc_size; /**< Table cache threshold for LRU eviction. */
uint32 tc_instances;
-static uint32 tc_active_instances= 1;
+uint32 tc_active_instances= 1;
static uint32 tc_contention_warning_reported;
/** Data collections. */
@@ -369,18 +369,30 @@ void tc_add_table(THD *thd, TABLE *table)
mysql_mutex_unlock(&element->LOCK_table_share);
mysql_mutex_lock(&tc[i].LOCK_table_cache);
- if (tc[i].records == tc_size && (LRU_table= tc[i].free_tables.pop_front()))
+ if (tc[i].records == tc_size)
{
- LRU_table->s->tdc->free_tables[i].list.remove(LRU_table);
- /* Needed if MDL deadlock detector chimes in before tc_remove_table() */
- LRU_table->in_use= thd;
+ if ((LRU_table= tc[i].free_tables.pop_front()))
+ {
+ LRU_table->s->tdc->free_tables[i].list.remove(LRU_table);
+ /* Needed if MDL deadlock detector chimes in before tc_remove_table() */
+ LRU_table->in_use= thd;
+ mysql_mutex_unlock(&tc[i].LOCK_table_cache);
+ /* Keep out of locked LOCK_table_cache */
+ tc_remove_table(LRU_table);
+ }
+ else
+ {
+ tc[i].records++;
+ mysql_mutex_unlock(&tc[i].LOCK_table_cache);
+ }
+ /* Keep out of locked LOCK_table_cache */
+ status_var_increment(thd->status_var.table_open_cache_overflows);
}
else
+ {
tc[i].records++;
- mysql_mutex_unlock(&tc[i].LOCK_table_cache);
-
- if (LRU_table)
- tc_remove_table(LRU_table);
+ mysql_mutex_unlock(&tc[i].LOCK_table_cache);
+ }
}
@@ -815,7 +827,7 @@ retry:
lf_hash_search_unpin(thd->tdc_hash_pins);
DBUG_ASSERT(element);
- if (!(share= alloc_table_share(tl->db, tl->table_name, key, key_length)))
+ if (!(share= alloc_table_share(tl->db.str, tl->table_name.str, key, key_length)))
{
lf_hash_delete(&tdc_hash, thd->tdc_hash_pins, key, key_length);
DBUG_RETURN(0);
@@ -841,7 +853,10 @@ retry:
tdc_purge(false);
if (out_table)
+ {
+ status_var_increment(thd->status_var.table_open_cache_misses);
*out_table= 0;
+ }
share->m_psi= PSI_CALL_get_table_share(false, share);
goto end;
}
@@ -858,8 +873,10 @@ retry:
DBUG_ASSERT(element->share);
DBUG_ASSERT(!element->share->error);
DBUG_ASSERT(!element->share->is_view);
+ status_var_increment(thd->status_var.table_open_cache_hits);
DBUG_RETURN(element->share);
}
+ status_var_increment(thd->status_var.table_open_cache_misses);
}
mysql_mutex_lock(&element->LOCK_table_share);