@@ -77,8 +77,7 @@ static void markQueryForLocking(Query *qry, Node *jtnode,
77
77
bool pushedDown );
78
78
static List * matchLocks (CmdType event , RuleLock * rulelocks ,
79
79
int varno , Query * parsetree , bool * hasUpdate );
80
- static Query * fireRIRrules (Query * parsetree , List * activeRIRs ,
81
- bool forUpdatePushedDown );
80
+ static Query * fireRIRrules (Query * parsetree , List * activeRIRs );
82
81
static bool view_has_instead_trigger (Relation view , CmdType event );
83
82
static Bitmapset * adjust_view_column_set (Bitmapset * cols , List * targetlist );
84
83
@@ -1453,8 +1452,7 @@ ApplyRetrieveRule(Query *parsetree,
1453
1452
RewriteRule * rule ,
1454
1453
int rt_index ,
1455
1454
Relation relation ,
1456
- List * activeRIRs ,
1457
- bool forUpdatePushedDown )
1455
+ List * activeRIRs )
1458
1456
{
1459
1457
Query * rule_action ;
1460
1458
RangeTblEntry * rte ,
@@ -1545,28 +1543,27 @@ ApplyRetrieveRule(Query *parsetree,
1545
1543
}
1546
1544
1547
1545
/*
1548
- * If FOR [KEY] UPDATE/SHARE of view, be sure we get right initial lock on
1549
- * the relations it references.
1546
+ * Check if there's a FOR [KEY] UPDATE/SHARE clause applying to this view.
1547
+ *
1548
+ * Note: we needn't explicitly consider any such clauses appearing in
1549
+ * ancestor query levels; their effects have already been pushed down to
1550
+ * here by markQueryForLocking, and will be reflected in "rc".
1550
1551
*/
1551
1552
rc = get_parse_rowmark (parsetree , rt_index );
1552
- forUpdatePushedDown |= (rc != NULL );
1553
1553
1554
1554
/*
1555
1555
* Make a modifiable copy of the view query, and acquire needed locks on
1556
- * the relations it mentions.
1556
+ * the relations it mentions. Force at least RowShareLock for all such
1557
+ * rels if there's a FOR [KEY] UPDATE/SHARE clause affecting this view.
1557
1558
*/
1558
1559
rule_action = copyObject (linitial (rule -> actions ));
1559
1560
1560
- AcquireRewriteLocks (rule_action , true, forUpdatePushedDown );
1561
+ AcquireRewriteLocks (rule_action , true, ( rc != NULL ) );
1561
1562
1562
1563
/*
1563
1564
* If FOR [KEY] UPDATE/SHARE of view, mark all the contained tables as
1564
1565
* implicit FOR [KEY] UPDATE/SHARE, the same as the parser would have done
1565
1566
* if the view's subquery had been written out explicitly.
1566
- *
1567
- * Note: we needn't consider forUpdatePushedDown for this; if there was an
1568
- * ancestor query level with a relevant FOR [KEY] UPDATE/SHARE clause,
1569
- * that's already been pushed down to here and is reflected in "rc".
1570
1567
*/
1571
1568
if (rc != NULL )
1572
1569
markQueryForLocking (rule_action , (Node * ) rule_action -> jointree ,
@@ -1581,7 +1578,7 @@ ApplyRetrieveRule(Query *parsetree,
1581
1578
* OLD rangetable entries by the action below (in a recursive call of this
1582
1579
* routine).
1583
1580
*/
1584
- rule_action = fireRIRrules (rule_action , activeRIRs , forUpdatePushedDown );
1581
+ rule_action = fireRIRrules (rule_action , activeRIRs );
1585
1582
1586
1583
/*
1587
1584
* Now, plug the view query in as a subselect, replacing the relation's
@@ -1698,7 +1695,7 @@ fireRIRonSubLink(Node *node, List *activeRIRs)
1698
1695
1699
1696
/* Do what we came for */
1700
1697
sub -> subselect = (Node * ) fireRIRrules ((Query * ) sub -> subselect ,
1701
- activeRIRs , false );
1698
+ activeRIRs );
1702
1699
/* Fall through to process lefthand args of SubLink */
1703
1700
}
1704
1701
@@ -1713,10 +1710,13 @@ fireRIRonSubLink(Node *node, List *activeRIRs)
1713
1710
1714
1711
/*
1715
1712
* fireRIRrules -
1716
- * Apply all RIR rules on each rangetable entry in a query
1713
+ * Apply all RIR rules on each rangetable entry in the given query
1714
+ *
1715
+ * activeRIRs is a list of the OIDs of views we're already processing RIR
1716
+ * rules for, used to detect/reject recursion.
1717
1717
*/
1718
1718
static Query *
1719
- fireRIRrules (Query * parsetree , List * activeRIRs , bool forUpdatePushedDown )
1719
+ fireRIRrules (Query * parsetree , List * activeRIRs )
1720
1720
{
1721
1721
int origResultRelation = parsetree -> resultRelation ;
1722
1722
int rt_index ;
@@ -1747,9 +1747,7 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
1747
1747
*/
1748
1748
if (rte -> rtekind == RTE_SUBQUERY )
1749
1749
{
1750
- rte -> subquery = fireRIRrules (rte -> subquery , activeRIRs ,
1751
- (forUpdatePushedDown ||
1752
- get_parse_rowmark (parsetree , rt_index ) != NULL ));
1750
+ rte -> subquery = fireRIRrules (rte -> subquery , activeRIRs );
1753
1751
continue ;
1754
1752
}
1755
1753
@@ -1835,8 +1833,7 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
1835
1833
rule ,
1836
1834
rt_index ,
1837
1835
rel ,
1838
- activeRIRs ,
1839
- forUpdatePushedDown );
1836
+ activeRIRs );
1840
1837
}
1841
1838
1842
1839
activeRIRs = list_delete_first (activeRIRs );
@@ -1852,7 +1849,7 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
1852
1849
CommonTableExpr * cte = (CommonTableExpr * ) lfirst (lc );
1853
1850
1854
1851
cte -> ctequery = (Node * )
1855
- fireRIRrules ((Query * ) cte -> ctequery , activeRIRs , false );
1852
+ fireRIRrules ((Query * ) cte -> ctequery , activeRIRs );
1856
1853
}
1857
1854
1858
1855
/*
@@ -3604,7 +3601,7 @@ QueryRewrite(Query *parsetree)
3604
3601
{
3605
3602
Query * query = (Query * ) lfirst (l );
3606
3603
3607
- query = fireRIRrules (query , NIL , false );
3604
+ query = fireRIRrules (query , NIL );
3608
3605
3609
3606
query -> queryId = input_query_id ;
3610
3607
0 commit comments