mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Better bugfix for "HAVING when refering to RAND()" (Bug #8216)
Ensure that references in HAVING, ORDER BY or GROUP BY are calculated after fields in SELECT. This will ensure that any reference to these has a valid value. Generalized the code for split_sum_func() BitKeeper/etc/ignore: added support-files/ndb-config-2-node.ini mysql-test/r/group_by.result: More complicated test to assure that rand() is only calulated once mysql-test/r/user_var.result: Back to old results :( (ok but not perfect) mysql-test/t/group_by.test: More complicated test to assure that rand() is only calulated once sql/item.cc: Better bugfix for "HAVING when refering to RAND()" This will ensure that when refering to things like RAND() in HAVING through an alias we will not recalculate that rand() value in the HAVING part but use the value in the row Generalize split_sum_func() sql/item.h: Better bugfix for "HAVING when refering to RAND()" T sql/item_cmpfunc.cc: Better bugfix for "HAVING when refering to RAND()" Use generalized split_sum_func2() function sql/item_func.cc: Better bugfix for "HAVING when refering to RAND()" Use generalized split_sum_func2() function sql/item_row.cc: Better bugfix for "HAVING when refering to RAND()" Use generalized split_sum_func2() function sql/item_strfunc.cc: Better bugfix for "HAVING when refering to RAND()" Use generalized split_sum_func2() function sql/sql_list.h: Add functions to concatenate lists sql/sql_select.cc: Better bugfix for "HAVING when refering to RAND()" Ensure that references in HAVING, ORDER BY or GROUP BY are calculated after fields in SELECT. This will ensure that any reference to these has a valid value.
This commit is contained in:
@ -8502,6 +8502,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
|
||||
res_selected_fields.empty();
|
||||
res_all_fields.empty();
|
||||
List_iterator_fast<Item> itr(res_all_fields);
|
||||
List<Item> extra_funcs;
|
||||
uint i, border= all_fields.elements - elements;
|
||||
DBUG_ENTER("setup_copy_fields");
|
||||
|
||||
@ -8563,7 +8564,12 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
|
||||
*/
|
||||
if (!(pos=new Item_copy_string(pos)))
|
||||
goto err;
|
||||
if (param->copy_funcs.push_back(pos))
|
||||
if (i < border) // HAVING, ORDER and GROUP BY
|
||||
{
|
||||
if (extra_funcs.push_back(pos))
|
||||
goto err;
|
||||
}
|
||||
else if (param->copy_funcs.push_back(pos))
|
||||
goto err;
|
||||
}
|
||||
res_all_fields.push_back(pos);
|
||||
@ -8575,6 +8581,12 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
|
||||
for (i= 0; i < border; i++)
|
||||
itr++;
|
||||
itr.sublist(res_selected_fields, elements);
|
||||
/*
|
||||
Put elements from HAVING, ORDER BY and GROUP BY last to ensure that any
|
||||
reference used in these will resolve to a item that is already calculated
|
||||
*/
|
||||
param->copy_funcs.concat(&extra_funcs);
|
||||
|
||||
DBUG_RETURN(0);
|
||||
|
||||
err:
|
||||
|
Reference in New Issue
Block a user