From 86211a1b446fe0d164f19d25f966d5fbfc9963fb Mon Sep 17 00:00:00 2001
From: "gluh@gluh.mysql.r18.ru" <>
Date: Tue, 16 Mar 2004 11:33:03 +0400
Subject: [PATCH] Fix for bug #2629 NULLIF() doesn't behave as described in
 manual

---
 mysql-test/r/func_if.result | 6 ++++++
 mysql-test/t/func_if.test   | 6 ++++++
 sql/item_cmpfunc.cc         | 6 +++---
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result
index 0ab41258091..470004d2646 100644
--- a/mysql-test/r/func_if.result
+++ b/mysql-test/r/func_if.result
@@ -40,6 +40,12 @@ a
 aa
 aaa
 drop table t1;
+select NULLIF(NULL,NULL), NULLIF(NULL,1), NULLIF(NULL,1.0), NULLIF(NULL,"test");
+NULLIF(NULL,NULL)	NULLIF(NULL,1)	NULLIF(NULL,1.0)	NULLIF(NULL,"test")
+NULL	NULL	NULL	NULL
+select NULLIF(1,NULL), NULLIF(1.0, NULL), NULLIF("test", NULL);
+NULLIF(1,NULL)	NULLIF(1.0, NULL)	NULLIF("test", NULL)
+1	1.0	test
 create table t1 (num  double(12,2));
 insert into t1 values (144.54);
 select sum(if(num is null,0.00,num)) from t1;
diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test
index 85553d1a2fd..1f95239bf4b 100644
--- a/mysql-test/t/func_if.test
+++ b/mysql-test/t/func_if.test
@@ -20,6 +20,12 @@ select if(u=1,binary st,st) s from t1 order by s;
 select if(u=1,st,binary st) s from t1 where st like "%a%" order by s;
 drop table t1;
 
+#
+# Bug 2629
+#
+select NULLIF(NULL,NULL), NULLIF(NULL,1), NULLIF(NULL,1.0), NULLIF(NULL,"test");
+select NULLIF(1,NULL), NULLIF(1.0, NULL), NULLIF("test", NULL);
+
 #
 # Problem with IF()
 #
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 82f368970e2..d84dab3425a 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -616,7 +616,7 @@ double
 Item_func_nullif::val()
 {
   double value;
-  if (!(this->*cmp_func)() || null_value)
+  if (!(this->*cmp_func)())
   {
     null_value=1;
     return 0.0;
@@ -630,7 +630,7 @@ longlong
 Item_func_nullif::val_int()
 {
   longlong value;
-  if (!(this->*cmp_func)() || null_value)
+  if (!(this->*cmp_func)())
   {
     null_value=1;
     return 0;
@@ -644,7 +644,7 @@ String *
 Item_func_nullif::val_str(String *str)
 {
   String *res;
-  if (!(this->*cmp_func)() || null_value)
+  if (!(this->*cmp_func)())
   {
     null_value=1;
     return 0;
-- 
2.30.9