*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.94 1999/09/04 22:00:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.95 1999/09/05 17:43:47 tgl Exp $
*
*
* INTERFACE ROUTINES
#include "miscadmin.h"
#include "access/heapam.h"
+#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/heap.h"
bool istemp = (get_temp_rel_by_name(relname) != NULL);
/* ----------------
- * first open the relation. if the relation does exist,
+ * first open the relation. if the relation doesn't exist,
* heap_openr() returns NULL.
* ----------------
*/
elog(ERROR, "System relation '%s' cannot be destroyed",
&rel->rd_rel->relname);
+ /* ----------------
+ * We do not allow DROP TABLE within a transaction block, because
+ * if the transaction is later rolled back there would be no way to
+ * undo the unlink of the relation's physical file. The sole exception
+ * is for relations created in the current transaction, since the post-
+ * abort state would be that they don't exist anyway.
+ * ----------------
+ */
+ if (IsTransactionBlock() && ! rel->rd_myxactonly)
+ elog(ERROR, "Cannot destroy relation within a transaction block");
+
/* ----------------
* remove inheritance information
* ----------------
*/
ReleaseRelationBuffers(rel);
- /* ----------------
- * flush the relation from the relcache
- * ----------------
- * Does nothing!!! Flushing moved below. - vadim 06/04/97
- RelationIdInvalidateRelationCacheByRelationId(rel->rd_id);
- */
-
RemoveConstraints(rel);
/* ----------------
- * unlink the relation and finish up.
+ * unlink the relation's physical file and finish up.
* ----------------
*/
if (!(rel->rd_isnoname) || !(rel->rd_nonameunlinked))
heap_close(rel);
+ /* ----------------
+ * flush the relation from the relcache
+ * ----------------
+ */
RelationForgetRelation(rid);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.88 1999/09/04 22:00:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.89 1999/09/05 17:43:47 tgl Exp $
*
*
* INTERFACE ROUTINES
#include "access/genam.h"
#include "access/heapam.h"
#include "access/istrat.h"
+#include "access/xact.h"
#include "bootstrap/bootstrap.h"
#include "catalog/catname.h"
#include "catalog/heap.h"
/* Open now to obtain lock by referencing table? bjm */
userindexRelation = index_open(indexId);
+ /* ----------------
+ * We do not allow DROP INDEX within a transaction block, because
+ * if the transaction is later rolled back there would be no way to
+ * undo the unlink of the relation's physical file. The sole exception
+ * is for relations created in the current transaction, since the post-
+ * abort state would be that they don't exist anyway.
+ * ----------------
+ */
+ if (IsTransactionBlock() && ! userindexRelation->rd_myxactonly)
+ elog(ERROR, "Cannot destroy index within a transaction block");
+
/* ----------------
* fix RELATION relation
* ----------------
ReleaseRelationBuffers(userindexRelation);
if (smgrunlink(DEFAULT_SMGR, userindexRelation) != SM_SUCCESS)
- elog(ERROR, "amdestroyr: unlink: %m");
+ elog(ERROR, "index_destroy: unlink: %m");
index_close(userindexRelation);
RelationForgetRelation(RelationGetRelid(userindexRelation));