Server crashes when using a prepared statement with a function
Hello, I have a SQL function (myFunc) that computes the sum of the records on a table (tbl1) and returns the sum (along with other attributes) as a table. tbl1 references tables tbl2 and tbl3 through fk_tbl2_id and fk_tbl3_id's, respectively. Since I want to use this function in a Node.js API and the parameters for the function will come from the users of the API, it is safer to use a prepared statement to bind the parameters. Whenever I try to execute the following prepared statement with the function:
PREPARE SELECT * FROM myFunc(?, ?, ?); EXEC (2008, 1, 2);
The server crashes, as shown in the server log and dmesg:
2016-07-12 10:56:40 MSG merovingian[3110]: database 'testdb' (19875) was killed by signal SIGSEGV
mserver5[18201]: segfault at 30 ip 00007f2d87be51e4 sp 00007f2d86f63b80 error 4 in lib_sql.so[7f2d87b85000+199000]
The SQL function for myFunc is the following:
CREATE FUNCTION myFunc(year int, table2_id int, table3_id int) RETURNS TABLE(name text, total bigint) BEGIN RETURN ( SELECT 'Overall', COALESCE(SUM(t1.num_enrollments), 0) FROM tbl1 AS t1 WHERE t1.census_year = year AND (CASE(table2_id) WHEN 0 THEN (t1.fk_table2_id > 0) ELSE (t1.fk_table2_id = table2_id) END) AND (CASE(table3_id) WHEN 0 THEN (t1.fk_table3_id > 0) ELSE (t1.fk_table3_id = table3_id) END) ); END;
I'm running MonetDB v11.21.19 (Jul2015-SP4) on Ubuntu 14.04 LTS. I could not find any bug reports related to the issue. How can I debug it further? Any help is deeply appreciated. Best regards, João Victor Risso.
participants (1)
-
João Victor Risso