def count_orphan_resource_providers(db):
    """Count all orphan resource providers in the nova_api database."""
    sql = '''\
    SELECT COUNT(*)
    FROM   nova_api.resource_providers rp JOIN nova.compute_nodes cn
    ON     cn.hypervisor_hostname = rp.name
    WHERE  cn.deleted = 0
       AND rp.uuid != cn.uuid
    '''
    return db.query(sql)