diff --git a/.travis.yml b/.travis.yml index 6f7474d..80d5de7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,18 +20,24 @@ notifications: on_failure: always env: + - PG_VERSION=16 LEVEL=nightmare + - PG_VERSION=16 LEVEL=hardcore + - PG_VERSION=16 + - PG_VERSION=15 LEVEL=nightmare + - PG_VERSION=15 LEVEL=hardcore + - PG_VERSION=15 + - PG_VERSION=14 LEVEL=nightmare + - PG_VERSION=14 LEVEL=hardcore + - PG_VERSION=14 - PG_VERSION=13 LEVEL=nightmare - PG_VERSION=13 LEVEL=hardcore - PG_VERSION=13 - # - PG_VERSION=12 LEVEL=nightmare + - PG_VERSION=12 LEVEL=nightmare - PG_VERSION=12 LEVEL=hardcore - PG_VERSION=12 - # - PG_VERSION=11 LEVEL=nightmare + - PG_VERSION=11 LEVEL=nightmare - PG_VERSION=11 LEVEL=hardcore - PG_VERSION=11 - - PG_VERSION=10 - - PG_VERSION=9.6 - - PG_VERSION=9.5 # XXX: consider fixing nightmare mode matrix: @@ -39,3 +45,6 @@ matrix: - env: PG_VERSION=11 LEVEL=nightmare - env: PG_VERSION=12 LEVEL=nightmare - env: PG_VERSION=13 LEVEL=nightmare + - env: PG_VERSION=14 LEVEL=nightmare + - env: PG_VERSION=15 LEVEL=nightmare + - env: PG_VERSION=16 LEVEL=nightmare diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 0bcd176..2792b6e 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -6,7 +6,7 @@ RUN apk add --no-cache \ perl perl-ipc-run \ make musl-dev gcc bison flex coreutils \ zlib-dev libedit-dev linux-headers \ - clang clang-analyzer; + pkgconf icu-dev clang clang15 clang-analyzer; # Install fresh valgrind RUN apk add valgrind \ diff --git a/Makefile b/Makefile index f95c39f..7253e93 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ DATA_built = $(EXTENSION)--$(EXTVERSION).sql PGFILEDESC = "pg_variables - sessional variables" -REGRESS = pg_variables pg_variables_any pg_variables_trans pg_variables_atx +REGRESS = pg_variables pg_variables_any pg_variables_trans pg_variables_atx \ + pg_variables_atx_pkg ifdef USE_PGXS PG_CONFIG = pg_config diff --git a/expected/pg_variables_atx_1.out b/expected/pg_variables_atx_1.out deleted file mode 100644 index b5d8a07..0000000 --- a/expected/pg_variables_atx_1.out +++ /dev/null @@ -1,465 +0,0 @@ -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------- --- Non-transactional variables ------------------------------- -select pgv_set('vars', 'int1', 101); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102); - pgv_set ---------- - -(1 row) - - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_set('vars', 'int3', 103); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 101, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars', 'int1', 1001); -ERROR: current transaction is aborted, commands ignored until end of transaction block - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ --- 1001, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars', 'int2', 1002); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; - commit; -WARNING: there is no transaction in progress --- 1001, 1002, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); -ERROR: unrecognized variable "int3" - select pgv_set('vars', 'int3', 1003); - pgv_set ---------- - -(1 row) - -rollback; -WARNING: there is no transaction in progress --- 1001, 1002, 1003: -select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 101 | 102 | 1003 -(1 row) - --- vars:int1, vars:int2, vars:int3: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | f - vars | int2 | f - vars | int3 | f -(3 rows) - -select pgv_free(); - pgv_free ----------- - -(1 row) - --------------------------- --- Transactional variables --------------------------- -select pgv_set('vars', 'int1', 101, true); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102, true); - pgv_set ---------- - -(1 row) - - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_set('vars', 'int3', 103, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 103: - select pgv_get('vars', 'int3', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_set('vars', 'int2', 1002, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 1002: - select pgv_get('vars', 'int2', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; --- 103: - select pgv_get('vars', 'int3', null::int); -ERROR: unrecognized variable "int3" - commit; -WARNING: there is no transaction in progress - select pgv_set('vars', 'int1', 1001, true); - pgv_set ---------- - -(1 row) - --- 1001: - select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 1001 -(1 row) - --- 102: - select pgv_get('vars', 'int2', null::int); -ERROR: unrecognized variable "int2" -rollback; -WARNING: there is no transaction in progress --- 101: -select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 1001 -(1 row) - --- vars:int1: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | t -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - ----------- --- Cursors ----------- -select pgv_insert('test', 'x', row (1::int, 2::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (2::int, 3::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (3::int, 4::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (10::int, 20::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (20::int, 30::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (30::int, 40::int), true); - pgv_insert ------------- - -(1 row) - -begin; - declare r1_cur cursor for select pgv_select('test', 'x'); - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_insert('test', 'z', row (11::int, 22::int), false); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_insert('test', 'z', row (22::int, 33::int), false); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_insert('test', 'z', row (33::int, 44::int), false); -ERROR: current transaction is aborted, commands ignored until end of transaction block - declare r11_cur cursor for select pgv_select('test', 'x'); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- (1,2),(2,3): - fetch 2 in r11_cur; -ERROR: current transaction is aborted, commands ignored until end of transaction block - declare r2_cur cursor for select pgv_select('test', 'y'); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- correct error: unrecognized variable "y" - fetch 2 in r2_cur; -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback; - rollback; -WARNING: there is no transaction in progress - rollback; -WARNING: there is no transaction in progress - rollback; -WARNING: there is no transaction in progress - rollback; -WARNING: there is no transaction in progress - declare r2_cur cursor for select pgv_select('test', 'y'); -ERROR: DECLARE CURSOR can only be used in transaction blocks - declare r3_cur cursor for select pgv_select('test', 'z'); -ERROR: DECLARE CURSOR can only be used in transaction blocks --- (1,2),(2,3): - fetch 2 in r1_cur; -ERROR: cursor "r1_cur" does not exist --- (10,20),(20,30): - fetch 2 in r2_cur; -ERROR: cursor "r2_cur" does not exist --- (11,22),(22,33): - fetch 2 in r3_cur; -ERROR: cursor "r3_cur" does not exist -rollback; -WARNING: there is no transaction in progress -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------- --- Savepoint: rollback in main transaction ------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 101, true); - pgv_set ---------- - -(1 row) - --- 101: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 101 -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 102, true); - pgv_set ---------- - -(1 row) - --- 102: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 102 -(1 row) - - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_set('vars', 'trans_int', 103, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 103: - select pgv_get('vars', 'trans_int', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; --- 102: - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks -commit; -WARNING: there is no transaction in progress --- 101: -select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------- --- Savepoint: rollback in autonomous transaction ------------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 1, true); - pgv_set ---------- - -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 100, true); - pgv_set ---------- - -(1 row) - - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_set('vars1', 'int1', 2); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 4 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: no such savepoint --- 3 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- vars1:int1, vars1:trans_int1: - select * from pgv_list() order by package, name; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int2', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int3', 5, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'int2', 3); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback; - commit; -WARNING: there is no transaction in progress - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks --- 1 - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: unrecognized package "vars1" --- 3 - select pgv_get('vars1', 'int2', null::int); -ERROR: unrecognized package "vars1" --- vars:trans_int, vars1:int1, vars1:int2: - select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ -(0 rows) - -commit; -WARNING: there is no transaction in progress -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------------------- --- Sample with (subxact inside ATX) == (subxact outside ATX) ------------------------------------------------------------- -select pgv_set('vars1', 'int1', 0); - pgv_set ---------- - -(1 row) - -select pgv_set('vars1', 'trans_int1', 0, true); - pgv_set ---------- - -(1 row) - -begin; - begin autonomous; -ERROR: syntax error at or near "autonomous" -LINE 1: begin autonomous; - ^ - select pgv_set('vars1', 'int1', 1); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 2, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: no such savepoint --- 2 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; -rollback; -WARNING: there is no transaction in progress --- vars1:int1, vars1:trans_int1 -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------------+------------------ - vars1 | int1 | f - vars1 | trans_int1 | t -(2 rows) - --- 1 -select pgv_get('vars1', 'int1', null::int); - pgv_get ---------- - 0 -(1 row) - --- 0 -select pgv_get('vars1', 'trans_int1', null::int); - pgv_get ---------- - 0 -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - diff --git a/expected/pg_variables_atx_2.out b/expected/pg_variables_atx_2.out deleted file mode 100644 index c6f44a7..0000000 --- a/expected/pg_variables_atx_2.out +++ /dev/null @@ -1,497 +0,0 @@ -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------- --- Non-transactional variables ------------------------------- -select pgv_set('vars', 'int1', 101); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102); - pgv_set ---------- - -(1 row) - - begin autonomous; - select pgv_set('vars', 'int3', 103); - pgv_set ---------- - -(1 row) - --- 101, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 101 | 102 | 103 -(1 row) - - select pgv_set('vars', 'int1', 1001); - pgv_set ---------- - -(1 row) - - begin autonomous; --- 1001, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 102 | 103 -(1 row) - - select pgv_set('vars', 'int2', 1002); - pgv_set ---------- - -(1 row) - - commit; - commit; --- 1001, 1002, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 1002 | 103 -(1 row) - - select pgv_set('vars', 'int3', 1003); - pgv_set ---------- - -(1 row) - -rollback; --- 1001, 1002, 1003: -select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 1002 | 1003 -(1 row) - --- vars:int1, vars:int2, vars:int3: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | f - vars | int2 | f - vars | int3 | f -(3 rows) - -select pgv_free(); - pgv_free ----------- - -(1 row) - --------------------------- --- Transactional variables --------------------------- -select pgv_set('vars', 'int1', 101, true); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102, true); - pgv_set ---------- - -(1 row) - - begin autonomous; - select pgv_set('vars', 'int3', 103, true); - pgv_set ---------- - -(1 row) - --- 103: - select pgv_get('vars', 'int3', null::int); - pgv_get ---------- - 103 -(1 row) - - begin autonomous; - select pgv_set('vars', 'int2', 1002, true); - pgv_set ---------- - -(1 row) - --- 1002: - select pgv_get('vars', 'int2', null::int); - pgv_get ---------- - 1002 -(1 row) - - commit; --- 103: - select pgv_get('vars', 'int3', null::int); - pgv_get ---------- - 103 -(1 row) - - commit; - select pgv_set('vars', 'int1', 1001, true); - pgv_set ---------- - -(1 row) - --- 1001: - select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 1001 -(1 row) - --- 102: - select pgv_get('vars', 'int2', null::int); - pgv_get ---------- - 102 -(1 row) - -rollback; --- 101: -select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 101 -(1 row) - --- vars:int1: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | t -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - ----------- --- Cursors ----------- -select pgv_insert('test', 'x', row (1::int, 2::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (2::int, 3::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (3::int, 4::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (10::int, 20::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (20::int, 30::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (30::int, 40::int), true); - pgv_insert ------------- - -(1 row) - -begin; - declare r1_cur cursor for select pgv_select('test', 'x'); - begin autonomous; - begin autonomous; - begin autonomous; - begin autonomous; - begin autonomous; - select pgv_insert('test', 'z', row (11::int, 22::int), false); - pgv_insert ------------- - -(1 row) - - select pgv_insert('test', 'z', row (22::int, 33::int), false); - pgv_insert ------------- - -(1 row) - - select pgv_insert('test', 'z', row (33::int, 44::int), false); - pgv_insert ------------- - -(1 row) - - declare r11_cur cursor for select pgv_select('test', 'x'); --- (1,2),(2,3): - fetch 2 in r11_cur; - pgv_select ------------- - (1,2) - (2,3) -(2 rows) - - declare r2_cur cursor for select pgv_select('test', 'y'); --- correct error: unrecognized variable "y" - fetch 2 in r2_cur; -ERROR: unrecognized variable "y" - rollback; - rollback; - rollback; - rollback; - rollback; - declare r2_cur cursor for select pgv_select('test', 'y'); - declare r3_cur cursor for select pgv_select('test', 'z'); --- (1,2),(2,3): - fetch 2 in r1_cur; - pgv_select ------------- - (1,2) - (2,3) -(2 rows) - --- (10,20),(20,30): - fetch 2 in r2_cur; - pgv_select ------------- - (10,20) - (20,30) -(2 rows) - --- (11,22),(22,33): - fetch 2 in r3_cur; - pgv_select ------------- - (11,22) - (22,33) -(2 rows) - -rollback; -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------- --- Savepoint: rollback in main transaction ------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 101, true); - pgv_set ---------- - -(1 row) - --- 101: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 101 -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 102, true); - pgv_set ---------- - -(1 row) - --- 102: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 102 -(1 row) - - begin autonomous; -ERROR: in_memory extension is incompatible with autonomous transactions - select pgv_set('vars', 'trans_int', 103, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 103: - select pgv_get('vars', 'trans_int', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; --- 102: - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks -commit; -WARNING: there is no transaction in progress --- 101: -select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------- --- Savepoint: rollback in autonomous transaction ------------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 1, true); - pgv_set ---------- - -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 100, true); - pgv_set ---------- - -(1 row) - - begin autonomous; -ERROR: in_memory extension is incompatible with autonomous transactions - begin autonomous; -ERROR: in_memory extension is incompatible with autonomous transactions - select pgv_set('vars1', 'int1', 2); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 4 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: savepoint "sp2" does not exist --- 3 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- vars1:int1, vars1:trans_int1: - select * from pgv_list() order by package, name; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int2', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int3', 5, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'int2', 3); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback; - commit; -WARNING: there is no transaction in progress - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks --- 1 - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: unrecognized package "vars1" --- 3 - select pgv_get('vars1', 'int2', null::int); -ERROR: unrecognized package "vars1" --- vars:trans_int, vars1:int1, vars1:int2: - select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ -(0 rows) - -commit; -WARNING: there is no transaction in progress -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------------------- --- Sample with (subxact inside ATX) == (subxact outside ATX) ------------------------------------------------------------- -select pgv_set('vars1', 'int1', 0); - pgv_set ---------- - -(1 row) - -select pgv_set('vars1', 'trans_int1', 0, true); - pgv_set ---------- - -(1 row) - -begin; - begin autonomous; -ERROR: in_memory extension is incompatible with autonomous transactions - select pgv_set('vars1', 'int1', 1); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 2, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: savepoint "sp2" does not exist --- 2 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; -rollback; -WARNING: there is no transaction in progress --- vars1:int1, vars1:trans_int1 -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------------+------------------ - vars1 | int1 | f - vars1 | trans_int1 | t -(2 rows) - --- 1 -select pgv_get('vars1', 'int1', null::int); - pgv_get ---------- - 0 -(1 row) - --- 0 -select pgv_get('vars1', 'trans_int1', null::int); - pgv_get ---------- - 0 -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - diff --git a/expected/pg_variables_atx_3.out b/expected/pg_variables_atx_3.out deleted file mode 100644 index ad1ae89..0000000 --- a/expected/pg_variables_atx_3.out +++ /dev/null @@ -1,497 +0,0 @@ -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------- --- Non-transactional variables ------------------------------- -select pgv_set('vars', 'int1', 101); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102); - pgv_set ---------- - -(1 row) - - begin autonomous; - select pgv_set('vars', 'int3', 103); - pgv_set ---------- - -(1 row) - --- 101, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 101 | 102 | 103 -(1 row) - - select pgv_set('vars', 'int1', 1001); - pgv_set ---------- - -(1 row) - - begin autonomous; --- 1001, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 102 | 103 -(1 row) - - select pgv_set('vars', 'int2', 1002); - pgv_set ---------- - -(1 row) - - commit; - commit; --- 1001, 1002, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 1002 | 103 -(1 row) - - select pgv_set('vars', 'int3', 1003); - pgv_set ---------- - -(1 row) - -rollback; --- 1001, 1002, 1003: -select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 1002 | 1003 -(1 row) - --- vars:int1, vars:int2, vars:int3: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | f - vars | int2 | f - vars | int3 | f -(3 rows) - -select pgv_free(); - pgv_free ----------- - -(1 row) - --------------------------- --- Transactional variables --------------------------- -select pgv_set('vars', 'int1', 101, true); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102, true); - pgv_set ---------- - -(1 row) - - begin autonomous; - select pgv_set('vars', 'int3', 103, true); - pgv_set ---------- - -(1 row) - --- 103: - select pgv_get('vars', 'int3', null::int); - pgv_get ---------- - 103 -(1 row) - - begin autonomous; - select pgv_set('vars', 'int2', 1002, true); - pgv_set ---------- - -(1 row) - --- 1002: - select pgv_get('vars', 'int2', null::int); - pgv_get ---------- - 1002 -(1 row) - - commit; --- 103: - select pgv_get('vars', 'int3', null::int); - pgv_get ---------- - 103 -(1 row) - - commit; - select pgv_set('vars', 'int1', 1001, true); - pgv_set ---------- - -(1 row) - --- 1001: - select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 1001 -(1 row) - --- 102: - select pgv_get('vars', 'int2', null::int); - pgv_get ---------- - 102 -(1 row) - -rollback; --- 101: -select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 101 -(1 row) - --- vars:int1: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | t -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - ----------- --- Cursors ----------- -select pgv_insert('test', 'x', row (1::int, 2::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (2::int, 3::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (3::int, 4::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (10::int, 20::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (20::int, 30::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (30::int, 40::int), true); - pgv_insert ------------- - -(1 row) - -begin; - declare r1_cur cursor for select pgv_select('test', 'x'); - begin autonomous; - begin autonomous; - begin autonomous; - begin autonomous; - begin autonomous; - select pgv_insert('test', 'z', row (11::int, 22::int), false); - pgv_insert ------------- - -(1 row) - - select pgv_insert('test', 'z', row (22::int, 33::int), false); - pgv_insert ------------- - -(1 row) - - select pgv_insert('test', 'z', row (33::int, 44::int), false); - pgv_insert ------------- - -(1 row) - - declare r11_cur cursor for select pgv_select('test', 'x'); --- (1,2),(2,3): - fetch 2 in r11_cur; - pgv_select ------------- - (1,2) - (2,3) -(2 rows) - - declare r2_cur cursor for select pgv_select('test', 'y'); --- correct error: unrecognized variable "y" - fetch 2 in r2_cur; -ERROR: unrecognized variable "y" - rollback; - rollback; - rollback; - rollback; - rollback; - declare r2_cur cursor for select pgv_select('test', 'y'); - declare r3_cur cursor for select pgv_select('test', 'z'); --- (1,2),(2,3): - fetch 2 in r1_cur; - pgv_select ------------- - (1,2) - (2,3) -(2 rows) - --- (10,20),(20,30): - fetch 2 in r2_cur; - pgv_select ------------- - (10,20) - (20,30) -(2 rows) - --- (11,22),(22,33): - fetch 2 in r3_cur; - pgv_select ------------- - (11,22) - (22,33) -(2 rows) - -rollback; -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------- --- Savepoint: rollback in main transaction ------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 101, true); - pgv_set ---------- - -(1 row) - --- 101: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 101 -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 102, true); - pgv_set ---------- - -(1 row) - --- 102: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 102 -(1 row) - - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - select pgv_set('vars', 'trans_int', 103, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 103: - select pgv_get('vars', 'trans_int', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; --- 102: - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks -commit; -WARNING: there is no transaction in progress --- 101: -select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------- --- Savepoint: rollback in autonomous transaction ------------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 1, true); - pgv_set ---------- - -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 100, true); - pgv_set ---------- - -(1 row) - - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - select pgv_set('vars1', 'int1', 2); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 4 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: no such savepoint --- 3 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- vars1:int1, vars1:trans_int1: - select * from pgv_list() order by package, name; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int2', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int3', 5, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'int2', 3); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback; - commit; -WARNING: there is no transaction in progress - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks --- 1 - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: unrecognized package "vars1" --- 3 - select pgv_get('vars1', 'int2', null::int); -ERROR: unrecognized package "vars1" --- vars:trans_int, vars1:int1, vars1:int2: - select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ -(0 rows) - -commit; -WARNING: there is no transaction in progress -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------------------- --- Sample with (subxact inside ATX) == (subxact outside ATX) ------------------------------------------------------------- -select pgv_set('vars1', 'int1', 0); - pgv_set ---------- - -(1 row) - -select pgv_set('vars1', 'trans_int1', 0, true); - pgv_set ---------- - -(1 row) - -begin; - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - select pgv_set('vars1', 'int1', 1); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 2, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: no such savepoint --- 2 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; -rollback; -WARNING: there is no transaction in progress --- vars1:int1, vars1:trans_int1 -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------------+------------------ - vars1 | int1 | f - vars1 | trans_int1 | t -(2 rows) - --- 1 -select pgv_get('vars1', 'int1', null::int); - pgv_get ---------- - 0 -(1 row) - --- 0 -select pgv_get('vars1', 'trans_int1', null::int); - pgv_get ---------- - 0 -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - diff --git a/expected/pg_variables_atx_4.out b/expected/pg_variables_atx_4.out deleted file mode 100644 index 914725a..0000000 --- a/expected/pg_variables_atx_4.out +++ /dev/null @@ -1,497 +0,0 @@ -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------- --- Non-transactional variables ------------------------------- -select pgv_set('vars', 'int1', 101); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102); - pgv_set ---------- - -(1 row) - - begin autonomous; - select pgv_set('vars', 'int3', 103); - pgv_set ---------- - -(1 row) - --- 101, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 101 | 102 | 103 -(1 row) - - select pgv_set('vars', 'int1', 1001); - pgv_set ---------- - -(1 row) - - begin autonomous; --- 1001, 102, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 102 | 103 -(1 row) - - select pgv_set('vars', 'int2', 1002); - pgv_set ---------- - -(1 row) - - commit; - commit; --- 1001, 1002, 103: - select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 1002 | 103 -(1 row) - - select pgv_set('vars', 'int3', 1003); - pgv_set ---------- - -(1 row) - -rollback; --- 1001, 1002, 1003: -select pgv_get('vars', 'int1', null::int), pgv_get('vars', 'int2', null::int), pgv_get('vars', 'int3', null::int); - pgv_get | pgv_get | pgv_get ----------+---------+--------- - 1001 | 1002 | 1003 -(1 row) - --- vars:int1, vars:int2, vars:int3: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | f - vars | int2 | f - vars | int3 | f -(3 rows) - -select pgv_free(); - pgv_free ----------- - -(1 row) - --------------------------- --- Transactional variables --------------------------- -select pgv_set('vars', 'int1', 101, true); - pgv_set ---------- - -(1 row) - -begin; - select pgv_set('vars', 'int2', 102, true); - pgv_set ---------- - -(1 row) - - begin autonomous; - select pgv_set('vars', 'int3', 103, true); - pgv_set ---------- - -(1 row) - --- 103: - select pgv_get('vars', 'int3', null::int); - pgv_get ---------- - 103 -(1 row) - - begin autonomous; - select pgv_set('vars', 'int2', 1002, true); - pgv_set ---------- - -(1 row) - --- 1002: - select pgv_get('vars', 'int2', null::int); - pgv_get ---------- - 1002 -(1 row) - - commit; --- 103: - select pgv_get('vars', 'int3', null::int); - pgv_get ---------- - 103 -(1 row) - - commit; - select pgv_set('vars', 'int1', 1001, true); - pgv_set ---------- - -(1 row) - --- 1001: - select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 1001 -(1 row) - --- 102: - select pgv_get('vars', 'int2', null::int); - pgv_get ---------- - 102 -(1 row) - -rollback; --- 101: -select pgv_get('vars', 'int1', null::int); - pgv_get ---------- - 101 -(1 row) - --- vars:int1: -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ - vars | int1 | t -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - ----------- --- Cursors ----------- -select pgv_insert('test', 'x', row (1::int, 2::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (2::int, 3::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'x', row (3::int, 4::int), false); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (10::int, 20::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (20::int, 30::int), true); - pgv_insert ------------- - -(1 row) - -select pgv_insert('test', 'y', row (30::int, 40::int), true); - pgv_insert ------------- - -(1 row) - -begin; - declare r1_cur cursor for select pgv_select('test', 'x'); - begin autonomous; - begin autonomous; - begin autonomous; - begin autonomous; - begin autonomous; - select pgv_insert('test', 'z', row (11::int, 22::int), false); - pgv_insert ------------- - -(1 row) - - select pgv_insert('test', 'z', row (22::int, 33::int), false); - pgv_insert ------------- - -(1 row) - - select pgv_insert('test', 'z', row (33::int, 44::int), false); - pgv_insert ------------- - -(1 row) - - declare r11_cur cursor for select pgv_select('test', 'x'); --- (1,2),(2,3): - fetch 2 in r11_cur; - pgv_select ------------- - (1,2) - (2,3) -(2 rows) - - declare r2_cur cursor for select pgv_select('test', 'y'); --- correct error: unrecognized variable "y" - fetch 2 in r2_cur; -ERROR: unrecognized variable "y" - rollback; - rollback; - rollback; - rollback; - rollback; - declare r2_cur cursor for select pgv_select('test', 'y'); - declare r3_cur cursor for select pgv_select('test', 'z'); --- (1,2),(2,3): - fetch 2 in r1_cur; - pgv_select ------------- - (1,2) - (2,3) -(2 rows) - --- (10,20),(20,30): - fetch 2 in r2_cur; - pgv_select ------------- - (10,20) - (20,30) -(2 rows) - --- (11,22),(22,33): - fetch 2 in r3_cur; - pgv_select ------------- - (11,22) - (22,33) -(2 rows) - -rollback; -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------- --- Savepoint: rollback in main transaction ------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 101, true); - pgv_set ---------- - -(1 row) - --- 101: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 101 -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 102, true); - pgv_set ---------- - -(1 row) - --- 102: - select pgv_get('vars', 'trans_int', null::int); - pgv_get ---------- - 102 -(1 row) - - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - select pgv_set('vars', 'trans_int', 103, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 103: - select pgv_get('vars', 'trans_int', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; --- 102: - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks -commit; -WARNING: there is no transaction in progress --- 101: -select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------- --- Savepoint: rollback in autonomous transaction ------------------------------------------------- -begin; - select pgv_set('vars', 'trans_int', 1, true); - pgv_set ---------- - -(1 row) - - savepoint sp1; - select pgv_set('vars', 'trans_int', 100, true); - pgv_set ---------- - -(1 row) - - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - select pgv_set('vars1', 'int1', 2); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- 4 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: savepoint "sp2" does not exist --- 3 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block --- vars1:int1, vars1:trans_int1: - select * from pgv_list() order by package, name; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int2', 4, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int3', 5, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'int2', 3); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback; - commit; -WARNING: there is no transaction in progress - rollback to sp1; -ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks --- 1 - select pgv_get('vars', 'trans_int', null::int); -ERROR: unrecognized package "vars" --- 2 - select pgv_get('vars1', 'int1', null::int); -ERROR: unrecognized package "vars1" --- 3 - select pgv_get('vars1', 'int2', null::int); -ERROR: unrecognized package "vars1" --- vars:trans_int, vars1:int1, vars1:int2: - select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------+------------------ -(0 rows) - -commit; -WARNING: there is no transaction in progress -select pgv_free(); - pgv_free ----------- - -(1 row) - ------------------------------------------------------------- --- Sample with (subxact inside ATX) == (subxact outside ATX) ------------------------------------------------------------- -select pgv_set('vars1', 'int1', 0); - pgv_set ---------- - -(1 row) - -select pgv_set('vars1', 'trans_int1', 0, true); - pgv_set ---------- - -(1 row) - -begin; - begin autonomous; -ERROR: Extension in_memory is not compatible with autonomous transactions and connection pooling - select pgv_set('vars1', 'int1', 1); -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 2, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - savepoint sp2; -ERROR: current transaction is aborted, commands ignored until end of transaction block - select pgv_set('vars1', 'trans_int1', 3, true); -ERROR: current transaction is aborted, commands ignored until end of transaction block - rollback to sp2; -ERROR: savepoint "sp2" does not exist --- 2 - select pgv_get('vars1', 'trans_int1', null::int); -ERROR: current transaction is aborted, commands ignored until end of transaction block - commit; -rollback; -WARNING: there is no transaction in progress --- vars1:int1, vars1:trans_int1 -select * from pgv_list() order by package, name; - package | name | is_transactional ----------+------------+------------------ - vars1 | int1 | f - vars1 | trans_int1 | t -(2 rows) - --- 1 -select pgv_get('vars1', 'int1', null::int); - pgv_get ---------- - 0 -(1 row) - --- 0 -select pgv_get('vars1', 'trans_int1', null::int); - pgv_get ---------- - 0 -(1 row) - -select pgv_free(); - pgv_free ----------- - -(1 row) - diff --git a/expected/pg_variables_atx_pkg.out b/expected/pg_variables_atx_pkg.out new file mode 100644 index 0000000..e9c8412 --- /dev/null +++ b/expected/pg_variables_atx_pkg.out @@ -0,0 +1,473 @@ +-- +-- PGPRO-7614: function pgv_free() inside autonomous transaction +-- +SELECT pgv_free(); + pgv_free +---------- + +(1 row) + +-- +-- +-- Functions pgv_free() + pgv_get() inside autonomous transaction; package +-- with regular variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- regular variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- regular variable; autonomous transaction with rollback. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + ROLLBACK; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- transactional variable; autonomous transaction with rollback. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1, true); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + ROLLBACK; + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- transactional variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1, true); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" +ROLLBACK; +-- +-- +-- Function pgv_free() inside recursive autonomous transactions. +-- +BEGIN; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" + COMMIT; +ROLLBACK; +-- +-- +-- Function pgv_free() inside recursive autonomous transactions; +-- recreating the package after deletion with using regular +-- variable. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + BEGIN AUTONOMOUS; + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" + COMMIT; + SELECT pgv_set('vars', 'int1', 2); + pgv_set +--------- + +(1 row) + + COMMIT; + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 2 +(1 row) + +ROLLBACK; +-- +-- +-- Function pgv_free() inside recursive autonomous transactions; +-- recreating the package after deletion with using transactional +-- variable. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; + BEGIN AUTONOMOUS; + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" + COMMIT; + SELECT pgv_set('vars', 'int1', 2, true); + pgv_set +--------- + +(1 row) + + SELECT pgv_list(); + pgv_list +--------------- + (vars,int1,t) +(1 row) + + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: unrecognized package "vars" +ROLLBACK; +-- +-- +-- Test for case: do not free hash_seq_search scans of parent transaction +-- at end of the autonomous transaction. +-- +BEGIN; + SELECT pgv_insert('test', 'x', row (1::int, 2::int), false); + pgv_insert +------------ + +(1 row) + + SELECT pgv_insert('test', 'x', row (3::int, 4::int), false); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); +-- (1,2) + FETCH 1 IN r1_cur; + pgv_select +------------ + (1,2) +(1 row) + + BEGIN AUTONOMOUS; + ROLLBACK; +-- (3,4) + FETCH 1 IN r1_cur; + pgv_select +------------ + (3,4) +(1 row) + + SELECT pgv_remove('test', 'x'); + pgv_remove +------------ + +(1 row) + +-- ERROR: unrecognized package "test" + FETCH 1 IN r1_cur; +ERROR: unrecognized package "test" +ROLLBACK; +-- +-- +-- Test for case: pgv_free() should free hash_seq_search scans of all +-- (current ATX + parent) transactions. +-- +BEGIN; + SELECT pgv_insert('test', 'x', row (1::int, 2::int), false); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); +-- (1,2) + FETCH 1 IN r1_cur; + pgv_select +------------ + (1,2) +(1 row) + + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + ROLLBACK; +-- ERROR: unrecognized package "test" + FETCH 1 IN r1_cur; +ERROR: unrecognized package "test" +ROLLBACK; +-- +-- +-- Test for case: pgv_set() created a regular variable; rollback +-- removes package state and creates a new state to make package valid. +-- Commit of next autonomous transaction should not replace this new +-- state (this is not allowed for autonomous transaction). +-- +BEGIN; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + ROLLBACK; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 2); + pgv_set +--------- + +(1 row) + + COMMIT; +ROLLBACK; +SELECT pgv_remove('vars', 'int1'); + pgv_remove +------------ + +(1 row) + +-- +-- +-- Test for case: pgv_set() created a regular variable and package with +-- (atxlevel=1, level=1). COMMIT changes this level to (atxlevel=1, level=0). +-- In the next autonomous transaction (atxlevel=1, level=1) we erroneously +-- detect that the package changed in upper transaction and remove the +-- package state (this is not allowed for autonomous transaction). +-- +BEGIN; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 2); + pgv_set +--------- + +(1 row) + + COMMIT; + BEGIN AUTONOMOUS; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + SELECT pgv_set('vars', 'int1', 2, true); + pgv_set +--------- + +(1 row) + + COMMIT; +ROLLBACK; +-- +-- +-- Test for case: pgv_set() created a regular variable and package with +-- (atxlevel=1, level=1). ROLLBACK changes this level to (atxlevel=0, level=0). +-- But ROLLBACK shouldn't change atxlevel in case rollback of sub-transaction. +-- +BEGIN; + BEGIN AUTONOMOUS; + SAVEPOINT sp1; + SELECT pgv_set('vars1', 'int1', 0); + pgv_set +--------- + +(1 row) + + ROLLBACK TO sp1; + COMMIT; +ROLLBACK; +SELECT pgv_remove('vars1', 'int1'); + pgv_remove +------------ + +(1 row) + +SELECT pgv_free(); + pgv_free +---------- + +(1 row) + +-- +-- +-- PGPRO-7856 +-- Test for case: we don't remove the package object without any variables at +-- the end of autonomous transaction but need to move the state of this object +-- to upper level. +-- +BEGIN; + BEGIN AUTONOMOUS; + SAVEPOINT sp1; + SELECT pgv_set('vars2', 'any1', 'variable exists'::text, true); + pgv_set +--------- + +(1 row) + + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + RELEASE sp1; + ROLLBACK; + BEGIN AUTONOMOUS; + SAVEPOINT sp2; + SAVEPOINT sp3; + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +ROLLBACK; diff --git a/expected/pg_variables_atx_pkg_1.out b/expected/pg_variables_atx_pkg_1.out new file mode 100644 index 0000000..8e36d0a --- /dev/null +++ b/expected/pg_variables_atx_pkg_1.out @@ -0,0 +1,515 @@ +-- +-- PGPRO-7614: function pgv_free() inside autonomous transaction +-- +SELECT pgv_free(); + pgv_free +---------- + +(1 row) + +-- +-- +-- Functions pgv_free() + pgv_get() inside autonomous transaction; package +-- with regular variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_get('vars', 'int1', null::int); +ERROR: current transaction is aborted, commands ignored until end of transaction block + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- regular variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- regular variable; autonomous transaction with rollback. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + ROLLBACK; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- transactional variable; autonomous transaction with rollback. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1, true); +ERROR: variable "int1" already created as NOT TRANSACTIONAL + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + ROLLBACK; + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- transactional variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1, true); +ERROR: variable "int1" already created as NOT TRANSACTIONAL + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside recursive autonomous transactions. +-- +BEGIN; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_set('vars', 'int1', 1); +ERROR: current transaction is aborted, commands ignored until end of transaction block + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + COMMIT; +WARNING: there is no transaction in progress +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + COMMIT; +WARNING: there is no transaction in progress +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside recursive autonomous transactions; +-- recreating the package after deletion with using regular +-- variable. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_get('vars', 'int1', null::int); +ERROR: current transaction is aborted, commands ignored until end of transaction block + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + COMMIT; +WARNING: there is no transaction in progress + SELECT pgv_set('vars', 'int1', 2); + pgv_set +--------- + +(1 row) + + COMMIT; +WARNING: there is no transaction in progress + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 2 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Function pgv_free() inside recursive autonomous transactions; +-- recreating the package after deletion with using transactional +-- variable. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + pgv_set +--------- + +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_get('vars', 'int1', null::int); +ERROR: current transaction is aborted, commands ignored until end of transaction block + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + + COMMIT; +WARNING: there is no transaction in progress + SELECT pgv_set('vars', 'int1', 2, true); +ERROR: variable "int1" already created as NOT TRANSACTIONAL + SELECT pgv_list(); + pgv_list +--------------- + (vars,int1,f) +(1 row) + + COMMIT; +WARNING: there is no transaction in progress +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + pgv_get +--------- + 1 +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Test for case: do not free hash_seq_search scans of parent transaction +-- at end of the autonomous transaction. +-- +BEGIN; + SELECT pgv_insert('test', 'x', row (1::int, 2::int), false); + pgv_insert +------------ + +(1 row) + + SELECT pgv_insert('test', 'x', row (3::int, 4::int), false); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); +-- (1,2) + FETCH 1 IN r1_cur; + pgv_select +------------ + (1,2) +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + ROLLBACK; +-- (3,4) + FETCH 1 IN r1_cur; +ERROR: cursor "r1_cur" does not exist + SELECT pgv_remove('test', 'x'); + pgv_remove +------------ + +(1 row) + +-- ERROR: unrecognized package "test" + FETCH 1 IN r1_cur; +ERROR: cursor "r1_cur" does not exist +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Test for case: pgv_free() should free hash_seq_search scans of all +-- (current ATX + parent) transactions. +-- +BEGIN; + SELECT pgv_insert('test', 'x', row (1::int, 2::int), false); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); +-- (1,2) + FETCH 1 IN r1_cur; + pgv_select +------------ + (1,2) +(1 row) + + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + ROLLBACK; +-- ERROR: unrecognized package "test" + FETCH 1 IN r1_cur; +ERROR: cursor "r1_cur" does not exist +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Test for case: pgv_set() created a regular variable; rollback +-- removes package state and creates a new state to make package valid. +-- Commit of next autonomous transaction should not replace this new +-- state (this is not allowed for autonomous transaction). +-- +BEGIN; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_set('vars', 'int1', 1); +ERROR: current transaction is aborted, commands ignored until end of transaction block + ROLLBACK; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_set('vars', 'int1', 2); + pgv_set +--------- + +(1 row) + + COMMIT; +WARNING: there is no transaction in progress +ROLLBACK; +WARNING: there is no transaction in progress +SELECT pgv_remove('vars', 'int1'); + pgv_remove +------------ + +(1 row) + +-- +-- +-- Test for case: pgv_set() created a regular variable and package with +-- (atxlevel=1, level=1). COMMIT changes this level to (atxlevel=1, level=0). +-- In the next autonomous transaction (atxlevel=1, level=1) we erroneously +-- detect that the package changed in upper transaction and remove the +-- package state (this is not allowed for autonomous transaction). +-- +BEGIN; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_set('vars', 'int1', 2); +ERROR: current transaction is aborted, commands ignored until end of transaction block + COMMIT; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + SELECT pgv_set('vars', 'int1', 2, true); + pgv_set +--------- + +(1 row) + + COMMIT; +WARNING: there is no transaction in progress +ROLLBACK; +WARNING: there is no transaction in progress +-- +-- +-- Test for case: pgv_set() created a regular variable and package with +-- (atxlevel=1, level=1). ROLLBACK changes this level to (atxlevel=0, level=0). +-- But ROLLBACK shouldn't change atxlevel in case rollback of sub-transaction. +-- +BEGIN; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SAVEPOINT sp1; +ERROR: current transaction is aborted, commands ignored until end of transaction block + SELECT pgv_set('vars1', 'int1', 0); +ERROR: current transaction is aborted, commands ignored until end of transaction block + ROLLBACK TO sp1; +ERROR: savepoint "sp1" does not exist + COMMIT; +ROLLBACK; +WARNING: there is no transaction in progress +SELECT pgv_remove('vars1', 'int1'); +ERROR: unrecognized package "vars1" +SELECT pgv_free(); + pgv_free +---------- + +(1 row) + +-- +-- +-- PGPRO-7856 +-- Test for case: we don't remove the package object without any variables at +-- the end of autonomous transaction but need to move the state of this object +-- to upper level. +-- +BEGIN; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SAVEPOINT sp1; +ERROR: current transaction is aborted, commands ignored until end of transaction block + SELECT pgv_set('vars2', 'any1', 'variable exists'::text, true); +ERROR: current transaction is aborted, commands ignored until end of transaction block + SELECT pgv_free(); +ERROR: current transaction is aborted, commands ignored until end of transaction block + RELEASE sp1; +ERROR: current transaction is aborted, commands ignored until end of transaction block + ROLLBACK; + BEGIN AUTONOMOUS; +ERROR: syntax error at or near "AUTONOMOUS" +LINE 1: BEGIN AUTONOMOUS; + ^ + SAVEPOINT sp2; +ERROR: SAVEPOINT can only be used in transaction blocks + SAVEPOINT sp3; +ERROR: SAVEPOINT can only be used in transaction blocks + SELECT pgv_free(); + pgv_free +---------- + +(1 row) + + COMMIT; +WARNING: there is no transaction in progress +ROLLBACK; +WARNING: there is no transaction in progress diff --git a/expected/pg_variables_trans.out b/expected/pg_variables_trans.out index 09f56c8..4370646 100644 --- a/expected/pg_variables_trans.out +++ b/expected/pg_variables_trans.out @@ -3834,3 +3834,51 @@ SELECT pgv_free(); -- SELECT pgv_insert('test', 'x5', ROW ((2::int, 1::int)), TRUE); ERROR: could not identify a hash function for type record +-- +-- Test case for PGPRO-7614: crash by using cursor after rollback of cursor +-- creation. +-- +BEGIN; + SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), true); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); + SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_select +------------ + (1,2) +(1 row) + + ROLLBACK TO SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_select +------------ +(0 rows) + +ROLLBACK; +BEGIN; + SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), TRUE); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_stats(); + SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_stats +-------------- + (test,32768) +(1 row) + + ROLLBACK TO SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_stats +----------- +(0 rows) + +ROLLBACK; diff --git a/expected/pg_variables_trans_0.out b/expected/pg_variables_trans_0.out index 7c29138..8a3c54c 100644 --- a/expected/pg_variables_trans_0.out +++ b/expected/pg_variables_trans_0.out @@ -3838,3 +3838,51 @@ SELECT pgv_insert('test', 'x5', ROW ((2::int, 1::int)), TRUE); (1 row) +-- +-- Test case for PGPRO-7614: crash by using cursor after rollback of cursor +-- creation. +-- +BEGIN; + SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), true); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); + SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_select +------------ + (1,2) +(1 row) + + ROLLBACK TO SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_select +------------ +(0 rows) + +ROLLBACK; +BEGIN; + SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), TRUE); + pgv_insert +------------ + +(1 row) + + DECLARE r1_cur CURSOR FOR SELECT pgv_stats(); + SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_stats +-------------- + (test,32768) +(1 row) + + ROLLBACK TO SAVEPOINT sp1; + FETCH 1 in r1_cur; + pgv_stats +----------- +(0 rows) + +ROLLBACK; diff --git a/pg_variables.c b/pg_variables.c index 633b029..c8ee939 100644 --- a/pg_variables.c +++ b/pg_variables.c @@ -47,7 +47,9 @@ PG_FUNCTION_INFO_V1(get_packages_and_variables); PG_FUNCTION_INFO_V1(get_packages_stats); extern void _PG_init(void); +#if PG_VERSION_NUM < 150000 extern void _PG_fini(void); +#endif static void ensurePackagesHashExists(void); static void getKeyFromName(text *name, char *key); @@ -62,8 +64,8 @@ static void resetVariablesCache(void); /* Functions to work with transactional objects */ static void createSavepoint(TransObject *object, TransObjectType type); -static void releaseSavepoint(TransObject *object, TransObjectType type); -static void rollbackSavepoint(TransObject *object, TransObjectType type); +static void releaseSavepoint(TransObject *object, TransObjectType type, bool sub); +static void rollbackSavepoint(TransObject *object, TransObjectType type, bool sub); static void copyValue(VarState *src, VarState *dest, Variable *destVar); static void freeValue(VarState *varstate, bool is_record); @@ -164,12 +166,14 @@ typedef struct tagVariableStatEntry Variable *variable; Package *package; Levels levels; + void **user_fctx; /* pointer to funcctx->user_fctx */ } VariableStatEntry; typedef struct tagPackageStatEntry { HASH_SEQ_STATUS *status; Levels levels; + void **user_fctx; /* pointer to funcctx->user_fctx */ } PackageStatEntry; #ifdef PGPRO_EE @@ -266,6 +270,25 @@ PackageStatEntry_status_ptr(void *entry) return ((PackageStatEntry *) entry)->status; } +/* + * VariableStatEntry and PackageStatEntry functions for clear function context. + */ +static void +VariableStatEntry_clear_fctx(void *entry) +{ + VariableStatEntry *e = (VariableStatEntry *) entry; + if (e->user_fctx) + *e->user_fctx = NULL; +} + +static void +PackageStatEntry_clear_fctx(void *entry) +{ + PackageStatEntry *e = (PackageStatEntry *) entry; + if (e->user_fctx) + *e->user_fctx = NULL; +} + /* * Generic remove_if algorithm. * @@ -287,6 +310,7 @@ typedef struct tagRemoveIfContext HASH_SEQ_STATUS *(*getter) (void *); /* status getter */ bool match_first; /* return on first match */ bool term; /* hash_seq_term on match */ + void (*clear_fctx) (void *); /* clear function context */ } RemoveIfContext; static void @@ -308,7 +332,13 @@ list_remove_if(RemoveIfContext ctx) *ctx.list = list_delete_cell(*ctx.list, cell, prev); if (ctx.term) +#ifdef PGPRO_EE + hash_seq_term_all_levels(ctx.getter(entry)); +#else hash_seq_term(ctx.getter(entry)); +#endif + + ctx.clear_fctx(entry); pfree(ctx.getter(entry)); pfree(entry); @@ -340,7 +370,13 @@ list_remove_if(RemoveIfContext ctx) *ctx.list = foreach_delete_current(*ctx.list, cell); if (ctx.term) +#ifdef PGPRO_EE + hash_seq_term_all_levels(ctx.getter(entry)); +#else hash_seq_term(ctx.getter(entry)); +#endif + + ctx.clear_fctx(entry); pfree(ctx.getter(entry)); pfree(entry); @@ -365,7 +401,8 @@ remove_variables_status(List **list, HASH_SEQ_STATUS *status) .eq = VariableStatEntry_status_eq, .getter = VariableStatEntry_status_ptr, .match_first = true, - .term = false + .term = false, + .clear_fctx = VariableStatEntry_clear_fctx }; list_remove_if(ctx); @@ -388,7 +425,8 @@ remove_variables_variable(List **list, Variable *variable) .eq = VariableStatEntry_variable_eq, .getter = VariableStatEntry_status_ptr, .match_first = false, - .term = true + .term = true, + .clear_fctx = VariableStatEntry_clear_fctx }; list_remove_if(ctx); @@ -407,7 +445,8 @@ remove_variables_package(List **list, Package *package) .eq = VariableStatEntry_package_eq, .getter = VariableStatEntry_status_ptr, .match_first = false, - .term = true + .term = true, + .clear_fctx = VariableStatEntry_clear_fctx }; list_remove_if(ctx); @@ -426,7 +465,8 @@ remove_variables_level(List **list, Levels *levels) .eq = VariableStatEntry_level_eq, .getter = VariableStatEntry_status_ptr, .match_first = false, - .term = false + .term = false, + .clear_fctx = VariableStatEntry_clear_fctx }; list_remove_if(ctx); @@ -445,7 +485,8 @@ remove_variables_all(List **list) .eq = VariableStatEntry_eq_all, .getter = VariableStatEntry_status_ptr, .match_first = false, - .term = true + .term = true, + .clear_fctx = VariableStatEntry_clear_fctx }; list_remove_if(ctx); @@ -464,7 +505,8 @@ remove_packages_status(List **list, HASH_SEQ_STATUS *status) .eq = PackageStatEntry_status_eq, .getter = PackageStatEntry_status_ptr, .match_first = true, - .term = false + .term = false, + .clear_fctx = PackageStatEntry_clear_fctx }; list_remove_if(ctx); @@ -483,7 +525,8 @@ remove_packages_level(List **list, Levels *levels) .eq = PackageStatEntry_level_eq, .getter = PackageStatEntry_status_ptr, .match_first = false, - .term = true + .term = true, + .clear_fctx = PackageStatEntry_clear_fctx }; list_remove_if(ctx); @@ -503,7 +546,8 @@ remove_variables_transactional(List **list) .eq = VariableStatEntry_is_transactional, .getter = VariableStatEntry_status_ptr, .match_first = false, - .term = true + .term = true, + .clear_fctx = VariableStatEntry_clear_fctx }; list_remove_if(ctx); @@ -1017,6 +1061,7 @@ variable_select(PG_FUNCTION_ARGS) #ifdef PGPRO_EE entry->levels.atxlevel = getNestLevelATX(); #endif + entry->user_fctx = &funcctx->user_fctx; variables_stats = lcons((void *) entry, variables_stats); MemoryContextSwitchTo(oldcontext); @@ -1026,6 +1071,15 @@ variable_select(PG_FUNCTION_ARGS) funcctx = SRF_PERCALL_SETUP(); + if (funcctx->user_fctx == NULL) + { + /* + * VariableStatEntry was removed. For example, after call + * 'ROLLBACK TO SAVEPOINT ...' + */ + SRF_RETURN_DONE(funcctx); + } + /* Get next hash record */ rstat = (HASH_SEQ_STATUS *) funcctx->user_fctx; item = (HashRecordEntry *) hash_seq_search(rstat); @@ -1336,12 +1390,18 @@ remove_package(PG_FUNCTION_ARGS) package_name = PG_GETARG_TEXT_PP(0); package = getPackage(package_name, true); + /* + * Need to remove variables before removing package because + * remove_variables_package() calls hash_seq_term() which uses + * "entry->status->hashp->frozen" but memory context of "hashp" + * for regular variables can be deleted in removePackageInternal(). + */ + remove_variables_package(&variables_stats, package); + removePackageInternal(package); resetVariablesCache(); - remove_variables_package(&variables_stats, package); - PG_FREE_IF_COPY(package_name, 0); PG_RETURN_VOID(); } @@ -1428,6 +1488,14 @@ remove_packages(PG_FUNCTION_ARGS) if (packagesHash == NULL) PG_RETURN_VOID(); + /* + * Need to remove variables before removing packages because + * remove_variables_all() calls hash_seq_term() which uses + * "entry->status->hashp->frozen" but memory context of "hashp" + * for regular variables can be deleted in removePackageInternal(). + */ + remove_variables_all(&variables_stats); + /* Get packages list */ hash_seq_init(&pstat, packagesHash); while ((package = (Package *) hash_seq_search(&pstat)) != NULL) @@ -1436,7 +1504,6 @@ remove_packages(PG_FUNCTION_ARGS) } resetVariablesCache(); - remove_variables_all(&variables_stats); PG_RETURN_VOID(); } @@ -1580,7 +1647,7 @@ getMemoryTotalSpace(MemoryContext context, int level, Size *totalspace) MemoryContext child; MemoryContextCounters totals; - AssertArg(MemoryContextIsValid(context)); + Assert(MemoryContextIsValid(context)); /* Examine the context itself */ memset(&totals, 0, sizeof(totals)); @@ -1651,6 +1718,7 @@ get_packages_stats(PG_FUNCTION_ARGS) #ifdef PGPRO_EE entry->levels.atxlevel = getNestLevelATX(); #endif + entry->user_fctx = &funcctx->user_fctx; packages_stats = lcons((void *) entry, packages_stats); MemoryContextSwitchTo(ctx); } @@ -2138,7 +2206,7 @@ removeState(TransObject *object, TransObjectType type, TransState *stateToDelete } /* Remove package or variable (either transactional or regular) */ -void +bool removeObject(TransObject *object, TransObjectType type) { bool found; @@ -2150,6 +2218,18 @@ removeObject(TransObject *object, TransObjectType type) #ifdef PGPRO_EE PackageContext *context, *next; + + /* + * Do not delete package inside autonomous transaction: it could be + * used in parent transaction. But we can delete package without any + * states: this means that the package was created in the current + * transaction. + */ + if (getNestLevelATX() > 0 && !dlist_is_empty(&object->states)) + { + GetActualState(object)->is_valid = false; + return false; + } #endif package = (Package *) object; @@ -2169,6 +2249,8 @@ removeObject(TransObject *object, TransObjectType type) while (context) { next = context->next; + if (context->hctxTransact) + MemoryContextDelete(context->hctxTransact); pfree(context); context = next; } @@ -2185,14 +2267,20 @@ removeObject(TransObject *object, TransObjectType type) var->package->varHashRegular; } + /* + * Need to remove variables before removing state because + * remove_variables_variable() calls hash_seq_term() which uses + * "entry->status->hashp->frozen" but memory context of "hashp" + * for regular variables can be deleted in removeState() in freeValue(). + */ + /* Remove object from hash table */ + hash_search(hash, object->name, HASH_REMOVE, &found); + remove_variables_variable(&variables_stats, (Variable*)object); + /* Remove all object's states */ while (!dlist_is_empty(&object->states)) removeState(object, type, GetActualState(object)); - /* Remove object from hash table */ - hash_search(hash, object->name, HASH_REMOVE, &found); - remove_variables_variable(&variables_stats, (Variable *) object); - /* Remove package if it became empty */ if (type == TRANS_VARIABLE && isPackageEmpty(package)) { @@ -2201,6 +2289,8 @@ removeObject(TransObject *object, TransObjectType type) } resetVariablesCache(); + + return true; } /* @@ -2244,7 +2334,7 @@ numOfRegVars(Package *package) * Rollback object to its previous state */ static void -rollbackSavepoint(TransObject *object, TransObjectType type) +rollbackSavepoint(TransObject *object, TransObjectType type, bool sub) { TransState *state; @@ -2269,7 +2359,14 @@ rollbackSavepoint(TransObject *object, TransObjectType type) /* ...create a new state to make package valid. */ initObjectHistory(object, type); #ifdef PGPRO_EE - GetActualState(object)->levels.atxlevel = getNestLevelATX(); + /* + * Package inside autonomous transaction should not be detected + * as 'object has been changed in upper level' because in this + * case we will remove state in releaseSavepoint() but this + * state may be used in pgvRestoreContext(). So atxlevel should + * be 0 in case of rollback of autonomous transaction. + */ + GetActualState(object)->levels.atxlevel = sub ? getNestLevelATX() : 0; #endif GetActualState(object)->levels.level = GetCurrentTransactionNestLevel() - 1; if (!dlist_is_empty(changesStack)) @@ -2316,11 +2413,14 @@ rollbackSavepoint(TransObject *object, TransObjectType type) * Remove previous state of object */ static void -releaseSavepoint(TransObject *object, TransObjectType type) +releaseSavepoint(TransObject *object, TransObjectType type, bool sub) { dlist_head *states = &object->states; Assert(GetActualState(object)->levels.level == GetCurrentTransactionNestLevel()); +#ifdef PGPRO_EE + Assert(GetActualState(object)->levels.atxlevel == getNestLevelATX()); +#endif /* * If the object is not valid and does not exist at a higher level (or if @@ -2331,8 +2431,8 @@ releaseSavepoint(TransObject *object, TransObjectType type) dlist_is_empty(changesStack)) ) { - removeObject(object, type); - return; + if (removeObject(object, type)) + return; } /* @@ -2346,6 +2446,15 @@ releaseSavepoint(TransObject *object, TransObjectType type) nodeToDelete = dlist_next_node(states, dlist_head_node(states)); stateToDelete = dlist_container(TransState, node, nodeToDelete); +#ifdef PGPRO_EE + /* + * We can not delete package state inside autonomous transaction + * because the state can be used in pgvRestoreContext(). + * Exception: the state was created within this autonomous transaction. + */ + Assert(type != TRANS_PACKAGE || getNestLevelATX() == 0 || + stateToDelete->levels.atxlevel == getNestLevelATX()); +#endif removeState(object, type, stateToDelete); } @@ -2358,6 +2467,12 @@ releaseSavepoint(TransObject *object, TransObjectType type) /* Change subxact level due to release */ GetActualState(object)->levels.level--; + +#ifdef PGPRO_EE + /* Change ATX level due to finish autonomous transaction */ + if (!sub && getNestLevelATX() > 0) + GetActualState(object)->levels.atxlevel = 0; +#endif } static void @@ -2555,7 +2670,7 @@ typedef enum Action * Apply savepoint actions on list of variables or packages. */ static void -applyAction(Action action, TransObjectType type, dlist_head *list) +applyAction(Action action, TransObjectType type, dlist_head *list, bool sub) { dlist_iter iter; @@ -2567,7 +2682,7 @@ applyAction(Action action, TransObjectType type, dlist_head *list) switch (action) { case ROLLBACK_TO_SAVEPOINT: - rollbackSavepoint(object, type); + rollbackSavepoint(object, type, sub); break; case RELEASE_SAVEPOINT: @@ -2585,7 +2700,7 @@ applyAction(Action action, TransObjectType type, dlist_head *list) GetActualState(variable)->is_valid = false; } - releaseSavepoint(object, type); + releaseSavepoint(object, type, sub); break; } } @@ -2596,7 +2711,7 @@ applyAction(Action action, TransObjectType type, dlist_head *list) * apply corresponding action on them */ static void -processChanges(Action action) +processChanges(Action action, bool sub) { ChangesStackNode *bottom_list; @@ -2605,8 +2720,8 @@ processChanges(Action action) bottom_list = dlist_container(ChangesStackNode, node, dlist_pop_head_node(changesStack)); - applyAction(action, TRANS_VARIABLE, bottom_list->changedVarsList); - applyAction(action, TRANS_PACKAGE, bottom_list->changedPacksList); + applyAction(action, TRANS_VARIABLE, bottom_list->changedVarsList, sub); + applyAction(action, TRANS_PACKAGE, bottom_list->changedPacksList, sub); /* Remove changes list of current level */ MemoryContextDelete(bottom_list->ctx); @@ -2762,20 +2877,36 @@ pgvRestoreContext() PackageContext *next = context->next; TransObject *object = &package->transObject; TransState *state; + bool actual_valid_state; /* Restore transactional variables from context */ package->hctxTransact = context->hctxTransact; package->varHashTransact = context->varHashTransact; + /* Save last actual state of package */ + actual_valid_state = GetActualState(object)->is_valid; + /* Remove all package states, generated in ATX transaction */ while ((state = GetActualState(object)) != context->state) { + removeState(object, TRANS_PACKAGE, state); if (dlist_is_empty(&object->states)) elog(ERROR, "pg_variables extension can not find " "transaction state for package"); - removeState(object, TRANS_PACKAGE, state); } + /* + * Package could be removed in the autonomous transaction. So + * need to mark it as invalid. Or removed package could be + * re-created - so need to mark it as valid. + */ + if (actual_valid_state != GetActualState(object)->is_valid) + GetActualState(object)->is_valid = actual_valid_state; + + /* Mark empty package as deleted. */ + if (GetPackState(package)->trans_var_num + numOfRegVars(package) == 0) + GetActualState(object)->is_valid = false; + pfree(context); package->context = next; } @@ -2827,10 +2958,10 @@ pgvSubTransCallback(SubXactEvent event, SubTransactionId mySubid, compatibility_check(); break; case SUBXACT_EVENT_COMMIT_SUB: - processChanges(RELEASE_SAVEPOINT); + processChanges(RELEASE_SAVEPOINT, true); break; case SUBXACT_EVENT_ABORT_SUB: - processChanges(ROLLBACK_TO_SAVEPOINT); + processChanges(ROLLBACK_TO_SAVEPOINT, true); break; case SUBXACT_EVENT_PRE_COMMIT_SUB: break; @@ -2857,16 +2988,16 @@ pgvTransCallback(XactEvent event, void *arg) { case XACT_EVENT_PRE_COMMIT: compatibility_check(); - processChanges(RELEASE_SAVEPOINT); + processChanges(RELEASE_SAVEPOINT, false); break; case XACT_EVENT_ABORT: - processChanges(ROLLBACK_TO_SAVEPOINT); + processChanges(ROLLBACK_TO_SAVEPOINT, false); break; case XACT_EVENT_PARALLEL_PRE_COMMIT: - processChanges(RELEASE_SAVEPOINT); + processChanges(RELEASE_SAVEPOINT, false); break; case XACT_EVENT_PARALLEL_ABORT: - processChanges(ROLLBACK_TO_SAVEPOINT); + processChanges(ROLLBACK_TO_SAVEPOINT, false); break; default: break; @@ -2919,7 +3050,11 @@ freeStatsLists(void) { VariableStatEntry *entry = (VariableStatEntry *) lfirst(cell); +#ifdef PGPRO_EE + hash_seq_term_all_levels(entry->status); +#else hash_seq_term(entry->status); +#endif } variables_stats = NIL; @@ -2928,7 +3063,11 @@ freeStatsLists(void) { PackageStatEntry *entry = (PackageStatEntry *) lfirst(cell); +#ifdef PGPRO_EE + hash_seq_term_all_levels(entry->status); +#else hash_seq_term(entry->status); +#endif } packages_stats = NIL; @@ -2951,7 +3090,7 @@ _PG_init(void) NULL, NULL); -#if defined(PGPRO_EE) && (PG_VERSION_NUM >= 150000) +#ifdef PGPRO_EE PgproRegisterXactCallback(pgvTransCallback, NULL, XACT_EVENT_KIND_VANILLA | XACT_EVENT_KIND_ATX); #else RegisterXactCallback(pgvTransCallback, NULL); @@ -2963,6 +3102,7 @@ _PG_init(void) ExecutorEnd_hook = variable_ExecutorEnd; } +#if PG_VERSION_NUM < 150000 /* * Unregister callback function when module unloads */ @@ -2973,3 +3113,4 @@ _PG_fini(void) UnregisterSubXactCallback(pgvSubTransCallback, NULL); ExecutorEnd_hook = prev_ExecutorEnd; } +#endif diff --git a/pg_variables.h b/pg_variables.h index afa9b22..6508e9f 100644 --- a/pg_variables.h +++ b/pg_variables.h @@ -193,7 +193,7 @@ extern bool update_record(Variable *variable, HeapTupleHeader tupleHeader); extern bool delete_record(Variable *variable, Datum value, bool is_null); extern void insert_record_copy(RecordVar *dest_record, Datum src_tuple, Variable *variable); -extern void removeObject(TransObject *object, TransObjectType type); +extern bool removeObject(TransObject *object, TransObjectType type); #define GetActualState(object) \ (dlist_head_element(TransState, node, &((TransObject *) object)->states)) diff --git a/run_tests.sh b/run_tests.sh index 2e63dad..2d88e36 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -43,7 +43,7 @@ if [ "$LEVEL" = "hardcore" ] || \ # enable additional options ./configure \ CFLAGS='-O0 -ggdb3 -fno-omit-frame-pointer' \ - --enable-cassert \ + --enable-cassert --enable-debug \ --prefix=$CUSTOM_PG_BIN \ --quiet @@ -100,6 +100,7 @@ if [ "$LEVEL" = "nightmare" ]; then --time-stamp=yes \ --track-origins=yes \ --trace-children=yes \ + --trace-children-skip="/bin/*,/usr/bin/*,/lib/*" \ --gen-suppressions=all \ --suppressions=$CUSTOM_PG_SRC/src/tools/valgrind.supp \ --suppressions=$PWD/valgrind.supp \ diff --git a/sql/pg_variables_atx_pkg.sql b/sql/pg_variables_atx_pkg.sql new file mode 100644 index 0000000..49113d6 --- /dev/null +++ b/sql/pg_variables_atx_pkg.sql @@ -0,0 +1,238 @@ +-- +-- PGPRO-7614: function pgv_free() inside autonomous transaction +-- +SELECT pgv_free(); +-- +-- +-- Functions pgv_free() + pgv_get() inside autonomous transaction; package +-- with regular variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + BEGIN AUTONOMOUS; + SELECT pgv_get('vars', 'int1', null::int); + SELECT pgv_free(); +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- regular variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + BEGIN AUTONOMOUS; + SELECT pgv_free(); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- regular variable; autonomous transaction with rollback. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + BEGIN AUTONOMOUS; + SELECT pgv_free(); + ROLLBACK; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- transactional variable; autonomous transaction with rollback. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1, true); + BEGIN AUTONOMOUS; + SELECT pgv_free(); + ROLLBACK; + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Function pgv_free() inside autonomous transaction; package with +-- transactional variable; autonomous transaction with commit. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1, true); + BEGIN AUTONOMOUS; + SELECT pgv_free(); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Function pgv_free() inside recursive autonomous transactions. +-- +BEGIN; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 1); + BEGIN AUTONOMOUS; + BEGIN AUTONOMOUS; + SELECT pgv_free(); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + COMMIT; +ROLLBACK; +-- +-- +-- Function pgv_free() inside recursive autonomous transactions; +-- recreating the package after deletion with using regular +-- variable. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + BEGIN AUTONOMOUS; + BEGIN AUTONOMOUS; + SELECT pgv_get('vars', 'int1', null::int); + BEGIN AUTONOMOUS; + SELECT pgv_free(); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + COMMIT; + SELECT pgv_set('vars', 'int1', 2); + COMMIT; + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Function pgv_free() inside recursive autonomous transactions; +-- recreating the package after deletion with using transactional +-- variable. +-- +BEGIN; + SELECT pgv_set('vars', 'int1', 1); + BEGIN AUTONOMOUS; + BEGIN AUTONOMOUS; + SELECT pgv_get('vars', 'int1', null::int); + BEGIN AUTONOMOUS; + SELECT pgv_free(); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); + COMMIT; + SELECT pgv_set('vars', 'int1', 2, true); + SELECT pgv_list(); + COMMIT; +-- ERROR: unrecognized package "vars" + SELECT pgv_get('vars', 'int1', null::int); +ROLLBACK; +-- +-- +-- Test for case: do not free hash_seq_search scans of parent transaction +-- at end of the autonomous transaction. +-- +BEGIN; + SELECT pgv_insert('test', 'x', row (1::int, 2::int), false); + SELECT pgv_insert('test', 'x', row (3::int, 4::int), false); + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); +-- (1,2) + FETCH 1 IN r1_cur; + BEGIN AUTONOMOUS; + ROLLBACK; +-- (3,4) + FETCH 1 IN r1_cur; + SELECT pgv_remove('test', 'x'); +-- ERROR: unrecognized package "test" + FETCH 1 IN r1_cur; +ROLLBACK; +-- +-- +-- Test for case: pgv_free() should free hash_seq_search scans of all +-- (current ATX + parent) transactions. +-- +BEGIN; + SELECT pgv_insert('test', 'x', row (1::int, 2::int), false); + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); +-- (1,2) + FETCH 1 IN r1_cur; + BEGIN AUTONOMOUS; + SELECT pgv_free(); + ROLLBACK; +-- ERROR: unrecognized package "test" + FETCH 1 IN r1_cur; +ROLLBACK; +-- +-- +-- Test for case: pgv_set() created a regular variable; rollback +-- removes package state and creates a new state to make package valid. +-- Commit of next autonomous transaction should not replace this new +-- state (this is not allowed for autonomous transaction). +-- +BEGIN; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 1); + ROLLBACK; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 2); + COMMIT; +ROLLBACK; +SELECT pgv_remove('vars', 'int1'); +-- +-- +-- Test for case: pgv_set() created a regular variable and package with +-- (atxlevel=1, level=1). COMMIT changes this level to (atxlevel=1, level=0). +-- In the next autonomous transaction (atxlevel=1, level=1) we erroneously +-- detect that the package changed in upper transaction and remove the +-- package state (this is not allowed for autonomous transaction). +-- +BEGIN; + BEGIN AUTONOMOUS; + SELECT pgv_set('vars', 'int1', 2); + COMMIT; + BEGIN AUTONOMOUS; + SELECT pgv_free(); + SELECT pgv_set('vars', 'int1', 2, true); + COMMIT; +ROLLBACK; +-- +-- +-- Test for case: pgv_set() created a regular variable and package with +-- (atxlevel=1, level=1). ROLLBACK changes this level to (atxlevel=0, level=0). +-- But ROLLBACK shouldn't change atxlevel in case rollback of sub-transaction. +-- +BEGIN; + BEGIN AUTONOMOUS; + SAVEPOINT sp1; + SELECT pgv_set('vars1', 'int1', 0); + ROLLBACK TO sp1; + COMMIT; +ROLLBACK; +SELECT pgv_remove('vars1', 'int1'); + +SELECT pgv_free(); +-- +-- +-- PGPRO-7856 +-- Test for case: we don't remove the package object without any variables at +-- the end of autonomous transaction but need to move the state of this object +-- to upper level. +-- +BEGIN; + BEGIN AUTONOMOUS; + SAVEPOINT sp1; + SELECT pgv_set('vars2', 'any1', 'variable exists'::text, true); + SELECT pgv_free(); + RELEASE sp1; + ROLLBACK; + + BEGIN AUTONOMOUS; + SAVEPOINT sp2; + SAVEPOINT sp3; + SELECT pgv_free(); + COMMIT; +ROLLBACK; diff --git a/sql/pg_variables_trans.sql b/sql/pg_variables_trans.sql index ae69df7..23b7afd 100644 --- a/sql/pg_variables_trans.sql +++ b/sql/pg_variables_trans.sql @@ -1169,3 +1169,25 @@ SELECT pgv_free(); -- Test case for issue #38 [PGPRO-4676] -- SELECT pgv_insert('test', 'x5', ROW ((2::int, 1::int)), TRUE); + +-- +-- Test case for PGPRO-7614: crash by using cursor after rollback of cursor +-- creation. +-- +BEGIN; + SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), true); + DECLARE r1_cur CURSOR FOR SELECT pgv_select('test', 'x'); + SAVEPOINT sp1; + FETCH 1 in r1_cur; + ROLLBACK TO SAVEPOINT sp1; + FETCH 1 in r1_cur; +ROLLBACK; + +BEGIN; + SELECT pgv_insert('test', 'x', ROW (1::int, 2::int), TRUE); + DECLARE r1_cur CURSOR FOR SELECT pgv_stats(); + SAVEPOINT sp1; + FETCH 1 in r1_cur; + ROLLBACK TO SAVEPOINT sp1; + FETCH 1 in r1_cur; +ROLLBACK;
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: