From 8f9f1986034a2273e09ad10671e10d1adda21d1f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 16 Sep 2004 16:58:44 +0000 Subject: 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. --- src/include/c.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/include/c.h') diff --git a/src/include/c.h b/src/include/c.h index 4d295510dc..cfce57c070 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/c.h,v 1.171 2004/09/10 15:51:47 momjian Exp $ + * $PostgreSQL: pgsql/src/include/c.h,v 1.172 2004/09/16 16:58:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -351,7 +351,7 @@ typedef float float4; typedef double float8; /* - * Oid, RegProcedure, TransactionId, CommandId, AclId + * Oid, RegProcedure, TransactionId, SubTransactionId, CommandId, AclId */ /* typedef Oid is in postgres_ext.h */ @@ -365,6 +365,11 @@ typedef regproc RegProcedure; typedef uint32 TransactionId; +typedef uint32 SubTransactionId; + +#define InvalidSubTransactionId ((SubTransactionId) 0) +#define TopSubTransactionId ((SubTransactionId) 1) + typedef uint32 CommandId; #define FirstCommandId ((CommandId) 0) -- cgit v1.2.1