summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-08-08 16:04:40 +0400
committerAlexander Barkov <bar@mariadb.org>2016-08-08 16:04:40 +0400
commit1b3430a5ae6b2f6d5c251f1ff07f5c273b1dc175 (patch)
treebdd6adb32750fb059a58083597390d11ee56d565 /mysql-test
parent5e23b6344f3b229edcb0d9c42ec23b689c329a38 (diff)
downloadmariadb-git-1b3430a5ae6b2f6d5c251f1ff07f5c273b1dc175.tar.gz
MDEV-10500 CASE/IF Statement returns multiple values and shifts further result values to the next column
We assume all around the code that null_value==true is in sync with NULL value returned by val_str()/val_decimal(). Item_sum_sum::val_decimal() erroneously returned a non-NULL value together with null_value set to true. Fixing to return NULL instead.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/func_group.result27
-rw-r--r--mysql-test/t/func_group.test25
2 files changed, 52 insertions, 0 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index ac076ec4348..0253548236c 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -2270,3 +2270,30 @@ t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
EXECUTE stmt;
t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
DROP TABLE t1,t2,t3,t4,t5,t6;
+#
+# MDEV-10500 CASE/IF Statement returns multiple values and shifts further result values to the next column
+#
+CREATE TABLE t1 (
+id int not null AUTO_INCREMENT,
+active bool not null,
+data1 bigint,
+data2 bigint,
+data3 bigint,
+primary key (id)
+);
+INSERT INTO t1 (active,data1,data2,data3) VALUES (1,null,100,200);
+SELECT
+CASE WHEN active THEN SUM(data1) END AS C_1,
+SUM(data2) AS C_2,
+SUM(data3) AS C_3
+FROM t1;
+C_1 C_2 C_3
+NULL 100 200
+SELECT
+IF(active, SUM(data1), 5) AS C_1,
+SUM(data2) AS C_2,
+SUM(data3) AS C_3
+FROM t1;
+C_1 C_2 C_3
+NULL 100 200
+DROP TABLE t1;
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index bd3ed4ad32d..5824d99afa5 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -1565,3 +1565,28 @@ EXECUTE stmt;
EXECUTE stmt;
DROP TABLE t1,t2,t3,t4,t5,t6;
+
+--echo #
+--echo # MDEV-10500 CASE/IF Statement returns multiple values and shifts further result values to the next column
+--echo #
+
+CREATE TABLE t1 (
+ id int not null AUTO_INCREMENT,
+ active bool not null,
+ data1 bigint,
+ data2 bigint,
+ data3 bigint,
+ primary key (id)
+);
+INSERT INTO t1 (active,data1,data2,data3) VALUES (1,null,100,200);
+SELECT
+ CASE WHEN active THEN SUM(data1) END AS C_1,
+ SUM(data2) AS C_2,
+ SUM(data3) AS C_3
+FROM t1;
+SELECT
+ IF(active, SUM(data1), 5) AS C_1,
+ SUM(data2) AS C_2,
+ SUM(data3) AS C_3
+FROM t1;
+DROP TABLE t1;