diff options
Diffstat (limited to 'sql/sql_expression_cache.h')
-rw-r--r-- | sql/sql_expression_cache.h | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/sql/sql_expression_cache.h b/sql/sql_expression_cache.h index 48a8e33a787..33c67f8eaca 100644 --- a/sql/sql_expression_cache.h +++ b/sql/sql_expression_cache.h @@ -19,6 +19,7 @@ #include "sql_select.h" + /** Interface for expression cache @@ -62,6 +63,11 @@ public: Initialize this cache */ virtual void init()= 0; + + /** + Save this object's statistics into Expression_cache_stat object + */ + virtual void flush_stat()= 0; }; struct st_table_ref; @@ -69,6 +75,30 @@ struct st_join_table; class Item_field; +class Expression_cache_stat :public Sql_alloc +{ +public: + enum expr_cache_state {UNINITED, STOPPED, OK}; + Expression_cache_stat(Expression_cache *c) : + cache(c), hit(0), miss(0), state(UNINITED) + {} + + Expression_cache *cache; + ulong hit, miss; + enum expr_cache_state state; + + static const char* state_str[3]; + void set(ulong h, ulong m, enum expr_cache_state s) + {hit= h; miss= m; state= s;} + + void flush_stat() + { + if (cache) + cache->flush_stat(); + } +}; + + /** Implementation of expression cache over a temporary table */ @@ -85,6 +115,20 @@ public: bool is_inited() { return inited; }; void init(); + void set_stat(Expression_cache_stat *st) + { + stat= st; + flush_stat(); + } + virtual void flush_stat() + { + if (stat) + stat->set(hit, miss, (inited ? (cache_table ? + Expression_cache_stat::OK : + Expression_cache_stat::STOPPED) : + Expression_cache_stat::UNINITED)); + } + private: void disable_cache(); @@ -94,6 +138,8 @@ private: TABLE *cache_table; /* Thread handle for the temporary table */ THD *table_thd; + /* EXPALIN/ANALYZE statistics */ + Expression_cache_stat *stat; /* TABLE_REF for index lookup */ struct st_table_ref ref; /* Cached result */ @@ -103,7 +149,7 @@ private: /* Value Item example */ Item *val; /* hit/miss counters */ - uint hit, miss; + ulong hit, miss; /* Set on if the object has been succesfully initialized with init() */ bool inited; }; |