mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
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.
This commit is contained in:
@@ -93,6 +93,12 @@ NULL
|
||||
0R
|
||||
FR
|
||||
DROP TABLE bug19904;
|
||||
create table t1(f1 int);
|
||||
insert into t1 values(1),(2);
|
||||
explain select myfunc_int(f1) from t1 order by 1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
||||
drop table t1;
|
||||
End of 5.0 tests.
|
||||
DROP FUNCTION metaphon;
|
||||
DROP FUNCTION myfunc_double;
|
||||
|
||||
Reference in New Issue
Block a user