| 2931 | */ |
| 2932 | |
| 2933 | void Query_cache::free_query_internal(Query_cache_block *query_block) |
| 2934 | { |
| 2935 | DBUG_ENTER("Query_cache::free_query_internal"); |
| 2936 | DBUG_PRINT("qcache", ("free query %p %zu bytes result", |
| 2937 | query_block, |
| 2938 | query_block->query()->length() )); |
| 2939 | |
| 2940 | queries_in_cache--; |
| 2941 | |
| 2942 | Query_cache_query *query= query_block->query(); |
| 2943 | |
| 2944 | if (query->writer() != 0) |
| 2945 | { |
| 2946 | /* Tell MySQL that this query should not be cached anymore */ |
| 2947 | query->writer()->first_query_block= NULL; |
| 2948 | query->writer(0); |
| 2949 | } |
| 2950 | double_linked_list_exclude(query_block, &queries_blocks); |
| 2951 | Query_cache_block_table *table= query_block->table(0); |
| 2952 | |
| 2953 | for (TABLE_COUNTER_TYPE i= 0; i < query_block->n_tables; i++) |
| 2954 | unlink_table(table++); |
| 2955 | Query_cache_block *result_block= query->result(); |
| 2956 | |
| 2957 | /* |
| 2958 | The following is true when query destruction was called and no results |
| 2959 | in query . (query just registered and then abort/pack/flush called) |
| 2960 | */ |
| 2961 | if (result_block != 0) |
| 2962 | { |
| 2963 | if (result_block->type != Query_cache_block::RESULT) |
| 2964 | { |
| 2965 | // removing unfinished query |
| 2966 | refused++; |
| 2967 | inserts--; |
| 2968 | } |
| 2969 | Query_cache_block *block= result_block; |
| 2970 | do |
| 2971 | { |
| 2972 | Query_cache_block *current= block; |
| 2973 | block= block->next; |
| 2974 | free_memory_block(current); |
| 2975 | } while (block != result_block); |
| 2976 | } |
| 2977 | else |
| 2978 | { |
| 2979 | // removing unfinished query |
| 2980 | refused++; |
| 2981 | inserts--; |
| 2982 | } |
| 2983 | |
| 2984 | query->unlock_n_destroy(); |
| 2985 | free_memory_block(query_block); |
| 2986 | |
| 2987 | DBUG_VOID_RETURN; |
| 2988 | } |
| 2989 | |
| 2990 | |