From bc09288651bbda0cfca1a4909a4a5c0ca4e3e55f Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Wed, 16 Jun 2021 12:23:43 +0300 Subject: [PATCH] Get ready for Improve index backed constraint creation for online rebalancer See: https://github.com/citusdata/citus-enterprise/issues/616 --- .../distributed/operations/node_protocol.c | 32 +++++++++++-------- .../distributed/coordinator_protocol.h | 6 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/backend/distributed/operations/node_protocol.c b/src/backend/distributed/operations/node_protocol.c index c52f6efcf..f0ff1c82b 100644 --- a/src/backend/distributed/operations/node_protocol.c +++ b/src/backend/distributed/operations/node_protocol.c @@ -799,28 +799,32 @@ GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLE int indexFlags) { Oid indexId = indexForm->indexrelid; - char *statementDef = NULL; - bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm); /* get the corresponding constraint or index statement */ if (indexImpliedByConstraint) { - Oid constraintId = get_index_constraint(indexId); - Assert(constraintId != InvalidOid); + if (indexFlags & INCLUDE_CREATE_CONSTRAINT_STATEMENTS) + { + Oid constraintId = get_index_constraint(indexId); + Assert(constraintId != InvalidOid); - statementDef = pg_get_constraintdef_command(constraintId); + /* include constraints backed by indexes only when explicitly asked */ + char *statementDef = pg_get_constraintdef_command(constraintId); + *indexDDLEventList = + lappend(*indexDDLEventList, + makeTableDDLCommandString(statementDef)); + } } - else + else if (indexFlags & INCLUDE_CREATE_INDEX_STATEMENTS) { - statementDef = pg_get_indexdef_string(indexId); - } - - /* append found constraint or index definition to the list */ - if (indexFlags & INCLUDE_CREATE_INDEX_STATEMENTS) - { - *indexDDLEventList = lappend(*indexDDLEventList, makeTableDDLCommandString( - statementDef)); + /* + * Include indexes that are not backing constraints only when + * explicitly asked. + */ + char *statementDef = pg_get_indexdef_string(indexId); + *indexDDLEventList = lappend(*indexDDLEventList, + makeTableDDLCommandString(statementDef)); } /* if table is clustered on this index, append definition to the list */ diff --git a/src/include/distributed/coordinator_protocol.h b/src/include/distributed/coordinator_protocol.h index ab5490fca..7f43138d2 100644 --- a/src/include/distributed/coordinator_protocol.h +++ b/src/include/distributed/coordinator_protocol.h @@ -101,9 +101,11 @@ typedef enum TableDDLCommandType typedef enum IndexDefinitionDeparseFlags { INCLUDE_CREATE_INDEX_STATEMENTS = 1 << 0, - INCLUDE_INDEX_CLUSTERED_STATEMENTS = 1 << 1, - INCLUDE_INDEX_STATISTICS_STATEMENTTS = 1 << 2, + INCLUDE_CREATE_CONSTRAINT_STATEMENTS = 1 << 1, + INCLUDE_INDEX_CLUSTERED_STATEMENTS = 1 << 2, + INCLUDE_INDEX_STATISTICS_STATEMENTTS = 1 << 3, INCLUDE_INDEX_ALL_STATEMENTS = INCLUDE_CREATE_INDEX_STATEMENTS | + INCLUDE_CREATE_CONSTRAINT_STATEMENTS | INCLUDE_INDEX_CLUSTERED_STATEMENTS | INCLUDE_INDEX_STATISTICS_STATEMENTTS } IndexDefinitionDeparseFlags;