#At file:///export/home/thek/bzr/mysql-5.1-bug38551/
2735 Kristofer Pettersson 2008-09-08
Bug#38551 query cache can still consume [very little] cpu time even when it is off.
When the query cache size is zero, all query cache functionallity should be
skipped. Since query_cache_size is protected from any changes by the
barrier in Query_cache::resize() we can safely add a test at the begining
of the invalidate* functions to avoid having mutexes locked when
the query cache is ment to be disabled.
modified:
sql/sql_cache.cc
per-file messages:
sql/sql_cache.cc
Added enable/disable checks for all invalidate interface methods.
+ Removed redundant call to current_thd
=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc 2008-07-25 15:12:47 +0000
+++ b/sql/sql_cache.cc 2008-09-08 11:29:43 +0000
@@ -1484,7 +1484,8 @@ err:
void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
my_bool using_transactions)
{
- DBUG_ENTER("Query_cache::invalidate (table list)");
+ if (query_cache_size == 0)
+ return;
using_transactions= using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
@@ -1506,22 +1507,20 @@ void Query_cache::invalidate(THD *thd, T
invalidate_table(thd, tables_used);
}
- DBUG_VOID_RETURN;
+ return;
}
void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used)
{
- DBUG_ENTER("Query_cache::invalidate (changed table list)");
+ if (query_cache_size == 0)
+ return;
THD *thd= current_thd;
for (; tables_used; tables_used= tables_used->next)
{
thd_proc_info(thd, "invalidating query cache entries (table list)");
invalidate_table(thd, (uchar*) tables_used->key, tables_used->key_length);
- DBUG_PRINT("qcache", ("db: %s table: %s", tables_used->key,
- tables_used->key+
- strlen(tables_used->key)+1));
}
- DBUG_VOID_RETURN;
+ return;
}
@@ -1537,19 +1536,19 @@ void Query_cache::invalidate(CHANGED_TAB
*/
void Query_cache::invalidate_locked_for_write(TABLE_LIST *tables_used)
{
+ if (query_cache_size == 0)
+ return;
THD *thd= current_thd;
- DBUG_ENTER("Query_cache::invalidate_locked_for_write");
for (; tables_used; tables_used= tables_used->next_local)
{
thd_proc_info(thd, "invalidating query cache entries (table)");
if (tables_used->lock_type & (TL_WRITE_LOW_PRIORITY | TL_WRITE) &&
tables_used->table)
{
- THD *thd= current_thd;
invalidate_table(thd, tables_used->table);
}
}
- DBUG_VOID_RETURN;
+ return;
}
/*
@@ -1559,8 +1558,8 @@ void Query_cache::invalidate_locked_for_
void Query_cache::invalidate(THD *thd, TABLE *table,
my_bool using_transactions)
{
- DBUG_ENTER("Query_cache::invalidate (table)");
-
+ if (query_cache_size == 0)
+ return;
using_transactions= using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
if (using_transactions &&
@@ -1568,15 +1567,14 @@ void Query_cache::invalidate(THD *thd, T
thd->add_changed_table(table);
else
invalidate_table(thd, table);
-
-
- DBUG_VOID_RETURN;
+ return;
}
void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length,
my_bool using_transactions)
{
- DBUG_ENTER("Query_cache::invalidate (key)");
+ if (query_cache_size == 0)
+ return;
using_transactions= using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
@@ -1585,7 +1583,7 @@ void Query_cache::invalidate(THD *thd, c
else
invalidate_table(thd, (uchar*)key, key_length);
- DBUG_VOID_RETURN;
+ return;
}
@@ -1636,8 +1634,9 @@ void Query_cache::wait_while_table_flush
void Query_cache::invalidate(char *db)
{
+ if (query_cache_size == 0)
+ return;
bool restart= FALSE;
- DBUG_ENTER("Query_cache::invalidate (db)");
STRUCT_LOCK(&structure_guard_mutex);
bool interrupt;
@@ -1704,13 +1703,14 @@ void Query_cache::invalidate(char *db)
}
STRUCT_UNLOCK(&structure_guard_mutex);
- DBUG_VOID_RETURN;
+ return;
}
void Query_cache::invalidate_by_MyISAM_filename(const char *filename)
{
- DBUG_ENTER("Query_cache::invalidate_by_MyISAM_filename");
+ if (query_cache_size == 0)
+ return;
/* Calculate the key outside the lock to make the lock shorter */
char key[MAX_DBKEY_LENGTH];
@@ -1718,7 +1718,7 @@ void Query_cache::invalidate_by_MyISAM_f
uint key_length= filename_2_table_key(key, filename, &db_length);
THD *thd= current_thd;
invalidate_table(thd,(uchar *)key, key_length);
- DBUG_VOID_RETURN;
+ return;
}
/* Remove all queries from cache */
@@ -2506,6 +2506,9 @@ my_bool Query_cache::allocate_data_chain
void Query_cache::invalidate_table(THD *thd, TABLE_LIST *table_list)
{
+ if (query_cache_size == 0)
+ return;
+
if (table_list->table != 0)
invalidate_table(thd, table_list->table); // Table is open
else
@@ -2523,12 +2526,17 @@ void Query_cache::invalidate_table(THD *
void Query_cache::invalidate_table(THD *thd, TABLE *table)
{
+ if (query_cache_size == 0)
+ return;
+
invalidate_table(thd, (uchar*) table->s->table_cache_key.str,
table->s->table_cache_key.length);
}
void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length)
{
+ if (query_cache_size == 0)
+ return;
bool interrupt;
STRUCT_LOCK(&structure_guard_mutex);
wait_while_table_flush_is_in_progress(&interrupt);
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (kristofer.pettersson:2735) Bug#38551 | Kristofer Pettersson | 8 Sep |