1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

MDEV-7811: EXPLAIN/ANALYZE FORMAT=JSON should show subquery cache

This commit is contained in:
Oleksandr Byelkin
2015-03-25 18:27:10 +01:00
committed by Sergei Petrunia
parent 498a264d19
commit c6aee27b73
11 changed files with 401 additions and 9 deletions

View File

@ -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;
};