diff options
Diffstat (limited to 'sql/sql_cache.cc')
-rw-r--r-- | sql/sql_cache.cc | 84 |
1 files changed, 48 insertions, 36 deletions
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 69d967a0be6..68964d80bf7 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -610,6 +610,7 @@ void query_cache_insert(NET *net, const char *packet, ulong length) DBUG_VOID_RETURN; } header->result(result); + header->last_pkt_nr= net->pkt_nr; BLOCK_UNLOCK_WR(query_block); } else @@ -776,6 +777,8 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) bzero(&flags, QUERY_CACHE_FLAGS_SIZE); flags.client_long_flag= (thd->client_capabilities & CLIENT_LONG_FLAG ? 1 : 0); + flags.client_protocol_41= (thd->client_capabilities & CLIENT_PROTOCOL_41 ? + 1 : 0); flags.character_set_client_num= thd->variables.character_set_client->number; flags.character_set_results_num= @@ -934,11 +937,16 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) /* Test if the query is a SELECT - (pre-space is removed in dispatch_command) + (pre-space is removed in dispatch_command). + + First '/' looks like comment before command it is not + frequently appeared in real lihe, consequently we can + check all such queries, too. */ - if (my_toupper(system_charset_info, sql[0]) != 'S' || - my_toupper(system_charset_info, sql[1]) != 'E' || - my_toupper(system_charset_info,sql[2]) !='L') + if ((my_toupper(system_charset_info, sql[0]) != 'S' || + my_toupper(system_charset_info, sql[1]) != 'E' || + my_toupper(system_charset_info,sql[2]) !='L') && + sql[0] != '/') { DBUG_PRINT("qcache", ("The statement is not a SELECT; Not cached")); goto err; @@ -968,6 +976,8 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) bzero(&flags, QUERY_CACHE_FLAGS_SIZE); flags.client_long_flag= (thd->client_capabilities & CLIENT_LONG_FLAG ? 1 : 0); + flags.client_protocol_41= (thd->client_capabilities & CLIENT_PROTOCOL_41 ? + 1 : 0); flags.character_set_client_num= thd->variables.character_set_client->number; flags.character_set_results_num= (thd->variables.character_set_results ? @@ -1024,7 +1034,6 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) { TABLE_LIST table_list; TABLE *tmptable; - Query_cache_table *table = block_table->parent; /* @@ -1035,8 +1044,9 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) */ for (tmptable= thd->temporary_tables; tmptable ; tmptable= tmptable->next) { - if (tmptable->key_length - TMP_TABLE_KEY_EXTRA == table->key_length() && - !memcmp(tmptable->table_cache_key, table->data(), + if (tmptable->s->key_length - TMP_TABLE_KEY_EXTRA == + table->key_length() && + !memcmp(tmptable->s->table_cache_key, table->data(), table->key_length())) { DBUG_PRINT("qcache", @@ -1056,7 +1066,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) bzero((char*) &table_list,sizeof(table_list)); table_list.db = table->db(); - table_list.alias= table_list.real_name= table->table(); + table_list.alias= table_list.table_name= table->table(); #ifndef NO_EMBEDDED_ACCESS_CHECKS if (check_table_access(thd,SELECT_ACL,&table_list,1)) { @@ -1124,6 +1134,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) ALIGN_SIZE(sizeof(Query_cache_result)))) break; // Client aborted result_block = result_block->next; + thd->net.pkt_nr= query->last_pkt_nr; // Keep packet number updated } while (result_block != first_result_block); #else { @@ -1162,17 +1173,17 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used, using_transactions = using_transactions && (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)); - for (; tables_used; tables_used=tables_used->next) + for (; tables_used; tables_used= tables_used->next_local) { DBUG_ASSERT(!using_transactions || tables_used->table!=0); if (tables_used->derived) continue; - if (using_transactions && - (tables_used->table->file->table_cache_type() == + if (using_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' + Only 'drop' invalidate not opened table, but 'drop' force transaction finish. */ thd->add_changed_table(tables_used->table); @@ -1194,7 +1205,7 @@ void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used) if (query_cache_size > 0) { DUMP(this); - for (; tables_used; tables_used=tables_used->next) + for (; tables_used; tables_used= tables_used->next) { invalidate_table((byte*) tables_used->key, tables_used->key_length); DBUG_PRINT("qcache", (" db %s, table %s", tables_used->key, @@ -1220,14 +1231,14 @@ void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used) */ void Query_cache::invalidate_locked_for_write(TABLE_LIST *tables_used) { - DBUG_ENTER("Query_cache::invalidate (changed table list)"); + DBUG_ENTER("Query_cache::invalidate_locked_for_write"); if (query_cache_size > 0 && tables_used) { STRUCT_LOCK(&structure_guard_mutex); if (query_cache_size > 0) { DUMP(this); - for (; tables_used; tables_used= tables_used->next) + for (; tables_used; tables_used= tables_used->next_local) { if (tables_used->lock_type & (TL_WRITE_LOW_PRIORITY | TL_WRITE)) invalidate_table(tables_used->table); @@ -2059,7 +2070,7 @@ void Query_cache::invalidate_table(TABLE_LIST *table_list) uint key_length; Query_cache_block *table_block; key_length=(uint) (strmov(strmov(key,table_list->db)+1, - table_list->real_name) -key)+ 1; + table_list->table_name) -key)+ 1; // We don't store temporary tables => no key_length+=4 ... if ((table_block = (Query_cache_block*) @@ -2070,7 +2081,7 @@ void Query_cache::invalidate_table(TABLE_LIST *table_list) void Query_cache::invalidate_table(TABLE *table) { - invalidate_table((byte*) table->table_cache_key, table->key_length); + invalidate_table((byte*) table->s->table_cache_key, table->s->key_length); } void Query_cache::invalidate_table(byte * key, uint32 key_length) @@ -2113,24 +2124,26 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block, Query_cache_block_table *block_table = block->table(0); - for (n=0; tables_used; tables_used=tables_used->next, n++, block_table++) + for (n= 0; + tables_used; + tables_used= tables_used->next_global, n++, block_table++) { DBUG_PRINT("qcache", ("table %s, db %s, openinfo at 0x%lx, keylen %u, key at 0x%lx", - tables_used->real_name, tables_used->db, + tables_used->table_name, tables_used->db, (ulong) tables_used->table, - tables_used->table->key_length, - (ulong) tables_used->table->table_cache_key)); - block_table->n=n; - if (!insert_table(tables_used->table->key_length, - tables_used->table->table_cache_key, block_table, + tables_used->table->s->key_length, + (ulong) tables_used->table->s->table_cache_key)); + block_table->n= n; + if (!insert_table(tables_used->table->s->key_length, + tables_used->table->s->table_cache_key, block_table, tables_used->db_length, tables_used->table->file->table_cache_type(), tables_used->callback_func, tables_used->engine_data)) break; - if (tables_used->table->db_type == DB_TYPE_MRG_MYISAM) + if (tables_used->table->s->db_type == DB_TYPE_MRG_MYISAM) { ha_myisammrg *handler = (ha_myisammrg *) tables_used->table->file; MYRG_INFO *file = handler->myrg_info(); @@ -2687,19 +2700,19 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len, lex->select_lex.options, (int) thd->variables.query_cache_type)); - for (; tables_used; tables_used= tables_used->next) + for (; tables_used; tables_used= tables_used->next_global) { table_count++; DBUG_PRINT("qcache", ("table %s, db %s, type %u", - tables_used->real_name, - tables_used->db, tables_used->table->db_type)); + tables_used->table_name, + tables_used->db, tables_used->table->s->db_type)); *tables_type|= tables_used->table->file->table_cache_type(); /* table_alias_charset used here because it depends of lower_case_table_names variable */ - if (tables_used->table->tmp_table != NO_TMP_TABLE || + if (tables_used->table->s->tmp_table != NO_TMP_TABLE || (*tables_type & HA_CACHE_TBL_NOCACHE) || (tables_used->db_length == 5 && my_strnncoll(table_alias_charset, (uchar*)tables_used->db, 6, @@ -2710,7 +2723,7 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len, other non-cacheable table(s)")); DBUG_RETURN(0); } - if (tables_used->table->db_type == DB_TYPE_MRG_MYISAM) + if (tables_used->table->s->db_type == DB_TYPE_MRG_MYISAM) { ha_myisammrg *handler = (ha_myisammrg *)tables_used->table->file; MYRG_INFO *file = handler->myrg_info(); @@ -2754,12 +2767,11 @@ my_bool Query_cache::ask_handler_allowance(THD *thd, { DBUG_ENTER("Query_cache::ask_handler_allowance"); - for (; tables_used; tables_used= tables_used->next) + for (; tables_used; tables_used= tables_used->next_global) { TABLE *table= tables_used->table; - handler *handler= table->file; - if (!handler->cached_table_registration(thd, table->table_cache_key, - table->key_length, + if (!handler->cached_table_registration(thd, table->s->table_cache_key, + table->s->key_length, &tables_used->callback_func, &tables_used->engine_data)) { @@ -3205,7 +3217,7 @@ void Query_cache::wreck(uint line, const char *message) DBUG_PRINT("warning", ("%5d QUERY CACHE WRECK => DISABLED",line)); DBUG_PRINT("warning", ("==================================")); if (thd) - thd->killed = 1; + thd->killed= THD::KILL_CONNECTION; cache_dump(); /* check_integrity(0); */ /* Can't call it here because of locks */ bins_dump(); |