summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/func_if.result17
-rw-r--r--mysql-test/t/func_if.test13
-rw-r--r--sql/item_cmpfunc.cc4
3 files changed, 32 insertions, 2 deletions
diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result
index 955a784f04c..8d3507f6bed 100644
--- a/mysql-test/r/func_if.result
+++ b/mysql-test/r/func_if.result
@@ -186,3 +186,20 @@ MAX(IFNULL(CAST(c AS UNSIGNED), 0))
12345678901234567890
DROP TABLE t1;
End of 5.0 tests
+#
+# LP bug#998321 Simple query with IF expression causes an
+# assertion abort (see also mysql Bug#12620084)
+#
+SELECT if(0, (SELECT min('hello')), NULL);
+if(0, (SELECT min('hello')), NULL)
+NULL
+SELECT if(1, (SELECT min('hello')), NULL);
+if(1, (SELECT min('hello')), NULL)
+hello
+SELECT if(0, NULL, (SELECT min('hello')));
+if(0, NULL, (SELECT min('hello')))
+hello
+SELECT if(1, NULL, (SELECT min('hello')));
+if(1, NULL, (SELECT min('hello')))
+NULL
+End of 5.2 tests
diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test
index 8142f57c0de..0d51b95ebe4 100644
--- a/mysql-test/t/func_if.test
+++ b/mysql-test/t/func_if.test
@@ -170,6 +170,19 @@ DROP TABLE t1;
--echo End of 5.0 tests
+
+--echo #
+--echo # LP bug#998321 Simple query with IF expression causes an
+--echo # assertion abort (see also mysql Bug#12620084)
+--echo #
+
+SELECT if(0, (SELECT min('hello')), NULL);
+SELECT if(1, (SELECT min('hello')), NULL);
+SELECT if(0, NULL, (SELECT min('hello')));
+SELECT if(1, NULL, (SELECT min('hello')));
+
+--echo End of 5.2 tests
+
--disable_query_log
# Restore timezone to default
set time_zone= @@global.time_zone;
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index c4d56a93af6..ea216944dbb 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -2659,8 +2659,8 @@ Item_func_if::fix_length_and_dec()
enum Item_result arg1_type=args[1]->result_type();
enum Item_result arg2_type=args[2]->result_type();
- bool null1=args[1]->const_item() && args[1]->null_value;
- bool null2=args[2]->const_item() && args[2]->null_value;
+ bool null1=args[1]->basic_const_item() && args[1]->null_value;
+ bool null2=args[2]->basic_const_item() && args[2]->null_value;
if (null1)
{