[MDEV-18100] User defined aggregate functions not working correctly when the schema is changed Created: 2018-12-28  Updated: 2020-05-16  Resolved: 2020-05-15

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.5.4, 10.3.24, 10.4.14

Type: Bug Priority: Major
Reporter: Varun Gupta (Inactive) Assignee: Varun Gupta (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-21763 Stored Aggregate Functions return NUL... Closed

 Description   

CREATE SCHEMA IF NOT EXISTS common_schema;
DELIMITER $$
DROP FUNCTION IF EXISTS common_schema.add_ints $$
CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL 
BEGIN 
    RETURN int_1 + int_2; 
END $$ 
DROP FUNCTION IF EXISTS common_schema.sum_ints $$
CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT 
BEGIN 
    DECLARE result INT DEFAULT 0; 
    DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result; 
    LOOP FETCH GROUP NEXT ROW; 
        SET result = common_schema.add_ints(result, int_val); 
    END LOOP; 
END $$
 
DELIMITER ;

MariaDB [test]> USE common_schema;
Database changed
MariaDB [common_schema]> SELECT common_schema.sum_ints(seq)
    -> FROM (SELECT 1 seq UNION ALL SELECT 2) t;
+-----------------------------+
| common_schema.sum_ints(seq) |
+-----------------------------+
|                           3 |
+-----------------------------+
1 row in set (0.009 sec)

MariaDB [test]> USE another_schema;
Database changed
MariaDB [another_schema]> SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
+-----------------------------+
| common_schema.sum_ints(seq) |
+-----------------------------+
|                        NULL |
+-----------------------------+
1 row in set (0.028 sec)

On changing the schema the custom aggregate function returns NULL , which is incorrect



 Comments   
Comment by Varun Gupta (Inactive) [ 2019-01-07 ]

Patch
http://lists.askmonty.org/pipermail/commits/2019-January/013253.html

Comment by Oleksandr Byelkin [ 2020-05-13 ]

OK to push

Generated at Thu Feb 08 08:41:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.