修复 当游标使用复合类型在异常场景下导致OG core的问题

This commit is contained in:
changying.yue
2023-08-11 06:49:32 +00:00
parent 22fb751a06
commit 8786eb4076
3 changed files with 97 additions and 0 deletions

View File

@ -3900,6 +3900,8 @@ static void AbortTransaction(bool PerfectRollback, bool STP_rollback)
/* reset flag is_delete_function */
u_sess->plsql_cxt.is_delete_function = false;
list_free_ext(u_sess->plsql_cxt.CursorRecordTypeList);
/*
* do abort processing
*/

View File

@ -959,6 +959,65 @@ fetch c3;
(1 row)
close c3;
---- 不在 TRANSACTION Block里的游标声明导致 core的问题
--游标依赖row type,后续alter type
drop type if exists type_cursor_bugfix_0001;
NOTICE: type "type_cursor_bugfix_0001" does not exist, skipping
create type type_cursor_bugfix_0001 as (a int, b int);
--游标依赖type,alter type报错
begin;
declare c5 cursor for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
fetch c5;
row
----------------
(1,1073741824)
(1 row)
fetch c5;
row
----------------
(2,1073741824)
(1 row)
alter type type_cursor_bugfix_0001 alter attribute b type text;--error
ERROR: cannot ALTER TABLE "type_cursor_bugfix_0001" because it is being used by active queries in this session
end;
/
--close后,可以成功alter
begin;
ERROR: syntax error at or near "/"
LINE 1: /
^
declare c7 cursor for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
ERROR: DECLARE CURSOR can only be used in transaction blocks
fetch c7;
ERROR: cursor "c7" does not exist
fetch c7;
ERROR: cursor "c7" does not exist
close c7;
ERROR: cursor "c7" does not exist
alter type type_cursor_bugfix_0001 alter attribute b type text;--success
declare c8 cursor for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
ERROR: DECLARE CURSOR can only be used in transaction blocks
fetch c8;
ERROR: cursor "c8" does not exist
fetch c8;
ERROR: cursor "c8" does not exist
rollback;
NOTICE: there is no transaction in progress
/
begin;
ERROR: syntax error at or near "/"
LINE 1: /
^
cursor c9 for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
ERROR: DECLARE CURSOR can only be used in transaction blocks
close c9;
ERROR: cursor "c9" does not exist
alter type type_cursor_bugfix_0001 alter attribute b type text;--success
end;
WARNING: there is no transaction in progress
drop type if exists type_cursor_bugfix_0001;
---- clean ----
drop package pck1;
NOTICE: drop cascades to function plpgsql_cursor_rowtype.p1()

View File

@ -758,6 +758,42 @@ alter type foo alter attribute b type text;--success
fetch c3;
close c3;
---- 不在 TRANSACTION Block里的游标声明导致 core的问题
--row typealter type
drop type if exists type_cursor_bugfix_0001;
create type type_cursor_bugfix_0001 as (a int, b int);
--typealter type报错
begin;
declare c5 cursor for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
fetch c5;
fetch c5;
alter type type_cursor_bugfix_0001 alter attribute b type text;--error
end;
/
--close后alter
begin;
declare c7 cursor for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
fetch c7;
fetch c7;
close c7;
alter type type_cursor_bugfix_0001 alter attribute b type text;--success
declare c8 cursor for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
fetch c8;
fetch c8;
rollback;
/
begin;
cursor c9 for select (i,2^30)::type_cursor_bugfix_0001 from generate_series(1,10) i;
close c9;
alter type type_cursor_bugfix_0001 alter attribute b type text;--success
end;
drop type if exists type_cursor_bugfix_0001;
---- clean ----
drop package pck1;
drop package pck2;