142{
145 bool found;
150
153
154 /* pg_class will show 0 when the value is actually MyDatabaseTableSpace */
156 reltablespace = 0;
157
159 key.reltablespace = reltablespace;
160 key.relfilenumber = relfilenumber;
161
162 /*
163 * Check cache and return entry if one is found. Even if no target
164 * relation can be found later on we store the negative match and return a
165 * InvalidOid from cache. That's not really necessary for performance
166 * since querying invalid values isn't supposed to be a frequent thing,
167 * but it's basically free.
168 */
170
171 if (found)
173
174 /* ok, no previous cache entry, do it the hard way */
175
176 /* initialize empty/negative cache entry before doing the actual lookups */
178
179 if (reltablespace == GLOBALTABLESPACE_OID)
180 {
181 /*
182 * Ok, shared table, check relmapper.
183 */
185 }
186 else
187 {
189
190 /*
191 * Not a shared table, could either be a plain relation or a
192 * non-shared, nailed one, like e.g. pg_class.
193 */
194
195 /* check for plain relations by looking in pg_class */
197
198 /* copy scankey to local copy and set scan arguments */
202
204 ClassTblspcRelfilenodeIndexId,
205 true,
206 NULL,
207 2,
208 skey);
209
210 found = false;
211
213 {
215
216 if (classform->relpersistence == RELPERSISTENCE_TEMP)
217 continue;
218
219 if (found)
221 "unexpected duplicate for tablespace %u, relfilenumber %u",
222 reltablespace, relfilenumber);
223 found = true;
224
225 Assert(classform->reltablespace == reltablespace);
226 Assert(classform->relfilenode == relfilenumber);
227 relid = classform->oid;
228 }
229
232
233 /* check for tables that are mapped but not shared */
234 if (!found)
236 }
237
238 /*
239 * Only enter entry into cache now, our opening of pg_class could have
240 * caused cache invalidations to be executed which would have deleted a
241 * new entry if we had entered it above.
242 */
244 if (found)
246 entry->
relid = relid;
247
248 return relid;
249}
#define MemSet(start, val, len)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
FormData_pg_class * Form_pg_class
static Datum ObjectIdGetDatum(Oid X)
static ScanKeyData relfilenumber_skey[2]
static void InitializeRelfilenumberMap(void)
static HTAB * RelfilenumberMapHash
Oid RelationMapFilenumberToOid(RelFileNumber filenumber, bool shared)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)