sql_expression_cache.h 2.29 KB
Newer Older
unknown's avatar
unknown committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#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.
*/

unknown's avatar
unknown committed
15
extern ulong subquery_cache_miss, subquery_cache_hit;
unknown's avatar
unknown committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

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;
35 36 37 38 39

  /**
    Print cache parameters
  */
  virtual void print(String *str, enum_query_type query_type)= 0;
unknown's avatar
unknown committed
40 41 42 43 44 45 46 47 48

  /**
    Is this cache initialized
  */
  virtual bool is_inited()= 0;
  /**
    Initialize this cache
  */
  virtual void init()= 0;
unknown's avatar
unknown committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62
};

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:
unknown's avatar
unknown committed
63
  Expression_cache_tmptable(THD *thd, List<Item> &dependants, Item *value);
unknown's avatar
unknown committed
64 65 66 67
  virtual ~Expression_cache_tmptable();
  virtual result check_value(Item **value);
  virtual my_bool put_value(Item *value);

68
  void print(String *str, enum_query_type query_type);
unknown's avatar
unknown committed
69 70
  bool is_inited() { return inited; };
  void init();
71

unknown's avatar
unknown committed
72
private:
73
  void disable_cache();
unknown's avatar
unknown committed
74 75 76 77 78 79 80 81 82 83 84

  /* 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;
unknown's avatar
unknown committed
85 86
  /* List of parameter items */
  List<Item> &items;
unknown's avatar
unknown committed
87 88
  /* Value Item example */
  Item *val;
89 90
  /* hit/miss counters */
  uint hit, miss;
unknown's avatar
unknown committed
91 92 93 94 95
  /* Set on if the object has been succesfully initialized with init() */
  bool inited;
};

#endif /* SQL_EXPRESSION_CACHE_INCLUDED */