You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing a crash when attempting to use an aggregate function inside a case statement in a having clause. The server restarts correctly but the crash is reproducible every time.
Below is an example. One use case for this is that I am computing a formula on aggregated data, and want to ensure no divide by zero occurs.
-- Works
select
"c1",
sum("d1") as "d1",
sum("d2") as "d2"
from "t1"
group by "c1"
having sum("d1") < case when 5 > 10 then 500 else 400 end;
-- Works
select
"c1",
sum("d1")as "d1",
sum("d2") as "d2",
1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null end) as "formula"
from "t1"
group by "c1";
-- Crashes
select
"c1",
sum("d1")as "d1",
sum("d2") as "d2",
1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null end) as "formula"
from "t1"
group by "c1"
having (1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null end)) > 1;
Looking in merovingian.log:
2018-01-29 14:47:15 ERR test[2879]: *** Error in `/usr/bin/mserver5': double free or corruption (out): 0x00007f57200ea4b0 ***
2018-01-29 14:47:18 MSG merovingian[504]: database 'test' (2879) has crashed (dumped core)
2018-01-29 14:49:35 MSG merovingian[504]: database 'test' has crashed after start on 2018-01-29 14:42:36, attempting restart, up min/avg/max: 0s/0s/0s, crash average: 1.00 0.20 0.07 (2-0=2)
2
Date: 2018-01-30 21:26:25 +0100
From: Trevor <>
To: SQL devs <>
Version: 11.27.11 (Jul2017-SP3)
CC: @njnes
Last updated: 2018-03-29 15:38:57 +0200
Comment 26137
Date: 2018-01-30 21:26:25 +0100
From: Trevor <>
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0
Build Identifier:
I am experiencing a crash when attempting to use an aggregate function inside a case statement in a having clause. The server restarts correctly but the crash is reproducible every time.
Below is an example. One use case for this is that I am computing a formula on aggregated data, and want to ensure no divide by zero occurs.
Are case statements in having clauses supported?
create table "t1" (
"id" int,
"c1" varchar(100),
"d1" int,
"d2" int
);
insert into "t1" values
(1, 'A', 50, 80),
(2, 'A', 200, 350),
(3, 'A', 89, 125),
(4, 'B', 4845, 13),
(5, 'B', 194, 597),
(6, 'C', 5636, 5802),
(7, 'C', 375, 3405),
(7, 'D', 365, 0),
(7, 'D', 87, 0);
-- Works
select
"c1",
sum("d1") as "d1",
sum("d2") as "d2"
from "t1"
group by "c1"
having sum("d1") < case when 5 > 10 then 500 else 400 end;
-- Works
select
"c1",
sum("d1")as "d1",
sum("d2") as "d2",
1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null end) as "formula"
from "t1"
group by "c1";
-- Crashes
select
"c1",
sum("d1")as "d1",
sum("d2") as "d2",
1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null end) as "formula"
from "t1"
group by "c1"
having (1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null end)) > 1;
Looking in merovingian.log:
2018-01-29 14:47:15 ERR test[2879]: *** Error in `/usr/bin/mserver5': double free or corruption (out): 0x00007f57200ea4b0 ***
2018-01-29 14:47:18 MSG merovingian[504]: database 'test' (2879) has crashed (dumped core)
2018-01-29 14:49:35 MSG merovingian[504]: database 'test' has crashed after start on 2018-01-29 14:42:36, attempting restart, up min/avg/max: 0s/0s/0s, crash average: 1.00 0.20 0.07 (2-0=2)
2
Reproducible: Always
Steps to Reproduce:
Run queries provided in details.
Actual Results:
Database crashes.
Expected Results:
Query completes and returns correct results.
Comment 26153
Date: 2018-02-01 10:28:33 +0100
From: MonetDB Mercurial Repository <>
Changeset 567582612f6f made by Sjoerd Mullender sjoerd@acm.org in the MonetDB repo, refers to this bug.
For complete details, see https//devmonetdborg/hg/MonetDB?cmd=changeset;node=567582612f6f
Changeset description:
Comment 26210
Date: 2018-02-17 09:27:48 +0100
From: MonetDB Mercurial Repository <>
Changeset 4d9b69cdf41d made by Niels Nes niels@cwi.nl in the MonetDB repo, refers to this bug.
For complete details, see https//devmonetdborg/hg/MonetDB?cmd=changeset;node=4d9b69cdf41d
Changeset description:
Comment 26211
Date: 2018-02-17 09:29:03 +0100
From: @njnes
fixed. Pass the information of handling the 'having' properly in the case statement
Comment 26295
Date: 2018-03-29 15:38:57 +0200
From: @sjoerdmullender
The Mar2018 version has been released.
The text was updated successfully, but these errors were encountered: