my ( $dba, $type ) = @_;
# compare total count of typewith number of toplevel type, if they're the same,
# then we can use the key
my $sth = $dba->dbc()->prepare("SELECT COUNT(*) FROM $type");
$sth->execute();
my $total = ( $sth->fetchrow_array() )[0];
$sth =
$dba->dbc()
->prepare( "SELECT COUNT(*) "
. "FROM $type t, seq_region_attrib sra, attrib_type at "
. "WHERE t.seq_region_id=sra.seq_region_id "
. "AND sra.attrib_type_id=at.attrib_type_id "
. "AND at.code='toplevel'" );
$sth->execute();
my $toplevel = ( $sth->fetchrow_array() )[0];
if ( $toplevel > 0 ) {
return $total == $toplevel;
}