@@ -955,6 +955,7 @@ removePackageInternal(Package *package)
955
955
{
956
956
MemoryContextDelete (package -> hctxRegular );
957
957
package -> hctxRegular = NULL ;
958
+ package -> varHashRegular = NULL ;
958
959
}
959
960
960
961
/* Add to changes list */
@@ -967,6 +968,17 @@ removePackageInternal(Package *package)
967
968
GetActualState (package )-> is_valid = false;
968
969
}
969
970
971
+ static bool
972
+ isPackageEmpty (Package * package )
973
+ {
974
+ int var_num = hash_get_num_entries (package -> varHashTransact );
975
+
976
+ if (package -> varHashRegular )
977
+ var_num += hash_get_num_entries (package -> varHashRegular );
978
+
979
+ return var_num == 0 ;
980
+ }
981
+
970
982
/*
971
983
* Reset cache variables to their default values. It is necessary to do in case
972
984
* of some changes: removing, rollbacking, etc.
@@ -1657,6 +1669,7 @@ removeObject(TransObject *object, TransObjectType type)
1657
1669
{
1658
1670
bool found ;
1659
1671
HTAB * hash ;
1672
+ Package * package = NULL ;
1660
1673
1661
1674
/*
1662
1675
* Delete an object from the change history of the overlying
@@ -1666,16 +1679,20 @@ removeObject(TransObject *object, TransObjectType type)
1666
1679
removeFromChangesStack (object , type );
1667
1680
if (type == TRANS_PACKAGE )
1668
1681
{
1669
- Package * package = (Package * ) object ;
1682
+ package = (Package * ) object ;
1670
1683
1671
1684
/* Regular variables had already removed */
1672
1685
MemoryContextDelete (package -> hctxTransact );
1673
1686
hash = packagesHash ;
1674
1687
}
1675
1688
else
1676
- hash = ((Variable * ) object )-> is_transactional ?
1677
- ((Variable * ) object )-> package -> varHashTransact :
1678
- ((Variable * ) object )-> package -> varHashRegular ;
1689
+ {
1690
+ Variable * var = (Variable * ) object ;
1691
+ package = var -> package ;
1692
+ hash = var -> is_transactional ?
1693
+ var -> package -> varHashTransact :
1694
+ var -> package -> varHashRegular ;
1695
+ }
1679
1696
1680
1697
/* Remove all object's states */
1681
1698
while (!dlist_is_empty (& object -> states ))
@@ -1684,6 +1701,12 @@ removeObject(TransObject *object, TransObjectType type)
1684
1701
/* Remove object from hash table */
1685
1702
hash_search (hash , object -> name , HASH_REMOVE , & found );
1686
1703
1704
+ /* Remove package if it is became empty */
1705
+ if (type == TRANS_VARIABLE &&
1706
+ isObjectChangedInCurrentTrans (& package -> transObject ) &&
1707
+ isPackageEmpty (package ))
1708
+ GetActualState (& package -> transObject )-> is_valid = false;
1709
+
1687
1710
resetVariablesCache (true);
1688
1711
}
1689
1712
@@ -1725,8 +1748,19 @@ rollbackSavepoint(TransObject *object, TransObjectType type)
1725
1748
{
1726
1749
if (!state -> is_valid )
1727
1750
{
1728
- dlist_pop_head_node (& object -> states );
1729
- pfree (state );
1751
+ if (isPackageEmpty ((Package * )object ))
1752
+ {
1753
+ removeObject (object , TRANS_PACKAGE );
1754
+ return ;
1755
+ }
1756
+
1757
+ if (dlist_has_next (& object -> states , & state -> node ))
1758
+ {
1759
+ dlist_pop_head_node (& object -> states );
1760
+ pfree (state );
1761
+ }
1762
+ else
1763
+ state -> is_valid = true;
1730
1764
/* Restore regular vars HTAB */
1731
1765
makePackHTAB ((Package * ) object , false);
1732
1766
}
@@ -1797,6 +1831,13 @@ releaseSavepoint(TransObject *object, TransObjectType type)
1797
1831
!dlist_has_next (states , dlist_head_node (states )))
1798
1832
{
1799
1833
removeObject (object , type );
1834
+ /* Remove package if it becomes empty */
1835
+ if (type == TRANS_VARIABLE )
1836
+ {
1837
+ Package * pack = ((Variable * ) object )-> package ;
1838
+ if (isPackageEmpty (pack ))
1839
+ (GetActualState (& pack -> transObject ))-> is_valid = false;
1840
+ }
1800
1841
return ;
1801
1842
}
1802
1843
}
0 commit comments