aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2010-07-23 00:43:17 +0000
committerRobert Haas <rhaas@postgresql.org>2010-07-23 00:43:17 +0000
commit733959b9614f7a274c4f4a51857c7120ddd5cea6 (patch)
tree2ddd606cd71bfd92e653f5b7245f61c0383e69c0 /src
parent7fce4dc6cc27e9421e06cedbf90f2668e1998fc4 (diff)
downloadpostgresql-733959b9614f7a274c4f4a51857c7120ddd5cea6.tar.gz
postgresql-733959b9614f7a274c4f4a51857c7120ddd5cea6.zip
Avoid deep recursion when assigning XIDs to multiple levels of subxacts.
Backpatch to 8.0. Andres Freund, with cleanup and adjustment for older branches by me.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xact.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index f3ba0cfc425..cc20929fae6 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.274.2.3 2010/01/24 21:49:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.274.2.4 2010/07/23 00:43:17 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -399,10 +399,32 @@ AssignTransactionId(TransactionState s)
/*
* Ensure parent(s) have XIDs, so that a child always has an XID later
- * than its parent.
+ * than its parent. Musn't recurse here, or we might get a stack overflow
+ * if we're at the bottom of a huge stack of subtransactions none of which
+ * have XIDs yet.
*/
if (isSubXact && !TransactionIdIsValid(s->parent->transactionId))
- AssignTransactionId(s->parent);
+ {
+ TransactionState p = s->parent;
+ TransactionState *parents;
+ size_t parentOffset = 0;
+
+ parents = palloc(sizeof(TransactionState) * s->nestingLevel);
+ while (p != NULL && !TransactionIdIsValid(p->transactionId))
+ {
+ parents[parentOffset++] = p;
+ p = p->parent;
+ }
+
+ /*
+ * This is technically a recursive call, but the recursion will
+ * never be more than one layer deep.
+ */
+ while (parentOffset != 0)
+ AssignTransactionId(parents[--parentOffset]);
+
+ pfree(parents);
+ }
/*
* Generate a new Xid and record it in PG_PROC and pg_subtrans.