@@ -286,6 +286,7 @@ The query cache interfaces with the rest of the server code through 7
286
286
if (and only if) this query has a registered result set writer
287
287
(thd->net.query_cache_query).
288
288
4. Query_cache::invalidate
289
+ Query_cache::invalidate_locked_for_write
289
290
- Called from various places to invalidate query cache based on data-
290
291
base, table and myisam file name. During an on going invalidation
291
292
the query cache is temporarily disabled.
@@ -851,7 +852,7 @@ Query_cache::insert(Query_cache_tls *query_cache_tls,
851
852
DBUG_ENTER (" Query_cache::insert" );
852
853
853
854
/* See the comment on double-check locking usage above. */
854
- if (query_cache_tls->first_query_block == NULL )
855
+ if (is_disabled () || query_cache_tls->first_query_block == NULL )
855
856
DBUG_VOID_RETURN;
856
857
857
858
DBUG_EXECUTE_IF (" wait_in_query_cache_insert" ,
@@ -913,7 +914,7 @@ Query_cache::abort(Query_cache_tls *query_cache_tls)
913
914
THD *thd= current_thd;
914
915
915
916
/* See the comment on double-check locking usage above. */
916
- if (query_cache_tls->first_query_block == NULL )
917
+ if (is_disabled () || query_cache_tls->first_query_block == NULL )
917
918
DBUG_VOID_RETURN;
918
919
919
920
if (try_lock ())
@@ -1055,7 +1056,7 @@ Query_cache::Query_cache(ulong query_cache_limit_arg,
1055
1056
min_result_data_size(ALIGN_SIZE(min_result_data_size_arg)),
1056
1057
def_query_hash_size(ALIGN_SIZE(def_query_hash_size_arg)),
1057
1058
def_table_hash_size(ALIGN_SIZE(def_table_hash_size_arg)),
1058
- initialized(0 )
1059
+ initialized(0 ), m_query_cache_is_disabled( FALSE )
1059
1060
{
1060
1061
ulong min_needed= (ALIGN_SIZE (sizeof (Query_cache_block)) +
1061
1062
ALIGN_SIZE (sizeof (Query_cache_block_table)) +
@@ -1362,8 +1363,8 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
1362
1363
1363
1364
See also a note on double-check locking usage above.
1364
1365
*/
1365
- if (thd-> locked_tables || thd->variables . query_cache_type == 0 ||
1366
- query_cache_size == 0 )
1366
+ if (is_disabled () || thd->locked_tables ||
1367
+ thd-> variables . query_cache_type == 0 || query_cache_size == 0 )
1367
1368
goto err;
1368
1369
1369
1370
if (!thd->lex ->safe_to_cache_query )
@@ -1669,6 +1670,8 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
1669
1670
my_bool using_transactions)
1670
1671
{
1671
1672
DBUG_ENTER (" Query_cache::invalidate (table list)" );
1673
+ if (is_disabled ())
1674
+ DBUG_VOID_RETURN;
1672
1675
1673
1676
using_transactions= using_transactions &&
1674
1677
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
@@ -1699,6 +1702,9 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
1699
1702
void Query_cache::invalidate (CHANGED_TABLE_LIST *tables_used)
1700
1703
{
1701
1704
DBUG_ENTER (" Query_cache::invalidate (changed table list)" );
1705
+ if (is_disabled ())
1706
+ DBUG_VOID_RETURN;
1707
+
1702
1708
THD *thd= current_thd;
1703
1709
for (; tables_used; tables_used= tables_used->next )
1704
1710
{
@@ -1724,8 +1730,11 @@ void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used)
1724
1730
*/
1725
1731
void Query_cache::invalidate_locked_for_write (TABLE_LIST *tables_used)
1726
1732
{
1727
- THD *thd= current_thd;
1728
1733
DBUG_ENTER (" Query_cache::invalidate_locked_for_write" );
1734
+ if (is_disabled ())
1735
+ DBUG_VOID_RETURN;
1736
+
1737
+ THD *thd= current_thd;
1729
1738
for (; tables_used; tables_used= tables_used->next_local )
1730
1739
{
1731
1740
thd_proc_info (thd, " invalidating query cache entries (table)" );
@@ -1746,7 +1755,9 @@ void Query_cache::invalidate(THD *thd, TABLE *table,
1746
1755
my_bool using_transactions)
1747
1756
{
1748
1757
DBUG_ENTER (" Query_cache::invalidate (table)" );
1749
-
1758
+ if (is_disabled ())
1759
+ DBUG_VOID_RETURN;
1760
+
1750
1761
using_transactions= using_transactions &&
1751
1762
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
1752
1763
if (using_transactions &&
@@ -1763,6 +1774,8 @@ void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length,
1763
1774
my_bool using_transactions)
1764
1775
{
1765
1776
DBUG_ENTER (" Query_cache::invalidate (key)" );
1777
+ if (is_disabled ())
1778
+ DBUG_VOID_RETURN;
1766
1779
1767
1780
using_transactions= using_transactions &&
1768
1781
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
@@ -1781,9 +1794,12 @@ void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length,
1781
1794
1782
1795
void Query_cache::invalidate (char *db)
1783
1796
{
1784
- bool restart= FALSE ;
1797
+
1785
1798
DBUG_ENTER (" Query_cache::invalidate (db)" );
1799
+ if (is_disabled ())
1800
+ DBUG_VOID_RETURN;
1786
1801
1802
+ bool restart= FALSE ;
1787
1803
/*
1788
1804
Lock the query cache and queue all invalidation attempts to avoid
1789
1805
the risk of a race between invalidation, cache inserts and flushes.
@@ -1868,6 +1884,9 @@ void Query_cache::invalidate_by_MyISAM_filename(const char *filename)
1868
1884
void Query_cache::flush ()
1869
1885
{
1870
1886
DBUG_ENTER (" Query_cache::flush" );
1887
+ if (is_disabled ())
1888
+ DBUG_VOID_RETURN;
1889
+
1871
1890
DBUG_EXECUTE_IF (" wait_in_query_cache_flush1" ,
1872
1891
debug_wait_for_kill (" wait_in_query_cache_flush1" ););
1873
1892
@@ -1899,6 +1918,9 @@ void Query_cache::pack(ulong join_limit, uint iteration_limit)
1899
1918
{
1900
1919
DBUG_ENTER (" Query_cache::pack" );
1901
1920
1921
+ if (is_disabled ())
1922
+ DBUG_VOID_RETURN;
1923
+
1902
1924
/*
1903
1925
If the entire qc is being invalidated we can bail out early
1904
1926
instead of waiting for the lock.
@@ -1956,6 +1978,15 @@ void Query_cache::init()
1956
1978
pthread_cond_init (&COND_cache_status_changed, NULL );
1957
1979
m_cache_lock_status= Query_cache::UNLOCKED;
1958
1980
initialized = 1 ;
1981
+ /*
1982
+ If we explicitly turn off query cache from the command line query cache will
1983
+ be disabled for the reminder of the server life time. This is because we
1984
+ want to avoid locking the QC specific mutex if query cache isn't going to
1985
+ be used.
1986
+ */
1987
+ if (global_system_variables.query_cache_type == 0 )
1988
+ query_cache.disable_query_cache ();
1989
+
1959
1990
DBUG_VOID_RETURN;
1960
1991
}
1961
1992
@@ -4660,3 +4691,4 @@ my_bool Query_cache::in_table_list(Query_cache_block_table * root,
4660
4691
#endif /* DBUG_OFF */
4661
4692
4662
4693
#endif /* HAVE_QUERY_CACHE*/
4694
+
0 commit comments