@@ -97,7 +97,7 @@ static ObjectAddress AddNewRelationType(const char *typeName,
97
97
Oid new_row_type ,
98
98
Oid new_array_type );
99
99
static void RelationRemoveInheritance (Oid relid );
100
- static void StoreRelCheck (Relation rel , char * ccname , Node * expr ,
100
+ static Oid StoreRelCheck (Relation rel , char * ccname , Node * expr ,
101
101
bool is_validated , bool is_local , int inhcount ,
102
102
bool is_no_inherit , bool is_internal );
103
103
static void StoreConstraints (Relation rel , List * cooked_constraints ,
@@ -1852,8 +1852,10 @@ heap_drop_with_catalog(Oid relid)
1852
1852
1853
1853
/*
1854
1854
* Store a default expression for column attnum of relation rel.
1855
+ *
1856
+ * Returns the OID of the new pg_attrdef tuple.
1855
1857
*/
1856
- void
1858
+ Oid
1857
1859
StoreAttrDefault (Relation rel , AttrNumber attnum ,
1858
1860
Node * expr , bool is_internal )
1859
1861
{
@@ -1958,15 +1960,19 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
1958
1960
*/
1959
1961
InvokeObjectPostCreateHookArg (AttrDefaultRelationId ,
1960
1962
RelationGetRelid (rel ), attnum , is_internal );
1963
+
1964
+ return attrdefOid ;
1961
1965
}
1962
1966
1963
1967
/*
1964
1968
* Store a check-constraint expression for the given relation.
1965
1969
*
1966
1970
* Caller is responsible for updating the count of constraints
1967
1971
* in the pg_class entry for the relation.
1972
+ *
1973
+ * The OID of the new constraint is returned.
1968
1974
*/
1969
- static void
1975
+ static Oid
1970
1976
StoreRelCheck (Relation rel , char * ccname , Node * expr ,
1971
1977
bool is_validated , bool is_local , int inhcount ,
1972
1978
bool is_no_inherit , bool is_internal )
@@ -1976,6 +1982,7 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
1976
1982
List * varList ;
1977
1983
int keycount ;
1978
1984
int16 * attNos ;
1985
+ Oid constrOid ;
1979
1986
1980
1987
/*
1981
1988
* Flatten expression to string form for storage.
@@ -2027,42 +2034,47 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
2027
2034
/*
2028
2035
* Create the Check Constraint
2029
2036
*/
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? */
2058
2066
2059
2067
pfree (ccbin );
2060
2068
pfree (ccsrc );
2069
+
2070
+ return constrOid ;
2061
2071
}
2062
2072
2063
2073
/*
2064
2074
* Store defaults and constraints (passed as a list of CookedConstraint).
2065
2075
*
2076
+ * Each CookedConstraint struct is modified to store the new catalog tuple OID.
2077
+ *
2066
2078
* NOTE: only pre-cooked expressions will be passed this way, which is to
2067
2079
* say expressions inherited from an existing relation. Newly parsed
2068
2080
* expressions can be added later, by direct calls to StoreAttrDefault
@@ -2074,7 +2086,7 @@ StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
2074
2086
int numchecks = 0 ;
2075
2087
ListCell * lc ;
2076
2088
2077
- if (! cooked_constraints )
2089
+ if (cooked_constraints == NIL )
2078
2090
return ; /* nothing to do */
2079
2091
2080
2092
/*
@@ -2091,12 +2103,15 @@ StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
2091
2103
switch (con -> contype )
2092
2104
{
2093
2105
case CONSTR_DEFAULT :
2094
- StoreAttrDefault (rel , con -> attnum , con -> expr , is_internal );
2106
+ con -> conoid = StoreAttrDefault (rel , con -> attnum , con -> expr ,
2107
+ is_internal );
2095
2108
break ;
2096
2109
case 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 );
2100
2115
numchecks ++ ;
2101
2116
break ;
2102
2117
default :
@@ -2184,6 +2199,7 @@ AddRelationNewConstraints(Relation rel,
2184
2199
{
2185
2200
RawColumnDefault * colDef = (RawColumnDefault * ) lfirst (cell );
2186
2201
Form_pg_attribute atp = rel -> rd_att -> attrs [colDef -> attnum - 1 ];
2202
+ Oid defOid ;
2187
2203
2188
2204
expr = cookDefault (pstate , colDef -> raw_default ,
2189
2205
atp -> atttypid , atp -> atttypmod ,
@@ -2204,10 +2220,11 @@ AddRelationNewConstraints(Relation rel,
2204
2220
(IsA (expr , Const ) && ((Const * ) expr )-> constisnull ))
2205
2221
continue ;
2206
2222
2207
- StoreAttrDefault (rel , colDef -> attnum , expr , is_internal );
2223
+ defOid = StoreAttrDefault (rel , colDef -> attnum , expr , is_internal );
2208
2224
2209
2225
cooked = (CookedConstraint * ) palloc (sizeof (CookedConstraint ));
2210
2226
cooked -> contype = CONSTR_DEFAULT ;
2227
+ cooked -> conoid = defOid ;
2211
2228
cooked -> name = NULL ;
2212
2229
cooked -> attnum = colDef -> attnum ;
2213
2230
cooked -> expr = expr ;
@@ -2227,6 +2244,7 @@ AddRelationNewConstraints(Relation rel,
2227
2244
{
2228
2245
Constraint * cdef = (Constraint * ) lfirst (cell );
2229
2246
char * ccname ;
2247
+ Oid constrOid ;
2230
2248
2231
2249
if (cdef -> contype != CONSTR_CHECK )
2232
2250
continue ;
@@ -2329,13 +2347,15 @@ AddRelationNewConstraints(Relation rel,
2329
2347
/*
2330
2348
* OK, store it.
2331
2349
*/
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 );
2334
2353
2335
2354
numchecks ++ ;
2336
2355
2337
2356
cooked = (CookedConstraint * ) palloc (sizeof (CookedConstraint ));
2338
2357
cooked -> contype = CONSTR_CHECK ;
2358
+ cooked -> conoid = constrOid ;
2339
2359
cooked -> name = ccname ;
2340
2360
cooked -> attnum = 0 ;
2341
2361
cooked -> expr = expr ;
0 commit comments