diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index 88140bc..4ce50f3 100644 *** a/src/backend/rewrite/rewriteHandler.c --- b/src/backend/rewrite/rewriteHandler.c *************** ApplyRetrieveRule(Query *parsetree, *** 1560,1566 **** --- 1560,1584 ---- AcquireRewriteLocks(rule_action, true, forUpdatePushedDown); /* + * If FOR [KEY] UPDATE/SHARE of view, mark all the contained tables as + * implicit FOR [KEY] UPDATE/SHARE, the same as the parser would have done + * if the view's subquery had been written out explicitly. + * + * Note: we needn't consider forUpdatePushedDown for this; if there was an + * ancestor query level with a relevant FOR [KEY] UPDATE/SHARE clause, + * that's already been pushed down to here and is reflected in "rc". + */ + if (rc != NULL) + markQueryForLocking(rule_action, (Node *) rule_action->jointree, + rc->strength, rc->waitPolicy, true); + + /* * Recursively expand any view references inside the view. + * + * Note: this must happen after markQueryForLocking. That way, any UPDATE + * permission bits needed for sub-views are initially applied to their + * RTE_RELATION RTEs by markQueryForLocking, and then transferred to their + * OLD rangetable entries by this routine's action below. */ rule_action = fireRIRrules(rule_action, activeRIRs, forUpdatePushedDown); *************** ApplyRetrieveRule(Query *parsetree, *** 1594,1611 **** rte->insertedCols = NULL; rte->updatedCols = NULL; - /* - * If FOR [KEY] UPDATE/SHARE of view, mark all the contained tables as - * implicit FOR [KEY] UPDATE/SHARE, the same as the parser would have done - * if the view's subquery had been written out explicitly. - * - * Note: we don't consider forUpdatePushedDown here; such marks will be - * made by recursing from the upper level in markQueryForLocking. - */ - if (rc != NULL) - markQueryForLocking(rule_action, (Node *) rule_action->jointree, - rc->strength, rc->waitPolicy, true); - return parsetree; } --- 1612,1617 ----