mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-19 04:46:59 +08:00
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.
50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* spi_priv.h
|
|
* Server Programming Interface private declarations
|
|
*
|
|
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* $PostgreSQL: pgsql/src/include/executor/spi_priv.h,v 1.21 2004/09/16 16:58:40 tgl Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef SPI_PRIV_H
|
|
#define SPI_PRIV_H
|
|
|
|
#include "executor/spi.h"
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint32 processed; /* by Executor */
|
|
SPITupleTable *tuptable;
|
|
MemoryContext procCxt; /* procedure context */
|
|
MemoryContext execCxt; /* executor context */
|
|
MemoryContext savedcxt;
|
|
SubTransactionId connectSubid; /* ID of connecting subtransaction */
|
|
} _SPI_connection;
|
|
|
|
typedef struct
|
|
{
|
|
/* Context containing _SPI_plan itself as well as subsidiary data */
|
|
MemoryContext plancxt;
|
|
/* Original query string (used for error reporting) */
|
|
const char *query;
|
|
/* List of List of querytrees; one sublist per original parsetree */
|
|
List *qtlist;
|
|
/* List of plan trees --- length == # of querytrees, but flat list */
|
|
List *ptlist;
|
|
/* Argument types, if a prepared plan */
|
|
int nargs;
|
|
Oid *argtypes;
|
|
} _SPI_plan;
|
|
|
|
|
|
#define _SPI_CPLAN_CURCXT 0
|
|
#define _SPI_CPLAN_PROCXT 1
|
|
#define _SPI_CPLAN_TOPCXT 2
|
|
|
|
#endif /* SPI_PRIV_H */
|