mirror of https://github.com/citusdata/citus.git
Implement GetPgDependTuplesForDependingObjects
(cherry picked from commit 04a4167a8a
)
pull/4693/head
parent
8401acb761
commit
44459be1ab
|
@ -1033,25 +1033,13 @@ BuildViewDependencyGraph(Oid relationId, HTAB *nodeMap)
|
||||||
node->remainingDependencyCount = 0;
|
node->remainingDependencyCount = 0;
|
||||||
node->dependingNodes = NIL;
|
node->dependingNodes = NIL;
|
||||||
|
|
||||||
ObjectAddress target = { 0 };
|
Oid targetObjectClassId = RelationRelationId;
|
||||||
ObjectAddressSet(target, RelationRelationId, relationId);
|
Oid targetObjectId = relationId;
|
||||||
|
List *dependencyTupleList = GetPgDependTuplesForDependingObjects(targetObjectClassId,
|
||||||
|
targetObjectId);
|
||||||
|
|
||||||
ScanKeyData key[2];
|
|
||||||
HeapTuple depTup = NULL;
|
HeapTuple depTup = NULL;
|
||||||
|
foreach_ptr(depTup, dependencyTupleList)
|
||||||
/*
|
|
||||||
* iterate the actual pg_depend catalog
|
|
||||||
*/
|
|
||||||
Relation depRel = table_open(DependRelationId, AccessShareLock);
|
|
||||||
|
|
||||||
ScanKeyInit(&key[0], Anum_pg_depend_refclassid, BTEqualStrategyNumber, F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(target.classId));
|
|
||||||
ScanKeyInit(&key[1], Anum_pg_depend_refobjid, BTEqualStrategyNumber, F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(target.objectId));
|
|
||||||
SysScanDesc depScan = systable_beginscan(depRel, DependReferenceIndexId,
|
|
||||||
true, NULL, 2, key);
|
|
||||||
|
|
||||||
while (HeapTupleIsValid(depTup = systable_getnext(depScan)))
|
|
||||||
{
|
{
|
||||||
Form_pg_depend pg_depend = (Form_pg_depend) GETSTRUCT(depTup);
|
Form_pg_depend pg_depend = (Form_pg_depend) GETSTRUCT(depTup);
|
||||||
|
|
||||||
|
@ -1066,13 +1054,48 @@ BuildViewDependencyGraph(Oid relationId, HTAB *nodeMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
systable_endscan(depScan);
|
|
||||||
relation_close(depRel, AccessShareLock);
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GetPgDependTuplesForDependingObjects scans pg_depend for given object and
|
||||||
|
* returns a list of heap tuples for the objects depending on it.
|
||||||
|
*/
|
||||||
|
List *
|
||||||
|
GetPgDependTuplesForDependingObjects(Oid targetObjectClassId, Oid targetObjectId)
|
||||||
|
{
|
||||||
|
List *dependencyTupleList = NIL;
|
||||||
|
|
||||||
|
Relation pgDepend = table_open(DependRelationId, AccessShareLock);
|
||||||
|
|
||||||
|
ScanKeyData key[2];
|
||||||
|
int scanKeyCount = 2;
|
||||||
|
|
||||||
|
ScanKeyInit(&key[0], Anum_pg_depend_refclassid, BTEqualStrategyNumber, F_OIDEQ,
|
||||||
|
ObjectIdGetDatum(targetObjectClassId));
|
||||||
|
ScanKeyInit(&key[1], Anum_pg_depend_refobjid, BTEqualStrategyNumber, F_OIDEQ,
|
||||||
|
ObjectIdGetDatum(targetObjectId));
|
||||||
|
|
||||||
|
bool useIndex = true;
|
||||||
|
SysScanDesc depScan = systable_beginscan(pgDepend, DependReferenceIndexId,
|
||||||
|
useIndex, NULL, scanKeyCount, key);
|
||||||
|
|
||||||
|
HeapTuple dependencyTuple = NULL;
|
||||||
|
while (HeapTupleIsValid(dependencyTuple = systable_getnext(depScan)))
|
||||||
|
{
|
||||||
|
/* copy the tuple first */
|
||||||
|
dependencyTuple = heap_copytuple(dependencyTuple);
|
||||||
|
dependencyTupleList = lappend(dependencyTupleList, dependencyTuple);
|
||||||
|
}
|
||||||
|
|
||||||
|
systable_endscan(depScan);
|
||||||
|
relation_close(pgDepend, AccessShareLock);
|
||||||
|
|
||||||
|
return dependencyTupleList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetDependingViews takes a relation id, finds the views that depend on the relation
|
* GetDependingViews takes a relation id, finds the views that depend on the relation
|
||||||
* and returns list of the oids of those views. It recurses on the pg_depend table to
|
* and returns list of the oids of those views. It recurses on the pg_depend table to
|
||||||
|
|
|
@ -21,6 +21,8 @@ extern List * GetUniqueDependenciesList(List *objectAddressesList);
|
||||||
extern List * GetDependenciesForObject(const ObjectAddress *target);
|
extern List * GetDependenciesForObject(const ObjectAddress *target);
|
||||||
extern List * OrderObjectAddressListInDependencyOrder(List *objectAddressList);
|
extern List * OrderObjectAddressListInDependencyOrder(List *objectAddressList);
|
||||||
extern bool SupportedDependencyByCitus(const ObjectAddress *address);
|
extern bool SupportedDependencyByCitus(const ObjectAddress *address);
|
||||||
|
extern List * GetPgDependTuplesForDependingObjects(Oid targetObjectClassId,
|
||||||
|
Oid targetObjectId);
|
||||||
extern List * GetDependingViews(Oid relationId);
|
extern List * GetDependingViews(Oid relationId);
|
||||||
|
|
||||||
#endif /* CITUS_DEPENDENCY_H */
|
#endif /* CITUS_DEPENDENCY_H */
|
||||||
|
|
Loading…
Reference in New Issue