@@ -691,6 +691,8 @@ UpdateIndexRelation(Oid indexoid,
691
691
*nonzero to specify a preselected OID.
692
692
* parentIndexRelid: if creating an index partition, the OID of the
693
693
*parent index; otherwise InvalidOid.
694
+ * parentConstraintId: if creating a constraint on a partition, the OID
695
+ *of the constraint in the parent; otherwise InvalidOid.
694
696
* relFileNode: normally, pass InvalidOid to get new storage. May be
695
697
*nonzero to attach an existing valid build.
696
698
* indexInfo: same info executor uses to insert into the index
@@ -722,6 +724,7 @@ UpdateIndexRelation(Oid indexoid,
722
724
*(only if INDEX_CREATE_ADD_CONSTRAINT is set)
723
725
* allow_system_table_mods: allow table to be a system catalog
724
726
* is_internal: if true, post creation hook for new index
727
+ * constraintId: if not NULL, receives OID of created constraint
725
728
*
726
729
* Returns the OID of the created index.
727
730
*/
@@ -730,6 +733,7 @@ index_create(Relation heapRelation,
730
733
const char * indexRelationName ,
731
734
Oid indexRelationId ,
732
735
Oid parentIndexRelid ,
736
+ Oid parentConstraintId ,
733
737
Oid relFileNode ,
734
738
IndexInfo * indexInfo ,
735
739
List * indexColNames ,
@@ -742,7 +746,8 @@ index_create(Relation heapRelation,
742
746
bits16 flags ,
743
747
bits16 constr_flags ,
744
748
bool allow_system_table_mods ,
745
- bool is_internal )
749
+ bool is_internal ,
750
+ Oid * constraintId )
746
751
{
747
752
Oid heapRelationId = RelationGetRelid (heapRelation );
748
753
Relation pg_class ;
@@ -989,6 +994,7 @@ index_create(Relation heapRelation,
989
994
if ((flags & INDEX_CREATE_ADD_CONSTRAINT )!= 0 )
990
995
{
991
996
char constraintType ;
997
+ ObjectAddress localaddr ;
992
998
993
999
if (isprimary )
994
1000
constraintType = CONSTRAINT_PRIMARY ;
@@ -1002,14 +1008,17 @@ index_create(Relation heapRelation,
1002
1008
constraintType = 0 ;/* keep compiler quiet */
1003
1009
}
1004
1010
1005
- index_constraint_create (heapRelation ,
1011
+ localaddr = index_constraint_create (heapRelation ,
1006
1012
indexRelationId ,
1013
+ parentConstraintId ,
1007
1014
indexInfo ,
1008
1015
indexRelationName ,
1009
1016
constraintType ,
1010
1017
constr_flags ,
1011
1018
allow_system_table_mods ,
1012
1019
is_internal );
1020
+ if (constraintId )
1021
+ * constraintId = localaddr .objectId ;
1013
1022
}
1014
1023
else
1015
1024
{
@@ -1181,6 +1190,8 @@ index_create(Relation heapRelation,
1181
1190
*
1182
1191
* heapRelation: table owning the index (must be suitably locked by caller)
1183
1192
* indexRelationId: OID of the index
1193
+ * parentConstraintId: if constraint is on a partition, the OID of the
1194
+ *constraint in the parent.
1184
1195
* indexInfo: same info executor uses to insert into the index
1185
1196
* constraintName: what it say (generally, should match name of index)
1186
1197
* constraintType: one of CONSTRAINT_PRIMARY, CONSTRAINT_UNIQUE, or
@@ -1198,6 +1209,7 @@ index_create(Relation heapRelation,
1198
1209
ObjectAddress
1199
1210
index_constraint_create (Relation heapRelation ,
1200
1211
Oid indexRelationId ,
1212
+ Oid parentConstraintId ,
1201
1213
IndexInfo * indexInfo ,
1202
1214
const char * constraintName ,
1203
1215
char constraintType ,
@@ -1212,6 +1224,9 @@ index_constraint_create(Relation heapRelation,
1212
1224
bool deferrable ;
1213
1225
bool initdeferred ;
1214
1226
bool mark_as_primary ;
1227
+ bool islocal ;
1228
+ bool noinherit ;
1229
+ int inhcount ;
1215
1230
1216
1231
deferrable = (constr_flags & INDEX_CONSTR_CREATE_DEFERRABLE )!= 0 ;
1217
1232
initdeferred = (constr_flags & INDEX_CONSTR_CREATE_INIT_DEFERRED )!= 0 ;
@@ -1246,6 +1261,19 @@ index_constraint_create(Relation heapRelation,
1246
1261
deleteDependencyRecordsForClass (RelationRelationId ,indexRelationId ,
1247
1262
RelationRelationId ,DEPENDENCY_AUTO );
1248
1263
1264
+ if (OidIsValid (parentConstraintId ))
1265
+ {
1266
+ islocal = false;
1267
+ inhcount = 1 ;
1268
+ noinherit = false;
1269
+ }
1270
+ else
1271
+ {
1272
+ islocal = true;
1273
+ inhcount = 0 ;
1274
+ noinherit = true;
1275
+ }
1276
+
1249
1277
/*
1250
1278
* Construct a pg_constraint entry.
1251
1279
*/
@@ -1273,9 +1301,9 @@ index_constraint_create(Relation heapRelation,
1273
1301
NULL ,/* no check constraint */
1274
1302
NULL ,
1275
1303
NULL ,
1276
- true, /* islocal */
1277
- 0 , /* inhcount */
1278
- true, /* noinherit */
1304
+ islocal ,
1305
+ inhcount ,
1306
+ noinherit ,
1279
1307
is_internal );
1280
1308
1281
1309
/*
@@ -1294,6 +1322,18 @@ index_constraint_create(Relation heapRelation,
1294
1322
1295
1323
recordDependencyOn (& myself ,& referenced ,DEPENDENCY_INTERNAL );
1296
1324
1325
+ /*
1326
+ * Also, if this is a constraint on a partition, mark it as depending
1327
+ * on the constraint in the parent.
1328
+ */
1329
+ if (OidIsValid (parentConstraintId ))
1330
+ {
1331
+ ObjectAddress parentConstr ;
1332
+
1333
+ ObjectAddressSet (parentConstr ,ConstraintRelationId ,parentConstraintId );
1334
+ recordDependencyOn (& referenced ,& parentConstr ,DEPENDENCY_INTERNAL_AUTO );
1335
+ }
1336
+
1297
1337
/*
1298
1338
* If the constraint is deferrable, create the deferred uniqueness
1299
1339
* checking trigger. (The trigger will be given an internal dependency on