mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-18100: User defined aggregate functions not working correctly when the schema is changed
The issue here was that when the schema was changed the value for the THD::server_status is ored with SERVER_SESSION_STATE_CHANGED. For custom aggregate functions, currently we check if the server_status is equal to SERVER_STATUS_LAST_ROW_SENT then we should terminate the execution of the custom aggregate function as there are no more rows to fetch. So the check should be that if the server status has the bit set for SERVER_STATUS_LAST_ROW_SENT then we should terminate the execution of the custom aggregate function.
This commit is contained in:
@ -965,3 +965,36 @@ select i, sum(i) from t1 group by i with rollup;
|
||||
# Cleanup
|
||||
drop function agg_sum;
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # User defined aggregate functions not working correctly when the schema is changed
|
||||
--echo #
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS common_schema;
|
||||
CREATE SCHEMA IF NOT EXISTS another_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 ;|
|
||||
|
||||
use common_schema;
|
||||
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
|
||||
|
||||
USE another_schema;
|
||||
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
|
||||
|
||||
drop database common_schema;
|
||||
drop database another_schema;
|
||||
|
Reference in New Issue
Block a user