diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 359bf34f48e..c2739974573 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -688,6 +688,10 @@ UpdateIndexRelation(Oid indexoid, * already exists. * INDEX_CREATE_PARTITIONED: * create a partitioned index (table must be partitioned) + * INDEX_CREATE_DEFERRABLE: + * index supports a deferrable constraint, mark it as + * non-immediate (indimmediate = false). + * * constr_flags: flags passed to index_constraint_create * (only if INDEX_CREATE_ADD_CONSTRAINT is set) * allow_system_table_mods: allow table to be a system catalog @@ -1000,7 +1004,8 @@ index_create(Relation heapRelation, indexInfo, collationObjectId, classObjectId, coloptions, isprimary, is_exclusion, - (constr_flags & INDEX_CONSTR_CREATE_DEFERRABLE) == 0, + (constr_flags & INDEX_CONSTR_CREATE_DEFERRABLE) == 0 && + (flags & INDEX_CREATE_DEFERRABLE) == 0, !concurrent && !invalid, !concurrent); @@ -1271,6 +1276,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, List *indexColNames = NIL; List *indexExprs = NIL; List *indexPreds = NIL; + bits16 flags = INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT; + Form_pg_index indexForm; indexRelation = index_open(oldIndexId, RowExclusiveLock); @@ -1290,6 +1297,13 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(oldIndexId)); if (!HeapTupleIsValid(indexTuple)) elog(ERROR, "cache lookup failed for index %u", oldIndexId); + + indexForm = (Form_pg_index) GETSTRUCT(indexTuple); + + /* Old index is deferrable, do the same for the new index */ + if (!indexForm->indimmediate) + flags |= INDEX_CREATE_DEFERRABLE; + indclassDatum = SysCacheGetAttr(INDEXRELID, indexTuple, Anum_pg_index_indclass, &isnull); Assert(!isnull); @@ -1398,8 +1412,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, indclass->values, indcoloptions->values, optionDatum, - INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT, - 0, + flags, + 0, /* constr_flags */ true, /* allow table to be a system catalog? */ false, /* is_internal? */ NULL); diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index 008f723e104..74cea78fac6 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -65,6 +65,7 @@ extern void index_check_primary_key(Relation heapRel, #define INDEX_CREATE_IF_NOT_EXISTS (1 << 4) #define INDEX_CREATE_PARTITIONED (1 << 5) #define INDEX_CREATE_INVALID (1 << 6) +#define INDEX_CREATE_DEFERRABLE (1 << 7) extern Oid index_create(Relation heapRelation, const char *indexRelationName,