summaryrefslogtreecommitdiff
path: root/src/include/access
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-09-16 16:58:44 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-09-16 16:58:44 +0000
commit8f9f1986034a2273e09ad10671e10d1adda21d1f (patch)
tree4c2c8a226db335cf1e653b09026402363d0488e7 /src/include/access
parent42c0d1f3cd01ac737b182353934531d1fd382c80 (diff)
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.
Diffstat (limited to 'src/include/access')
-rw-r--r--src/include/access/xact.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index c30c741f27e..9fa6a1d2406 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -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/access/xact.h,v 1.72 2004/09/05 23:01:26 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/xact.h,v 1.73 2004/09/16 16:58:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,14 +46,21 @@ extern bool XactReadOnly;
*/
typedef enum
{
- XACT_EVENT_ABORT,
XACT_EVENT_COMMIT,
- XACT_EVENT_START_SUB,
- XACT_EVENT_ABORT_SUB,
- XACT_EVENT_COMMIT_SUB
+ XACT_EVENT_ABORT
} XactEvent;
-typedef void (*XactCallback) (XactEvent event, TransactionId parentXid, void *arg);
+typedef void (*XactCallback) (XactEvent event, void *arg);
+
+typedef enum
+{
+ SUBXACT_EVENT_START_SUB,
+ SUBXACT_EVENT_COMMIT_SUB,
+ SUBXACT_EVENT_ABORT_SUB
+} SubXactEvent;
+
+typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
+ SubTransactionId parentSubid, void *arg);
/* ----------------
@@ -101,6 +108,8 @@ extern bool IsTransactionState(void);
extern bool IsAbortedTransactionBlockState(void);
extern TransactionId GetTopTransactionId(void);
extern TransactionId GetCurrentTransactionId(void);
+extern TransactionId GetCurrentTransactionIdIfAny(void);
+extern SubTransactionId GetCurrentSubTransactionId(void);
extern CommandId GetCurrentCommandId(void);
extern AbsoluteTime GetCurrentTransactionStartTime(void);
extern AbsoluteTime GetCurrentTransactionStartTimeUsec(int *usec);
@@ -129,6 +138,8 @@ extern void RequireTransactionChain(void *stmtNode, const char *stmtType);
extern bool IsInTransactionChain(void *stmtNode);
extern void RegisterXactCallback(XactCallback callback, void *arg);
extern void UnregisterXactCallback(XactCallback callback, void *arg);
+extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
+extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);
extern void RecordTransactionCommit(void);