diff options
author | unknown <thek@adventure.(none)> | 2007-08-17 16:55:20 +0200 |
---|---|---|
committer | unknown <thek@adventure.(none)> | 2007-08-17 16:55:20 +0200 |
commit | bd80048fdbcd828622858520ff69707056da6595 (patch) | |
tree | bd6aa41892045dd6b60e4f78c7d3215fb8d20bbb /sql/sql_cache.cc | |
parent | 07955aea2dc369be7637f28331bd1072a995d572 (diff) | |
download | mariadb-git-bd80048fdbcd828622858520ff69707056da6595.tar.gz |
Bug #30269 Query cache eats memory
Although the query cache doesn't support retrieval of statements containing
column level access control, it was still possible to cache such statements
thus wasting memory.
This patch extends the access control check on the target tables to avoid
caching a statement with column level restrictions.
mysql-test/r/query_cache.result:
Added test
mysql-test/t/query_cache.test:
Added test
sql/sql_cache.cc:
The function check_table_access leaves the artifact
grant.want_privileges= 1, if a statement refers to tables with column level
privileges. To avoid the statement from being stored into the query cache,
it is enough to check this flag and set 'safe_to_cache_query' to zero.
sql/sql_cache.h:
- Removed 'static' attribute or class methods
- Added THD parameter to process_and_count_tables
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r-- | sql/sql_cache.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 33d658ce6a1..4a5bb263a5f 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -2991,14 +2991,31 @@ void Query_cache::double_linked_list_join(Query_cache_block *head_tail, >0 number of tables */ -static TABLE_COUNTER_TYPE process_and_count_tables(TABLE_LIST *tables_used, - uint8 *tables_type) +TABLE_COUNTER_TYPE +Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used, + uint8 *tables_type) { DBUG_ENTER("process_and_count_tables"); TABLE_COUNTER_TYPE table_count = 0; for (; tables_used; tables_used= tables_used->next_global) { table_count++; +#ifdef HAVE_QUERY_CACHE + /* + Disable any attempt to store this statement if there are + column level grants on any referenced tables. + The grant.want_privileges flag was set to 1 in the + check_grant() function earlier if the TABLE_LIST object + had any associated column privileges. + */ + if (tables_used->grant.want_privilege) + { + DBUG_PRINT("qcache", ("Don't cache statement as it refers to " + "tables with column privileges.")); + thd->lex->safe_to_cache_query= 0; + DBUG_RETURN(0); + } +#endif if (tables_used->view) { DBUG_PRINT("qcache", ("view: %s db: %s", @@ -3071,7 +3088,8 @@ Query_cache::is_cacheable(THD *thd, uint32 query_len, char *query, LEX *lex, (long) lex->select_lex.options, (int) thd->variables.query_cache_type)); - if (!(table_count= process_and_count_tables(tables_used, tables_type))) + if (!(table_count= process_and_count_tables(thd, tables_used, + tables_type))) DBUG_RETURN(0); if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) && |