Commit 1b3430a5 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10500 CASE/IF Statement returns multiple values and shifts further result...

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.
parent 5e23b634
...@@ -2270,3 +2270,30 @@ t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1) ...@@ -2270,3 +2270,30 @@ t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
EXECUTE stmt; EXECUTE stmt;
t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1) t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
DROP TABLE t1,t2,t3,t4,t5,t6; 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;
...@@ -1565,3 +1565,28 @@ EXECUTE stmt; ...@@ -1565,3 +1565,28 @@ EXECUTE stmt;
EXECUTE stmt; EXECUTE stmt;
DROP TABLE t1,t2,t3,t4,t5,t6; 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;
...@@ -1462,7 +1462,7 @@ my_decimal *Item_sum_sum::val_decimal(my_decimal *val) ...@@ -1462,7 +1462,7 @@ my_decimal *Item_sum_sum::val_decimal(my_decimal *val)
if (aggr) if (aggr)
aggr->endup(); aggr->endup();
if (hybrid_type == DECIMAL_RESULT) if (hybrid_type == DECIMAL_RESULT)
return (dec_buffs + curr_dec_buff); return null_value ? NULL : (dec_buffs + curr_dec_buff);
return val_decimal_from_real(val); return val_decimal_from_real(val);
} }
......
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