Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddf4a22

Browse files
author
Maxim Orlov
committed
Issue#27: Add tests and comment.
1 parent1b9dc66 commitddf4a22

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

‎expected/pg_variables_trans.out‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,3 +3510,49 @@ SELECT pgv_free();
35103510

35113511
(1 row)
35123512

3513+
-- take #4
3514+
SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), TRUE);
3515+
pgv_insert
3516+
------------
3517+
3518+
(1 row)
3519+
3520+
SELECT pgv_insert('test', 'x', ROW (2::int, 3::int), TRUE);
3521+
pgv_insert
3522+
------------
3523+
3524+
(1 row)
3525+
3526+
BEGIN;
3527+
DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x');
3528+
SAVEPOINT sp1;
3529+
FETCH 1 in r1_cur;
3530+
pgv_select
3531+
------------
3532+
(1,2)
3533+
(1 row)
3534+
3535+
ROLLBACK TO SAVEPOINT sp1;
3536+
COMMIT;
3537+
BEGIN;
3538+
DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x');
3539+
SAVEPOINT sp1;
3540+
FETCH 2 in r1_cur;
3541+
pgv_select
3542+
------------
3543+
(1,2)
3544+
(2,3)
3545+
(2 rows)
3546+
3547+
ROLLBACK TO SAVEPOINT sp1;
3548+
COMMIT;
3549+
BEGIN;
3550+
SAVEPOINT sp1;
3551+
SELECT pgv_select('test', 'x') LIMIT 1;
3552+
pgv_select
3553+
------------
3554+
(1,2)
3555+
(1 row)
3556+
3557+
ROLLBACK TO SAVEPOINT sp1;
3558+
COMMIT;

‎pg_variables.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,20 @@ static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
129129
staticdlist_head*changesStack=NULL;
130130
staticMemoryContextchangesStackContext=NULL;
131131

132-
/* List to store all the running hash_seq_search scan for hash table */
132+
/*
133+
* List to store all the running hash_seq_search scan for hash table.
134+
*
135+
* NOTE: In function variable_select we use hash_seq_search to find next tuple.
136+
* So, in case user do not get all the data from set at once (use cursors or
137+
* LIMIT) we have to call hash_seq_term to not to leak hash_seq_search scans.
138+
*
139+
* For doing this, we alloc all of the rstats in the TopTransactionContext and
140+
* save pointers to the rstats into list. Once transaction ended (commited or
141+
* aborted) we clear all the "active" hash_seq_search by calling hash_seq_term.
142+
*
143+
* TopTransactionContext is handy here, becouse it wount be reset by the time
144+
* pgvTransCallback is called.
145+
*/
133146
staticList*rstats=NIL;
134147

135148
/* Returns a lists of packages and variables changed at current subxact level */

‎sql/pg_variables_trans.sql‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,26 @@ COMMIT;
10071007
SELECT pgv_select('test','z3');
10081008

10091009
SELECT pgv_free();
1010+
-- take #4
1011+
SELECT pgv_insert('test','x', ROW (1::int,2::int), TRUE);
1012+
SELECT pgv_insert('test','x', ROW (2::int,3::int), TRUE);
1013+
1014+
BEGIN;
1015+
DECLARE r1_cur CURSOR FORSELECT pgv_select('test','x');
1016+
SAVEPOINT sp1;
1017+
FETCH1in r1_cur;
1018+
ROLLBACK TO SAVEPOINT sp1;
1019+
COMMIT;
1020+
1021+
BEGIN;
1022+
DECLARE r1_cur CURSOR FORSELECT pgv_select('test','x');
1023+
SAVEPOINT sp1;
1024+
FETCH2in r1_cur;
1025+
ROLLBACK TO SAVEPOINT sp1;
1026+
COMMIT;
1027+
1028+
BEGIN;
1029+
SAVEPOINT sp1;
1030+
SELECT pgv_select('test','x')LIMIT1;
1031+
ROLLBACK TO SAVEPOINT sp1;
1032+
COMMIT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp