summaryrefslogtreecommitdiff
path: root/sql/item_cmpfunc.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2022-08-04 16:58:42 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2022-08-04 16:58:42 +0200
commitee620a7416ac1719de322f16593fe403f5c43833 (patch)
treee8eb1e37d02d2b4aa29942b7732f3e3e9d5367da /sql/item_cmpfunc.cc
parent558f1eff64e7708b594ef0315e23bdeb1d23ccf7 (diff)
parent3b071bad1981a12e76769cbfc31b62fbd7362372 (diff)
downloadmariadb-git-ee620a7416ac1719de322f16593fe403f5c43833.tar.gz
Merge branch '10.5' into 10.6
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r--sql/item_cmpfunc.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 7ccd44d7408..426496dca67 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -318,7 +318,18 @@ static bool convert_const_to_int(THD *thd, Item_field *field_item,
field_item->field_type() != MYSQL_TYPE_YEAR)
return 1;
- if ((*item)->can_eval_in_optimize())
+ /*
+ Replace (*item) with its value if the item can be computed.
+
+ Do not replace items that contain aggregate functions:
+ There can be such items that are constants, e.g. COLLATION(AVG(123)),
+ but this function is called at Name Resolution phase.
+ Removing aggregate functions may confuse query plan generation code, e.g.
+ the optimizer might conclude that the query doesn't need to do grouping
+ at all.
+ */
+ if ((*item)->can_eval_in_optimize() &&
+ !(*item)->with_sum_func())
{
TABLE *table= field->table;
MY_BITMAP *old_maps[2] = { NULL, NULL };