diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-09-16 16:58:44 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-09-16 16:58:44 +0000 |
commit | 8f9f1986034a2273e09ad10671e10d1adda21d1f (patch) | |
tree | 4c2c8a226db335cf1e653b09026402363d0488e7 /src/backend/executor | |
parent | 42c0d1f3cd01ac737b182353934531d1fd382c80 (diff) | |
download | postgresql-8f9f1986034a2273e09ad10671e10d1adda21d1f.tar.gz postgresql-8f9f1986034a2273e09ad10671e10d1adda21d1f.zip |
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/backend/executor')
-rw-r--r-- | src/backend/executor/spi.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 6650da9b626..ab26a91c1aa 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.127 2004/09/13 20:06:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.128 2004/09/16 16:58:29 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -104,7 +104,7 @@ SPI_connect(void) _SPI_current = &(_SPI_stack[_SPI_connected]); _SPI_current->processed = 0; _SPI_current->tuptable = NULL; - _SPI_current->connectXid = GetCurrentTransactionId(); + _SPI_current->connectSubid = GetCurrentSubTransactionId(); /* * Create memory contexts for this procedure @@ -198,10 +198,10 @@ AtEOXact_SPI(bool isCommit) * Clean up SPI state at subtransaction commit or abort. * * During commit, there shouldn't be any unclosed entries remaining from - * the current transaction; we throw them away if found. + * the current subtransaction; we emit a warning if any are found. */ void -AtEOSubXact_SPI(bool isCommit, TransactionId childXid) +AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid) { bool found = false; @@ -209,7 +209,7 @@ AtEOSubXact_SPI(bool isCommit, TransactionId childXid) { _SPI_connection *connection = &(_SPI_stack[_SPI_connected]); - if (connection->connectXid != childXid) + if (connection->connectSubid != mySubid) break; /* couldn't be any underneath it either */ found = true; @@ -235,7 +235,7 @@ AtEOSubXact_SPI(bool isCommit, TransactionId childXid) ereport(WARNING, (errcode(ERRCODE_WARNING), errmsg("subtransaction left non-empty SPI stack"), - errhint("Check for missing \"SPI_finish\" calls"))); + errhint("Check for missing \"SPI_finish\" calls."))); } @@ -1692,8 +1692,7 @@ _SPI_copy_plan(_SPI_plan *plan, int location) parentcxt = _SPI_current->procCxt; else if (location == _SPI_CPLAN_TOPCXT) parentcxt = TopMemoryContext; - else -/* (this case not currently used) */ + else /* (this case not currently used) */ parentcxt = CurrentMemoryContext; /* |