summaryrefslogtreecommitdiff
path: root/sql/sql_cache.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2012-02-15 18:08:08 +0100
committerSergei Golubchik <sergii@pisem.net>2012-02-15 18:08:08 +0100
commit25609313ffbd9205e921d0793cf423f711d10ced (patch)
treef04a1c26fabcc5463aca51a860f03131e02d94f7 /sql/sql_cache.cc
parent47a54a2e087a7c1fc861bcbc114c14987f492cfe (diff)
parent764eeeee74f999fe2107fc362236563be0025093 (diff)
downloadmariadb-git-25609313ffbd9205e921d0793cf423f711d10ced.tar.gz
5.3.4 merge
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r--sql/sql_cache.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 0a1185a9924..9c86b2838c4 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1463,10 +1463,10 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
In case the wait time can't be determined there is an upper limit which
causes try_lock() to abort with a time out.
- The 'TRUE' parameter indicate that the lock is allowed to timeout
+ The 'TIMEOUT' parameter indicate that the lock is allowed to timeout
*/
- if (try_lock(thd, Query_cache::WAIT))
+ if (try_lock(thd, Query_cache::TIMEOUT))
DBUG_VOID_RETURN;
if (query_cache_size == 0)
{
@@ -1674,6 +1674,17 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length)
if (is_disabled() || thd->locked_tables_mode ||
thd->variables.query_cache_type == 0)
goto err;
+
+ /*
+ The following can only happen for prepared statements that was found
+ during parsing or later that the query was not cacheable.
+ */
+ if (!thd->lex->safe_to_cache_query)
+ {
+ DBUG_PRINT("qcache", ("SELECT is non-cacheable"));
+ goto err;
+ }
+
DBUG_ASSERT(query_cache_size != 0); // otherwise cache would be disabled
thd->query_cache_is_applicable= 1;
@@ -1959,6 +1970,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
faster.
*/
thd->query_cache_is_applicable= 0; // Query can't be cached
+ thd->lex->safe_to_cache_query= 0; // For prepared statements
BLOCK_UNLOCK_RD(query_block);
DBUG_RETURN(-1);
}
@@ -1975,6 +1987,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
table_list.db, table_list.alias));
unlock();
thd->query_cache_is_applicable= 0; // Query can't be cached
+ thd->lex->safe_to_cache_query= 0; // For prepared statements
BLOCK_UNLOCK_RD(query_block);
DBUG_RETURN(-1); // Privilege error
}
@@ -1984,6 +1997,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
table_list.db, table_list.alias));
BLOCK_UNLOCK_RD(query_block);
thd->query_cache_is_applicable= 0; // Query can't be cached
+ thd->lex->safe_to_cache_query= 0; // For prepared statements
goto err_unlock; // Parse query
}
#endif /*!NO_EMBEDDED_ACCESS_CHECKS*/
@@ -2007,7 +2021,13 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
table->key_length());
}
else
+ {
+ /*
+ As this can change from call to call, don't reset set
+ thd->lex->safe_to_cache_query
+ */
thd->query_cache_is_applicable= 0; // Query can't be cached
+ }
/* End the statement transaction potentially started by engine. */
trans_rollback_stmt(thd);
goto err_unlock; // Parse query
@@ -3901,6 +3921,7 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used,
DBUG_PRINT("qcache", ("Don't cache statement as it refers to "
"tables with column privileges."));
thd->query_cache_is_applicable= 0; // Query can't be cached
+ thd->lex->safe_to_cache_query= 0; // For prepared statements
DBUG_RETURN(0);
}
#endif
@@ -4037,6 +4058,10 @@ my_bool Query_cache::ask_handler_allowance(THD *thd,
{
DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s",
tables_used->db, tables_used->alias));
+ /*
+ As this can change from call to call, don't reset set
+ thd->lex->safe_to_cache_query
+ */
thd->query_cache_is_applicable= 0; // Query can't be cached
DBUG_RETURN(1);
}