File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
src/backend/access/transam Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 1010 *
1111 *
1212 * IDENTIFICATION
13- * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.293 2010/07/06 19:18:55 momjian Exp $
13+ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.294 2010/07/23 00:43:00 rhaas Exp $
1414 *
1515 *-------------------------------------------------------------------------
1616 */
@@ -408,10 +408,32 @@ AssignTransactionId(TransactionState s)
408408
409409 /*
410410 * Ensure parent(s) have XIDs, so that a child always has an XID later
411- * than its parent.
411+ * than its parent. Musn't recurse here, or we might get a stack overflow
412+ * if we're at the bottom of a huge stack of subtransactions none of which
413+ * have XIDs yet.
412414 */
413415 if (isSubXact && !TransactionIdIsValid (s -> parent -> transactionId ))
414- AssignTransactionId (s -> parent );
416+ {
417+ TransactionState p = s -> parent ;
418+ TransactionState * parents ;
419+ size_t parentOffset = 0 ;
420+
421+ parents = palloc (sizeof (TransactionState ) * s -> nestingLevel );
422+ while (p != NULL && !TransactionIdIsValid (p -> transactionId ))
423+ {
424+ parents [parentOffset ++ ] = p ;
425+ p = p -> parent ;
426+ }
427+
428+ /*
429+ * This is technically a recursive call, but the recursion will
430+ * never be more than one layer deep.
431+ */
432+ while (parentOffset != 0 )
433+ AssignTransactionId (parents [-- parentOffset ]);
434+
435+ pfree (parents );
436+ }
415437
416438 /*
417439 * Generate a new Xid and record it in PG_PROC and pg_subtrans.
You can’t perform that action at this time.
0 commit comments