summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsergefp@mysql.com <>2005-07-12 16:30:45 +0000
committersergefp@mysql.com <>2005-07-12 16:30:45 +0000
commit55e70fd1f66cfd259d382e422c60d01cd914e05a (patch)
tree3ca9612bc0b1d028336ef2672e7d24505bac79f2
parent1042a275fe50e0939ca7f28e268be8dab8fefd9f (diff)
downloadmariadb-git-55e70fd1f66cfd259d382e422c60d01cd914e05a.tar.gz
Fix for BUG#11821: Make Item_type_holder be able to work with MIN(field),
MAX(field).
-rw-r--r--mysql-test/r/subselect.result6
-rw-r--r--mysql-test/t/subselect.test8
-rw-r--r--sql/item.cc8
3 files changed, 20 insertions, 2 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 1f3542802a7..8615c8e661b 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/subselect.test b/mysql-test/t/subselect.test
index e585022563f..12593438805 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 c96794ff482..3bdaf856f2a 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) ||