@@ -1077,8 +1077,6 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
10771077 int error;
10781078 LEX *old_lex= thd->lex ;
10791079 LEX lex;
1080- uint8 saved_full_group_by_flag;
1081- nesting_map saved_allow_sum_func;
10821080 DBUG_ENTER (" fix_fields_part_func" );
10831081
10841082 if (init_lex_with_single_table (thd, table, &lex))
@@ -1103,19 +1101,22 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
11031101 This is a tricky call to prepare for since it can have a large number
11041102 of interesting side effects, both desirable and undesirable.
11051103 */
1106- saved_full_group_by_flag= thd-> lex -> current_select -> full_group_by_flag ;
1107- saved_allow_sum_func = thd->lex ->allow_sum_func ;
1108- thd->lex ->allow_sum_func = 0 ;
1109-
1110- error= func_expr-> fix_fields (thd, (Item**)&func_expr) ;
1104+ {
1105+ const bool save_agg_field = thd->lex ->current_select -> non_agg_field_used () ;
1106+ const bool save_agg_func= thd->lex ->current_select -> agg_func_used () ;
1107+ const nesting_map saved_allow_sum_func= thd-> lex -> allow_sum_func ;
1108+ thd-> lex -> allow_sum_func = 0 ;
11111109
1112- /*
1113- Restore full_group_by_flag and allow_sum_func,
1114- fix_fields should not affect mysql_select later, see Bug#46923.
1115- */
1116- thd->lex ->current_select ->full_group_by_flag = saved_full_group_by_flag;
1117- thd->lex ->allow_sum_func = saved_allow_sum_func;
1110+ error= func_expr->fix_fields (thd, (Item**)&func_expr);
11181111
1112+ /*
1113+ Restore agg_field/agg_func and allow_sum_func,
1114+ fix_fields should not affect mysql_select later, see Bug#46923.
1115+ */
1116+ thd->lex ->current_select ->set_non_agg_field_used (save_agg_field);
1117+ thd->lex ->current_select ->set_agg_func_used (save_agg_func);
1118+ thd->lex ->allow_sum_func = saved_allow_sum_func;
1119+ }
11191120 if (unlikely (error))
11201121 {
11211122 DBUG_PRINT (" info" , (" Field in partition function not part of table" ));
0 commit comments