处理issue:打开带for update的游标后,并没有锁住对应的记录
This commit is contained in:
@ -8373,6 +8373,11 @@ static int exec_stmt_open(PLpgSQL_execstate* estate, PLpgSQL_stmt_open* stmt)
|
||||
}
|
||||
#endif
|
||||
curvar->cursor_closed = false;
|
||||
/* Execute SQL through move cursor, only in A compatibility mode */
|
||||
if (u_sess->attr.attr_sql.sql_compatibility == A_FORMAT) {
|
||||
(void)PortalRunFetch(portal, FETCH_FORWARD, FETCH_ALL, None_Receiver);
|
||||
(void)PortalRunFetch(portal, FETCH_BACKWARD, FETCH_ALL, None_Receiver);
|
||||
}
|
||||
return PLPGSQL_RC_OK;
|
||||
}
|
||||
|
||||
|
@ -337,6 +337,50 @@ SQL statement "select complicate_process()"
|
||||
PL/pgSQL function process_test() line 4 at SQL statement
|
||||
referenced column: process_test
|
||||
NOTICE:
|
||||
QueryPlan
|
||||
|
||||
----------------------------NestLevel:3----------------------------
|
||||
Query Text: select teacher.name,stu.name from teacher left join course on course.cno = teacher.cno left join stu on stu.cno = course.cno
|
||||
Name: datanode1
|
||||
--?.*
|
||||
Output: teacher.name, stu.name
|
||||
Hash Cond: (course.cno = stu.cno)
|
||||
--?.*
|
||||
Output: teacher.name, course.cno
|
||||
Hash Cond: (course.cno = teacher.cno)
|
||||
--?.*
|
||||
Output: course.cno, course.name
|
||||
--?.*
|
||||
Output: teacher.name, teacher.cno
|
||||
--?.*
|
||||
Output: teacher.name, teacher.cno
|
||||
--?.*
|
||||
Output: stu.name, stu.cno
|
||||
--?.*
|
||||
Output: stu.name, stu.cno
|
||||
|
||||
|
||||
CONTEXT: PL/pgSQL function open_cursor() line 3 at OPEN
|
||||
referenced column: open_cursor
|
||||
SQL statement "select open_cursor()"
|
||||
PL/pgSQL function complicate_process() line 21 at SQL statement
|
||||
referenced column: complicate_process
|
||||
SQL statement "select complicate_process()"
|
||||
PL/pgSQL function process_test() line 4 at SQL statement
|
||||
referenced column: process_test
|
||||
NOTICE:
|
||||
----------------------------NestLevel:3----------------------------
|
||||
--?.*
|
||||
|
||||
CONTEXT: PL/pgSQL function open_cursor() line 3 at OPEN
|
||||
referenced column: open_cursor
|
||||
SQL statement "select open_cursor()"
|
||||
PL/pgSQL function complicate_process() line 21 at SQL statement
|
||||
referenced column: complicate_process
|
||||
SQL statement "select complicate_process()"
|
||||
PL/pgSQL function process_test() line 4 at SQL statement
|
||||
referenced column: process_test
|
||||
NOTICE:
|
||||
----------------------------NestLevel:2----------------------------
|
||||
--?.*
|
||||
|
||||
|
@ -1752,6 +1752,30 @@ select * from t1 order by c1;
|
||||
1 | a | Fri Sep 15 00:00:00 2023 | 1
|
||||
(1 row)
|
||||
|
||||
-- test for lock
|
||||
create table test_lock (a int);
|
||||
insert into test_lock values (1);
|
||||
\parallel on 2
|
||||
DECLARE
|
||||
v1 int;
|
||||
CURSOR emp_cur IS
|
||||
SELECT * from test_lock FOR update of test_lock ;
|
||||
begin
|
||||
OPEN emp_cur;
|
||||
perform pg_sleep(3);
|
||||
CLOSE emp_cur;
|
||||
end;
|
||||
/
|
||||
begin
|
||||
perform pg_sleep(1);
|
||||
perform * from test_lock for update nowait;
|
||||
end;
|
||||
/
|
||||
\parallel off
|
||||
ERROR: could not obtain lock on row in relation "test_lock"
|
||||
CONTEXT: SQL statement "SELECT * from test_lock for update nowait"
|
||||
PL/pgSQL function inline_code_block line 3 at PERFORM
|
||||
drop table test_lock;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
drop function t1_tri_func;
|
||||
|
@ -1194,6 +1194,29 @@ when not matched then insert values (5, 'e', '2023-09-20',0);
|
||||
|
||||
select * from t1 order by c1;
|
||||
|
||||
-- test for lock
|
||||
create table test_lock (a int);
|
||||
insert into test_lock values (1);
|
||||
\parallel on 2
|
||||
DECLARE
|
||||
v1 int;
|
||||
CURSOR emp_cur IS
|
||||
SELECT * from test_lock FOR update of test_lock ;
|
||||
begin
|
||||
OPEN emp_cur;
|
||||
perform pg_sleep(3);
|
||||
CLOSE emp_cur;
|
||||
end;
|
||||
/
|
||||
|
||||
begin
|
||||
perform pg_sleep(1);
|
||||
perform * from test_lock for update nowait;
|
||||
end;
|
||||
/
|
||||
\parallel off
|
||||
|
||||
drop table test_lock;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
drop function t1_tri_func;
|
||||
|
Reference in New Issue
Block a user