diff --git a/include/my_global.h b/include/my_global.h
index f2fa54f3e4a078801d68e3e4f15ed8219e880ce7..a7e6bba82b62544cfcdd61f7be2095b677325870 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -375,10 +375,7 @@ int	__void__;
 #endif
 
 /* Define some useful general macros */
-#if defined(__cplusplus) && defined(__GNUC__)
-#define max(a, b)	((a) >? (b))
-#define min(a, b)	((a) <? (b))
-#elif !defined(max)
+#if !defined(max)
 #define max(a, b)	((a) > (b) ? (a) : (b))
 #define min(a, b)	((a) < (b) ? (a) : (b))
 #endif
diff --git a/mysql-test/r/ndb_autodiscover.result b/mysql-test/r/ndb_autodiscover.result
index b278d6eb04804dac565eeacc0e7968b9802993de..5a1a82832fae87ac2d9d3969133e1d327627263d 100644
--- a/mysql-test/r/ndb_autodiscover.result
+++ b/mysql-test/r/ndb_autodiscover.result
@@ -358,20 +358,6 @@ Database
 mysql
 test
 use test;
-CREATE TABLE sys.SYSTAB_0 (a int);
-ERROR 42S01: Table 'SYSTAB_0' already exists
-select * from sys.SYSTAB_0;
-ERROR HY000: Failed to open 'SYSTAB_0', error while unpacking from engine
-CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int);
-show warnings;
-Level	Code	Message
-select * from sys.SYSTAB_0;
-ERROR HY000: Failed to open 'SYSTAB_0', error while unpacking from engine
-drop table sys.SYSTAB_0;
-ERROR 42S02: Unknown table 'SYSTAB_0'
-drop table IF EXISTS sys.SYSTAB_0;
-Warnings:
-Note	1051	Unknown table 'SYSTAB_0'
 CREATE TABLE t9 (
 a int NOT NULL PRIMARY KEY,
 b int
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 1f3542802a7a57aaf1172734a3091f28a4363344..8615c8e661b623992f2e089bfb9347fd536d7c2d 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -2721,3 +2721,9 @@ SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessioni
 ip	count( e.itemid )
 10.10.10.1	1
 drop tables t1,t2;
+create table t1 (fld enum('0','1'));
+insert into t1 values ('1');
+select * from (select max(fld) from t1) as foo;
+max(fld)
+1
+drop table t1;
diff --git a/mysql-test/t/ndb_autodiscover.test b/mysql-test/t/ndb_autodiscover.test
index 49ed8c894febe4e273fdc76fbb0e3b6a07ffd71c..1eed78b43df5bd94baaaee305e329d3614e78849 100644
--- a/mysql-test/t/ndb_autodiscover.test
+++ b/mysql-test/t/ndb_autodiscover.test
@@ -460,19 +460,20 @@ use test;
 # a table with tha same name as a table that can't be
 # discovered( for example a table created via NDBAPI)
 
---error 1050
-CREATE TABLE sys.SYSTAB_0 (a int);
---error 1105
-select * from sys.SYSTAB_0;
-
-CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int);
-show warnings;
---error 1105
-select * from sys.SYSTAB_0;
-
---error 1051
-drop table sys.SYSTAB_0;
-drop table IF EXISTS sys.SYSTAB_0;
+# Test disabled since it doesn't work on case insensitive systems
+#--error 1050
+#CREATE TABLE sys.SYSTAB_0 (a int);
+#--error 1105
+#select * from sys.SYSTAB_0;
+
+#CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int);
+#show warnings;
+#--error 1105
+#select * from sys.SYSTAB_0;
+
+#--error 1051
+#drop table sys.SYSTAB_0;
+#drop table IF EXISTS sys.SYSTAB_0;
 
 ######################################################
 # Note! This should always be the last step in this 
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index e585022563f83057b1813f427a03522e76036ba6..125934388053d66ec7b34347a9671074ff084dbe 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1746,3 +1746,11 @@ CREATE TABLE `t2` (
 INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
 drop tables t1,t2;
+
+# BUG#11821 : Select from subselect using aggregate function on an enum
+# segfaults:
+create table t1 (fld enum('0','1'));
+insert into t1 values ('1');
+select * from (select max(fld) from t1) as foo;
+drop table t1;
+
diff --git a/sql/item.cc b/sql/item.cc
index c96794ff482a00a196ab9cf7edef57081f8dba3c..3bdaf856f2a5c405a99795b14d6574f9bb8c0822 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -3121,9 +3121,13 @@ void Item_type_holder::get_full_info(Item *item)
   if (fld_type == MYSQL_TYPE_ENUM ||
       fld_type == MYSQL_TYPE_SET)
   {
+    if (item->type() == Item::SUM_FUNC_ITEM &&
+        (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
+         ((Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC))
+      item = ((Item_sum*)item)->args[0];
     /*
-      We can have enum/set type after merging only if we have one enum/set
-      field and number of NULL fields
+      We can have enum/set type after merging only if we have one enum|set
+      field (or MIN|MAX(enum|set field)) and number of NULL fields
     */
     DBUG_ASSERT((enum_set_typelib &&
                  get_real_type(item) == MYSQL_TYPE_NULL) ||