mirror of https://github.com/citusdata/citus.git
Cover DROP COLUMN commands dropping columns in the either side of fkeys
parent
f29d7f1983
commit
db5bae8ffa
|
@ -483,6 +483,21 @@ ForeignConstraintFindDistKeys(HeapTuple pgConstraintTuple,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* ColumnAppearsInForeignKey returns true if there is a foreign key constraint
|
||||
* from/to given column.
|
||||
*/
|
||||
bool
|
||||
ColumnAppearsInForeignKey(char *columnName, Oid relationId)
|
||||
{
|
||||
int searchForeignKeyColumnFlags = SEARCH_REFERENCING_RELATION |
|
||||
SEARCH_REFERENCED_RELATION;
|
||||
List *foreignKeyIdsColumnAppeared =
|
||||
GetForeignKeyIdsForColumn(columnName, relationId, searchForeignKeyColumnFlags);
|
||||
return list_length(foreignKeyIdsColumnAppeared) > 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ColumnAppearsInForeignKeyToReferenceTable checks if there is a foreign key
|
||||
* constraint from/to any reference table on the given column.
|
||||
|
|
|
@ -1099,6 +1099,17 @@ AlterTableCmdDropsFkey(AlterTableCmd *command, Oid relationId)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (alterTableType == AT_DropColumn)
|
||||
{
|
||||
char *columnName = command->name;
|
||||
if (ColumnAppearsInForeignKey(columnName, relationId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -159,7 +159,7 @@ extern void ErrorIfUnsupportedForeignConstraintExists(Relation relation,
|
|||
Var *distributionColumn,
|
||||
uint32 colocationId);
|
||||
extern void ErrorOutForFKeyBetweenPostgresAndCitusLocalTable(Oid localTableId);
|
||||
extern bool ColumnReferencedByAnyForeignKey(char *columnName, Oid relationId);
|
||||
extern bool ColumnAppearsInForeignKey(char *columnName, Oid relationId);
|
||||
extern bool ColumnAppearsInForeignKeyToReferenceTable(char *columnName, Oid
|
||||
relationId);
|
||||
extern List * GetReferencingForeignConstaintCommands(Oid relationOid);
|
||||
|
|
Loading…
Reference in New Issue