---------------- * relation_open - open any relation by relation OID * * If lockmode is not "NoLock", the specified kind of lock is * obtained on the relation. (Generally, NoLock should only be * used if the caller knows it has some appropriate lock on the * relation already.) * * An error is raised if the relation does not exist. * * NB: a "relation" is anything with a pg_class
| 45 | * ---------------- |
| 46 | */ |
| 47 | Relation |
| 48 | relation_open(Oid relationId, LOCKMODE lockmode) |
| 49 | { |
| 50 | Relation r; |
| 51 | |
| 52 | Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES); |
| 53 | |
| 54 | /* Get the lock before trying to open the relcache entry */ |
| 55 | if (lockmode != NoLock) |
| 56 | LockRelationOid(relationId, lockmode); |
| 57 | |
| 58 | /* The relcache does all the real work... */ |
| 59 | r = RelationIdGetRelation(relationId); |
| 60 | |
| 61 | if (!RelationIsValid(r)) |
| 62 | ereport(ERROR, |
| 63 | (errcode(ERRCODE_UNDEFINED_TABLE), |
| 64 | errmsg("could not open relation with OID %u", relationId), |
| 65 | errdetail("This can be validly caused by a concurrent delete operation on this object."))); |
| 66 | |
| 67 | /* |
| 68 | * If we didn't get the lock ourselves, assert that caller holds one, |
| 69 | * except in bootstrap mode where no locks are used. |
| 70 | */ |
| 71 | Assert(lockmode != NoLock || |
| 72 | IsBootstrapProcessingMode() || |
| 73 | CheckRelationLockedByMe(r, AccessShareLock, true)); |
| 74 | |
| 75 | #if 0 /* Upstream code not applicable to GPDB */ |
| 76 | /* Make note that we've accessed a temporary relation */ |
| 77 | if (RelationUsesLocalBuffers(r)) |
| 78 | MyXactFlags |= XACT_FLAGS_ACCESSEDTEMPNAMESPACE; |
| 79 | #endif |
| 80 | |
| 81 | pgstat_initstats(r); |
| 82 | |
| 83 | return r; |
| 84 | } |
| 85 | |
| 86 | /* ---------------- |
| 87 | * try_relation_open - open any relation by relation OID |
no test coverage detected