Get ready for Improve index backed constraint creation for online rebalancer

See:
https://github.com/citusdata/citus-enterprise/issues/616
(cherry picked from commit bc09288651)
pull/5098/head
Onder Kalaci 2021-06-16 12:23:43 +03:00
parent 4a904e070d
commit 3d6bc315ab
2 changed files with 22 additions and 16 deletions

View File

@ -799,28 +799,32 @@ GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLE
int indexFlags) int indexFlags)
{ {
Oid indexId = indexForm->indexrelid; Oid indexId = indexForm->indexrelid;
char *statementDef = NULL;
bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm); bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm);
/* get the corresponding constraint or index statement */ /* get the corresponding constraint or index statement */
if (indexImpliedByConstraint) if (indexImpliedByConstraint)
{ {
Oid constraintId = get_index_constraint(indexId); if (indexFlags & INCLUDE_CREATE_CONSTRAINT_STATEMENTS)
Assert(constraintId != InvalidOid); {
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); /*
} * Include indexes that are not backing constraints only when
* explicitly asked.
/* append found constraint or index definition to the list */ */
if (indexFlags & INCLUDE_CREATE_INDEX_STATEMENTS) char *statementDef = pg_get_indexdef_string(indexId);
{ *indexDDLEventList = lappend(*indexDDLEventList,
*indexDDLEventList = lappend(*indexDDLEventList, makeTableDDLCommandString( makeTableDDLCommandString(statementDef));
statementDef));
} }
/* if table is clustered on this index, append definition to the list */ /* if table is clustered on this index, append definition to the list */

View File

@ -101,9 +101,11 @@ typedef enum TableDDLCommandType
typedef enum IndexDefinitionDeparseFlags typedef enum IndexDefinitionDeparseFlags
{ {
INCLUDE_CREATE_INDEX_STATEMENTS = 1 << 0, INCLUDE_CREATE_INDEX_STATEMENTS = 1 << 0,
INCLUDE_INDEX_CLUSTERED_STATEMENTS = 1 << 1, INCLUDE_CREATE_CONSTRAINT_STATEMENTS = 1 << 1,
INCLUDE_INDEX_STATISTICS_STATEMENTTS = 1 << 2, INCLUDE_INDEX_CLUSTERED_STATEMENTS = 1 << 2,
INCLUDE_INDEX_STATISTICS_STATEMENTTS = 1 << 3,
INCLUDE_INDEX_ALL_STATEMENTS = INCLUDE_CREATE_INDEX_STATEMENTS | INCLUDE_INDEX_ALL_STATEMENTS = INCLUDE_CREATE_INDEX_STATEMENTS |
INCLUDE_CREATE_CONSTRAINT_STATEMENTS |
INCLUDE_INDEX_CLUSTERED_STATEMENTS | INCLUDE_INDEX_CLUSTERED_STATEMENTS |
INCLUDE_INDEX_STATISTICS_STATEMENTTS INCLUDE_INDEX_STATISTICS_STATEMENTTS
} IndexDefinitionDeparseFlags; } IndexDefinitionDeparseFlags;