mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
Mega-commit to make heap_open/heap_openr/heap_close take an
additional argument specifying the kind of lock to acquire/release (or 'NoLock' to do no lock processing). Ensure that all relations are locked with some appropriate lock level before being examined --- this ensures that relevant shared-inval messages have been processed and should prevent problems caused by concurrent VACUUM. Fix several bugs having to do with mismatched increment/decrement of relation ref count and mismatched heap_open/close (which amounts to the same thing). A bogus ref count on a relation doesn't matter much *unless* a SI Inval message happens to arrive at the wrong time, which is probably why we got away with this sloppiness for so long. Repair missing grab of AccessExclusiveLock in DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi. Recommend 'make clean all' after pulling this update; I modified the Relation struct layout slightly. Will post further discussion to pghackers list shortly.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: rel.h,v 1.25 1999/07/16 17:07:40 momjian Exp $
|
||||
* $Id: rel.h,v 1.26 1999/09/18 19:08:25 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -20,6 +20,26 @@
|
||||
#include "rewrite/prs2lock.h"
|
||||
#include "storage/fd.h"
|
||||
|
||||
|
||||
/*
|
||||
* LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
|
||||
* to declare them here so we can have a LockInfoData field in a Relation.
|
||||
*/
|
||||
|
||||
typedef struct LockRelId
|
||||
{
|
||||
Oid relId; /* a relation identifier */
|
||||
Oid dbId; /* a database identifier */
|
||||
} LockRelId;
|
||||
|
||||
typedef struct LockInfoData
|
||||
{
|
||||
LockRelId lockRelId;
|
||||
} LockInfoData;
|
||||
|
||||
typedef LockInfoData *LockInfo;
|
||||
|
||||
|
||||
typedef struct Trigger
|
||||
{
|
||||
char *tgname;
|
||||
@@ -44,20 +64,21 @@ typedef struct TriggerDesc
|
||||
Trigger *triggers;
|
||||
} TriggerDesc;
|
||||
|
||||
|
||||
typedef struct RelationData
|
||||
{
|
||||
File rd_fd; /* open file descriptor */
|
||||
int rd_nblocks; /* number of blocks in rel */
|
||||
uint16 rd_refcnt; /* reference count */
|
||||
bool rd_myxactonly; /* uses the local buffer mgr */
|
||||
bool rd_myxactonly; /* rel uses the local buffer mgr */
|
||||
bool rd_isnailed; /* rel is nailed in cache */
|
||||
bool rd_isnoname; /* rel has no name */
|
||||
bool rd_nonameunlinked; /* noname rel already unlinked */
|
||||
Form_pg_am rd_am; /* AM tuple */
|
||||
Form_pg_class rd_rel; /* RELATION tuple */
|
||||
Oid rd_id; /* relations's object id */
|
||||
Pointer lockInfo; /* ptr. to misc. info. */
|
||||
TupleDesc rd_att; /* tuple desciptor */
|
||||
Oid rd_id; /* relation's object id */
|
||||
LockInfoData rd_lockInfo; /* lock manager's info for locking relation */
|
||||
TupleDesc rd_att; /* tuple descriptor */
|
||||
RuleLock *rd_rules; /* rewrite rules */
|
||||
IndexStrategy rd_istrat;
|
||||
RegProcedure *rd_support;
|
||||
@@ -66,6 +87,7 @@ typedef struct RelationData
|
||||
|
||||
typedef RelationData *Relation;
|
||||
|
||||
|
||||
/* ----------------
|
||||
* RelationPtr is used in the executor to support index scans
|
||||
* where we have to keep track of several index relations in an
|
||||
@@ -74,7 +96,6 @@ typedef RelationData *Relation;
|
||||
*/
|
||||
typedef Relation *RelationPtr;
|
||||
|
||||
#define InvalidRelation ((Relation)NULL)
|
||||
|
||||
/*
|
||||
* RelationIsValid
|
||||
@@ -82,6 +103,8 @@ typedef Relation *RelationPtr;
|
||||
*/
|
||||
#define RelationIsValid(relation) PointerIsValid(relation)
|
||||
|
||||
#define InvalidRelation ((Relation) NULL)
|
||||
|
||||
/*
|
||||
* RelationGetSystemPort
|
||||
* Returns system port of a relation.
|
||||
@@ -91,13 +114,6 @@ typedef Relation *RelationPtr;
|
||||
*/
|
||||
#define RelationGetSystemPort(relation) ((relation)->rd_fd)
|
||||
|
||||
/*
|
||||
* RelationGetLockInfo
|
||||
* Returns the lock information structure in the reldesc
|
||||
*
|
||||
*/
|
||||
#define RelationGetLockInfo(relation) ((relation)->lockInfo)
|
||||
|
||||
/*
|
||||
* RelationHasReferenceCountZero
|
||||
* True iff relation reference count is zero.
|
||||
@@ -112,13 +128,13 @@ typedef Relation *RelationPtr;
|
||||
* RelationSetReferenceCount
|
||||
* Sets relation reference count.
|
||||
*/
|
||||
#define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = count)
|
||||
#define RelationSetReferenceCount(relation,count) ((relation)->rd_refcnt = (count))
|
||||
|
||||
/*
|
||||
* RelationIncrementReferenceCount
|
||||
* Increments relation reference count.
|
||||
*/
|
||||
#define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1);
|
||||
#define RelationIncrementReferenceCount(relation) ((relation)->rd_refcnt += 1)
|
||||
|
||||
/*
|
||||
* RelationDecrementReferenceCount
|
||||
@@ -135,7 +151,6 @@ typedef Relation *RelationPtr;
|
||||
*/
|
||||
#define RelationGetForm(relation) ((relation)->rd_rel)
|
||||
|
||||
|
||||
/*
|
||||
* RelationGetRelid
|
||||
*
|
||||
@@ -151,7 +166,6 @@ typedef Relation *RelationPtr;
|
||||
*/
|
||||
#define RelationGetFile(relation) ((relation)->rd_fd)
|
||||
|
||||
|
||||
/*
|
||||
* RelationGetRelationName
|
||||
*
|
||||
@@ -160,21 +174,19 @@ typedef Relation *RelationPtr;
|
||||
#define RelationGetRelationName(relation) (&(relation)->rd_rel->relname)
|
||||
|
||||
/*
|
||||
* RelationGetRelationName
|
||||
* RelationGetNumberOfAttributes
|
||||
*
|
||||
* Returns a the number of attributes.
|
||||
* Returns the number of attributes.
|
||||
*/
|
||||
#define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
|
||||
|
||||
/*
|
||||
* RelationGetDescr
|
||||
* Returns tuple descriptor for a relation.
|
||||
*
|
||||
* Note:
|
||||
* Assumes relation descriptor is valid.
|
||||
*/
|
||||
#define RelationGetDescr(relation) ((relation)->rd_att)
|
||||
|
||||
|
||||
extern IndexStrategy RelationGetIndexStrategy(Relation relation);
|
||||
|
||||
extern void RelationSetIndexSupport(Relation relation, IndexStrategy strategy,
|
||||
|
Reference in New Issue
Block a user