aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/cluster.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-07-06 11:39:09 -0400
committerRobert Haas <rhaas@postgresql.org>2022-07-06 11:39:09 -0400
commitb0a55e43299c4ea2a9a8c757f9c26352407d0ccc (patch)
tree2c22c2965f9976ae4469595cd28df13db6b943c2 /src/backend/commands/cluster.c
parent7775c748db1257523ecbed1060dadb608bdff6de (diff)
downloadpostgresql-b0a55e43299c4ea2a9a8c757f9c26352407d0ccc.tar.gz
postgresql-b0a55e43299c4ea2a9a8c757f9c26352407d0ccc.zip
Change internal RelFileNode references to RelFileNumber or RelFileLocator.
We have been using the term RelFileNode to refer to either (1) the integer that is used to name the sequence of files for a certain relation within the directory set aside for that tablespace/database combination; or (2) that value plus the OIDs of the tablespace and database; or occasionally (3) the whole series of files created for a relation based on those values. Using the same name for more than one thing is confusing. Replace RelFileNode with RelFileNumber when we're talking about just the single number, i.e. (1) from above, and with RelFileLocator when we're talking about all the things that are needed to locate a relation's files on disk, i.e. (2) from above. In the places where we refer to (3) as a relfilenode, instead refer to "relation storage". Since there is a ton of SQL code in the world that knows about pg_class.relfilenode, don't change the name of that column, or of other SQL-facing things that derive their name from it. On the other hand, do adjust closely-related internal terminology. For example, the structure member names dbNode and spcNode appear to be derived from the fact that the structure itself was called RelFileNode, so change those to dbOid and spcOid. Likewise, various variables with names like rnode and relnode get renamed appropriately, according to how they're being used in context. Hopefully, this is clearer than before. It is also preparation for future patches that intend to widen the relfilenumber fields from its current width of 32 bits. Variables that store a relfilenumber are now declared as type RelFileNumber rather than type Oid; right now, these are the same, but that can now more easily be changed. Dilip Kumar, per an idea from me. Reviewed also by Andres Freund. I fixed some whitespace issues, changed a couple of words in a comment, and made one other minor correction. Discussion: http://postgr.es/m/CA+TgmoamOtXbVAQf9hWFzonUo6bhhjS6toZQd7HZ-pmojtAmag@mail.gmail.com Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com Discussion: http://postgr.es/m/CAFiTN-vTe79M8uDH1yprOU64MNFE+R3ODRuA+JWf27JbhY4hJw@mail.gmail.com
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r--src/backend/commands/cluster.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index cea2c8be805..dc35b029102 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -293,7 +293,7 @@ cluster_multiple_rels(List *rtcs, ClusterParams *params)
* cluster_rel
*
* This clusters the table by creating a new, clustered table and
- * swapping the relfilenodes of the new table and the old table, so
+ * swapping the relfilenumbers of the new table and the old table, so
* the OID of the original table is preserved. Thus we do not lose
* GRANT, inheritance nor references to this table (this was a bug
* in releases through 7.3).
@@ -1025,8 +1025,8 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
/*
* Swap the physical files of two given relations.
*
- * We swap the physical identity (reltablespace, relfilenode) while keeping the
- * same logical identities of the two relations. relpersistence is also
+ * We swap the physical identity (reltablespace, relfilenumber) while keeping
+ * the same logical identities of the two relations. relpersistence is also
* swapped, which is critical since it determines where buffers live for each
* relation.
*
@@ -1061,9 +1061,9 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
reltup2;
Form_pg_class relform1,
relform2;
- Oid relfilenode1,
- relfilenode2;
- Oid swaptemp;
+ RelFileNumber relfilenumber1,
+ relfilenumber2;
+ RelFileNumber swaptemp;
char swptmpchr;
/* We need writable copies of both pg_class tuples. */
@@ -1079,13 +1079,14 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
elog(ERROR, "cache lookup failed for relation %u", r2);
relform2 = (Form_pg_class) GETSTRUCT(reltup2);
- relfilenode1 = relform1->relfilenode;
- relfilenode2 = relform2->relfilenode;
+ relfilenumber1 = relform1->relfilenode;
+ relfilenumber2 = relform2->relfilenode;
- if (OidIsValid(relfilenode1) && OidIsValid(relfilenode2))
+ if (RelFileNumberIsValid(relfilenumber1) &&
+ RelFileNumberIsValid(relfilenumber2))
{
/*
- * Normal non-mapped relations: swap relfilenodes, reltablespaces,
+ * Normal non-mapped relations: swap relfilenumbers, reltablespaces,
* relpersistence
*/
Assert(!target_is_pg_class);
@@ -1120,7 +1121,8 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
* Mapped-relation case. Here we have to swap the relation mappings
* instead of modifying the pg_class columns. Both must be mapped.
*/
- if (OidIsValid(relfilenode1) || OidIsValid(relfilenode2))
+ if (RelFileNumberIsValid(relfilenumber1) ||
+ RelFileNumberIsValid(relfilenumber2))
elog(ERROR, "cannot swap mapped relation \"%s\" with non-mapped relation",
NameStr(relform1->relname));
@@ -1148,12 +1150,12 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
/*
* Fetch the mappings --- shouldn't fail, but be paranoid
*/
- relfilenode1 = RelationMapOidToFilenode(r1, relform1->relisshared);
- if (!OidIsValid(relfilenode1))
+ relfilenumber1 = RelationMapOidToFilenumber(r1, relform1->relisshared);
+ if (!RelFileNumberIsValid(relfilenumber1))
elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u",
NameStr(relform1->relname), r1);
- relfilenode2 = RelationMapOidToFilenode(r2, relform2->relisshared);
- if (!OidIsValid(relfilenode2))
+ relfilenumber2 = RelationMapOidToFilenumber(r2, relform2->relisshared);
+ if (!RelFileNumberIsValid(relfilenumber2))
elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u",
NameStr(relform2->relname), r2);
@@ -1161,15 +1163,15 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
* Send replacement mappings to relmapper. Note these won't actually
* take effect until CommandCounterIncrement.
*/
- RelationMapUpdateMap(r1, relfilenode2, relform1->relisshared, false);
- RelationMapUpdateMap(r2, relfilenode1, relform2->relisshared, false);
+ RelationMapUpdateMap(r1, relfilenumber2, relform1->relisshared, false);
+ RelationMapUpdateMap(r2, relfilenumber1, relform2->relisshared, false);
/* Pass OIDs of mapped r2 tables back to caller */
*mapped_tables++ = r2;
}
/*
- * Recognize that rel1's relfilenode (swapped from rel2) is new in this
+ * Recognize that rel1's relfilenumber (swapped from rel2) is new in this
* subtransaction. The rel2 storage (swapped from rel1) may or may not be
* new.
*/
@@ -1180,9 +1182,9 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
rel1 = relation_open(r1, NoLock);
rel2 = relation_open(r2, NoLock);
rel2->rd_createSubid = rel1->rd_createSubid;
- rel2->rd_newRelfilenodeSubid = rel1->rd_newRelfilenodeSubid;
- rel2->rd_firstRelfilenodeSubid = rel1->rd_firstRelfilenodeSubid;
- RelationAssumeNewRelfilenode(rel1);
+ rel2->rd_newRelfilelocatorSubid = rel1->rd_newRelfilelocatorSubid;
+ rel2->rd_firstRelfilelocatorSubid = rel1->rd_firstRelfilelocatorSubid;
+ RelationAssumeNewRelfilelocator(rel1);
relation_close(rel1, NoLock);
relation_close(rel2, NoLock);
}
@@ -1523,7 +1525,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
table_close(relRelation, RowExclusiveLock);
}
- /* Destroy new heap with old filenode */
+ /* Destroy new heap with old filenumber */
object.classId = RelationRelationId;
object.objectId = OIDNewHeap;
object.objectSubId = 0;