diff options
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/analyze.c | 36 | ||||
-rw-r--r-- | src/backend/parser/parse_clause.c | 5 | ||||
-rw-r--r-- | src/backend/parser/parse_relation.c | 30 |
3 files changed, 27 insertions, 44 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 4dad0ae80af..03f53db2c96 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.318 2005/04/07 01:51:38 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.319 2005/04/13 16:50:54 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1536,6 +1536,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt, List **extras_before, List **extras_after) { Query *qry; + Relation rel; RangeTblEntry *oldrte; RangeTblEntry *newrte; @@ -1547,11 +1548,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt, * To avoid deadlock, make sure the first thing we do is grab * AccessExclusiveLock on the target relation. This will be needed by * DefineQueryRewrite(), and we don't want to grab a lesser lock - * beforehand. We don't need to hold a refcount on the relcache - * entry, however. + * beforehand. */ - heap_close(heap_openrv(stmt->relation, AccessExclusiveLock), - NoLock); + rel = heap_openrv(stmt->relation, AccessExclusiveLock); /* * NOTE: 'OLD' must always have a varno equal to 1 and 'NEW' equal to @@ -1559,12 +1558,12 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt, * rule qualification. */ Assert(pstate->p_rtable == NIL); - oldrte = addRangeTableEntry(pstate, stmt->relation, - makeAlias("*OLD*", NIL), - false, true); - newrte = addRangeTableEntry(pstate, stmt->relation, - makeAlias("*NEW*", NIL), - false, true); + oldrte = addRangeTableEntryForRelation(pstate, rel, + makeAlias("*OLD*", NIL), + false, true); + newrte = addRangeTableEntryForRelation(pstate, rel, + makeAlias("*NEW*", NIL), + false, true); /* Must override addRangeTableEntry's default access-check flags */ oldrte->requiredPerms = 0; newrte->requiredPerms = 0; @@ -1659,12 +1658,12 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt, * or they won't be accessible at all. We decide later * whether to put them in the joinlist. */ - oldrte = addRangeTableEntry(sub_pstate, stmt->relation, - makeAlias("*OLD*", NIL), - false, false); - newrte = addRangeTableEntry(sub_pstate, stmt->relation, - makeAlias("*NEW*", NIL), - false, false); + oldrte = addRangeTableEntryForRelation(sub_pstate, rel, + makeAlias("*OLD*", NIL), + false, false); + newrte = addRangeTableEntryForRelation(sub_pstate, rel, + makeAlias("*NEW*", NIL), + false, false); oldrte->requiredPerms = 0; newrte->requiredPerms = 0; addRTEtoQuery(sub_pstate, oldrte, false, true); @@ -1791,6 +1790,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt, stmt->actions = newactions; } + /* Close relation, but keep the exclusive lock */ + heap_close(rel, NoLock); + return qry; } diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 6d13e485b2e..42960d43760 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.139 2005/04/06 16:34:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.140 2005/04/13 16:50:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -144,7 +144,8 @@ setTargetTable(ParseState *pstate, RangeVar *relation, /* * Now build an RTE. */ - rte = addRangeTableEntry(pstate, relation, NULL, inh, false); + rte = addRangeTableEntryForRelation(pstate, pstate->p_target_relation, + NULL, inh, false); pstate->p_target_rangetblentry = rte; /* assume new rte is at end */ diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index edd59917e93..b68ae005150 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.105 2005/04/07 01:51:39 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.106 2005/04/13 16:50:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -809,34 +809,21 @@ addRangeTableEntry(ParseState *pstate, * Add an entry for a relation to the pstate's range table (p_rtable). * * This is just like addRangeTableEntry() except that it makes an RTE - * given a relation OID instead of a RangeVar reference. - * - * Note that an alias clause *must* be supplied. + * given an already-open relation instead of a RangeVar reference. */ RangeTblEntry * addRangeTableEntryForRelation(ParseState *pstate, - Oid relid, + Relation rel, Alias *alias, bool inh, bool inFromCl) { RangeTblEntry *rte = makeNode(RangeTblEntry); - char *refname = alias->aliasname; - LOCKMODE lockmode; - Relation rel; + char *refname = alias ? alias->aliasname : RelationGetRelationName(rel); rte->rtekind = RTE_RELATION; rte->alias = alias; - - /* - * Get the rel's relcache entry. This access ensures that we have an - * up-to-date relcache entry for the rel. Since this is typically the - * first access to a rel in a statement, be careful to get the right - * access level depending on whether we're doing SELECT FOR UPDATE. - */ - lockmode = isForUpdate(pstate, refname) ? RowShareLock : AccessShareLock; - rel = heap_open(relid, lockmode); - rte->relid = relid; + rte->relid = RelationGetRelid(rel); /* * Build the list of effective column names using user-supplied @@ -845,13 +832,6 @@ addRangeTableEntryForRelation(ParseState *pstate, rte->eref = makeAlias(refname, NIL); buildRelationAliases(rel->rd_att, alias, rte->eref); - /* - * Drop the rel refcount, but keep the access lock till end of - * transaction so that the table can't be deleted or have its schema - * modified underneath us. - */ - heap_close(rel, NoLock); - /*---------- * Flags: * - this RTE should be expanded to include descendant tables, |