@@ -192,6 +192,7 @@ static void init_tmptable_sum_functions(Item_sum **func);
192
192
static void update_tmptable_sum_func (Item_sum **func,TABLE *tmp_table);
193
193
static void copy_sum_funcs (Item_sum **func_ptr);
194
194
static bool add_ref_to_table_cond (THD *thd, JOIN_TAB *join_tab);
195
+ static bool setup_sum_funcs (THD *thd, Item_sum **func_ptr);
195
196
static bool init_sum_functions (Item_sum **func, Item_sum **end);
196
197
static bool update_sum_func (Item_sum **func);
197
198
static void select_describe (JOIN *join, bool need_tmp_table,bool need_order,
@@ -990,13 +991,15 @@ JOIN::optimize()
990
991
if (create_sort_index (thd, this , group_list,
991
992
HA_POS_ERROR, HA_POS_ERROR) ||
992
993
alloc_group_fields (this , group_list) ||
993
- make_sum_func_list (all_fields, fields_list, 1 ))
994
+ make_sum_func_list (all_fields, fields_list, 1 ) ||
995
+ setup_sum_funcs (thd, sum_funcs))
994
996
DBUG_RETURN (1 );
995
997
group_list=0 ;
996
998
}
997
999
else
998
1000
{
999
- if (make_sum_func_list (all_fields, fields_list, 0 ))
1001
+ if (make_sum_func_list (all_fields, fields_list, 0 ) ||
1002
+ setup_sum_funcs (thd, sum_funcs))
1000
1003
DBUG_RETURN (1 );
1001
1004
if (!group_list && ! exec_tmp_table1->distinct && order && simple_order)
1002
1005
{
@@ -1372,6 +1375,7 @@ JOIN::exec()
1372
1375
}
1373
1376
if (curr_join->make_sum_func_list (*curr_all_fields, *curr_fields_list,
1374
1377
1 , TRUE ) ||
1378
+ setup_sum_funcs (curr_join->thd , curr_join->sum_funcs ) ||
1375
1379
(tmp_error= do_select (curr_join, (List<Item> *) 0 , curr_tmp_table,
1376
1380
0 )))
1377
1381
{
@@ -1459,7 +1463,9 @@ JOIN::exec()
1459
1463
set_items_ref_array (items3);
1460
1464
1461
1465
if (curr_join->make_sum_func_list (*curr_all_fields, *curr_fields_list,
1462
- 1 , TRUE ) || thd->is_fatal_error )
1466
+ 1 , TRUE ) ||
1467
+ setup_sum_funcs (curr_join->thd , curr_join->sum_funcs ) ||
1468
+ thd->is_fatal_error )
1463
1469
DBUG_VOID_RETURN;
1464
1470
}
1465
1471
if (curr_join->group_list || curr_join->order )
@@ -11794,9 +11800,6 @@ bool JOIN::alloc_func_list()
11794
11800
before_group_by Set to 1 if this is called before GROUP BY handling
11795
11801
recompute Set to TRUE if sum_funcs must be recomputed
11796
11802
11797
- NOTES
11798
- Calls ::setup() for all item_sum objects in field_list
11799
-
11800
11803
RETURN
11801
11804
0 ok
11802
11805
1 error
@@ -11817,12 +11820,7 @@ bool JOIN::make_sum_func_list(List<Item> &field_list, List<Item> &send_fields,
11817
11820
while ((item=it++))
11818
11821
{
11819
11822
if (item->type () == Item::SUM_FUNC_ITEM && !item->const_item ())
11820
- {
11821
11823
*func++= (Item_sum*) item;
11822
- /* let COUNT(DISTINCT) create the temporary table */
11823
- if (((Item_sum*) item)->setup (thd))
11824
- DBUG_RETURN (TRUE );
11825
- }
11826
11824
}
11827
11825
if (before_group_by && rollup.state == ROLLUP::STATE_INITED)
11828
11826
{
@@ -11967,6 +11965,30 @@ change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
11967
11965
Code for calculating functions
11968
11966
******************************************************************************/
11969
11967
11968
+
11969
+ /*
11970
+ Call ::setup for all sum functions
11971
+
11972
+ SYNOPSIS
11973
+ setup_sum_funcs()
11974
+ thd thread handler
11975
+ func_ptr sum function list
11976
+
11977
+ RETURN
11978
+ FALSE ok
11979
+ TRUE error
11980
+ */
11981
+
11982
+ static bool setup_sum_funcs (THD *thd, Item_sum **func_ptr)
11983
+ {
11984
+ Item_sum *func;
11985
+ while ((func= *(func_ptr++)))
11986
+ if (func->setup (thd))
11987
+ return TRUE ;
11988
+ return FALSE ;
11989
+ }
11990
+
11991
+
11970
11992
static void
11971
11993
init_tmptable_sum_functions (Item_sum **func_ptr)
11972
11994
{
0 commit comments