mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +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:
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: analyze.c,v 1.118 1999/08/21 03:48:55 tgl Exp $
|
||||
* $Id: analyze.c,v 1.119 1999/09/18 19:07:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ parse_analyze(List *pl, ParseState *parentParseState)
|
||||
|
||||
parsetree = transformStmt(pstate, lfirst(pl));
|
||||
if (pstate->p_target_relation != NULL)
|
||||
heap_close(pstate->p_target_relation);
|
||||
heap_close(pstate->p_target_relation, AccessShareLock);
|
||||
pstate->p_target_relation = NULL;
|
||||
pstate->p_target_rangetblentry = NULL;
|
||||
|
||||
@@ -73,7 +73,7 @@ parse_analyze(List *pl, ParseState *parentParseState)
|
||||
result = lappend(result,
|
||||
transformStmt(pstate, lfirst(extras_before)));
|
||||
if (pstate->p_target_relation != NULL)
|
||||
heap_close(pstate->p_target_relation);
|
||||
heap_close(pstate->p_target_relation, AccessShareLock);
|
||||
pstate->p_target_relation = NULL;
|
||||
pstate->p_target_rangetblentry = NULL;
|
||||
extras_before = lnext(extras_before);
|
||||
@@ -86,7 +86,7 @@ parse_analyze(List *pl, ParseState *parentParseState)
|
||||
result = lappend(result,
|
||||
transformStmt(pstate, lfirst(extras_after)));
|
||||
if (pstate->p_target_relation != NULL)
|
||||
heap_close(pstate->p_target_relation);
|
||||
heap_close(pstate->p_target_relation, AccessShareLock);
|
||||
pstate->p_target_relation = NULL;
|
||||
pstate->p_target_rangetblentry = NULL;
|
||||
extras_after = lnext(extras_after);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.44 1999/08/21 03:48:55 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.45 1999/09/18 19:07:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -75,11 +75,11 @@ setTargetTable(ParseState *pstate, char *relname)
|
||||
|
||||
/* This could only happen for multi-action rules */
|
||||
if (pstate->p_target_relation != NULL)
|
||||
heap_close(pstate->p_target_relation);
|
||||
heap_close(pstate->p_target_relation, AccessShareLock);
|
||||
|
||||
pstate->p_target_rangetblentry = rte;
|
||||
pstate->p_target_relation = heap_open(rte->relid);
|
||||
/* will close relation later */
|
||||
pstate->p_target_relation = heap_open(rte->relid, AccessShareLock);
|
||||
/* will close relation later, see analyze.c */
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.54 1999/08/22 20:15:03 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.55 1999/09/18 19:07:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ agg_get_candidates(char *aggname,
|
||||
fmgr_info(F_NAMEEQ, (FmgrInfo *) &aggKey[0].sk_func);
|
||||
aggKey[0].sk_argument = NameGetDatum(aggname);
|
||||
|
||||
pg_aggregate_desc = heap_openr(AggregateRelationName);
|
||||
pg_aggregate_desc = heap_openr(AggregateRelationName, AccessShareLock);
|
||||
pg_aggregate_scan = heap_beginscan(pg_aggregate_desc,
|
||||
0,
|
||||
SnapshotSelf, /* ??? */
|
||||
@@ -159,7 +159,7 @@ agg_get_candidates(char *aggname,
|
||||
}
|
||||
|
||||
heap_endscan(pg_aggregate_scan);
|
||||
heap_close(pg_aggregate_desc);
|
||||
heap_close(pg_aggregate_desc, AccessShareLock);
|
||||
|
||||
return ncandidates;
|
||||
} /* agg_get_candidates() */
|
||||
@@ -310,11 +310,11 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
|
||||
if (attisset)
|
||||
{
|
||||
toid = exprType(first_arg);
|
||||
rd = heap_openr(typeidTypeName(toid));
|
||||
rd = heap_openr(typeidTypeName(toid), NoLock);
|
||||
if (RelationIsValid(rd))
|
||||
{
|
||||
relname = RelationGetRelationName(rd)->data;
|
||||
heap_close(rd);
|
||||
heap_close(rd, NoLock);
|
||||
}
|
||||
else
|
||||
elog(ERROR, "Type '%s' is not a relation type",
|
||||
@@ -646,7 +646,7 @@ func_get_candidates(char *funcname, int nargs)
|
||||
CandidateList current_candidate;
|
||||
int i;
|
||||
|
||||
heapRelation = heap_openr(ProcedureRelationName);
|
||||
heapRelation = heap_openr(ProcedureRelationName, AccessShareLock);
|
||||
ScanKeyEntryInitialize(&skey,
|
||||
(bits16) 0x0,
|
||||
(AttrNumber) 1,
|
||||
@@ -690,7 +690,7 @@ func_get_candidates(char *funcname, int nargs)
|
||||
|
||||
index_endscan(sd);
|
||||
index_close(idesc);
|
||||
heap_close(heapRelation);
|
||||
heap_close(heapRelation, AccessShareLock);
|
||||
|
||||
return candidates;
|
||||
}
|
||||
@@ -1086,7 +1086,7 @@ find_inheritors(Oid relid, Oid **supervec)
|
||||
visited = DLNewList();
|
||||
|
||||
|
||||
inhrel = heap_openr(InheritsRelationName);
|
||||
inhrel = heap_openr(InheritsRelationName, AccessShareLock);
|
||||
inhtupdesc = RelationGetDescr(inhrel);
|
||||
|
||||
/*
|
||||
@@ -1140,12 +1140,12 @@ find_inheritors(Oid relid, Oid **supervec)
|
||||
|
||||
if (qentry != (SuperQE *) NULL)
|
||||
{
|
||||
|
||||
/* save the type id, rather than the relation id */
|
||||
if ((rd = heap_open(qentry->sqe_relid)) == (Relation) NULL)
|
||||
rd = heap_open(qentry->sqe_relid, NoLock);
|
||||
if (! RelationIsValid(rd))
|
||||
elog(ERROR, "Relid %u does not exist", qentry->sqe_relid);
|
||||
qentry->sqe_relid = typeTypeId(typenameType(RelationGetRelationName(rd)->data));
|
||||
heap_close(rd);
|
||||
heap_close(rd, NoLock);
|
||||
|
||||
DLAddTail(visited, qe);
|
||||
|
||||
@@ -1153,7 +1153,7 @@ find_inheritors(Oid relid, Oid **supervec)
|
||||
}
|
||||
} while (qentry != (SuperQE *) NULL);
|
||||
|
||||
heap_close(inhrel);
|
||||
heap_close(inhrel, AccessShareLock);
|
||||
|
||||
if (nvisited > 0)
|
||||
{
|
||||
@@ -1370,16 +1370,13 @@ ParseComplexProjection(ParseState *pstate,
|
||||
*/
|
||||
|
||||
/* add a tlist to the func node and return the Iter */
|
||||
rd = heap_openr(typeidTypeName(argtype));
|
||||
rd = heap_openr(typeidTypeName(argtype), NoLock);
|
||||
if (RelationIsValid(rd))
|
||||
{
|
||||
relid = RelationGetRelid(rd);
|
||||
heap_close(rd);
|
||||
}
|
||||
if (RelationIsValid(rd))
|
||||
{
|
||||
func->func_tlist = setup_tlist(funcname, argrelid);
|
||||
iter->itertype = attnumTypeId(rd, attnum);
|
||||
heap_close(rd, NoLock);
|
||||
return (Node *) iter;
|
||||
}
|
||||
else
|
||||
@@ -1427,16 +1424,12 @@ ParseComplexProjection(ParseState *pstate,
|
||||
{
|
||||
|
||||
/* add a tlist to the func node */
|
||||
rd = heap_openr(typeidTypeName(argtype));
|
||||
if (RelationIsValid(rd))
|
||||
{
|
||||
relid = RelationGetRelid(rd);
|
||||
heap_close(rd);
|
||||
}
|
||||
rd = heap_openr(typeidTypeName(argtype), NoLock);
|
||||
if (RelationIsValid(rd))
|
||||
{
|
||||
Expr *newexpr;
|
||||
|
||||
relid = RelationGetRelid(rd);
|
||||
funcnode->func_tlist = setup_tlist(funcname, argrelid);
|
||||
funcnode->functype = attnumTypeId(rd, attnum);
|
||||
|
||||
@@ -1446,8 +1439,11 @@ ParseComplexProjection(ParseState *pstate,
|
||||
newexpr->oper = (Node *) funcnode;
|
||||
newexpr->args = expr->args;
|
||||
|
||||
heap_close(rd, NoLock);
|
||||
|
||||
return (Node *) newexpr;
|
||||
}
|
||||
/* XXX why not an error condition if it's not there? */
|
||||
|
||||
}
|
||||
|
||||
@@ -1461,18 +1457,19 @@ ParseComplexProjection(ParseState *pstate,
|
||||
* If the Param is a complex type, this could be a
|
||||
* projection
|
||||
*/
|
||||
rd = heap_openr(typeidTypeName(param->paramtype));
|
||||
rd = heap_openr(typeidTypeName(param->paramtype), NoLock);
|
||||
if (RelationIsValid(rd))
|
||||
{
|
||||
relid = RelationGetRelid(rd);
|
||||
heap_close(rd);
|
||||
if ((attnum = get_attnum(relid, funcname))
|
||||
!= InvalidAttrNumber)
|
||||
{
|
||||
param->paramtype = attnumTypeId(rd, attnum);
|
||||
param->param_tlist = setup_tlist(funcname, relid);
|
||||
heap_close(rd, NoLock);
|
||||
return (Node *) param;
|
||||
}
|
||||
heap_close(rd, NoLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.31 1999/08/26 04:59:15 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.32 1999/09/18 19:07:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -75,7 +75,6 @@ binary_oper_get_candidates(char *opname,
|
||||
HeapScanDesc pg_operator_scan;
|
||||
HeapTuple tup;
|
||||
Form_pg_operator oper;
|
||||
int nkeys;
|
||||
int ncandidates = 0;
|
||||
ScanKeyData opKey[3];
|
||||
|
||||
@@ -91,13 +90,11 @@ binary_oper_get_candidates(char *opname,
|
||||
F_CHAREQ,
|
||||
CharGetDatum('b'));
|
||||
|
||||
nkeys = 2;
|
||||
|
||||
pg_operator_desc = heap_openr(OperatorRelationName);
|
||||
pg_operator_desc = heap_openr(OperatorRelationName, AccessShareLock);
|
||||
pg_operator_scan = heap_beginscan(pg_operator_desc,
|
||||
0,
|
||||
SnapshotSelf, /* ??? */
|
||||
nkeys,
|
||||
2,
|
||||
opKey);
|
||||
|
||||
while (HeapTupleIsValid(tup = heap_getnext(pg_operator_scan, 0)))
|
||||
@@ -114,7 +111,7 @@ binary_oper_get_candidates(char *opname,
|
||||
}
|
||||
|
||||
heap_endscan(pg_operator_scan);
|
||||
heap_close(pg_operator_desc);
|
||||
heap_close(pg_operator_desc, AccessShareLock);
|
||||
|
||||
return ncandidates;
|
||||
} /* binary_oper_get_candidates() */
|
||||
@@ -522,7 +519,7 @@ unary_oper_get_candidates(char *op,
|
||||
fmgr_info(F_CHAREQ, (FmgrInfo *) &opKey[1].sk_func);
|
||||
opKey[1].sk_argument = CharGetDatum(rightleft);
|
||||
|
||||
pg_operator_desc = heap_openr(OperatorRelationName);
|
||||
pg_operator_desc = heap_openr(OperatorRelationName, AccessShareLock);
|
||||
pg_operator_scan = heap_beginscan(pg_operator_desc,
|
||||
0,
|
||||
SnapshotSelf, /* ??? */
|
||||
@@ -545,7 +542,7 @@ unary_oper_get_candidates(char *op,
|
||||
}
|
||||
|
||||
heap_endscan(pg_operator_scan);
|
||||
heap_close(pg_operator_desc);
|
||||
heap_close(pg_operator_desc, AccessShareLock);
|
||||
|
||||
return ncandidates;
|
||||
} /* unary_oper_get_candidates() */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.26 1999/07/19 00:26:20 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.27 1999/09/18 19:07:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -202,14 +202,9 @@ addRangeTableEntry(ParseState *pstate,
|
||||
rte->relname = pstrdup(relname);
|
||||
rte->refname = pstrdup(refname);
|
||||
|
||||
relation = heap_openr(relname);
|
||||
if (relation == NULL)
|
||||
elog(ERROR, "%s: %s",
|
||||
relname, aclcheck_error_strings[ACLCHECK_NO_CLASS]);
|
||||
|
||||
relation = heap_openr(relname, AccessShareLock);
|
||||
rte->relid = RelationGetRelid(relation);
|
||||
|
||||
heap_close(relation);
|
||||
heap_close(relation, AccessShareLock);
|
||||
|
||||
/*
|
||||
* Flags - zero or more from inheritance,union,version or recursive
|
||||
@@ -246,10 +241,7 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno)
|
||||
if (rte == NULL)
|
||||
rte = addRangeTableEntry(pstate, relname, refname, FALSE, FALSE);
|
||||
|
||||
rel = heap_open(rte->relid);
|
||||
if (rel == NULL)
|
||||
elog(ERROR, "Unable to expand all -- heap_open failed on %s",
|
||||
rte->refname);
|
||||
rel = heap_open(rte->relid, AccessShareLock);
|
||||
|
||||
maxattrs = RelationGetNumberOfAttributes(rel);
|
||||
|
||||
@@ -278,7 +270,7 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno)
|
||||
te_list = lappend(te_list, te);
|
||||
}
|
||||
|
||||
heap_close(rel);
|
||||
heap_close(rel, AccessShareLock);
|
||||
|
||||
return te_list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user