presto-main/src/main/java/io/prestosql/sql/planner/iterative/Memo.java/Memo/getAllReferences
class Memo:    private Set<Integer> getAllReferences(PlanNode node)
    {
        return node.getSources().stream()
                .map(GroupReference.class::cast)
                .map(GroupReference::getGroupId)
                .collect(Collectors.toSet());
    }