diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-11-12 01:22:45 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-11-12 01:22:45 -0500 |
commit | aa3299f25601c1a27e52c1c49e92b7f11441e76b (patch) | |
tree | abf3f60c301f697c3082e6d862ae2e895450739c | |
parent | a6ce8ba2f3b280bb06cbca84a5375d42a25bea5f (diff) | |
download | postgresql-aa3299f25601c1a27e52c1c49e92b7f11441e76b.tar.gz postgresql-aa3299f25601c1a27e52c1c49e92b7f11441e76b.zip |
Avoid retaining multiple relation locks in RangeVarGetRelid.
If it turns out we've locked the wrong OID, release the old lock. In
most cases, it's pretty harmless to retain the extra lock, but this
seems tidier and avoids using lock table slots unnecessarily.
Per discussion with Tom Lane.
-rw-r--r-- | src/backend/catalog/namespace.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index fcc90fed5fd..6d4d4b1cccf 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -322,9 +322,18 @@ RangeVarGetRelid(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok, * If, upon retry, we get back the same OID we did last time, then * the invalidation messages we processed did not change the final * answer. So we're done. + * + * If we got a different OID, we've locked the relation that used to + * have this name rather than the one that does now. So release + * the lock. */ - if (retry && relId == oldRelId) - break; + if (retry) + { + if (relId == oldRelId) + break; + if (OidIsValid(oldRelId)) + UnlockRelationOid(oldRelId, lockmode); + } /* * Lock relation. This will also accept any pending invalidation |