mirror of https://github.com/citusdata/citus.git
Implement get_relation_constraint_oid_compat helper (#3836)
parent
4ad10adbc4
commit
8f9ef63e8a
|
@ -42,6 +42,7 @@ static void ForeignConstraintFindDistKeys(HeapTuple pgConstraintTuple,
|
|||
Var *referencedDistColumn,
|
||||
int *referencingAttrIndex,
|
||||
int *referencedAttrIndex);
|
||||
static Oid get_relation_constraint_oid_compat(HeapTuple heapTuple);
|
||||
|
||||
/*
|
||||
* ConstraintIsAForeignKeyToReferenceTable checks if the given constraint is a
|
||||
|
@ -514,9 +515,7 @@ GetTableForeignConstraintCommands(Oid relationId)
|
|||
|
||||
if (!inheritedConstraint && constraintForm->contype == CONSTRAINT_FOREIGN)
|
||||
{
|
||||
Oid constraintId = get_relation_constraint_oid(relationId,
|
||||
constraintForm->conname.data,
|
||||
true);
|
||||
Oid constraintId = get_relation_constraint_oid_compat(heapTuple);
|
||||
char *statementDef = pg_get_constraintdef_command(constraintId);
|
||||
|
||||
tableForeignConstraints = lappend(tableForeignConstraints, statementDef);
|
||||
|
@ -536,6 +535,31 @@ GetTableForeignConstraintCommands(Oid relationId)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_relation_constraint_oid_compat returns OID of the constraint represented
|
||||
* by the constraintForm, which is passed as an heapTuple. OID of the contraint
|
||||
* is already stored in the constraintForm struct if major PostgreSQL version is
|
||||
* 12. However, in the older versions, we should utilize HeapTupleGetOid to deduce
|
||||
* that OID with no cost.
|
||||
*/
|
||||
static Oid
|
||||
get_relation_constraint_oid_compat(HeapTuple heapTuple)
|
||||
{
|
||||
Assert(heapTuple != NULL);
|
||||
|
||||
Oid constraintOid = InvalidOid;
|
||||
|
||||
#if PG_VERSION_NUM >= PG_VERSION_12
|
||||
Form_pg_constraint constraintForm = (Form_pg_constraint) GETSTRUCT(heapTuple);
|
||||
constraintOid = constraintForm->oid;
|
||||
#else
|
||||
constraintOid = HeapTupleGetOid(heapTuple);
|
||||
#endif
|
||||
|
||||
return constraintOid;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* HasForeignKeyToReferenceTable function scans the pgConstraint table to
|
||||
* fetch all of the constraints on the given relationId and see if at least one
|
||||
|
|
Loading…
Reference in New Issue