13
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.273 2009/05/13 20:27:17 tgl Exp $
13
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.274 2009/06/11 14:48:54 momjian Exp $
15
15
*-------------------------------------------------------------------------
457
457
* "used" must be TRUE if the caller intends to use the command ID to mark
458
458
* inserted/updated/deleted tuples. FALSE means the ID is being fetched
459
* for read-only purposes (ie, as a snapshot validity cutoff). See
459
* for read-only purposes (ie, as a snapshot validity cutoff). See
460
460
* CommandCounterIncrement() for discussion.
604
605
CommandCounterIncrement(void)
607
* If the current value of the command counter hasn't been "used" to
608
* mark tuples, we need not increment it, since there's no need to
609
* distinguish a read-only command from others. This helps postpone
610
* command counter overflow, and keeps no-op CommandCounterIncrement
608
* If the current value of the command counter hasn't been "used" to mark
609
* tuples, we need not increment it, since there's no need to distinguish
610
* a read-only command from others. This helps postpone command counter
611
* overflow, and keeps no-op CommandCounterIncrement operations cheap.
613
613
if (currentCommandIdUsed)
615
615
currentCommandId += 1;
616
if (currentCommandId == FirstCommandId) /* check for overflow */
616
if (currentCommandId == FirstCommandId) /* check for overflow */
618
618
currentCommandId -= 1;
620
620
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
621
errmsg("cannot have more than 2^32-1 commands in a transaction")));
621
errmsg("cannot have more than 2^32-1 commands in a transaction")));
623
623
currentCommandIdUsed = false;
625
625
/* Propagate new command ID into static snapshots */
626
626
SnapshotSetCommandId(currentCommandId);
629
* Make any catalog changes done by the just-completed command
630
* visible in the local syscache. We obviously don't need to do
631
* this after a read-only command. (But see hacks in inval.c
632
* to make real sure we don't think a command that queued inval
633
* messages was read-only.)
629
* Make any catalog changes done by the just-completed command visible
630
* in the local syscache. We obviously don't need to do this after a
631
* read-only command. (But see hacks in inval.c to make real sure we
632
* don't think a command that queued inval messages was read-only.)
635
634
AtCommit_LocalCache();
639
638
* Make any other backends' catalog changes visible to me.
641
* XXX this is probably in the wrong place: CommandCounterIncrement
642
* should be purely a local operation, most likely. However fooling
643
* with this will affect asynchronous cross-backend interactions,
644
* which doesn't seem like a wise thing to do in late beta, so save
645
* improving this for another day - tgl 2007-11-30
640
* XXX this is probably in the wrong place: CommandCounterIncrement should
641
* be purely a local operation, most likely. However fooling with this
642
* will affect asynchronous cross-backend interactions, which doesn't seem
643
* like a wise thing to do in late beta, so save improving this for
644
* another day - tgl 2007-11-30
1086
1085
/* Allocate or enlarge the parent array if necessary */
1087
1086
if (s->parent->maxChildXids < new_nChildXids)
1089
int new_maxChildXids;
1090
TransactionId *new_childXids;
1088
int new_maxChildXids;
1089
TransactionId *new_childXids;
1093
1092
* Make it 2x what's needed right now, to avoid having to enlarge it
1094
* repeatedly. But we can't go above MaxAllocSize. (The latter
1095
* limit is what ensures that we don't need to worry about integer
1096
* overflow here or in the calculation of new_nChildXids.)
1093
* repeatedly. But we can't go above MaxAllocSize. (The latter limit
1094
* is what ensures that we don't need to worry about integer overflow
1095
* here or in the calculation of new_nChildXids.)
1098
1097
new_maxChildXids = Min(new_nChildXids * 2,
1099
1098
(int) (MaxAllocSize / sizeof(TransactionId)));
1112
1111
if (s->parent->childXids == NULL)
1113
1112
new_childXids =
1114
MemoryContextAlloc(TopTransactionContext,
1113
MemoryContextAlloc(TopTransactionContext,
1115
1114
new_maxChildXids * sizeof(TransactionId));
1117
new_childXids = repalloc(s->parent->childXids,
1118
new_maxChildXids * sizeof(TransactionId));
1116
new_childXids = repalloc(s->parent->childXids,
1117
new_maxChildXids * sizeof(TransactionId));
1120
s->parent->childXids = new_childXids;
1119
s->parent->childXids = new_childXids;
1121
1120
s->parent->maxChildXids = new_maxChildXids;
1127
1126
* Note: We rely on the fact that the XID of a child always follows that
1128
1127
* of its parent. By copying the XID of this subtransaction before the
1129
* XIDs of its children, we ensure that the array stays ordered. Likewise,
1130
* all XIDs already in the array belong to subtransactions started and
1131
* subcommitted before us, so their XIDs must precede ours.
1128
* XIDs of its children, we ensure that the array stays ordered.
1129
* Likewise, all XIDs already in the array belong to subtransactions
1130
* started and subcommitted before us, so their XIDs must precede ours.
1133
1132
s->parent->childXids[s->parent->nChildXids] = s->transactionId;
1801
1800
/* NOTIFY and flatfiles will be handled below */
1804
* Don't allow PREPARE TRANSACTION if we've accessed a temporary table
1805
* in this transaction. Having the prepared xact hold locks on another
1803
* Don't allow PREPARE TRANSACTION if we've accessed a temporary table in
1804
* this transaction. Having the prepared xact hold locks on another
1806
1805
* backend's temp table seems a bad idea --- for instance it would prevent
1807
* the backend from exiting. There are other problems too, such as how
1808
* to clean up the source backend's local buffers and ON COMMIT state
1809
* if the prepared xact includes a DROP of a temp table.
1806
* the backend from exiting. There are other problems too, such as how to
1807
* clean up the source backend's local buffers and ON COMMIT state if the
1808
* prepared xact includes a DROP of a temp table.
1811
* We must check this after executing any ON COMMIT actions, because
1812
* they might still access a temp relation.
1810
* We must check this after executing any ON COMMIT actions, because they
1811
* might still access a temp relation.
1814
1813
* XXX In principle this could be relaxed to allow some useful special
1815
1814
* cases, such as a temp table created and dropped all within the
2022
2021
* Reset user ID which might have been changed transiently. We need this
2023
2022
* to clean up in case control escaped out of a SECURITY DEFINER function
2024
* or other local change of CurrentUserId; therefore, the prior value
2025
* of SecurityDefinerContext also needs to be restored.
2023
* or other local change of CurrentUserId; therefore, the prior value of
2024
* SecurityDefinerContext also needs to be restored.
2027
2026
* (Note: it is not necessary to restore session authorization or role
2028
2027
* settings here because those can only be changed via GUC, and GUC will
3749
3748
/* Must CCI to ensure commands of subtransaction are seen as done */
3750
3749
CommandCounterIncrement();
3753
* Prior to 8.4 we marked subcommit in clog at this point. We now only
3752
* Prior to 8.4 we marked subcommit in clog at this point. We now only
3754
3753
* perform that step, if required, as part of the atomic update of the
3755
3754
* whole transaction tree at top level commit or abort.
4353
4352
appendStringInfo(buf, "; rels:");
4354
4353
for (i = 0; i < xlrec->nrels; i++)
4356
char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
4355
char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
4357
4357
appendStringInfo(buf, " %s", path);
4380
4380
appendStringInfo(buf, "; rels:");
4381
4381
for (i = 0; i < xlrec->nrels; i++)
4383
char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
4383
char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
4384
4385
appendStringInfo(buf, " %s", path);