|
10 | 10 | *
|
11 | 11 | *
|
12 | 12 | * 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 $ |
14 | 14 | *
|
15 | 15 | *-------------------------------------------------------------------------
|
16 | 16 | */
|
@@ -408,10 +408,32 @@ AssignTransactionId(TransactionState s)
|
408 | 408 |
|
409 | 409 | /*
|
410 | 410 | * 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. |
412 | 414 | */
|
413 | 415 | if (isSubXact&& !TransactionIdIsValid(s->parent->transactionId))
|
414 |
| -AssignTransactionId(s->parent); |
| 416 | +{ |
| 417 | +TransactionStatep=s->parent; |
| 418 | +TransactionState*parents; |
| 419 | +size_tparentOffset=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 | +} |
415 | 437 |
|
416 | 438 | /*
|
417 | 439 | * Generate a new Xid and record it in PG_PROC and pg_subtrans.
|
|