mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Restructure subtransaction handling to reduce resource consumption,
as per recent discussions. Invent SubTransactionIds that are managed like CommandIds (ie, counter is reset at start of each top transaction), and use these instead of TransactionIds to keep track of subtransaction status in those modules that need it. This means that a subtransaction does not need an XID unless it actually inserts/modifies rows in the database. Accordingly, don't assign it an XID nor take a lock on the XID until it tries to do that. This saves a lot of overhead for subtransactions that are only used for error recovery (eg plpgsql exceptions). Also, arrange to release a subtransaction's XID lock as soon as the subtransaction exits, in both the commit and abort cases. This avoids holding many unique locks after a long series of subtransactions. The price is some additional overhead in XactLockTableWait, but that seems acceptable. Finally, restructure the state machine in xact.c to have a more orthogonal set of states for subtransactions.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.79 2004/08/29 05:06:59 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.80 2004/09/16 16:58:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -115,12 +115,12 @@ typedef struct RelationData
|
||||
bool rd_isvalid; /* relcache entry is valid */
|
||||
char rd_indexvalid; /* state of rd_indexlist: 0 = not valid, 1
|
||||
* = valid, 2 = temporarily forced */
|
||||
TransactionId rd_createxact; /* rel was created in current xact */
|
||||
SubTransactionId rd_createSubid; /* rel was created in current xact */
|
||||
|
||||
/*
|
||||
* rd_createxact is the XID of the highest subtransaction the rel has
|
||||
* rd_createSubid is the ID of the highest subtransaction the rel has
|
||||
* survived into; or zero if the rel was not created in the current
|
||||
* transaction. This should be relied on only for optimization
|
||||
* top transaction. This should be relied on only for optimization
|
||||
* purposes; it is possible for new-ness to be "forgotten" (eg, after
|
||||
* CLUSTER).
|
||||
*/
|
||||
@@ -241,7 +241,8 @@ typedef Relation *RelationPtr;
|
||||
* Beware of multiple eval of argument
|
||||
*/
|
||||
#define RELATION_IS_LOCAL(relation) \
|
||||
((relation)->rd_istemp || TransactionIdIsValid((relation)->rd_createxact))
|
||||
((relation)->rd_istemp || \
|
||||
(relation)->rd_createSubid != InvalidSubTransactionId)
|
||||
|
||||
/* routines in utils/cache/relcache.c */
|
||||
extern void RelationIncrementReferenceCount(Relation rel);
|
||||
|
||||
Reference in New Issue
Block a user