Skip to content

Commit

Permalink
Optimize objects removal in subtransaction rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
CherkashinSergey authored and za-arthur committed Feb 27, 2019
1 parent b53645f commit 21df5c3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
28 changes: 27 additions & 1 deletion expected/pg_variables_trans.out
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ RELEASE comm;
SELECT pgv_get('vars', 'any1',NULL::text);
ERROR: unrecognized variable "any1"
COMMIT;
-- Test for PGPRO-2440
-- Tests for PGPRO-2440
SELECT pgv_insert('vars3', 'r3', row(1 :: integer, NULL::varchar), true);
pgv_insert
------------
Expand Down Expand Up @@ -1909,6 +1909,32 @@ SELECT pgv_delete('vars3', 'r3', 3);
t
(1 row)

BEGIN;
SELECT pgv_set('vars1', 't1', ''::text);
pgv_set
---------

(1 row)

SELECT pgv_set('vars2', 't2', ''::text, true);
pgv_set
---------

(1 row)

SAVEPOINT sp1;
SAVEPOINT sp2;
SELECT pgv_free();
pgv_free
----------

(1 row)

ERROR;
ERROR: syntax error at or near "ERROR"
LINE 1: ERROR;
^
COMMIT;
SELECT pgv_free();
pgv_free
----------
Expand Down
16 changes: 5 additions & 11 deletions pg_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,6 @@ removeObject(TransObject *object, TransObjectType type)
package = (Package *) object;

/* Regular variables had already removed */
//Here we should think, when regular HTAB should be removed
if (package->hctxRegular)
MemoryContextDelete(package->hctxRegular);
if (package->hctxTransact)
Expand All @@ -1696,10 +1695,11 @@ removeObject(TransObject *object, TransObjectType type)
hash_search(hash, object->name, HASH_REMOVE, &found);

/* Remove package if it became empty */
if (type == TRANS_VARIABLE &&
isObjectChangedInCurrentTrans(&package->transObject) &&
isPackageEmpty(package))
if (type == TRANS_VARIABLE && isPackageEmpty(package))
{
Assert(isObjectChangedInCurrentTrans(&package->transObject));
GetActualState(&package->transObject)->is_valid = false;
}

resetVariablesCache(true);
}
Expand Down Expand Up @@ -1740,14 +1740,8 @@ rollbackSavepoint(TransObject *object, TransObjectType type)
state = GetActualState(object);
if (type == TRANS_PACKAGE)
{
if (!state->is_valid)
if (!state->is_valid && !isPackageEmpty((Package *)object))
{
if (isPackageEmpty((Package *)object))
{
removeObject(object, TRANS_PACKAGE);
return;
}

if (dlist_has_next(&object->states, &state->node))
{
dlist_pop_head_node(&object->states);
Expand Down
11 changes: 10 additions & 1 deletion sql/pg_variables_trans.sql
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ RELEASE comm;
SELECT pgv_get('vars', 'any1',NULL::text);
COMMIT;

-- Test for PGPRO-2440
-- Tests for PGPRO-2440
SELECT pgv_insert('vars3', 'r3', row(1 :: integer, NULL::varchar), true);
BEGIN;
SELECT pgv_insert('vars3', 'r3', row(2 :: integer, NULL::varchar), true);
Expand All @@ -491,4 +491,13 @@ SELECT pgv_insert('vars3', 'r3', row(3 :: integer, NULL::varchar), true);
COMMIT;
SELECT pgv_delete('vars3', 'r3', 3);

BEGIN;
SELECT pgv_set('vars1', 't1', ''::text);
SELECT pgv_set('vars2', 't2', ''::text, true);
SAVEPOINT sp1;
SAVEPOINT sp2;
SELECT pgv_free();
ERROR;
COMMIT;

SELECT pgv_free();

0 comments on commit 21df5c3

Please sign in to comment.