diff options
author | Mikael Ronstrom <mikael@mysql.com> | 2009-06-11 12:07:59 +0200 |
---|---|---|
committer | Mikael Ronstrom <mikael@mysql.com> | 2009-06-11 12:07:59 +0200 |
commit | a22c8c5be5ceadd23eed707ae2f1308ced2de977 (patch) | |
tree | 796cc97d1d103e18e0672d9b57dee4c54857073c /sql/sql_cache.cc | |
parent | 510835a0727fc1ebe98e2808cae91c8ab014d27e (diff) | |
parent | 585cf08fe6a8d6e237732daa94a969f93e5c84ec (diff) | |
download | mariadb-git-a22c8c5be5ceadd23eed707ae2f1308ced2de977.tar.gz |
Merge MySQL 5.1.35 into MySQL 5.4
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r-- | sql/sql_cache.cc | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index fcea4153eb0..7c104ccc455 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -419,6 +419,43 @@ TYPELIB query_cache_type_typelib= array_elements(query_cache_type_names)-1,"", query_cache_type_names, NULL }; + +/** + Helper function for determine if a SELECT statement has a SQL_NO_CACHE + directive. + + @param sql A pointer to the first white space character after SELECT + + @return + @retval TRUE The character string contains SQL_NO_CACHE + @retval FALSE No directive found. +*/ + +static bool has_no_cache_directive(char *sql) +{ + int i=0; + while (sql[i] == ' ') + ++i; + + if (my_toupper(system_charset_info, sql[i]) == 'S' && + my_toupper(system_charset_info, sql[i+1]) == 'Q' && + my_toupper(system_charset_info, sql[i+2]) == 'L' && + my_toupper(system_charset_info, sql[i+3]) == '_' && + my_toupper(system_charset_info, sql[i+4]) == 'N' && + my_toupper(system_charset_info, sql[i+5]) == 'O' && + my_toupper(system_charset_info, sql[i+6]) == '_' && + my_toupper(system_charset_info, sql[i+7]) == 'C' && + my_toupper(system_charset_info, sql[i+8]) == 'A' && + my_toupper(system_charset_info, sql[i+9]) == 'C' && + my_toupper(system_charset_info, sql[i+10]) == 'H' && + my_toupper(system_charset_info, sql[i+11]) == 'E' && + my_toupper(system_charset_info, sql[i+12]) == ' ') + return TRUE; + + return FALSE; +} + + /***************************************************************************** Query_cache_block_table method(s) *****************************************************************************/ @@ -1079,7 +1116,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", { memcpy(thd->query+thd->query_length+1, thd->db, thd->db_length); DBUG_PRINT("qcache", ("database: %s length: %u", - thd->db, thd->db_length)); + thd->db, (unsigned) thd->db_length)); } else { @@ -1242,6 +1279,16 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) DBUG_PRINT("qcache", ("The statement is not a SELECT; Not cached")); goto err; } + + if (query_length > 20 && has_no_cache_directive(&sql[i+6])) + { + /* + We do not increase 'refused' statistics here since it will be done + later when the query is parsed. + */ + DBUG_PRINT("qcache", ("The statement has a SQL_NO_CACHE directive")); + goto err; + } } STRUCT_LOCK(&structure_guard_mutex); @@ -1269,7 +1316,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) { memcpy(sql+query_length+1, thd->db, thd->db_length); DBUG_PRINT("qcache", ("database: '%s' length: %u", - thd->db, thd->db_length)); + thd->db, (unsigned)thd->db_length)); } else { @@ -1529,6 +1576,9 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used, invalidate_table(thd, tables_used); } + DBUG_EXECUTE_IF("wait_after_query_cache_invalidate", + debug_wait_for_kill("wait_after_query_cache_invalidate");); + DBUG_VOID_RETURN; } |