From 35943c90783d17b61a2f2ea39230e0242a251e3e Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Date: Mon, 12 Jun 2017 16:49:07 +0530
Subject: [PATCH 2/2] Macro for dendency between table and its composite type.

Create a macro for type dependency between a table and the composite type
associated with it using CREATE/ALTER TABLE ... OF ... command, so as to use
the same dependency type while creating and dropping the dependency in
different functions.

Ashutosh Bapat.
---
 src/backend/commands/tablecmds.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 9aef67b..2ac3646 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -291,6 +291,9 @@ struct DropRelationCallbackState
 #define child_dependency_type(child_is_partition)	\
 	((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
 
+/* Dependency between a table and its associated composite type. */
+#define TABLE_COMPOSITE_TYPE_DEPENDENCY DEPENDENCY_NORMAL
+
 static void truncate_check_rel(Relation rel);
 static List *MergeAttributes(List *schema, List *supers, char relpersistence,
 				bool is_partition, List **supOids, List **supconstr,
@@ -11845,7 +11848,7 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
 	/* If the table was already typed, drop the existing dependency. */
 	if (rel->rd_rel->reloftype)
 		drop_parent_dependency(relid, TypeRelationId, rel->rd_rel->reloftype,
-							   DEPENDENCY_NORMAL);
+							   TABLE_COMPOSITE_TYPE_DEPENDENCY);
 
 	/* Record a dependency on the new type. */
 	tableobj.classId = RelationRelationId;
@@ -11899,7 +11902,7 @@ ATExecDropOf(Relation rel, LOCKMODE lockmode)
 	 */
 
 	drop_parent_dependency(relid, TypeRelationId, rel->rd_rel->reloftype,
-						   DEPENDENCY_NORMAL);
+						   TABLE_COMPOSITE_TYPE_DEPENDENCY);
 
 	/* Clear pg_class.reloftype */
 	relationRelation = heap_open(RelationRelationId, RowExclusiveLock);
-- 
1.7.9.5

