2010-07-10 12:37:30 +02:00
|
|
|
#ifndef SQL_EXPRESSION_CACHE_INCLUDED
|
|
|
|
#define SQL_EXPRESSION_CACHE_INCLUDED
|
|
|
|
|
|
|
|
#include "sql_select.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Interface for expression cache
|
|
|
|
|
|
|
|
@note
|
|
|
|
Parameters of an expression cache interface are set on the creation of the
|
|
|
|
cache. They are passed when a cache object of the implementation class is
|
|
|
|
constructed. That's why they are not visible in this interface.
|
|
|
|
*/
|
|
|
|
|
2010-10-27 05:03:59 +02:00
|
|
|
extern ulong subquery_cache_miss, subquery_cache_hit;
|
2010-07-10 12:37:30 +02:00
|
|
|
|
|
|
|
class Expression_cache :public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum result {ERROR, HIT, MISS};
|
|
|
|
|
|
|
|
Expression_cache(){};
|
|
|
|
virtual ~Expression_cache() {};
|
|
|
|
/**
|
|
|
|
Shall check the presence of expression value in the cache for a given
|
|
|
|
set of values of the expression parameters. Return the result of the
|
|
|
|
expression if it's found in the cache.
|
|
|
|
*/
|
|
|
|
virtual result check_value(Item **value)= 0;
|
|
|
|
/**
|
|
|
|
Shall put the value of an expression for given set of its parameters
|
|
|
|
into the expression cache
|
|
|
|
*/
|
|
|
|
virtual my_bool put_value(Item *value)= 0;
|
2010-09-06 14:34:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Print cache parameters
|
|
|
|
*/
|
|
|
|
virtual void print(String *str, enum_query_type query_type)= 0;
|
2010-07-10 12:37:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct st_table_ref;
|
|
|
|
struct st_join_table;
|
|
|
|
class Item_field;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Implementation of expression cache over a temporary table
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Expression_cache_tmptable :public Expression_cache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Expression_cache_tmptable(THD *thd, List<Item*> &dependants, Item *value);
|
|
|
|
virtual ~Expression_cache_tmptable();
|
|
|
|
virtual result check_value(Item **value);
|
|
|
|
virtual my_bool put_value(Item *value);
|
|
|
|
|
2010-09-06 14:34:24 +02:00
|
|
|
void print(String *str, enum_query_type query_type);
|
|
|
|
|
2010-07-10 12:37:30 +02:00
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
|
|
|
|
/* tmp table parameters */
|
|
|
|
TMP_TABLE_PARAM cache_table_param;
|
|
|
|
/* temporary table to store this cache */
|
|
|
|
TABLE *cache_table;
|
|
|
|
/* Thread handle for the temporary table */
|
|
|
|
THD *table_thd;
|
|
|
|
/* TABLE_REF for index lookup */
|
|
|
|
struct st_table_ref ref;
|
|
|
|
/* Cached result */
|
|
|
|
Item_field *cached_result;
|
|
|
|
/* List of references to the parameters of the expression */
|
|
|
|
List<Item*> *list;
|
|
|
|
/* List of items */
|
|
|
|
List<Item> items;
|
|
|
|
/* Value Item example */
|
|
|
|
Item *val;
|
|
|
|
/* Set on if the object has been succesfully initialized with init() */
|
|
|
|
bool inited;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SQL_EXPRESSION_CACHE_INCLUDED */
|