mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Make DROP TABLE rollback-able: postpone physical file delete until commit.
(WAL logging for this is not done yet, however.) Clean up a number of really crufty things that are no longer needed now that DROP behaves nicely. Make temp table mapper do the right things when drop or rename affecting a temp table is rolled back. Also, remove "relation modified while in use" error check, in favor of locking tables at first reference and holding that lock throughout the statement.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.67 2000/10/05 19:48:20 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.68 2000/11/08 22:09:53 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* some of the executor utility code such as "ExecTypeFromTL" should be
|
||||
@@ -228,7 +228,9 @@ FreeTupleDesc(TupleDesc tupdesc)
|
||||
bool
|
||||
equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
{
|
||||
int i;
|
||||
int i,
|
||||
j,
|
||||
n;
|
||||
|
||||
if (tupdesc1->natts != tupdesc2->natts)
|
||||
return false;
|
||||
@@ -240,7 +242,9 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
/*
|
||||
* We do not need to check every single field here, and in fact
|
||||
* some fields such as attdispersion probably shouldn't be
|
||||
* compared.
|
||||
* compared. We can also disregard attnum (it was used to
|
||||
* place the row in the attrs array) and everything derived
|
||||
* from the column datatype.
|
||||
*/
|
||||
if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
|
||||
return false;
|
||||
@@ -260,32 +264,53 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
|
||||
if (constr2 == NULL)
|
||||
return false;
|
||||
if (constr1->num_defval != constr2->num_defval)
|
||||
if (constr1->has_not_null != constr2->has_not_null)
|
||||
return false;
|
||||
for (i = 0; i < (int) constr1->num_defval; i++)
|
||||
n = constr1->num_defval;
|
||||
if (n != (int) constr2->num_defval)
|
||||
return false;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
AttrDefault *defval1 = constr1->defval + i;
|
||||
AttrDefault *defval2 = constr2->defval + i;
|
||||
AttrDefault *defval2 = constr2->defval;
|
||||
|
||||
if (defval1->adnum != defval2->adnum)
|
||||
/*
|
||||
* We can't assume that the items are always read from the
|
||||
* system catalogs in the same order; so use the adnum field to
|
||||
* identify the matching item to compare.
|
||||
*/
|
||||
for (j = 0; j < n; defval2++, j++)
|
||||
{
|
||||
if (defval1->adnum == defval2->adnum)
|
||||
break;
|
||||
}
|
||||
if (j >= n)
|
||||
return false;
|
||||
if (strcmp(defval1->adbin, defval2->adbin) != 0)
|
||||
return false;
|
||||
}
|
||||
if (constr1->num_check != constr2->num_check)
|
||||
n = constr1->num_check;
|
||||
if (n != (int) constr2->num_check)
|
||||
return false;
|
||||
for (i = 0; i < (int) constr1->num_check; i++)
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
ConstrCheck *check1 = constr1->check + i;
|
||||
ConstrCheck *check2 = constr2->check + i;
|
||||
ConstrCheck *check2 = constr2->check;
|
||||
|
||||
if (strcmp(check1->ccname, check2->ccname) != 0)
|
||||
return false;
|
||||
if (strcmp(check1->ccbin, check2->ccbin) != 0)
|
||||
/*
|
||||
* Similarly, don't assume that the checks are always read
|
||||
* in the same order; match them up by name and contents.
|
||||
* (The name *should* be unique, but...)
|
||||
*/
|
||||
for (j = 0; j < n; check2++, j++)
|
||||
{
|
||||
if (strcmp(check1->ccname, check2->ccname) == 0 &&
|
||||
strcmp(check1->ccbin, check2->ccbin) == 0)
|
||||
break;
|
||||
}
|
||||
if (j >= n)
|
||||
return false;
|
||||
}
|
||||
if (constr1->has_not_null != constr2->has_not_null)
|
||||
return false;
|
||||
}
|
||||
else if (tupdesc2->constr != NULL)
|
||||
return false;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.63 2000/10/21 15:43:09 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.64 2000/11/08 22:09:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -266,13 +266,12 @@ gistbuild(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid hrelid = RelationGetRelid(heap);
|
||||
Oid irelid = RelationGetRelid(index);
|
||||
bool inplace = IsReindexProcessing();
|
||||
|
||||
heap_close(heap, NoLock);
|
||||
index_close(index);
|
||||
UpdateStats(hrelid, nhtups, inplace);
|
||||
UpdateStats(irelid, nitups, inplace);
|
||||
if (oldPred != NULL && !inplace)
|
||||
UpdateStats(hrelid, nhtups);
|
||||
UpdateStats(irelid, nitups);
|
||||
if (oldPred != NULL)
|
||||
{
|
||||
if (nitups == nhtups)
|
||||
pred = NULL;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.43 2000/10/21 15:43:11 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.44 2000/11/08 22:09:54 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This file contains only the public interface routines.
|
||||
@@ -217,13 +217,12 @@ hashbuild(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid hrelid = RelationGetRelid(heap);
|
||||
Oid irelid = RelationGetRelid(index);
|
||||
bool inplace = IsReindexProcessing();
|
||||
|
||||
heap_close(heap, NoLock);
|
||||
index_close(index);
|
||||
UpdateStats(hrelid, nhtups, inplace);
|
||||
UpdateStats(irelid, nitups, inplace);
|
||||
if (oldPred != NULL && !inplace)
|
||||
UpdateStats(hrelid, nhtups);
|
||||
UpdateStats(irelid, nitups);
|
||||
if (oldPred != NULL)
|
||||
{
|
||||
if (nitups == nhtups)
|
||||
pred = NULL;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.92 2000/10/29 18:33:39 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.93 2000/11/08 22:09:54 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -780,20 +780,14 @@ heap_beginscan(Relation relation,
|
||||
|
||||
/* ----------------
|
||||
* increment relation ref count while scanning relation
|
||||
*
|
||||
* This is just to make really sure the relcache entry won't go away
|
||||
* while the scan has a pointer to it. Caller should be holding the
|
||||
* rel open anyway, so this is redundant in all normal scenarios...
|
||||
* ----------------
|
||||
*/
|
||||
RelationIncrementReferenceCount(relation);
|
||||
|
||||
/* ----------------
|
||||
* Acquire AccessShareLock for the duration of the scan
|
||||
*
|
||||
* Note: we could get an SI inval message here and consequently have
|
||||
* to rebuild the relcache entry. The refcount increment above
|
||||
* ensures that we will rebuild it and not just flush it...
|
||||
* ----------------
|
||||
*/
|
||||
LockRelation(relation, AccessShareLock);
|
||||
|
||||
/* XXX someday assert SelfTimeQual if relkind == RELKIND_UNCATALOGED */
|
||||
if (relation->rd_rel->relkind == RELKIND_UNCATALOGED)
|
||||
snapshot = SnapshotSelf;
|
||||
@@ -809,13 +803,11 @@ heap_beginscan(Relation relation,
|
||||
scan->rs_snapshot = snapshot;
|
||||
scan->rs_nkeys = (short) nkeys;
|
||||
|
||||
/*
|
||||
* we do this here instead of in initscan() because heap_rescan
|
||||
* also calls initscan() and we don't want to allocate memory again
|
||||
*/
|
||||
if (nkeys)
|
||||
|
||||
/*
|
||||
* we do this here instead of in initscan() because heap_rescan
|
||||
* also calls initscan() and we don't want to allocate memory
|
||||
* again
|
||||
*/
|
||||
scan->rs_key = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys);
|
||||
else
|
||||
scan->rs_key = NULL;
|
||||
@@ -841,8 +833,6 @@ heap_rescan(HeapScanDesc scan,
|
||||
IncrHeapAccessStat(local_rescan);
|
||||
IncrHeapAccessStat(global_rescan);
|
||||
|
||||
/* Note: set relation level read lock is still set */
|
||||
|
||||
/* ----------------
|
||||
* unpin scan buffers
|
||||
* ----------------
|
||||
@@ -853,7 +843,7 @@ heap_rescan(HeapScanDesc scan,
|
||||
* reinitialize scan descriptor
|
||||
* ----------------
|
||||
*/
|
||||
scan->rs_atend = (bool) scanFromEnd;
|
||||
scan->rs_atend = scanFromEnd;
|
||||
initscan(scan, scan->rs_rd, scanFromEnd, scan->rs_nkeys, key);
|
||||
}
|
||||
|
||||
@@ -882,12 +872,6 @@ heap_endscan(HeapScanDesc scan)
|
||||
*/
|
||||
unpinscan(scan);
|
||||
|
||||
/* ----------------
|
||||
* Release AccessShareLock acquired by heap_beginscan()
|
||||
* ----------------
|
||||
*/
|
||||
UnlockRelation(scan->rs_rd, AccessShareLock);
|
||||
|
||||
/* ----------------
|
||||
* decrement relation reference count and free scan descriptor storage
|
||||
* ----------------
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.69 2000/11/01 20:39:58 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.70 2000/11/08 22:09:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -340,19 +340,16 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid hrelid = RelationGetRelid(heap);
|
||||
Oid irelid = RelationGetRelid(index);
|
||||
bool inplace = IsReindexProcessing();
|
||||
|
||||
heap_close(heap, NoLock);
|
||||
index_close(index);
|
||||
|
||||
UpdateStats(hrelid, nhtups, inplace);
|
||||
UpdateStats(irelid, nitups, inplace);
|
||||
UpdateStats(hrelid, nhtups);
|
||||
UpdateStats(irelid, nitups);
|
||||
if (oldPred != NULL)
|
||||
{
|
||||
if (nitups == nhtups)
|
||||
pred = NULL;
|
||||
if (!inplace)
|
||||
UpdateIndexPredicate(irelid, oldPred, pred);
|
||||
UpdateIndexPredicate(irelid, oldPred, pred);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.54 2000/10/21 15:43:20 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.55 2000/11/08 22:09:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -237,13 +237,12 @@ rtbuild(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid hrelid = RelationGetRelid(heap);
|
||||
Oid irelid = RelationGetRelid(index);
|
||||
bool inplace = IsReindexProcessing();
|
||||
|
||||
heap_close(heap, NoLock);
|
||||
index_close(index);
|
||||
UpdateStats(hrelid, nhtups, inplace);
|
||||
UpdateStats(irelid, nitups, inplace);
|
||||
if (oldPred != NULL && !inplace)
|
||||
UpdateStats(hrelid, nhtups);
|
||||
UpdateStats(irelid, nitups);
|
||||
if (oldPred != NULL)
|
||||
{
|
||||
if (nitups == nhtups)
|
||||
pred = NULL;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.31 2000/11/03 11:39:35 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.32 2000/11/08 22:09:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -130,7 +130,7 @@ VariableRelationPutNextXid(TransactionId xid)
|
||||
|
||||
TransactionIdStore(xid, &(var->nextXidData));
|
||||
|
||||
FlushBuffer(buf, TRUE);
|
||||
FlushBuffer(buf, true, true);
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.80 2000/11/05 22:50:19 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.81 2000/11/08 22:09:55 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -167,6 +167,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "storage/proc.h"
|
||||
#include "storage/sinval.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/inval.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/portal.h"
|
||||
@@ -1105,6 +1106,9 @@ CommitTransaction(void)
|
||||
}
|
||||
|
||||
RelationPurgeLocalRelation(true);
|
||||
AtEOXact_temp_relations(true);
|
||||
smgrDoPendingDeletes(true);
|
||||
|
||||
AtEOXact_SPI();
|
||||
AtEOXact_nbtree();
|
||||
AtCommit_Cache();
|
||||
@@ -1181,8 +1185,11 @@ AbortTransaction(void)
|
||||
CloseSequences();
|
||||
AtEOXact_portals();
|
||||
RecordTransactionAbort();
|
||||
|
||||
RelationPurgeLocalRelation(false);
|
||||
remove_temp_rel_in_myxid();
|
||||
AtEOXact_temp_relations(false);
|
||||
smgrDoPendingDeletes(false);
|
||||
|
||||
AtEOXact_SPI();
|
||||
AtEOXact_nbtree();
|
||||
AtAbort_Cache();
|
||||
|
||||
@@ -171,9 +171,8 @@ XLogOpenLogRelation(void)
|
||||
sprintf(RelationGetPhysicalRelationName(logRelation), "pg_log");
|
||||
logRelation->rd_node.tblNode = InvalidOid;
|
||||
logRelation->rd_node.relNode = RelOid_pg_log;
|
||||
logRelation->rd_unlinked = false; /* must exists */
|
||||
logRelation->rd_fd = -1;
|
||||
logRelation->rd_fd = smgropen(DEFAULT_SMGR, logRelation);
|
||||
logRelation->rd_fd = smgropen(DEFAULT_SMGR, logRelation, false);
|
||||
if (logRelation->rd_fd < 0)
|
||||
elog(STOP, "XLogOpenLogRelation: failed to open pg_log");
|
||||
LogRelation = logRelation;
|
||||
@@ -384,9 +383,9 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
||||
|
||||
hentry->rdesc = res;
|
||||
|
||||
res->reldata.rd_unlinked = true; /* look smgropen */
|
||||
res->reldata.rd_fd = -1;
|
||||
res->reldata.rd_fd = smgropen(DEFAULT_SMGR, &(res->reldata));
|
||||
res->reldata.rd_fd = smgropen(DEFAULT_SMGR, &(res->reldata),
|
||||
true /* allow failure */);
|
||||
}
|
||||
|
||||
res->moreRecently = &(_xlrelarr[0]);
|
||||
|
||||
Reference in New Issue
Block a user