def get_descendant_ids(cur, node):
    """
    Return an iterator that yields a ``NodeData`` object of each element
    in the nodes subtree. Be careful when converting this iterator to an
    iterable (like list or set) because it could contain billions of
    objects.

    :param node:
    :type node: Node or uuid4
    """
    sql = """
        SELECT
          node
        FROM
          ancestors
        WHERE
          ancestor=%s;
    """
    cur.execute(sql, (str(node),))
    for result in cur:
        yield str(result['node'])
