aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-04-05 15:56:07 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-04-05 15:56:35 -0400
commit65eb2d00c6c1bab29db9fa6575185a40d823fe9d (patch)
tree4e238772e19eb36863f3a3af17a8d5e215206c68 /src
parent84adc8e20f54e93a003cd316fa1eb9b03e393288 (diff)
downloadpostgresql-65eb2d00c6c1bab29db9fa6575185a40d823fe9d.tar.gz
postgresql-65eb2d00c6c1bab29db9fa6575185a40d823fe9d.zip
Acquire locks on views in AcquirePlannerLocks, too.
Commit 47bb9db75 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
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/cache/plancache.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 77c2ba3f8f4..87210fcf627 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -1846,6 +1846,14 @@ ScanQueryForLocks(Query *parsetree, bool acquire)
break;
case RTE_SUBQUERY:
+ /* If this was a view, must lock/unlock the view */
+ if (OidIsValid(rte->relid))
+ {
+ if (acquire)
+ LockRelationOid(rte->relid, rte->rellockmode);
+ else
+ UnlockRelationOid(rte->relid, rte->rellockmode);
+ }
/* Recurse into subquery-in-FROM */
ScanQueryForLocks(rte->subquery, acquire);
break;