diff options
| author | Oleksandr Byelkin <sanja@mariadb.com> | 2015-03-25 18:27:10 +0100 |
|---|---|---|
| committer | Sergei Petrunia <psergey@askmonty.org> | 2015-06-30 23:07:14 +0300 |
| commit | c6aee27b73232fc6ba3e8b55adbb0abba4f0171b (patch) | |
| tree | c996b7f96ff4d063b2112e8b863825a2cff906b2 /sql/sql_expression_cache.h | |
| parent | 498a264d19f041c36d71e41a32c16ac40a014a3e (diff) | |
| download | mariadb-git-c6aee27b73232fc6ba3e8b55adbb0abba4f0171b.tar.gz | |
MDEV-7811: EXPLAIN/ANALYZE FORMAT=JSON should show subquery cache
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; }; |
