diff --git a/src/backend/partitioning/partdesc.c b/src/backend/partitioning/partdesc.c
index b207b765f2..91df607268 100644
--- a/src/backend/partitioning/partdesc.c
+++ b/src/backend/partitioning/partdesc.c
@@ -47,6 +47,18 @@ typedef struct PartitionDirectoryEntry
 	PartitionDesc pd;
 } PartitionDirectoryEntry;
 
+static PartitionDesc RelationBuildPartitionDesc(Relation rel);
+
+PartitionDesc
+RelationGetPartitionDesc(Relation rel)
+{
+	Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
+	if (rel->rd_partdesc)
+		return rel->rd_partdesc;
+
+	return RelationBuildPartitionDesc(rel);
+}
+
 /*
  * RelationBuildPartitionDesc
  *		Form rel's partition descriptor, and store in relcache entry
@@ -57,7 +69,7 @@ typedef struct PartitionDirectoryEntry
  * that's sufficient to prevent that can assume that rd_partdesc
  * won't change underneath it.
  */
-void
+static PartitionDesc
 RelationBuildPartitionDesc(Relation rel)
 {
 	PartitionDesc partdesc;
@@ -232,6 +244,7 @@ RelationBuildPartitionDesc(Relation rel)
 	}
 
 	rel->rd_partdesc = partdesc;
+	return partdesc;
 }
 
 /*
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 585dcee5db..851f002078 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1170,7 +1170,9 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
 	if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
 	{
 		RelationBuildPartitionKey(relation);
+#ifdef NOT_USED
 		RelationBuildPartitionDesc(relation);
+#endif
 	}
 	else
 	{
@@ -3920,6 +3922,7 @@ RelationCacheInitializePhase3(void)
 			restart = true;
 		}
 
+#ifdef NOT_USED
 		if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
 			relation->rd_partdesc == NULL)
 		{
@@ -3928,6 +3931,7 @@ RelationCacheInitializePhase3(void)
 
 			restart = true;
 		}
+#endif
 
 		if (relation->rd_tableam == NULL &&
 			(relation->rd_rel->relkind == RELKIND_RELATION ||
diff --git a/src/include/partitioning/partdesc.h b/src/include/partitioning/partdesc.h
index 38712c1550..d30c8feb48 100644
--- a/src/include/partitioning/partdesc.h
+++ b/src/include/partitioning/partdesc.h
@@ -29,7 +29,7 @@ typedef struct PartitionDescData
 	PartitionBoundInfo boundinfo;	/* collection of partition bounds */
 } PartitionDescData;
 
-extern void RelationBuildPartitionDesc(Relation rel);
+extern PartitionDesc RelationGetPartitionDesc(Relation rel);
 
 extern PartitionDirectory CreatePartitionDirectory(MemoryContext mcxt);
 extern PartitionDesc PartitionDirectoryLookup(PartitionDirectory, Relation);
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index a5cf804f9f..305319958e 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -19,6 +19,7 @@
 #include "catalog/pg_class.h"
 #include "catalog/pg_index.h"
 #include "catalog/pg_publication.h"
+#include "partitioning/partdesc.h"
 #include "nodes/bitmapset.h"
 #include "rewrite/prs2lock.h"
 #include "storage/block.h"
@@ -599,11 +600,7 @@ typedef struct ViewOptions
  */
 #define RelationGetPartitionKey(relation) ((relation)->rd_partkey)
 
-/*
- * RelationGetPartitionDesc
- *		Returns partition descriptor for a relation.
- */
-#define RelationGetPartitionDesc(relation) ((relation)->rd_partdesc)
+/* RelationGetPartitionDesc moved to partitioning/partdesc.h */
 
 /* routines in utils/cache/relcache.c */
 extern void RelationIncrementReferenceCount(Relation rel);
