Skip to content

Commit ffd2582

Browse files
committed
Make more use of RELKIND_HAS_STORAGE()
Make use of RELKIND_HAS_STORAGE() where appropriate, instead of listing out the relkinds individually. No behavior change intended. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/7a22bf51-2480-d999-1794-191ba67ff47c%402ndquadrant.com
1 parent 7aa4fb5 commit ffd2582

File tree

3 files changed

+31
-55
lines changed

3 files changed

+31
-55
lines changed

src/backend/catalog/heap.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,13 +1943,8 @@ heap_drop_with_catalog(Oid relid)
19431943
/*
19441944
* Schedule unlinking of the relation's physical files at commit.
19451945
*/
1946-
if (rel->rd_rel->relkind != RELKIND_VIEW &&
1947-
rel->rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1948-
rel->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1949-
rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1950-
{
1946+
if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
19511947
RelationDropStorage(rel);
1952-
}
19531948

19541949
/*
19551950
* Close relcache entry, but *keep* AccessExclusiveLock on the relation

src/backend/postmaster/pgstat.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,11 +1807,7 @@ pgstat_initstats(Relation rel)
18071807
char relkind = rel->rd_rel->relkind;
18081808

18091809
/* We only count stats for things that have storage */
1810-
if (!(relkind == RELKIND_RELATION ||
1811-
relkind == RELKIND_MATVIEW ||
1812-
relkind == RELKIND_INDEX ||
1813-
relkind == RELKIND_TOASTVALUE ||
1814-
relkind == RELKIND_SEQUENCE))
1810+
if (!RELKIND_HAS_STORAGE(relkind))
18151811
{
18161812
rel->pgstat_info = NULL;
18171813
return;

src/backend/utils/adt/dbsize.c

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -874,25 +874,18 @@ pg_relation_filenode(PG_FUNCTION_ARGS)
874874
PG_RETURN_NULL();
875875
relform = (Form_pg_class) GETSTRUCT(tuple);
876876

877-
switch (relform->relkind)
877+
if (RELKIND_HAS_STORAGE(relform->relkind))
878878
{
879-
case RELKIND_RELATION:
880-
case RELKIND_MATVIEW:
881-
case RELKIND_INDEX:
882-
case RELKIND_SEQUENCE:
883-
case RELKIND_TOASTVALUE:
884-
/* okay, these have storage */
885-
if (relform->relfilenode)
886-
result = relform->relfilenode;
887-
else /* Consult the relation mapper */
888-
result = RelationMapOidToFilenode(relid,
889-
relform->relisshared);
890-
break;
891-
892-
default:
893-
/* no storage, return NULL */
894-
result = InvalidOid;
895-
break;
879+
if (relform->relfilenode)
880+
result = relform->relfilenode;
881+
else /* Consult the relation mapper */
882+
result = RelationMapOidToFilenode(relid,
883+
relform->relisshared);
884+
}
885+
else
886+
{
887+
/* no storage, return NULL */
888+
result = InvalidOid;
896889
}
897890

898891
ReleaseSysCache(tuple);
@@ -951,38 +944,30 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
951944
PG_RETURN_NULL();
952945
relform = (Form_pg_class) GETSTRUCT(tuple);
953946

954-
switch (relform->relkind)
947+
if (RELKIND_HAS_STORAGE(relform->relkind))
948+
{
949+
/* This logic should match RelationInitPhysicalAddr */
950+
if (relform->reltablespace)
951+
rnode.spcNode = relform->reltablespace;
952+
else
953+
rnode.spcNode = MyDatabaseTableSpace;
954+
if (rnode.spcNode == GLOBALTABLESPACE_OID)
955+
rnode.dbNode = InvalidOid;
956+
else
957+
rnode.dbNode = MyDatabaseId;
958+
if (relform->relfilenode)
959+
rnode.relNode = relform->relfilenode;
960+
else /* Consult the relation mapper */
961+
rnode.relNode = RelationMapOidToFilenode(relid,
962+
relform->relisshared);
963+
}
964+
else
955965
{
956-
case RELKIND_RELATION:
957-
case RELKIND_MATVIEW:
958-
case RELKIND_INDEX:
959-
case RELKIND_SEQUENCE:
960-
case RELKIND_TOASTVALUE:
961-
/* okay, these have storage */
962-
963-
/* This logic should match RelationInitPhysicalAddr */
964-
if (relform->reltablespace)
965-
rnode.spcNode = relform->reltablespace;
966-
else
967-
rnode.spcNode = MyDatabaseTableSpace;
968-
if (rnode.spcNode == GLOBALTABLESPACE_OID)
969-
rnode.dbNode = InvalidOid;
970-
else
971-
rnode.dbNode = MyDatabaseId;
972-
if (relform->relfilenode)
973-
rnode.relNode = relform->relfilenode;
974-
else /* Consult the relation mapper */
975-
rnode.relNode = RelationMapOidToFilenode(relid,
976-
relform->relisshared);
977-
break;
978-
979-
default:
980966
/* no storage, return NULL */
981967
rnode.relNode = InvalidOid;
982968
/* some compilers generate warnings without these next two lines */
983969
rnode.dbNode = InvalidOid;
984970
rnode.spcNode = InvalidOid;
985-
break;
986971
}
987972

988973
if (!OidIsValid(rnode.relNode))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy