From ceb5468fd8bc9675d514949dd60c5bd7276bf3f4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jul 2010 13:37:30 +0300 Subject: Subquery cache (MWL#66) added. libmysqld/Makefile.am: The new file added. mysql-test/r/index_merge_myisam.result: subquery_cache optimization option added. mysql-test/r/myisam_mrr.result: subquery_cache optimization option added. mysql-test/r/subquery_cache.result: The subquery cache tests added. mysql-test/r/subselect3.result: Subquery cache switched off to avoid changing read statistics. mysql-test/r/subselect3_jcl6.result: Subquery cache switched off to avoid changing read statistics. mysql-test/r/subselect_no_mat.result: subquery_cache optimization option added. mysql-test/r/subselect_no_opts.result: subquery_cache optimization option added. mysql-test/r/subselect_no_semijoin.result: subquery_cache optimization option added. mysql-test/r/subselect_sj.result: subquery_cache optimization option added. mysql-test/r/subselect_sj_jcl6.result: subquery_cache optimization option added. mysql-test/t/subquery_cache.test: The subquery cache tests added. mysql-test/t/subselect3.test: Subquery cache switched off to avoid changing read statistics. sql/CMakeLists.txt: The new file added. sql/Makefile.am: The new files added. sql/item.cc: Expression cache item (Item_cache_wrapper) added. Item_ref and Item_field fixed for correct usage of result field and fast resolwing in SP. sql/item.h: Expression cache item (Item_cache_wrapper) added. Item_ref and Item_field fixed for correct usage of result field and fast resolwing in SP. sql/item_cmpfunc.cc: Subquery cache added. sql/item_cmpfunc.h: Subquery cache added. sql/item_subselect.cc: Subquery cache added. sql/item_subselect.h: Subquery cache added. sql/item_sum.cc: Registration of subquery parameters added. sql/mysql_priv.h: subquery_cache optimization option added. sql/mysqld.cc: subquery_cache optimization option added. sql/opt_range.cc: Fix due to subquery cache. sql/opt_subselect.cc: Parameters of the function cahnged. sql/procedure.h: .h file guard added. sql/sql_base.cc: Registration of subquery parameters added. sql/sql_class.cc: Option to allow add indeces to temporary table. sql/sql_class.h: Item iterators added. Option to allow add indeces to temporary table. sql/sql_expression_cache.cc: Expression cache for caching subqueries added. sql/sql_expression_cache.h: Expression cache for caching subqueries added. sql/sql_lex.cc: Registration of subquery parameters added. sql/sql_lex.h: Registration of subqueries and subquery parameters added. sql/sql_select.cc: Subquery cache added. sql/sql_select.h: Subquery cache added. sql/sql_union.cc: A new parameter to the function added. sql/sql_update.cc: A new parameter to the function added. sql/table.cc: Procedures to manage temporarty tables index added. sql/table.h: Procedures to manage temporarty tables index added. storage/maria/ha_maria.cc: Fix of handler to allow destoy a table in case of error during the table creation. storage/maria/ha_maria.h: .h file guard added. storage/myisam/ha_myisam.cc: Fix of handler to allow destoy a table in case of error during the table creation. --- sql/sql_expression_cache.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 sql/sql_expression_cache.h (limited to 'sql/sql_expression_cache.h') diff --git a/sql/sql_expression_cache.h b/sql/sql_expression_cache.h new file mode 100644 index 00000000000..bb5dc7a76a2 --- /dev/null +++ b/sql/sql_expression_cache.h @@ -0,0 +1,80 @@ +#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. +*/ + +extern ulonglong subquery_cache_miss, subquery_cache_hit; + +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; +}; + +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 &dependants, Item *value); + virtual ~Expression_cache_tmptable(); + virtual result check_value(Item **value); + virtual my_bool put_value(Item *value); + +private: + void init(); + bool make_equalities(); + + /* 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 *list; + /* List of items */ + List items; + /* Value Item example */ + Item *val; + /* Expression to check after index lookup */ + Item *equalities; + /* Set on if the object has been succesfully initialized with init() */ + bool inited; +}; + +#endif /* SQL_EXPRESSION_CACHE_INCLUDED */ -- cgit v1.2.1