@@ -212,6 +212,15 @@ static bool MatchNamedCall(HeapTuple proctup, int nargs, List *argnames,
212212 * If flags contains RVR_NOWAIT, throw an error if we'd have to wait for a
213213 * lock.
214214 *
215+ * If flags contains RVR_SKIP_LOCKED, return InvalidOid if we'd have to wait
216+ * for a lock.
217+ *
218+ * flags cannot contain both RVR_NOWAIT and RVR_SKIP_LOCKED.
219+ *
220+ * Note that if RVR_MISSING_OK and RVR_SKIP_LOCKED are both specified, a
221+ * return value of InvalidOid could either mean the relation is missing or it
222+ * could not be locked.
223+ *
215224 * Callback allows caller to check permissions or acquire additional locks
216225 * prior to grabbing the relation lock.
217226 */
@@ -226,6 +235,9 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
226235 bool retry = false;
227236 bool missing_ok = (flags & RVR_MISSING_OK ) != 0 ;
228237
238+ /* verify that flags do no conflict */
239+ Assert (!((flags & RVR_NOWAIT ) && (flags & RVR_SKIP_LOCKED )));
240+
229241 /*
230242 * We check the catalog name and then ignore it.
231243 */
@@ -363,20 +375,24 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
363375 */
364376 if (!OidIsValid (relId ))
365377 AcceptInvalidationMessages ();
366- else if (!(flags & RVR_NOWAIT ))
378+ else if (!(flags & ( RVR_NOWAIT | RVR_SKIP_LOCKED ) ))
367379 LockRelationOid (relId , lockmode );
368380 else if (!ConditionalLockRelationOid (relId , lockmode ))
369381 {
382+ int elevel = (flags & RVR_SKIP_LOCKED ) ? DEBUG1 : ERROR ;
383+
370384 if (relation -> schemaname )
371- ereport (ERROR ,
385+ ereport (elevel ,
372386 (errcode (ERRCODE_LOCK_NOT_AVAILABLE ),
373387 errmsg ("could not obtain lock on relation \"%s.%s\"" ,
374388 relation -> schemaname , relation -> relname )));
375389 else
376- ereport (ERROR ,
390+ ereport (elevel ,
377391 (errcode (ERRCODE_LOCK_NOT_AVAILABLE ),
378392 errmsg ("could not obtain lock on relation \"%s\"" ,
379393 relation -> relname )));
394+
395+ return InvalidOid ;
380396 }
381397
382398 /*
0 commit comments