diff options
author | Kristofer Pettersson <kristofer.pettersson@sun.com> | 2009-03-05 11:41:19 +0100 |
---|---|---|
committer | Kristofer Pettersson <kristofer.pettersson@sun.com> | 2009-03-05 11:41:19 +0100 |
commit | 5c42a6cf54fe0166b0e07e7361b100ff88118036 (patch) | |
tree | 4a3fb25cbf540145fb9484d01c786345d98ee6a8 /sql/sql_cache.cc | |
parent | d61f114f7f753e8443d48190826f121662066967 (diff) | |
download | mariadb-git-5c42a6cf54fe0166b0e07e7361b100ff88118036.tar.gz |
Bug#37416 When SQL_NO_CACHE is used, MySQL still lookup into the query cache
The query cache module did not check for the SQL_NO_CACHE keyword before
attempting to query the hash lookup table. This had a small performance impact.
By introducing a check on the query string before obtaining the hash mutex
we can gain some performance if the SQL_NO_CACHE directive is used often.
sql/sql_cache.cc:
* Introduced new helper function, has_no_cache_directive, for checking the
existance of a SQL_NO_CACHE directive before actual parsing of the query.
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r-- | sql/sql_cache.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 4a5b75c4f78..25907d4ec20 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -418,6 +418,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) *****************************************************************************/ @@ -1233,6 +1270,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); |