Fixed a bug in GREATES() and LEAST() function, that caused a core

dump when result was NULL.
parent 8dea612a
...@@ -165,3 +165,9 @@ SELECT f_acc.rank, a1.rank, a2.rank FROM t1 LEFT JOIN t1 f1 ON (f1.access_id=1 ...@@ -165,3 +165,9 @@ SELECT f_acc.rank, a1.rank, a2.rank FROM t1 LEFT JOIN t1 f1 ON (f1.access_id=1
rank rank rank rank rank rank
2 2 NULL 2 2 NULL
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (d varchar(6), k int);
INSERT INTO t1 VALUES (NULL, 2);
SELECT GREATEST(d,d) FROM t1 WHERE k=2;
GREATEST(d,d)
NULL
DROP TABLE t1;
...@@ -85,3 +85,11 @@ CREATE TABLE t2 ( access_id smallint(6) NOT NULL default '0', name varchar(20 ...@@ -85,3 +85,11 @@ CREATE TABLE t2 ( access_id smallint(6) NOT NULL default '0', name varchar(20
INSERT INTO t2 VALUES (1,'Everyone',2),(2,'Help',3),(3,'Customer Support',1); INSERT INTO t2 VALUES (1,'Everyone',2),(2,'Help',3),(3,'Customer Support',1);
SELECT f_acc.rank, a1.rank, a2.rank FROM t1 LEFT JOIN t1 f1 ON (f1.access_id=1 AND f1.faq_group_id = t1.faq_group_id) LEFT JOIN t2 a1 ON (a1.access_id = f1.access_id) LEFT JOIN t1 f2 ON (f2.access_id=3 AND f2.faq_group_id = t1.faq_group_id) LEFT JOIN t2 a2 ON (a2.access_id = f2.access_id), t2 f_acc WHERE LEAST(a1.rank,a2.rank) = f_acc.rank; SELECT f_acc.rank, a1.rank, a2.rank FROM t1 LEFT JOIN t1 f1 ON (f1.access_id=1 AND f1.faq_group_id = t1.faq_group_id) LEFT JOIN t2 a1 ON (a1.access_id = f1.access_id) LEFT JOIN t1 f2 ON (f2.access_id=3 AND f2.faq_group_id = t1.faq_group_id) LEFT JOIN t2 a2 ON (a2.access_id = f2.access_id), t2 f_acc WHERE LEAST(a1.rank,a2.rank) = f_acc.rank;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Test for GREATEST() and LEAST() bug, which segfaulted 4.1.1 server
#
CREATE TABLE t1 (d varchar(6), k int);
INSERT INTO t1 VALUES (NULL, 2);
SELECT GREATEST(d,d) FROM t1 WHERE k=2;
DROP TABLE t1;
...@@ -1068,6 +1068,8 @@ String *Item_func_min_max::val_str(String *str) ...@@ -1068,6 +1068,8 @@ String *Item_func_min_max::val_str(String *str)
} }
} }
} }
if (!res) // If NULL
return 0;
res->set_charset(collation.collation); res->set_charset(collation.collation);
return res; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment