summaryrefslogtreecommitdiff
path: root/sql/sql_cache.cc
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2003-02-18 16:28:31 +0200
committerunknown <bell@sanja.is.com.ua>2003-02-18 16:28:31 +0200
commitd4280aedcac74739511bfdc75cc8a25b0984ebd4 (patch)
treee04887f1c891d0c36d16e22774a2d7b4bbea66ec /sql/sql_cache.cc
parent49e6a2d0e443f5ba788026a6f9218db12ad23cc4 (diff)
parent64236d3bddb4bd9f80e5ae01acb6b4f6db64ed97 (diff)
downloadmariadb-git-d4280aedcac74739511bfdc75cc8a25b0984ebd4.tar.gz
Merge sanja.is.com.ua:/home/bell/mysql/mysql-4.1
into sanja.is.com.ua:/home/bell/mysql/work-qc-4.1 mysql-test/r/innodb_cache.result: Auto merged sql/ha_berkeley.h: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_innodb.h: Auto merged sql/handler.cc: Auto merged sql/sql_cache.cc: Auto merged
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r--sql/sql_cache.cc64
1 files changed, 41 insertions, 23 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 90fd61ebeb7..fcff8c13beb 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -750,9 +750,11 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
DBUG_ENTER("Query_cache::store_query");
if (query_cache_size == 0)
DBUG_VOID_RETURN;
+ uint8 tables_type= 0;
if ((local_tables = is_cacheable(thd, thd->query_length,
- thd->query, &thd->lex, tables_used)))
+ thd->query, &thd->lex, tables_used,
+ &tables_type)))
{
NET *net= &thd->net;
byte flags = (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0);
@@ -831,6 +833,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
net->query_cache_query= (gptr) query_block;
header->writer(net);
+ header->tables_type(tables_type);
// init_n_lock make query block locked
BLOCK_UNLOCK_WR(query_block);
}
@@ -877,15 +880,10 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
Query_cache_block_table *block_table, *block_table_end;
ulong tot_length;
byte flags;
+ bool check_tables;
DBUG_ENTER("Query_cache::send_result_to_client");
- if (query_cache_size == 0 ||
- /*
- it is not possible to check has_transactions() function of handler
- because tables not opened yet
- */
- (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) ||
- thd->variables.query_cache_type == 0)
+ if (query_cache_size == 0 || thd->variables.query_cache_type == 0)
goto err;
@@ -968,6 +966,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
}
DBUG_PRINT("qcache", ("Query have result 0x%lx", (ulong) query));
+ check_tables= query->tables_type() & HA_CACHE_TBL_ASKTRANSACT;
// Check access;
block_table= query_block->table(0);
block_table_end= block_table+query_block->n_tables;
@@ -995,9 +994,22 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
DBUG_PRINT("qcache", ("Need to check column privileges for %s.%s",
table_list.db, table_list.alias));
BLOCK_UNLOCK_RD(query_block);
- thd->lex.safe_to_cache_query=0; // Don't try to cache this
+ thd->lex.safe_to_cache_query= 0; // Don't try to cache this
+ goto err_unlock; // Parse query
+ }
+ if (check_tables && !handler::caching_allowed(thd, table->db(),
+ table->key_length(),
+ table->type()))
+ {
+ DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s",
+ table_list.db, table_list.alias));
+ BLOCK_UNLOCK_RD(query_block);
+ thd->lex.safe_to_cache_query= 0; // Don't try to cache this
goto err_unlock; // Parse query
}
+ else
+ DBUG_PRINT("qcache", ("handler allow caching (%d) %s,%s",
+ check_tables, table_list.db, table_list.alias));
}
move_to_query_list_end(query_block);
hits++;
@@ -1059,7 +1071,8 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
if (tables_used->derived)
continue;
if (using_transactions &&
- tables_used->table->file->has_transactions())
+ (tables_used->table->file->table_cache_type() ==
+ HA_CACHE_TBL_TRANSACT))
/*
Tables_used->table can't be 0 in transaction.
Only 'drop' invalidate not opened table, but 'drop'
@@ -1113,7 +1126,8 @@ void Query_cache::invalidate(THD *thd, TABLE *table,
{
using_transactions = using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
- if (using_transactions && table->file->has_transactions())
+ if (using_transactions &&
+ (table->file->table_cache_type() == HA_CACHE_TBL_TRANSACT))
thd->add_changed_table(table);
else
invalidate_table(table);
@@ -1932,7 +1946,8 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block,
block_table->n=n;
if (!insert_table(tables_used->table->key_length,
tables_used->table->table_cache_key, block_table,
- tables_used->db_length))
+ tables_used->db_length,
+ tables_used->table->file->table_cache_type()))
break;
if (tables_used->table->db_type == DB_TYPE_MRG_MYISAM)
@@ -1945,11 +1960,12 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block,
{
char key[MAX_DBKEY_LENGTH];
uint32 db_length;
- uint key_length =filename_2_table_key(key, table->table->filename,
+ uint key_length= filename_2_table_key(key, table->table->filename,
&db_length);
(++block_table)->n= ++n;
if (!insert_table(key_length, key, block_table,
- db_length))
+ db_length,
+ tables_used->table->file->table_cache_type()))
goto err;
}
}
@@ -1976,7 +1992,7 @@ err:
my_bool
Query_cache::insert_table(uint key_len, char *key,
Query_cache_block_table *node,
- uint32 db_length)
+ uint32 db_length, uint8 cache_type)
{
DBUG_ENTER("Query_cache::insert_table");
DBUG_PRINT("qcache", ("insert table node 0x%lx, len %d",
@@ -2014,6 +2030,8 @@ Query_cache::insert_table(uint key_len, char *key,
}
char *db = header->db();
header->table(db + db_length + 1);
+ header->key_length(key_len);
+ header->type(cache_type);
}
Query_cache_block_table *list_root = table_block->table(0);
@@ -2444,7 +2462,9 @@ void Query_cache::double_linked_list_join(Query_cache_block *head_tail,
TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
char *query,
- LEX *lex, TABLE_LIST *tables_used)
+ LEX *lex,
+ TABLE_LIST *tables_used,
+ uint8 *tables_type)
{
TABLE_COUNTER_TYPE table_count = 0;
DBUG_ENTER("Query_cache::is_cacheable");
@@ -2455,7 +2475,6 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
OPTION_TO_QUERY_CACHE))) &&
lex->safe_to_cache_query)
{
- my_bool has_transactions = 0;
DBUG_PRINT("qcache", ("options %lx %lx, type %u",
OPTION_TO_QUERY_CACHE,
lex->select_lex.options,
@@ -2467,8 +2486,7 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
DBUG_PRINT("qcache", ("table %s, db %s, type %u",
tables_used->real_name,
tables_used->db, tables_used->table->db_type));
- has_transactions = (has_transactions ||
- tables_used->table->file->has_transactions());
+ *tables_type|= tables_used->table->file->table_cache_type();
if (tables_used->table->db_type == DB_TYPE_MRG_ISAM ||
tables_used->table->tmp_table != NO_TMP_TABLE ||
@@ -2500,7 +2518,7 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
}
if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
- has_transactions)
+ ((*tables_type)&HA_CACHE_TBL_TRANSACT))
{
DBUG_PRINT("qcache", ("not in autocommin mode"));
DBUG_RETURN(0);
@@ -2941,7 +2959,7 @@ void Query_cache::bins_dump()
{
uint i;
- if (!initialized)
+ if (!initialized || query_cache_size == 0)
{
DBUG_PRINT("qcache", ("Query Cache not initialized"));
return;
@@ -2982,7 +3000,7 @@ void Query_cache::bins_dump()
void Query_cache::cache_dump()
{
- if (!initialized)
+ if (!initialized || query_cache_size == 0)
{
DBUG_PRINT("qcache", ("Query Cache not initialized"));
return;
@@ -3071,7 +3089,7 @@ void Query_cache::queries_dump()
void Query_cache::tables_dump()
{
- if (!initialized)
+ if (!initialized || query_cache_size == 0)
{
DBUG_PRINT("qcache", ("Query Cache not initialized"));
return;