def find_common_prefixes(rows):
    """
    Find any common prefixes for the registry names given in the provided lines, after splitting on _. E.g.

    PREFIX_a
    PREFIX_b_c
    ...

    Would return {'PREFIX'}. While

    PREFIX_PREFIX2_a
    PREFIX_PREFIX2_b_c
    ...

    Would return {'PREFIX_PREFIX2'}. We do this by finding the common ancestor that all have. If there is not at
    root level, then we just return the prefixes at root level, i.e.

    PREFIX1_a
    PREFIX2_b_c
    ...

    Would return {'PREFIX1', 'PREFIX2'}
    """

    if len(rows) <= 1:
        return set()

    splats = [row.name.split("_") for row in rows]
    previous_common_ancestor = None
    for i in range(1, max(len(s) for s in splats)):
        prefixes = set(["_".join(s[:i]) + "_" for s in splats])
        if len(prefixes) > 1:
            return prefixes if previous_common_ancestor is None else previous_common_ancestor
        previous_common_ancestor = prefixes
    else:
        raise RuntimeError("Couldn't find common prefixes!")