From 4ee2e07cc0235f873663676846a1d2467353fd25 Mon Sep 17 00:00:00 2001 From: "evgen@moonbone.local" <> Date: Wed, 26 Jul 2006 00:31:29 +0400 Subject: Fixed bug#19862: Sort with filesort by function evaluates function twice When there is no index defined filesort is used to sort the result of a query. If there is a function in the select list and the result set should be ordered by it's value then this function will be evaluated twice. First time to get the value of the sort key and second time to send its value to a user. This happens because filesort when sorts a table remembers only values of its fields but not values of functions. All functions are affected. But taking into account that SP and UDF functions can be both expensive and non-deterministic a temporary table should be used to store their results and then sort it to avoid twice SP evaluation and to get a correct result. If an expression referenced in an ORDER clause contains a SP or UDF function, force the use of a temporary table. A new Item_processor function called func_type_checker_processor is added to check whether the expression contains a function of a particular type. --- sql/item_func.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sql/item_func.cc') diff --git a/sql/item_func.cc b/sql/item_func.cc index 1d906b300b6..c31ac2bf047 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -398,6 +398,13 @@ Field *Item_func::tmp_table_field(TABLE *t_arg) return res; } + +bool Item_func::func_type_checker_processor(byte *arg) +{ + return *((Functype*)arg) == functype(); +} + + my_decimal *Item_func::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(fixed); -- cgit v1.2.1