From b0c1e004670c7119b75e517cea77bf9894a00cb4 Mon Sep 17 00:00:00 2001
From: unknown <bell@sanja.is.com.ua>
Date: Fri, 7 Jun 2002 21:26:43 +0300
Subject: [PATCH] temporary preventing subselect in HAVING clause

---
 sql/item_subselect.cc | 7 +++++++
 sql/sql_class.cc      | 4 ++--
 sql/sql_class.h       | 2 ++
 sql/sql_select.cc     | 6 +++++-
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index fc0228455f..c2349ed414 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -102,6 +102,13 @@ void Item_subselect::make_field (Send_field *tmp_field)
 
 bool Item_subselect::fix_fields(THD *thd,TABLE_LIST *tables)
 {
+
+  if (thd->having_fix_field)
+  {
+    //TODO: subselects in having do not suported now
+    my_printf_error(ER_SYNTAX_ERROR, ER(ER_SYNTAX_ERROR), MYF(0));
+    return 1;
+  } 
   // Is it one field subselect?
   if (select_lex->item_list.elements != 1)
   {  
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index cd548f36cf..86e4e6896e 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -80,8 +80,8 @@ static void free_var(user_var_entry *entry)
 ****************************************************************************/
 
 THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
-	   insert_id_used(0),in_lock_tables(0),
-	   global_read_lock(0),bootstrap(0)
+	   insert_id_used(0), in_lock_tables(0),
+	   global_read_lock(0), bootstrap(0), having_fix_field(0)
 {
   host=user=priv_user=db=query=ip=0;
   host_or_ip="unknown ip";
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 019217cb65..8a1a299cee 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -428,6 +428,8 @@ public:
   bool       query_error, bootstrap, cleanup_done;
   bool	     safe_to_cache_query;
   bool	     volatile killed;
+  //  TRUE when having fix field called
+  bool       having_fix_field;
   /*
     If we do a purge of binary logs, log index info of the threads
     that are currently reading it needs to be adjusted. To do that
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index d4f6504ec3..c10174a7b7 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -229,7 +229,11 @@ JOIN::prepare(TABLE_LIST *tables_init,
   {
     thd->where="having clause";
     thd->allow_sum_func=1;
-    if (having->fix_fields(thd,tables_list) || thd->fatal_error)
+    bool having_fix_field_store= thd->having_fix_field;
+    thd->having_fix_field= 1;
+    bool having_fix_rc= having->fix_fields(thd,tables_list);
+    thd->having_fix_field= having_fix_field_store;
+    if (having_fix_rc || thd->fatal_error)
       DBUG_RETURN(-1);				/* purecov: inspected */
     if (having->with_sum_func)
       having->split_sum_func(all_fields);
-- 
2.30.9