mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-7773: Aggregate stored functions
This commit implements aggregate stored functions. The basic idea behind the feature is: * Implement a special instruction FETCH GROUP NEXT ROW that will pause the execution of the stored function. When the instruction is reached, execution of the initial query resumes "as if" the function returned. This gives the server the opportunity to advance to the next row in the result set. * Stored aggregates behave like regular aggregate functions. The implementation of thus resides in the class Item_sum_sp. Because it is an aggregate function, for each new row in the group, the Item_sum_sp::add() method will be called. This is when execution resumes and the function does another iteration to "add" one extra element to the final result. * When the end of group is reached, val_xxx() method will be called for the item. This case is handled by another execute step for the stored function, only with a special flag to force a call to the return handler. See Item_sum_sp::execute() for details. To allow this pause and resume semantic, we must preserve the function context across executions. This is stored in Item_sp::sp_query_arena only for aggregate stored functions, but has no impact for regular functions. We also enforce aggregate functions to include the "FETCH GROUP NEXT ROW" instruction. Signed-off-by: Vicențiu Ciorbaru <vicentiu@mariadb.org>
This commit is contained in:
committed by
Vicențiu Ciorbaru
parent
7448b01bb5
commit
60c446584c
@ -1771,48 +1771,48 @@ Testcase 4.1.9:
|
||||
drop procedure
|
||||
--------------------------------------------------------------------------------
|
||||
SELECT * from mysql.proc where specific_name='sp9';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
DROP PROCEDURE IF EXISTS sp9;
|
||||
SELECT * from mysql.proc where specific_name='sp9';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
CREATE PROCEDURE sp9()SELECT * from t1;
|
||||
SELECT * from mysql.proc where specific_name='sp9';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db_storedproc sp9 PROCEDURE sp9 SQL CONTAINS_SQL NO DEFINER SELECT * from t1 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from t1
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
db_storedproc sp9 PROCEDURE sp9 SQL CONTAINS_SQL NO DEFINER SELECT * from t1 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from t1 NONE
|
||||
DROP PROCEDURE sp9;
|
||||
SELECT * from mysql.proc where specific_name='sp9';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
CREATE PROCEDURE sp9()SELECT * from t1;
|
||||
SELECT * from mysql.proc where specific_name='sp9';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db_storedproc sp9 PROCEDURE sp9 SQL CONTAINS_SQL NO DEFINER SELECT * from t1 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from t1
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
db_storedproc sp9 PROCEDURE sp9 SQL CONTAINS_SQL NO DEFINER SELECT * from t1 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from t1 NONE
|
||||
DROP PROCEDURE IF EXISTS sp9;
|
||||
SELECT * from mysql.proc where specific_name='sp9';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
|
||||
Testcase 4.1.10:
|
||||
----------------
|
||||
DROP FUNCTION
|
||||
--------------------------------------------------------------------------------
|
||||
SELECT * from mysql.proc where specific_name='fn10' and type='function';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
DROP FUNCTION IF EXISTS fn10;
|
||||
SELECT * from mysql.proc where specific_name='fn10' and type='function';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
CREATE FUNCTION fn10() returns int return 100;
|
||||
SELECT * from mysql.proc where specific_name='fn10' and type='function';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db_storedproc fn10 FUNCTION fn10 SQL CONTAINS_SQL NO DEFINER int(11) return 100 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci return 100
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
db_storedproc fn10 FUNCTION fn10 SQL CONTAINS_SQL NO DEFINER int(11) return 100 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci return 100 NONE
|
||||
DROP FUNCTION fn10;
|
||||
SELECT * from mysql.proc where specific_name='fn10' and type='function';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
CREATE FUNCTION fn10() returns int return 100;
|
||||
SELECT * from mysql.proc where specific_name='fn10' and type='function';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db_storedproc fn10 FUNCTION fn10 SQL CONTAINS_SQL NO DEFINER int(11) return 100 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci return 100
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
db_storedproc fn10 FUNCTION fn10 SQL CONTAINS_SQL NO DEFINER int(11) return 100 root@localhost created modified latin1 latin1_swedish_ci latin1_swedish_ci return 100 NONE
|
||||
DROP FUNCTION IF EXISTS fn10;
|
||||
SELECT * from mysql.proc where specific_name='fn10' and type='function';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
|
||||
Testcase 4.1.11:
|
||||
----------------
|
||||
@ -16172,15 +16172,15 @@ insert into t43 values('abcde', 'a!@#$%^&*(');
|
||||
CREATE PROCEDURE d1.sp4()
|
||||
SELECT * from d1.t43;
|
||||
SELECT * from mysql.proc where specific_name = 'sp4';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
d1 sp4 PROCEDURE sp4 SQL CONTAINS_SQL NO DEFINER SELECT * from d1.t43 root@localhost modified created latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from d1.t43
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
d1 sp4 PROCEDURE sp4 SQL CONTAINS_SQL NO DEFINER SELECT * from d1.t43 root@localhost modified created latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from d1.t43 NONE
|
||||
USE db_storedproc;
|
||||
DROP DATABASE d1;
|
||||
CREATE DATABASE d1;
|
||||
USE d1;
|
||||
create table t44(a char(5), b char(10));
|
||||
SELECT * from mysql.proc where specific_name = 'sp4';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
USE db_storedproc;
|
||||
DROP DATABASE d1;
|
||||
|
||||
@ -16222,8 +16222,8 @@ CREATE PROCEDURE sp8 ( n char(20) ) sql security DEFINER comment 'initial'
|
||||
USE d2;
|
||||
alter procedure d1.sp8 sql security DEFINER comment 'updated';
|
||||
SELECT * from mysql.proc where specific_name='sp8' and db='d1';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
d1 sp8 PROCEDURE sp8 SQL CONTAINS_SQL NO DEFINER n char(20) SELECT * from t1 where t1.f1 = n root@localhost modified created updated latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from t1 where t1.f1 = n
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
d1 sp8 PROCEDURE sp8 SQL CONTAINS_SQL NO DEFINER n char(20) SELECT * from t1 where t1.f1 = n root@localhost modified created updated latin1 latin1_swedish_ci latin1_swedish_ci SELECT * from t1 where t1.f1 = n NONE
|
||||
|
||||
Testcase 4.4.9:
|
||||
--------------------------------------------------------------------------------
|
||||
@ -16239,7 +16239,7 @@ END//
|
||||
USE d2;
|
||||
alter function d1.fn2 sql security DEFINER comment 'updated';
|
||||
SELECT * from mysql.proc where specific_name='fn2' and db='d1';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
d1 fn2 FUNCTION fn2 SQL CONTAINS_SQL NO DEFINER n int int(11) BEGIN
|
||||
declare a int;
|
||||
set a = 0.9 * n;
|
||||
@ -16248,7 +16248,7 @@ END root@localhost modified created updated latin1 latin1_swedish_ci latin1_swe
|
||||
declare a int;
|
||||
set a = 0.9 * n;
|
||||
return a;
|
||||
END
|
||||
END NONE
|
||||
|
||||
Testcase 4.4.10:
|
||||
--------------------------------------------------------------------------------
|
||||
@ -16258,7 +16258,7 @@ SELECT * from t1 where t1.f1 = n;
|
||||
USE d2;
|
||||
DROP PROCEDURE d1.sp9;
|
||||
SELECT * from mysql.proc where specific_name='sp9' and db='d1';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
|
||||
Testcase 4.4.11:
|
||||
--------------------------------------------------------------------------------
|
||||
@ -16272,7 +16272,7 @@ END//
|
||||
USE d2;
|
||||
DROP FUNCTION d1.fn3;
|
||||
SELECT * from mysql.proc where specific_name='fn3' and db='d1';
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8
|
||||
db name type specific_name language sql_data_access is_deterministic security_type param_list returns body definer created modified sql_mode comment character_set_client collation_connection db_collation body_utf8 aggregate
|
||||
USE db_storedproc;
|
||||
DROP DATABASE d1;
|
||||
DROP DATABASE d2;
|
||||
|
Reference in New Issue
Block a user