From 694d1a50bd7754c5357dde184f87d63b7032ee5e Mon Sep 17 00:00:00 2001 From: Galina Shalygina Date: Fri, 5 Apr 2019 22:55:20 +0300 Subject: MDEV-19185: Pushdown constant function defined with subquery The bug occurs because of the wrong pushdown of constant function defined with subquery from HAVING into WHERE. Subqueries can't be pushed into WHERE. To fix it with_subquery() call is added to check if the function contains subquery. --- sql/item.cc | 5 ++--- sql/item_func.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index 543dc971228..e511921b30b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -9060,9 +9060,8 @@ bool Item_args::excl_dep_on_grouping_fields(st_select_lex *sel) { for (uint i= 0; i < arg_count; i++) { - if (args[i]->type() == Item::SUBSELECT_ITEM || - (args[i]->type() == Item::FUNC_ITEM && - ((Item_func *)args[i])->functype() == Item_func::UDF_FUNC)) + if (args[i]->type() == Item::FUNC_ITEM && + ((Item_func *)args[i])->functype() == Item_func::UDF_FUNC) return false; if (args[i]->const_item()) continue; diff --git a/sql/item_func.h b/sql/item_func.h index a3bf4d78158..44e9691c9df 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -342,7 +342,7 @@ public: bool excl_dep_on_grouping_fields(st_select_lex *sel) { - if (has_rand_bit()) + if (has_rand_bit() || with_subquery()) return false; return Item_args::excl_dep_on_grouping_fields(sel); } -- cgit v1.2.1