|
10 | 10 | *
|
11 | 11 | *
|
12 | 12 | * IDENTIFICATION
|
13 |
| - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.257 2008/01/15 18:56:59 tgl Exp $ |
| 13 | + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.258 2008/03/04 19:54:06 tgl Exp $ |
14 | 14 | *
|
15 | 15 | *-------------------------------------------------------------------------
|
16 | 16 | */
|
@@ -62,6 +62,13 @@ bool XactSyncCommit = true;
|
62 | 62 | int CommitDelay = 0; /* precommit delay in microseconds */
|
63 | 63 | int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
|
64 | 64 |
|
| 65 | +/* |
| 66 | + * MyXactAccessedTempRel is set when a temporary relation is accessed. |
| 67 | + * We don't allow PREPARE TRANSACTION in that case. (This is global |
| 68 | + * so that it can be set from heapam.c.) |
| 69 | + */ |
| 70 | +bool MyXactAccessedTempRel = false; |
| 71 | + |
65 | 72 |
|
66 | 73 | /*
|
67 | 74 | * transaction states - transaction state from server perspective
|
@@ -1445,6 +1452,7 @@ StartTransaction(void)
|
1445 | 1452 | XactIsoLevel = DefaultXactIsoLevel;
|
1446 | 1453 | XactReadOnly = DefaultXactReadOnly;
|
1447 | 1454 | forceSyncCommit = false;
|
| 1455 | + MyXactAccessedTempRel = false; |
1448 | 1456 |
|
1449 | 1457 | /*
|
1450 | 1458 | * reinitialize within-transaction counters
|
@@ -1770,6 +1778,26 @@ PrepareTransaction(void)
|
1770 | 1778 |
|
1771 | 1779 | /* NOTIFY and flatfiles will be handled below */
|
1772 | 1780 |
|
| 1781 | + /* |
| 1782 | + * Don't allow PREPARE TRANSACTION if we've accessed a temporary table |
| 1783 | + * in this transaction. Having the prepared xact hold locks on another |
| 1784 | + * backend's temp table seems a bad idea --- for instance it would prevent |
| 1785 | + * the backend from exiting. There are other problems too, such as how |
| 1786 | + * to clean up the source backend's local buffers and ON COMMIT state |
| 1787 | + * if the prepared xact includes a DROP of a temp table. |
| 1788 | + * |
| 1789 | + * We must check this after executing any ON COMMIT actions, because |
| 1790 | + * they might still access a temp relation. |
| 1791 | + * |
| 1792 | + * XXX In principle this could be relaxed to allow some useful special |
| 1793 | + * cases, such as a temp table created and dropped all within the |
| 1794 | + * transaction. That seems to require much more bookkeeping though. |
| 1795 | + */ |
| 1796 | + if (MyXactAccessedTempRel) |
| 1797 | + ereport(ERROR, |
| 1798 | + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1799 | + errmsg("cannot PREPARE a transaction that has operated on temporary tables"))); |
| 1800 | + |
1773 | 1801 | /* Prevent cancel/die interrupt while cleaning up */
|
1774 | 1802 | HOLD_INTERRUPTS();
|
1775 | 1803 |
|
|
0 commit comments