@@ -97,7 +97,7 @@ static ObjectAddress AddNewRelationType(const char *typeName,
9797Oid new_row_type ,
9898Oid new_array_type );
9999static void RelationRemoveInheritance (Oid relid );
100- static void StoreRelCheck (Relation rel ,char * ccname ,Node * expr ,
100+ static Oid StoreRelCheck (Relation rel ,char * ccname ,Node * expr ,
101101bool is_validated ,bool is_local ,int inhcount ,
102102bool is_no_inherit ,bool is_internal );
103103static void StoreConstraints (Relation rel ,List * cooked_constraints ,
@@ -1852,8 +1852,10 @@ heap_drop_with_catalog(Oid relid)
18521852
18531853/*
18541854 * Store a default expression for column attnum of relation rel.
1855+ *
1856+ * Returns the OID of the new pg_attrdef tuple.
18551857 */
1856- void
1858+ Oid
18571859StoreAttrDefault (Relation rel ,AttrNumber attnum ,
18581860Node * expr ,bool is_internal )
18591861{
@@ -1958,15 +1960,19 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
19581960 */
19591961InvokeObjectPostCreateHookArg (AttrDefaultRelationId ,
19601962RelationGetRelid (rel ),attnum ,is_internal );
1963+
1964+ return attrdefOid ;
19611965}
19621966
19631967/*
19641968 * Store a check-constraint expression for the given relation.
19651969 *
19661970 * Caller is responsible for updating the count of constraints
19671971 * in the pg_class entry for the relation.
1972+ *
1973+ * The OID of the new constraint is returned.
19681974 */
1969- static void
1975+ static Oid
19701976StoreRelCheck (Relation rel ,char * ccname ,Node * expr ,
19711977bool is_validated ,bool is_local ,int inhcount ,
19721978bool is_no_inherit ,bool is_internal )
@@ -1976,6 +1982,7 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
19761982List * varList ;
19771983int keycount ;
19781984int16 * attNos ;
1985+ Oid constrOid ;
19791986
19801987/*
19811988 * Flatten expression to string form for storage.
@@ -2027,42 +2034,47 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
20272034/*
20282035 * Create the Check Constraint
20292036 */
2030- CreateConstraintEntry (ccname ,/* Constraint Name */
2031- RelationGetNamespace (rel ),/* namespace */
2032- CONSTRAINT_CHECK ,/* Constraint Type */
2033- false,/* Is Deferrable */
2034- false,/* Is Deferred */
2035- is_validated ,
2036- RelationGetRelid (rel ),/* relation */
2037- attNos ,/* attrs in the constraint */
2038- keycount ,/* # attrs in the constraint */
2039- InvalidOid ,/* not a domain constraint */
2040- InvalidOid ,/* no associated index */
2041- InvalidOid ,/* Foreign key fields */
2042- NULL ,
2043- NULL ,
2044- NULL ,
2045- NULL ,
2046- 0 ,
2047- ' ' ,
2048- ' ' ,
2049- ' ' ,
2050- NULL ,/* not an exclusion constraint */
2051- expr ,/* Tree form of check constraint */
2052- ccbin ,/* Binary form of check constraint */
2053- ccsrc ,/* Source form of check constraint */
2054- is_local ,/* conislocal */
2055- inhcount ,/* coninhcount */
2056- is_no_inherit ,/* connoinherit */
2057- is_internal );/* internally constructed? */
2037+ constrOid =
2038+ CreateConstraintEntry (ccname ,/* Constraint Name */
2039+ RelationGetNamespace (rel ),/* namespace */
2040+ CONSTRAINT_CHECK ,/* Constraint Type */
2041+ false,/* Is Deferrable */
2042+ false,/* Is Deferred */
2043+ is_validated ,
2044+ RelationGetRelid (rel ),/* relation */
2045+ attNos ,/* attrs in the constraint */
2046+ keycount ,/* # attrs in the constraint */
2047+ InvalidOid ,/* not a domain constraint */
2048+ InvalidOid ,/* no associated index */
2049+ InvalidOid ,/* Foreign key fields */
2050+ NULL ,
2051+ NULL ,
2052+ NULL ,
2053+ NULL ,
2054+ 0 ,
2055+ ' ' ,
2056+ ' ' ,
2057+ ' ' ,
2058+ NULL ,/* not an exclusion constraint */
2059+ expr ,/* Tree form of check constraint */
2060+ ccbin ,/* Binary form of check constraint */
2061+ ccsrc ,/* Source form of check constraint */
2062+ is_local ,/* conislocal */
2063+ inhcount ,/* coninhcount */
2064+ is_no_inherit ,/* connoinherit */
2065+ is_internal );/* internally constructed? */
20582066
20592067pfree (ccbin );
20602068pfree (ccsrc );
2069+
2070+ return constrOid ;
20612071}
20622072
20632073/*
20642074 * Store defaults and constraints (passed as a list of CookedConstraint).
20652075 *
2076+ * Each CookedConstraint struct is modified to store the new catalog tuple OID.
2077+ *
20662078 * NOTE: only pre-cooked expressions will be passed this way, which is to
20672079 * say expressions inherited from an existing relation. Newly parsed
20682080 * expressions can be added later, by direct calls to StoreAttrDefault
@@ -2074,7 +2086,7 @@ StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
20742086int numchecks = 0 ;
20752087ListCell * lc ;
20762088
2077- if (! cooked_constraints )
2089+ if (cooked_constraints == NIL )
20782090return ;/* nothing to do */
20792091
20802092/*
@@ -2091,12 +2103,15 @@ StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
20912103switch (con -> contype )
20922104{
20932105case CONSTR_DEFAULT :
2094- StoreAttrDefault (rel ,con -> attnum ,con -> expr ,is_internal );
2106+ con -> conoid = StoreAttrDefault (rel ,con -> attnum ,con -> expr ,
2107+ is_internal );
20952108break ;
20962109case CONSTR_CHECK :
2097- StoreRelCheck (rel ,con -> name ,con -> expr , !con -> skip_validation ,
2098- con -> is_local ,con -> inhcount ,
2099- con -> is_no_inherit ,is_internal );
2110+ con -> conoid =
2111+ StoreRelCheck (rel ,con -> name ,con -> expr ,
2112+ !con -> skip_validation ,con -> is_local ,
2113+ con -> inhcount ,con -> is_no_inherit ,
2114+ is_internal );
21002115numchecks ++ ;
21012116break ;
21022117default :
@@ -2184,6 +2199,7 @@ AddRelationNewConstraints(Relation rel,
21842199{
21852200RawColumnDefault * colDef = (RawColumnDefault * )lfirst (cell );
21862201Form_pg_attribute atp = rel -> rd_att -> attrs [colDef -> attnum - 1 ];
2202+ Oid defOid ;
21872203
21882204expr = cookDefault (pstate ,colDef -> raw_default ,
21892205atp -> atttypid ,atp -> atttypmod ,
@@ -2204,10 +2220,11 @@ AddRelationNewConstraints(Relation rel,
22042220(IsA (expr ,Const )&& ((Const * )expr )-> constisnull ))
22052221continue ;
22062222
2207- StoreAttrDefault (rel ,colDef -> attnum ,expr ,is_internal );
2223+ defOid = StoreAttrDefault (rel ,colDef -> attnum ,expr ,is_internal );
22082224
22092225cooked = (CookedConstraint * )palloc (sizeof (CookedConstraint ));
22102226cooked -> contype = CONSTR_DEFAULT ;
2227+ cooked -> conoid = defOid ;
22112228cooked -> name = NULL ;
22122229cooked -> attnum = colDef -> attnum ;
22132230cooked -> expr = expr ;
@@ -2227,6 +2244,7 @@ AddRelationNewConstraints(Relation rel,
22272244{
22282245Constraint * cdef = (Constraint * )lfirst (cell );
22292246char * ccname ;
2247+ Oid constrOid ;
22302248
22312249if (cdef -> contype != CONSTR_CHECK )
22322250continue ;
@@ -2329,13 +2347,15 @@ AddRelationNewConstraints(Relation rel,
23292347/*
23302348 * OK, store it.
23312349 */
2332- StoreRelCheck (rel ,ccname ,expr , !cdef -> skip_validation ,is_local ,
2333- is_local ?0 :1 ,cdef -> is_no_inherit ,is_internal );
2350+ constrOid =
2351+ StoreRelCheck (rel ,ccname ,expr , !cdef -> skip_validation ,is_local ,
2352+ is_local ?0 :1 ,cdef -> is_no_inherit ,is_internal );
23342353
23352354numchecks ++ ;
23362355
23372356cooked = (CookedConstraint * )palloc (sizeof (CookedConstraint ));
23382357cooked -> contype = CONSTR_CHECK ;
2358+ cooked -> conoid = constrOid ;
23392359cooked -> name = ccname ;
23402360cooked -> attnum = 0 ;
23412361cooked -> expr = expr ;