summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorGeorgi Kodinov <kgeorge@mysql.com>2008-11-24 17:30:47 +0200
committerGeorgi Kodinov <kgeorge@mysql.com>2008-11-24 17:30:47 +0200
commitd795963cba42fefd57a788eb1112bfc4cc13f6d3 (patch)
tree2a8f7f159454647868e51a2c60a0c657b62c8c8c /sql
parent60d5e900891bc849d7a6180b708290fe7a3e93ab (diff)
downloadmariadb-git-d795963cba42fefd57a788eb1112bfc4cc13f6d3.tar.gz
Bug #39656: Behaviour different for agg functions with & without where -
ONLY_FULL_GROUP_BY The check for non-aggregated columns in queries with aggregate function, but without GROUP BY was treating all the parts of the query as if they are in the SELECT list. Fixed by ignoring the non-aggregated fields in the WHERE clause. mysql-test/r/func_group.result: Bug #39656: test case mysql-test/t/func_group.test: Bug #39656: test case sql/sql_select.cc: Bug #39656: ignore the new non-aggregated column refs in a WHERE by saving the state so far and then adding only the new values of the other parts of the bitmask.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 428d1709f94..2ac33c4e07f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -390,11 +390,21 @@ inline int setup_without_group(THD *thd, Item **ref_pointer_array,
{
int res;
nesting_map save_allow_sum_func=thd->lex->allow_sum_func ;
+ /*
+ Need to save the value, so we can turn off only the new NON_AGG_FIELD
+ additions coming from the WHERE
+ */
+ uint8 saved_flag= thd->lex->current_select->full_group_by_flag;
DBUG_ENTER("setup_without_group");
thd->lex->allow_sum_func&= ~(1 << thd->lex->current_select->nest_level);
res= setup_conds(thd, tables, leaves, conds);
+ /* it's not wrong to have non-aggregated columns in a WHERE */
+ if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
+ thd->lex->current_select->full_group_by_flag= saved_flag |
+ (thd->lex->current_select->full_group_by_flag & ~NON_AGG_FIELD_USED);
+
thd->lex->allow_sum_func|= 1 << thd->lex->current_select->nest_level;
res= res || setup_order(thd, ref_pointer_array, tables, fields, all_fields,
order);