mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Add infrastructure for mapping relfilenodes to relation OIDs.
Future patches are expected to introduce logical replication that works by decoding WAL. WAL contains relfilenodes rather than relation OIDs, so this infrastructure will be needed to find the relation OID based on WAL contents. If logical replication does not make it into this release, we probably should consider reverting this, since it will add some overhead to DDL operations that create new relations. One additional index insert per pg_class row is not a large overhead, but it's more than zero. Another way of meeting the needs of logical replication would be to the relation OID to WAL, but that would burden DML operations, not only DDL. Andres Freund, with some changes by me. Design review, in earlier versions, by Álvaro Herrera.
This commit is contained in:
53
src/backend/utils/cache/relmapper.c
vendored
53
src/backend/utils/cache/relmapper.c
vendored
@@ -180,6 +180,59 @@ RelationMapOidToFilenode(Oid relationId, bool shared)
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/*
|
||||
* RelationMapFilenodeToOid
|
||||
*
|
||||
* Do the reverse of the normal direction of mapping done in
|
||||
* RelationMapOidToFilenode.
|
||||
*
|
||||
* This is not supposed to be used during normal running but rather for
|
||||
* information purposes when looking at the filesystem or xlog.
|
||||
*
|
||||
* Returns InvalidOid if the OID is not known; this can easily happen if the
|
||||
* relfilenode doesn't pertain to a mapped relation.
|
||||
*/
|
||||
Oid
|
||||
RelationMapFilenodeToOid(Oid filenode, bool shared)
|
||||
{
|
||||
const RelMapFile *map;
|
||||
int32 i;
|
||||
|
||||
/* If there are active updates, believe those over the main maps */
|
||||
if (shared)
|
||||
{
|
||||
map = &active_shared_updates;
|
||||
for (i = 0; i < map->num_mappings; i++)
|
||||
{
|
||||
if (filenode == map->mappings[i].mapfilenode)
|
||||
return map->mappings[i].mapoid;
|
||||
}
|
||||
map = &shared_map;
|
||||
for (i = 0; i < map->num_mappings; i++)
|
||||
{
|
||||
if (filenode == map->mappings[i].mapfilenode)
|
||||
return map->mappings[i].mapoid;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
map = &active_local_updates;
|
||||
for (i = 0; i < map->num_mappings; i++)
|
||||
{
|
||||
if (filenode == map->mappings[i].mapfilenode)
|
||||
return map->mappings[i].mapoid;
|
||||
}
|
||||
map = &local_map;
|
||||
for (i = 0; i < map->num_mappings; i++)
|
||||
{
|
||||
if (filenode == map->mappings[i].mapfilenode)
|
||||
return map->mappings[i].mapoid;
|
||||
}
|
||||
}
|
||||
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/*
|
||||
* RelationMapUpdateMap
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user