66 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
9- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.318 2005/04/07 01:51:38 neilc Exp $
9+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.319 2005/04/13 16:50:54 tgl Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -1536,6 +1536,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
15361536 List * * extras_before , List * * extras_after )
15371537{
15381538 Query * qry ;
1539+ Relation rel ;
15391540 RangeTblEntry * oldrte ;
15401541 RangeTblEntry * newrte ;
15411542
@@ -1547,24 +1548,22 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
15471548 * To avoid deadlock, make sure the first thing we do is grab
15481549 * AccessExclusiveLock on the target relation. This will be needed by
15491550 * DefineQueryRewrite(), and we don't want to grab a lesser lock
1550- * beforehand. We don't need to hold a refcount on the relcache
1551- * entry, however.
1551+ * beforehand.
15521552 */
1553- heap_close (heap_openrv (stmt -> relation , AccessExclusiveLock ),
1554- NoLock );
1553+ rel = heap_openrv (stmt -> relation , AccessExclusiveLock );
15551554
15561555 /*
15571556 * NOTE: 'OLD' must always have a varno equal to 1 and 'NEW' equal to
15581557 * 2. Set up their RTEs in the main pstate for use in parsing the
15591558 * rule qualification.
15601559 */
15611560 Assert (pstate -> p_rtable == NIL );
1562- oldrte = addRangeTableEntry (pstate , stmt -> relation ,
1563- makeAlias ("*OLD*" , NIL ),
1564- false, true);
1565- newrte = addRangeTableEntry (pstate , stmt -> relation ,
1566- makeAlias ("*NEW*" , NIL ),
1567- false, true);
1561+ oldrte = addRangeTableEntryForRelation (pstate , rel ,
1562+ makeAlias ("*OLD*" , NIL ),
1563+ false, true);
1564+ newrte = addRangeTableEntryForRelation (pstate , rel ,
1565+ makeAlias ("*NEW*" , NIL ),
1566+ false, true);
15681567 /* Must override addRangeTableEntry's default access-check flags */
15691568 oldrte -> requiredPerms = 0 ;
15701569 newrte -> requiredPerms = 0 ;
@@ -1659,12 +1658,12 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
16591658 * or they won't be accessible at all. We decide later
16601659 * whether to put them in the joinlist.
16611660 */
1662- oldrte = addRangeTableEntry (sub_pstate , stmt -> relation ,
1663- makeAlias ("*OLD*" , NIL ),
1664- false, false);
1665- newrte = addRangeTableEntry (sub_pstate , stmt -> relation ,
1666- makeAlias ("*NEW*" , NIL ),
1667- false, false);
1661+ oldrte = addRangeTableEntryForRelation (sub_pstate , rel ,
1662+ makeAlias ("*OLD*" , NIL ),
1663+ false, false);
1664+ newrte = addRangeTableEntryForRelation (sub_pstate , rel ,
1665+ makeAlias ("*NEW*" , NIL ),
1666+ false, false);
16681667 oldrte -> requiredPerms = 0 ;
16691668 newrte -> requiredPerms = 0 ;
16701669 addRTEtoQuery (sub_pstate , oldrte , false, true);
@@ -1791,6 +1790,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
17911790 stmt -> actions = newactions ;
17921791 }
17931792
1793+ /* Close relation, but keep the exclusive lock */
1794+ heap_close (rel , NoLock );
1795+
17941796 return qry ;
17951797}
17961798
0 commit comments