Skip to content

Commit 65eb2d0

Browse files
committed
Acquire locks on views in AcquirePlannerLocks, too.
Commit 47bb9db taught AcquireExecutorLocks to re-acquire locks on views using data from their RTE_SUBQUERY replacements, but it now seems like we should make AcquirePlannerLocks do the same. In this way, if a view has been redefined, we will notice that a bit earlier while checking validity of a cached plan and thereby avoid some wasted work. Report and patch by Amit Langote. Discussion: https://postgr.es/m/CA+HiwqH0xZOQ+GQAdKeckY1R4NOeHdzhtfxkAMJLSchpapNk5w@mail.gmail.com
1 parent 84adc8e commit 65eb2d0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/backend/utils/cache/plancache.c

+8
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,14 @@ ScanQueryForLocks(Query *parsetree, bool acquire)
18461846
break;
18471847

18481848
case RTE_SUBQUERY:
1849+
/* If this was a view, must lock/unlock the view */
1850+
if (OidIsValid(rte->relid))
1851+
{
1852+
if (acquire)
1853+
LockRelationOid(rte->relid, rte->rellockmode);
1854+
else
1855+
UnlockRelationOid(rte->relid, rte->rellockmode);
1856+
}
18491857
/* Recurse into subquery-in-FROM */
18501858
ScanQueryForLocks(rte->subquery, acquire);
18511859
break;

0 commit comments

Comments
 (0)