MCPcopy Create free account
hub / github.com/apache/cloudberry / RelationInitPhysicalAddr

Function RelationInitPhysicalAddr

src/backend/utils/cache/relcache.c:1365–1440  ·  view source on GitHub ↗

* Initialize the physical addressing info (RelFileNode) for a relcache entry * * Note: at the physical level, relations in the pg_global tablespace must * be treated as shared, even if relisshared isn't set. Hence we do not * look at relisshared here. */

Source from the content-addressed store, hash-verified

1363 * look at relisshared here.
1364 */
1365static void
1366RelationInitPhysicalAddr(Relation relation)
1367{
1368 Oid oldnode = relation->rd_node.relNode;
1369
1370 /* these relations kinds never have storage */
1371 if (!RELKIND_HAS_STORAGE(relation->rd_rel->relkind))
1372 return;
1373
1374 if (relation->rd_rel->reltablespace)
1375 relation->rd_node.spcNode = relation->rd_rel->reltablespace;
1376 else
1377 relation->rd_node.spcNode = MyDatabaseTableSpace;
1378 if (relation->rd_node.spcNode == GLOBALTABLESPACE_OID)
1379 relation->rd_node.dbNode = InvalidOid;
1380 else
1381 relation->rd_node.dbNode = MyDatabaseId;
1382
1383 if (relation->rd_rel->relfilenode)
1384 {
1385 /*
1386 * Even if we are using a decoding snapshot that doesn't represent the
1387 * current state of the catalog we need to make sure the filenode
1388 * points to the current file since the older file will be gone (or
1389 * truncated). The new file will still contain older rows so lookups
1390 * in them will work correctly. This wouldn't work correctly if
1391 * rewrites were allowed to change the schema in an incompatible way,
1392 * but those are prevented both on catalog tables and on user tables
1393 * declared as additional catalog tables.
1394 */
1395 if (HistoricSnapshotActive()
1396 && RelationIsAccessibleInLogicalDecoding(relation)
1397 && IsTransactionState())
1398 {
1399 HeapTuple phys_tuple;
1400 Form_pg_class physrel;
1401
1402 phys_tuple = ScanPgRelation(RelationGetRelid(relation),
1403 RelationGetRelid(relation) != ClassOidIndexId,
1404 true);
1405 if (!HeapTupleIsValid(phys_tuple))
1406 elog(ERROR, "could not find pg_class entry for %u",
1407 RelationGetRelid(relation));
1408 physrel = (Form_pg_class) GETSTRUCT(phys_tuple);
1409
1410 relation->rd_rel->reltablespace = physrel->reltablespace;
1411 relation->rd_rel->relfilenode = physrel->relfilenode;
1412 heap_freetuple(phys_tuple);
1413 }
1414
1415 relation->rd_node.relNode = relation->rd_rel->relfilenode;
1416 }
1417 else
1418 {
1419 /* Consult the relation mapper */
1420 relation->rd_node.relNode =
1421 RelationMapOidToFilenode(relation->rd_id,
1422 relation->rd_rel->relisshared);

Callers 7

RelationBuildDescFunction · 0.85
formrdescFunction · 0.85
RelationReloadIndexInfoFunction · 0.85
RelationReloadNailedFunction · 0.85
RelationCacheInvalidateFunction · 0.85
load_relcache_init_fileFunction · 0.85

Calls 6

HistoricSnapshotActiveFunction · 0.85
IsTransactionStateFunction · 0.85
ScanPgRelationFunction · 0.85
heap_freetupleFunction · 0.85
RelationMapOidToFilenodeFunction · 0.85
RelFileNodeSkippingWALFunction · 0.85

Tested by

no test coverage detected